From 15b69eef66fac3410ebd3c987688d06e034d83b1 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 1 Jun 2021 17:22:23 +0200 Subject: [PATCH] Profiler: Fix loading profiles which previously would crash the profiler The profiler tried to be clever when handling process_exit events by subtracting one from the timestamp. This was supposed to ensure that events after a process' death would be attributed to the new process in case the old process used execve(). However, if there was another event (e.g. a CPU sample) at the exact same time the process_exit event was recorded the profile would fail to load because we didn't find the process anymore. This changes introduces a new problem where samples would be attributed to the incorrect process if a CPU sample for the old process, a process_exit as well as a process_create event plus another CPU sample event for the new process happened at the exact same time. I think it's a reasonable compromise though. --- Userland/DevTools/Profiler/Profile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 2c5a9b65a3..fb46b33862 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -267,7 +267,7 @@ Result, String> Profile::load_from_perfcore_file(const St event.executable = perf_event.get("executable").to_string(); auto old_process = current_processes.get(event.pid).value(); - old_process->end_valid = event.timestamp - 1; + old_process->end_valid = event.timestamp; current_processes.remove(event.pid); @@ -282,7 +282,7 @@ Result, String> Profile::load_from_perfcore_file(const St continue; } else if (event.type == "process_exit"sv) { auto old_process = current_processes.get(event.pid).value(); - old_process->end_valid = event.timestamp - 1; + old_process->end_valid = event.timestamp; current_processes.remove(event.pid); continue;