1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 20:27:35 +00:00

Kernel: Move process creation perf events to PerformanceManager

This commit is contained in:
Brian Gianforcaro 2021-05-07 01:38:50 -07:00 committed by Andreas Kling
parent ccdcb6a635
commit 8bf4201f50
4 changed files with 23 additions and 13 deletions

View file

@ -13,8 +13,22 @@
namespace Kernel { namespace Kernel {
class PerformanceManager { class PerformanceManager {
public: 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) inline static void add_thread_created_event(Thread& thread)
{ {
if (auto* event_buffer = thread.process().current_perf_events_buffer()) { if (auto* event_buffer = thread.process().current_perf_events_buffer()) {

View file

@ -11,7 +11,7 @@
#include <Kernel/Debug.h> #include <Kernel/Debug.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/PerformanceEventBuffer.h> #include <Kernel/PerformanceManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/Time/TimeManagement.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.cr3 = space().page_directory().cr3();
tss.ss2 = pid().value(); tss.ss2 = pid().value();
if (auto* event_buffer = current_perf_events_buffer()) { PerformanceManager::add_process_exec_event(*this);
event_buffer->add_process(*this, ProcessEventType::Exec);
}
{ {
ScopedSpinLock lock(g_scheduler_lock); ScopedSpinLock lock(g_scheduler_lock);

View file

@ -7,7 +7,7 @@
#include <Kernel/Debug.h> #include <Kernel/Debug.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/PerformanceEventBuffer.h> #include <Kernel/PerformanceManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/VM/Region.h> #include <Kernel/VM/Region.h>
@ -85,10 +85,7 @@ KResultOr<pid_t> Process::sys$fork(RegisterState& regs)
g_processes->prepend(child); g_processes->prepend(child);
} }
if (g_profiling_all_threads) { PerformanceManager::add_process_created_event(*child);
VERIFY(g_global_perf_events);
g_global_perf_events->add_process(*child, ProcessEventType::Create);
}
ScopedSpinLock lock(g_scheduler_lock); ScopedSpinLock lock(g_scheduler_lock);
child_first_thread->set_affinity(Thread::current()->affinity()); child_first_thread->set_affinity(Thread::current()->affinity());

View file

@ -7,7 +7,7 @@
#include <Kernel/CoreDump.h> #include <Kernel/CoreDump.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/PerformanceEventBuffer.h> #include <Kernel/PerformanceManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
namespace Kernel { namespace Kernel {
@ -27,12 +27,13 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid)
g_global_perf_events->clear(); g_global_perf_events->clear();
else else
g_global_perf_events = PerformanceEventBuffer::try_create_with_size(32 * MiB).leak_ptr(); g_global_perf_events = PerformanceEventBuffer::try_create_with_size(32 * MiB).leak_ptr();
ScopedSpinLock lock(g_processes_lock); ScopedSpinLock lock(g_processes_lock);
g_profiling_all_threads = true;
Process::for_each([](auto& process) { Process::for_each([](auto& process) {
g_global_perf_events->add_process(process, ProcessEventType::Create); PerformanceManager::add_process_created_event(process);
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
g_profiling_all_threads = true;
return 0; return 0;
} }