diff options
-rw-r--r-- | Kernel/PerformanceManager.h | 16 | ||||
-rw-r--r-- | Kernel/Syscalls/execve.cpp | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/fork.cpp | 7 | ||||
-rw-r--r-- | Kernel/Syscalls/profiling.cpp | 7 |
4 files changed, 23 insertions, 13 deletions
diff --git a/Kernel/PerformanceManager.h b/Kernel/PerformanceManager.h index c3ffd33723..e4bef19db8 100644 --- a/Kernel/PerformanceManager.h +++ b/Kernel/PerformanceManager.h @@ -13,8 +13,22 @@ namespace Kernel { class PerformanceManager { - public: + inline static void add_process_created_event(Process& process) + { + if (g_profiling_all_threads) { + VERIFY(g_global_perf_events); + g_global_perf_events->add_process(process, ProcessEventType::Create); + } + } + + inline static void add_process_exec_event(Process& process) + { + if (auto* event_buffer = process.current_perf_events_buffer()) { + event_buffer->add_process(process, ProcessEventType::Exec); + } + } + inline static void add_thread_created_event(Thread& thread) { if (auto* event_buffer = thread.process().current_perf_events_buffer()) { diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 4aba395cf7..9d2924d9ac 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -11,7 +11,7 @@ #include <Kernel/Debug.h> #include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/FileDescription.h> -#include <Kernel/PerformanceEventBuffer.h> +#include <Kernel/PerformanceManager.h> #include <Kernel/Process.h> #include <Kernel/Random.h> #include <Kernel/Time/TimeManagement.h> @@ -636,9 +636,7 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description tss.cr3 = space().page_directory().cr3(); tss.ss2 = pid().value(); - if (auto* event_buffer = current_perf_events_buffer()) { - event_buffer->add_process(*this, ProcessEventType::Exec); - } + PerformanceManager::add_process_exec_event(*this); { ScopedSpinLock lock(g_scheduler_lock); diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index af6c265f30..274d449f2d 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -7,7 +7,7 @@ #include <Kernel/Debug.h> #include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/FileDescription.h> -#include <Kernel/PerformanceEventBuffer.h> +#include <Kernel/PerformanceManager.h> #include <Kernel/Process.h> #include <Kernel/VM/Region.h> @@ -85,10 +85,7 @@ KResultOr<pid_t> Process::sys$fork(RegisterState& regs) g_processes->prepend(child); } - if (g_profiling_all_threads) { - VERIFY(g_global_perf_events); - g_global_perf_events->add_process(*child, ProcessEventType::Create); - } + PerformanceManager::add_process_created_event(*child); ScopedSpinLock lock(g_scheduler_lock); child_first_thread->set_affinity(Thread::current()->affinity()); diff --git a/Kernel/Syscalls/profiling.cpp b/Kernel/Syscalls/profiling.cpp index 1c956faef0..ba7685488c 100644 --- a/Kernel/Syscalls/profiling.cpp +++ b/Kernel/Syscalls/profiling.cpp @@ -7,7 +7,7 @@ #include <Kernel/CoreDump.h> #include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/VirtualFileSystem.h> -#include <Kernel/PerformanceEventBuffer.h> +#include <Kernel/PerformanceManager.h> #include <Kernel/Process.h> namespace Kernel { @@ -27,12 +27,13 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid) g_global_perf_events->clear(); else g_global_perf_events = PerformanceEventBuffer::try_create_with_size(32 * MiB).leak_ptr(); + ScopedSpinLock lock(g_processes_lock); + g_profiling_all_threads = true; Process::for_each([](auto& process) { - g_global_perf_events->add_process(process, ProcessEventType::Create); + PerformanceManager::add_process_created_event(process); return IterationDecision::Continue; }); - g_profiling_all_threads = true; return 0; } |