From 5bef4b2437ed49a51bd0ea8c848a61136142160b Mon Sep 17 00:00:00 2001 From: Kevin Huck Date: Fri, 2 Apr 2021 13:13:06 -0400 Subject: [PATCH] Fixing measurement output when dump is called multiple times. --- src/apex/profiler.hpp | 3 +++ src/apex/profiler_listener.cpp | 17 +++++++++++++---- src/apex/profiler_listener.hpp | 4 +++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/apex/profiler.hpp b/src/apex/profiler.hpp index 54a97d62..ec8cf302 100644 --- a/src/apex/profiler.hpp +++ b/src/apex/profiler.hpp @@ -242,6 +242,9 @@ class profiler { return value; } else { using namespace std::chrono; + if (!stopped) { + end = MYCLOCK::now(); + } duration time_span = duration_cast>(end - start); if (scaled) { diff --git a/src/apex/profiler_listener.cpp b/src/apex/profiler_listener.cpp index 642c362b..7bc621ea 100644 --- a/src/apex/profiler_listener.cpp +++ b/src/apex/profiler_listener.cpp @@ -1338,8 +1338,10 @@ if (rc != 0) cout << "PAPI error! " << name << ": " << PAPI_strerror(rc) << endl if (_done) { return; } // stop the main timer, and process that profile? - stop_main_timer(); + yield_main_timer(); push_profiler((unsigned int)thread_instance::get_id(), main_timer); + // restart the main timer + resume_main_timer(); // trigger statistics updating #ifdef APEX_HAVE_HPX @@ -1447,9 +1449,6 @@ if (rc != 0) cout << "PAPI error! " << name << ": " << PAPI_strerror(rc) << endl close(task_scatterplot_sample_file); } #endif - // restart the main timer - main_timer = std::make_shared( - task_wrapper::get_apex_main_wrapper()); if (data.reset) { reset_all(); } @@ -1751,6 +1750,16 @@ if (rc != 0) cout << "PAPI error! " << name << ": " << PAPI_strerror(rc) << endl } + void profiler_listener::yield_main_timer(void) { + APEX_ASSERT(main_timer != nullptr); + main_timer->stop(true); + } + + void profiler_listener::resume_main_timer(void) { + APEX_ASSERT(main_timer != nullptr); + main_timer->restart(); + } + void profiler_listener::stop_main_timer(void) { static bool stopped{false}; if (!stopped) { diff --git a/src/apex/profiler_listener.hpp b/src/apex/profiler_listener.hpp index 4838f576..87ca9859 100644 --- a/src/apex/profiler_listener.hpp +++ b/src/apex/profiler_listener.hpp @@ -92,7 +92,7 @@ class profiler_listener : public event_listener { bool _initialized; std::atomic _done; std::atomic active_tasks; - std::shared_ptr main_timer; // not a shared pointer, yet... + std::shared_ptr main_timer; void write_one_timer(task_identifier &task_id, profile * p, std::stringstream &screen_output, std::stringstream &csv_output, @@ -252,6 +252,8 @@ class profiler_listener : public event_listener { std::vector& get_metric_names(void) { return metric_names; }; #endif void stop_main_timer(void); + void yield_main_timer(void); + void resume_main_timer(void); void push_profiler_public(std::shared_ptr &p); };