From 058505e9f077b4b20580ce8852842f2039429fd0 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 12 Jul 2024 17:58:18 +0300 Subject: [PATCH] Support explicitly creating & destroying profiler frames --- libs/prof/include/psemek/prof/profiler.hpp | 2 ++ libs/prof/source/profiler.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/libs/prof/include/psemek/prof/profiler.hpp b/libs/prof/include/psemek/prof/profiler.hpp index 0c569b08..25f61f05 100644 --- a/libs/prof/include/psemek/prof/profiler.hpp +++ b/libs/prof/include/psemek/prof/profiler.hpp @@ -16,7 +16,9 @@ namespace psemek::prof ~ profiler(); + static void start_frame(std::string const & name); static void push(std::string const & name, std::chrono::duration duration); + static void end_frame(std::chrono::duration duration); template static void push(std::string const & name, Duration duration) diff --git a/libs/prof/source/profiler.cpp b/libs/prof/source/profiler.cpp index b2bf2086..b48d58c8 100644 --- a/libs/prof/source/profiler.cpp +++ b/libs/prof/source/profiler.cpp @@ -191,6 +191,14 @@ namespace psemek::prof current = current->parent; } + void profiler::start_frame(std::string const & name) + { + get_current(); + + std::lock_guard lock{*(current->mutex)}; + current = current->child(name); + } + void profiler::push(std::string const & name, std::chrono::duration duration) { get_current(); @@ -199,4 +207,11 @@ namespace psemek::prof current->child(name)->execution_time.push(duration.count()); } + void profiler::end_frame(std::chrono::duration duration) + { + std::lock_guard lock{*(current->mutex)}; + current->execution_time.push(duration.count()); + current = current->parent; + } + }