From 2920f97911c1499dadcc751b1022f61c4df40867 Mon Sep 17 00:00:00 2001 From: joshuakr Date: Thu, 21 Jan 2021 17:07:31 -0800 Subject: [PATCH] Imported Chrome traces bring over thread names --- import-chrome/src/import-chrome.cpp | 11 ++++++++++- server/TracyWorker.cpp | 18 ++++++++++++++---- server/TracyWorker.hpp | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/import-chrome/src/import-chrome.cpp b/import-chrome/src/import-chrome.cpp index a5186e4d..a03888d9 100644 --- a/import-chrome/src/import-chrome.cpp +++ b/import-chrome/src/import-chrome.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "json.hpp" @@ -56,6 +57,7 @@ int main( int argc, char** argv ) std::vector timeline; std::vector messages; std::vector plots; + std::unordered_map threadNames; if( j.is_object() && j.contains( "traceEvents" ) ) { @@ -156,6 +158,13 @@ int main( int argc, char** argv ) } } } + else if (type == "M") + { + if (v.contains("name") && v["name"] == "thread_name" && v.contains("args") && v["args"].is_object() && v["args"].contains("name")) + { + threadNames[v["tid"].get()] = v["args"]["name"].get(); + } + } } std::stable_sort( timeline.begin(), timeline.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } ); @@ -189,7 +198,7 @@ int main( int argc, char** argv ) while( *program ) program++; program--; while( program > input && ( *program != '/' || *program != '\\' ) ) program--; - tracy::Worker worker( program, timeline, messages, plots ); + tracy::Worker worker( program, timeline, messages, plots, threadNames ); auto w = std::unique_ptr( tracy::FileWrite::Open( output, clev ) ); if( !w ) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 6fb4ffcc..a519274f 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -275,7 +275,7 @@ Worker::Worker( const char* addr, uint16_t port ) m_threadNet = std::thread( [this] { SetThreadName( "Tracy Network" ); Network(); } ); } -Worker::Worker( const std::string& program, const std::vector& timeline, const std::vector& messages, const std::vector& plots ) +Worker::Worker( const std::string& program, const std::vector& timeline, const std::vector& messages, const std::vector& plots, const std::unordered_map& threadNames ) : m_hasData( true ) , m_delay( 0 ) , m_resolution( 0 ) @@ -428,9 +428,19 @@ Worker::Worker( const std::string& program, const std::vectorsecond.c_str()); + AddThreadString(t.first, buf, len); + } + else + { + char buf[64]; + sprintf( buf, "%" PRIu64, t.first ); + AddThreadString( t.first, buf, strlen( buf ) ); + } } m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) { diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 2fe6ba00..b2f9a3d1 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -394,7 +394,7 @@ public: }; Worker( const char* addr, uint16_t port ); - Worker( const std::string& program, const std::vector& timeline, const std::vector& messages, const std::vector& plots ); + Worker( const std::string& program, const std::vector& timeline, const std::vector& messages, const std::vector& plots, const std::unordered_map& threadNames ); Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true ); ~Worker();