From 2e9d8f821523dae0a66b57fa68790d6ffe055ba2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 30 Apr 2023 13:55:49 +0200 Subject: [PATCH] Check if external threads are local. For some unknown reason, local threads may be attributed to an external process (at least when profiling on Windows). This causes some problems, for example the CPU usage graph may show that CPU is pegged by some other program, when it reality it is the profiled program that uses the CPU time. Workaround by checking first, if the thread id is known to be local by the profiler, i.e. if there were user-generated events originating from it. This still leaves other things, such as the CPU data list, being wrong, but the CPU data is meant to show raw TID -> PID mapping. If the source data is wrong, there's not much to fix here. --- server/TracyWorker.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 061a94bc..e96e814d 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -7091,7 +7091,8 @@ void Worker::ReconstructContextSwitchUsage() { const auto ct = !cpus[i].startDone ? cpus[i].it->Start() : cpus[i].it->End(); if( nextTime != ct ) break; - const auto isOwn = GetPidFromTid( DecompressThreadExternal( cpus[i].it->Thread() ) ) == m_pid; + const auto tid = DecompressThreadExternal( cpus[i].it->Thread() ); + const auto isOwn = IsThreadLocal( tid ) || GetPidFromTid( tid ) == m_pid; if( !cpus[i].startDone ) { if( isOwn )