From f268ec5d34532d5b116a4fb8d0d5cd7e9305e023 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 21 Apr 2018 01:39:21 +0300 Subject: [PATCH] Measure total time for NavMesh build from first pop --- .../detournavigator/asyncnavmeshupdater.cpp | 18 +++++++++++++++++- .../detournavigator/asyncnavmeshupdater.hpp | 8 +++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 424d1f260c..c9fca3c92f 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -105,6 +105,8 @@ namespace DetourNavigator const auto start = std::chrono::steady_clock::now(); + setFirstStart(start); + const auto recastMesh = getRecastMesh(); const auto status = updateNavMesh(job.mAgentHalfExtents, *recastMesh, job.mChangedTile, mSettings, @@ -117,7 +119,8 @@ namespace DetourNavigator using FloatMs = std::chrono::duration; log("cache updated for agent=", job.mAgentHalfExtents, " status=", status, - " time=", std::chrono::duration_cast(finish - start).count(), "ms"); + " time=", std::chrono::duration_cast(finish - start).count(), "ms", + " total_time=", std::chrono::duration_cast(finish - getFirstStart()).count(), "ms"); } boost::optional AsyncNavMeshUpdater::getNextJob() @@ -168,4 +171,17 @@ namespace DetourNavigator const std::lock_guard lock(mRecastMeshMutex); mRecastMesh = value; } + + std::chrono::steady_clock::time_point AsyncNavMeshUpdater::getFirstStart() + { + const std::lock_guard lock(mFirstStartMutex); + return *mFirstStart; + } + + void AsyncNavMeshUpdater::setFirstStart(const std::chrono::steady_clock::time_point& value) + { + const std::lock_guard lock(mFirstStartMutex); + if (!mFirstStart) + mFirstStart = value; + } } diff --git a/components/detournavigator/asyncnavmeshupdater.hpp b/components/detournavigator/asyncnavmeshupdater.hpp index 7ffa8f5f06..721b89cec7 100644 --- a/components/detournavigator/asyncnavmeshupdater.hpp +++ b/components/detournavigator/asyncnavmeshupdater.hpp @@ -10,8 +10,8 @@ #include #include +#include #include -#include #include #include #include @@ -58,6 +58,8 @@ namespace DetourNavigator Jobs mJobs; std::mutex mRecastMeshMutex; std::shared_ptr mRecastMesh; + std::mutex mFirstStartMutex; + boost::optional mFirstStart; std::thread mThread; void process() throw(); @@ -73,6 +75,10 @@ namespace DetourNavigator std::shared_ptr getRecastMesh(); void setRecastMesh(const std::shared_ptr& value); + + std::chrono::steady_clock::time_point getFirstStart(); + + void setFirstStart(const std::chrono::steady_clock::time_point& value); }; }