mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:37:34 +00:00
Kernel: Add PerformanceManager static class, move perf event APIs there
The current method of emitting performance events requires a bit of boiler plate at every invocation, as well as having to ignore the return code which isn't used outside of the perf event syscall. This change attempts to clean that up by exposing high level API's that can be used around the code base.
This commit is contained in:
parent
43b3fd748a
commit
ccdcb6a635
7 changed files with 70 additions and 33 deletions
47
Kernel/PerformanceManager.h
Normal file
47
Kernel/PerformanceManager.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/PerformanceEventBuffer.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class PerformanceManager {
|
||||
|
||||
public:
|
||||
inline static void add_thread_created_event(Thread& thread)
|
||||
{
|
||||
if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_CREATE, thread.tid().value(), 0, nullptr, &thread);
|
||||
}
|
||||
}
|
||||
|
||||
inline static void add_thread_exit_event(Thread& thread)
|
||||
{
|
||||
if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_EXIT, thread.tid().value(), 0, nullptr, &thread);
|
||||
}
|
||||
}
|
||||
|
||||
inline static void add_mmap_perf_event(Process& current_process, Region const& region)
|
||||
{
|
||||
if (auto* event_buffer = current_process.current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MMAP, region.vaddr().get(), region.size(), region.name());
|
||||
}
|
||||
}
|
||||
|
||||
inline static void add_unmap_perf_event(Process& current_process, Range const& region)
|
||||
{
|
||||
if (auto* event_buffer = current_process.current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MUNMAP, region.base().get(), region.size(), nullptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue