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

Kernel: Start working on a syscall for logging performance events

This patch introduces sys$perf_event() with two event types:

- PERF_EVENT_MALLOC
- PERF_EVENT_FREE

After the first call to sys$perf_event(), a process will begin keeping
these events in a buffer. When the process dies, that buffer will be
written out to "perfcore" in the current directory unless that filename
is already taken.

This is probably not the best way to do this, but it's a start and will
make it possible to start doing memory allocation profiling. :^)
This commit is contained in:
Andreas Kling 2020-02-02 20:26:27 +01:00
parent 25b635c841
commit 3879e5b9d4
7 changed files with 225 additions and 1 deletions

View file

@ -2940,6 +2940,15 @@ void Process::finalize()
dbg() << "Finalizing process " << *this;
#endif
if (m_perf_event_buffer) {
auto description_or_error = VFS::the().open("perfcore", O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { m_uid, m_gid });
if (!description_or_error.is_error()) {
auto& description = description_or_error.value();
auto json = m_perf_event_buffer->to_json(m_pid, m_executable ? m_executable->absolute_path() : "");
description->write(json.data(), json.size());
}
}
m_fds.clear();
m_tty = nullptr;
m_executable = nullptr;
@ -4670,3 +4679,10 @@ int Process::sys$unveil(const Syscall::SC_unveil_params* user_params)
m_veil_state = VeilState::Dropped;
return 0;
}
int Process::sys$perf_event(int type, uintptr_t arg1, uintptr_t arg2)
{
if (!m_perf_event_buffer)
m_perf_event_buffer = make<PerformanceEventBuffer>();
return m_perf_event_buffer->append(type, arg1, arg2);
}