From d7a13dbaa7312ef83054478399c847ae3b4b6813 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 22 Feb 2020 10:54:50 +0100 Subject: [PATCH] Kernel: Reset profiling state on exec() (but keep it going) We now log the new executable on exec() and throw away all the samples we've accumulated so far. But profiling keeps going. --- Kernel/Process.cpp | 3 +++ Kernel/Profiling.cpp | 6 ++++++ Kernel/Profiling.h | 1 + 3 files changed, 10 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index cf4e793249..db9040e0f7 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1015,6 +1015,9 @@ int Process::do_exec(NonnullRefPtr main_program_description, Ve kprintf("Process %u (%s) exec'd %s @ %p\n", pid(), name().characters(), path.characters(), tss.eip); #endif + if (is_profiling()) + Profiling::did_exec(path); + new_main_thread->set_state(Thread::State::Skip1SchedulerPass); big_lock().force_unlock_if_locked(); return 0; diff --git a/Kernel/Profiling.cpp b/Kernel/Profiling.cpp index 90cc9fa2d2..1c64512ba9 100644 --- a/Kernel/Profiling.cpp +++ b/Kernel/Profiling.cpp @@ -90,6 +90,12 @@ void stop() s_process = nullptr; } +void did_exec(const String& new_executable_path) +{ + executable_path() = new_executable_path; + s_next_slot_index = 0; +} + void for_each_sample(Function callback) { for (size_t i = 0; i < s_next_slot_index; ++i) { diff --git a/Kernel/Profiling.h b/Kernel/Profiling.h index d94c81ece0..dc419a34a6 100644 --- a/Kernel/Profiling.h +++ b/Kernel/Profiling.h @@ -51,6 +51,7 @@ extern String& executable_path(); Sample& next_sample_slot(); void start(Process&); void stop(); +void did_exec(const String& new_executable_path); void for_each_sample(Function); }