From 2f9204cb6391ba4f8b61dbd45d4050c13f40e8a3 Mon Sep 17 00:00:00 2001 From: Kevin Huck Date: Tue, 3 Jan 2023 10:53:28 -0800 Subject: [PATCH] Debugging perfetto trace with hpx - make sure the trace is closed on exit --- src/apex/CMakeLists.hpx | 4 ++-- src/apex/perfetto_listener.cpp | 11 ++++++++++- src/apex/perfetto_listener.hpp | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/apex/CMakeLists.hpx b/src/apex/CMakeLists.hpx index eafe096c..aae50402 100644 --- a/src/apex/CMakeLists.hpx +++ b/src/apex/CMakeLists.hpx @@ -338,7 +338,7 @@ set(apex_sources gzstream.cpp handler.cpp memory_wrapper.cpp - ${APEX_SOURCE_DIR}/../perfetto_sdk/perfetto.cc + ../perfetto_sdk/perfetto.cc perfetto_listener.cpp perfetto_static.cpp policy_handler.cpp @@ -398,7 +398,7 @@ target_include_directories(apex PUBLIC $ $ $ - $ + $ $) # To have the compile options and definitions diff --git a/src/apex/perfetto_listener.cpp b/src/apex/perfetto_listener.cpp index 759e78f8..ec5ca640 100644 --- a/src/apex/perfetto_listener.cpp +++ b/src/apex/perfetto_listener.cpp @@ -51,7 +51,10 @@ perfetto_listener::perfetto_listener (void) { tracing_session->StartBlocking(); } -perfetto_listener::~perfetto_listener (void) { +void perfetto_listener::close_trace() { + static bool closed{false}; + if (closed) return; + closed = true; // Make sure the last event is closed for this example. perfetto::TrackEvent::Flush(); @@ -72,6 +75,11 @@ perfetto_listener::~perfetto_listener (void) { "text form, run `./tools/traceconv text example.pftrace`"); */ close(file_descriptor); + +} + +perfetto_listener::~perfetto_listener (void) { + close_trace(); } void perfetto_listener::on_startup(startup_event_data &data) { @@ -95,6 +103,7 @@ void perfetto_listener::on_pre_shutdown(void) { void perfetto_listener::on_shutdown(shutdown_event_data &data) { APEX_UNUSED(data); + close_trace(); return; } diff --git a/src/apex/perfetto_listener.hpp b/src/apex/perfetto_listener.hpp index 2abfd909..ae5b08f5 100644 --- a/src/apex/perfetto_listener.hpp +++ b/src/apex/perfetto_listener.hpp @@ -49,6 +49,7 @@ class perfetto_listener : public event_listener { private: void get_file_name(); size_t make_tid (base_thread_node &node); + void close_trace(); std::unique_ptr tracing_session; std::string filename; int file_descriptor;