From b71c9c12c4a9b72159e755beb45dafebf58bdff1 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 6 May 2021 20:47:03 -0400 Subject: map {tid,pid} from catapult into a virtual tid --- import-chrome/src/import-chrome.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'import-chrome') diff --git a/import-chrome/src/import-chrome.cpp b/import-chrome/src/import-chrome.cpp index 74656cba..9c909b38 100644 --- a/import-chrome/src/import-chrome.cpp +++ b/import-chrome/src/import-chrome.cpp @@ -133,11 +133,30 @@ int main( int argc, char** argv ) printf( "\33[2KParsing...\r" ); fflush( stdout ); + struct PidTid { + uint64_t tid; + uint64_t pid; + uint64_t both; // fake thread id, unique within Tracy + }; + + std::vector tids; std::vector timeline; std::vector messages; std::vector plots; std::unordered_map threadNames; + const auto getTid = [&](uint64_t pid, uint64_t tid) -> uint64_t { + for ( auto &pair : tids ) { + if ( pair.pid == pid && pair.tid == tid ) { + return pair.both; + } + } + + const auto result = tids.size(); + tids.emplace_back(PidTid {.tid=tid, .pid=pid, .both=result}); + return result; + }; + if( j.is_object() && j.contains( "traceEvents" ) ) { j = j["traceEvents"]; @@ -162,10 +181,15 @@ int main( int argc, char** argv ) } } + uint64_t pid = 0; + if ( v.contains( "pid" ) ) { + pid = v["pid"].get(); + } + if( type == "B" ) { timeline.emplace_back( tracy::Worker::ImportEventTimeline { - v["tid"].get(), + getTid(pid, v["tid"].get()), uint64_t( v["ts"].get() * 1000. ), v["name"].get(), std::move(zoneText), @@ -175,7 +199,7 @@ int main( int argc, char** argv ) else if( type == "E" ) { timeline.emplace_back( tracy::Worker::ImportEventTimeline { - v["tid"].get(), + getTid(pid, v["tid"].get()), uint64_t( v["ts"].get() * 1000. ), "", std::move(zoneText), @@ -194,7 +218,7 @@ int main( int argc, char** argv ) else if( type == "i" || type == "I" ) { messages.emplace_back( tracy::Worker::ImportEventMessages { - v["tid"].get(), + getTid(pid, v["tid"].get()), uint64_t( v["ts"].get() * 1000. ), v["name"].get() } ); @@ -241,7 +265,8 @@ int main( int argc, char** argv ) { 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(); + const auto tid = getTid(pid, v["tid"].get()); + threadNames[tid] = v["args"]["name"].get(); } } } -- cgit v1.2.3