Skip to content

Commit

Permalink
Debugging perfetto trace with hpx - make sure the trace is closed on …
Browse files Browse the repository at this point in the history
…exit
  • Loading branch information
khuck committed Jan 3, 2023
1 parent bbe371e commit 2f9204c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/apex/CMakeLists.hpx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -398,7 +398,7 @@ target_include_directories(apex PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${APEX_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${APEX_SOURCE_DIR}/../perfetto_sdk>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../perfetto_sdk>
$<INSTALL_INTERFACE:include>)

# To have the compile options and definitions
Expand Down
11 changes: 10 additions & 1 deletion src/apex/perfetto_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/apex/perfetto_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<perfetto::TracingSession> tracing_session;
std::string filename;
int file_descriptor;
Expand Down

0 comments on commit 2f9204c

Please sign in to comment.