From c6e173a34e9257ea4f5e7c390a710f6121f53c42 Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 29 Dec 2022 00:56:37 -0500 Subject: [PATCH] Basic intervals on the profiler --- include/blt/profiling/profiler.h | 16 +++++++++++++--- src/blt/profiling/profiler.cpp | 24 +++++++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/blt/profiling/profiler.h b/include/blt/profiling/profiler.h index 78d2ed1..f767be8 100644 --- a/include/blt/profiling/profiler.h +++ b/include/blt/profiling/profiler.h @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef PHMAP_ENABLED #include @@ -30,17 +31,26 @@ namespace BLT { #ifdef PHMAP_ENABLED typedef phmap::parallel_flat_hash_map INTERVAL_MAP; typedef phmap::parallel_flat_hash_map POINT_MAP; + typedef phmap::parallel_flat_hash_map ORDER_MAP; #else typedef std::unordered_map INTERVAL_MAP; typedef std::unordered_map POINT_MAP; + typedef std::unordered_map ORDER_MAP; #endif class Profiler { private: - INTERVAL_MAP intervals; - POINT_MAP points; + INTERVAL_MAP intervals{}; + POINT_MAP points{}; + ORDER_MAP order{}; + + std::mutex timerLock{}; + int lastOrder = 0; public: - Profiler(); + Profiler() = default; + void finishCycle(); + void startInterval(const std::string_view& name); + void endInterval(const std::string_view& name); }; } diff --git a/src/blt/profiling/profiler.cpp b/src/blt/profiling/profiler.cpp index 34f21cd..b85c681 100644 --- a/src/blt/profiling/profiler.cpp +++ b/src/blt/profiling/profiler.cpp @@ -4,7 +4,29 @@ * See LICENSE file for license detail */ #include +#include +#include namespace BLT { - + + void Profiler::finishCycle() { + + } + + static inline auto getCurrentTimeNanoseconds() { + return std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); + } + + void Profiler::startInterval(const std::string_view& name) { + std::scoped_lock lock(timerLock); + CaptureInterval interval{}; + interval.start = {getCurrentTimeNanoseconds()}; + intervals[name] = interval; + } + + void Profiler::endInterval(const std::string_view& name) { + std::scoped_lock lock(timerLock); + intervals[name].end = {getCurrentTimeNanoseconds()}; + order[lastOrder++] = name; + } } \ No newline at end of file