summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-02 20:26:27 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-02 20:26:27 +0100
commit3879e5b9d454e08b301721ad3044f90d03026db3 (patch)
tree7931babdd2127410ed93915d788ab3883144c156 /Kernel/Process.cpp
parent25b635c841e209c7fd67be5406a941fa829f9bf2 (diff)
downloadserenity-3879e5b9d454e08b301721ad3044f90d03026db3.zip
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. :^)
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index acac5fb086..484147c12c 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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);
+}