From b512ce3fa822cf88d16313c694c7873a995290c3 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 10 May 2021 11:49:07 -0400 Subject: [PATCH] do not mangle tid if there is no pid --- import-chrome/src/import-chrome.cpp | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/import-chrome/src/import-chrome.cpp b/import-chrome/src/import-chrome.cpp index 29d7406e..126e3797 100644 --- a/import-chrome/src/import-chrome.cpp +++ b/import-chrome/src/import-chrome.cpp @@ -148,22 +148,27 @@ int main( int argc, char** argv ) std::unordered_map threadNames; const auto getPseudoTid = [&](json& val) -> uint64_t { - uint64_t pid = 0; - if ( val.contains( "pid" ) ) { - pid = val["pid"].get(); - } - const auto real_tid = val["tid"].get(); - for ( auto &pair : tid_encoders) { - if ( pair.pid == pid && pair.tid == real_tid ) { - return pair.pseudo_tid; - } - } + if ( val.contains( "pid" ) ) { + // there might be multiple processes so we allocate a pseudo-tid + // for each pair (pid, real_tid) + const auto pid = val["pid"].get(); - const auto pseudo_tid = tid_encoders.size(); - tid_encoders.emplace_back(PidTidEncoder {real_tid, pid, pseudo_tid}); - return pseudo_tid; + for ( auto &pair : tid_encoders) { + if ( pair.pid == pid && pair.tid == real_tid ) { + return pair.pseudo_tid; + } + } + + const auto pseudo_tid = tid_encoders.size(); + tid_encoders.emplace_back(PidTidEncoder {real_tid, pid, pseudo_tid}); + return pseudo_tid; + } + else + { + return real_tid; + } }; if( j.is_object() && j.contains( "traceEvents" ) )