mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user