1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

Kernel+LibC: Add support for filtering profiling events

This adds the -t command-line argument for the profile tool. Using this
argument you can filter which event types you want in your profile.
This commit is contained in:
Gunnar Beutner 2021-05-14 08:10:43 +02:00 committed by Andreas Kling
parent 8b2ace0326
commit 572bbf28cc
10 changed files with 72 additions and 33 deletions

View file

@ -15,8 +15,9 @@ namespace Kernel {
bool g_profiling_all_threads;
PerformanceEventBuffer* g_global_perf_events;
u64 g_profiling_event_mask;
KResultOr<int> Process::sys$profiling_enable(pid_t pid)
KResultOr<int> Process::sys$profiling_enable(pid_t pid, u64 event_mask)
{
REQUIRE_NO_PROMISES;
@ -24,6 +25,7 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid)
if (!is_superuser())
return EPERM;
ScopedCritical critical;
g_profiling_event_mask = event_mask;
if (g_global_perf_events)
g_global_perf_events->clear();
else
@ -33,6 +35,7 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid)
if (!TimeManagement::the().enable_profile_timer())
return ENOTSUP;
g_profiling_all_threads = true;
PerformanceManager::add_process_created_event(*Scheduler::colonel());
Process::for_each([](auto& process) {
PerformanceManager::add_process_created_event(process);
return IterationDecision::Continue;
@ -52,6 +55,7 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid)
return ENOMEM;
if (!TimeManagement::the().enable_profile_timer())
return ENOTSUP;
g_profiling_event_mask = event_mask;
process->set_profiling(true);
return 0;
}