From 59ae71df2be6c3f8b6dcd104fb8abc55a9d062c4 Mon Sep 17 00:00:00 2001 From: jkriegshauser Date: Fri, 2 Sep 2022 10:44:37 -0700 Subject: [PATCH] Import frame messages (#459) Co-authored-by: Joshua Kriegshauser Co-authored-by: Bartosz Taudul --- NEWS | 3 ++ import-chrome/src/import-chrome.cpp | 7 +++ server/TracyWorker.cpp | 75 ++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index 759cacc3..38db5c17 100644 --- a/NEWS +++ b/NEWS @@ -80,6 +80,9 @@ v0.x.x (xxxx-xx-xx) instead of "/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../ include/c++/12.2.0/bits/std_mutex.h" Tracy will now report such file as "/usr/include/c++/12.2.0/bits/std_mutex.h". +- The import-chrome utility interprets Instant (`i`/`I`) events where the + `name` field contains the word `frame` as a frame event. The `name` is the + frame set name. v0.8.2 (2022-06-28) diff --git a/import-chrome/src/import-chrome.cpp b/import-chrome/src/import-chrome.cpp index 06b71297..4421570c 100644 --- a/import-chrome/src/import-chrome.cpp +++ b/import-chrome/src/import-chrome.cpp @@ -30,6 +30,13 @@ using json = nlohmann::json; void Usage() { printf( "Usage: import-chrome input.json output.tracy\n\n" ); + printf( "The following chrome-tracing phases are supported:\n\n" ); + printf( " b/B/e/E - Timeline events such as ZoneNamed\n" ); + printf( " X - Timeline events such as ZoneNamed\n" ); + printf( " i/I - Message events such as TracyMessage\n" ); + printf( " * Messages containing the word \"frame\" are interpreted as frame events such as FrameMarkNamed\n" ); + printf( " C - Plot events such as TracyPlot\n" ); + printf( " M - Metadata of type \"thread_name\" is used to name threads\n" ); exit( 1 ); } diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 72c3712b..1278701d 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -423,21 +423,46 @@ Worker::Worker( const char* name, const char* program, const std::vector frameNames; + for( auto& v : messages ) { - auto msg = m_slab.Alloc(); - msg->time = v.timestamp; - msg->ref = StringRef( StringRef::Type::Idx, StoreString( v.message.c_str(), v.message.size() ).idx ); - msg->thread = CompressThread( v.tid ); - msg->color = 0xFFFFFFFF; - msg->callstack.SetVal( 0 ); - - if( m_threadCtx != v.tid ) + // There is no specific chrome-tracing type for frame events. We use messages that contain the word "frame" + std::string lower( v.message ); + std::transform( lower.begin(), lower.end(), lower.begin(), []( char c ) { return char( std::tolower( c ) ); } ); + if( lower.find( "frame" ) != std::string::npos ) { - m_threadCtx = v.tid; - m_threadCtxData = nullptr; + // Reserve 0 as the default FrameSet, since it replaces the name with "Frame" and we want to keep our custom names. + auto result = frameNames.emplace( v.message, frameNames.size() + 1 ); + auto fd = m_data.frames.Retrieve( result.first->second, [&] ( uint64_t name ) { + auto fd = m_slab.AllocInit(); + fd->name = name; + fd->continuous = 1; + return fd; + }, [&] ( uint64_t name ) { + HandleFrameName( name, v.message.c_str(), v.message.length() ); + }); + + int64_t time = v.timestamp; + fd->frames.push_back( FrameEvent{ time, -1, -1 } ); + if ( m_data.lastTime < time ) m_data.lastTime = time; + } + else + { + auto msg = m_slab.Alloc(); + msg->time = v.timestamp; + msg->ref = StringRef( StringRef::Type::Idx, StoreString( v.message.c_str(), v.message.size() ).idx ); + msg->thread = CompressThread( v.tid ); + msg->color = 0xFFFFFFFF; + msg->callstack.SetVal( 0 ); + + if( m_threadCtx != v.tid ) + { + m_threadCtx = v.tid; + m_threadCtxData = nullptr; + } + InsertMessageData( msg ); } - InsertMessageData( msg ); } for( auto& v : plots ) @@ -512,19 +537,23 @@ Worker::Worker( const char* name, const char* program, const std::vector(); - fd->name = name; - fd->continuous = 1; - return fd; - }, [this] ( uint64_t name ) { - assert( name == 0 ); - char tmp[6] = "Frame"; - HandleFrameName( name, tmp, 5 ); - } ); + // Add a default frame if we didn't have any framesets + if( frameNames.empty() ) + { + m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) { + auto fd = m_slab.AllocInit(); + fd->name = name; + fd->continuous = 1; + return fd; + }, [this] ( uint64_t name ) { + assert( name == 0 ); + char tmp[6] = "Frame"; + HandleFrameName( name, tmp, 5 ); + } ); - m_data.framesBase->frames.push_back( FrameEvent{ 0, -1, -1 } ); - m_data.framesBase->frames.push_back( FrameEvent{ 0, -1, -1 } ); + m_data.framesBase->frames.push_back( FrameEvent{ 0, -1, -1 } ); + m_data.framesBase->frames.push_back( FrameEvent{ 0, -1, -1 } ); + } } Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )