1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

Kernel+Profiler: Make profiling per-process and without core dumps

This patch merges the profiling functionality in the kernel with the
performance events mechanism. A profiler sample is now just another
perf event, rather than a dedicated thing.

Since perf events were already per-process, this now makes profiling
per-process as well.

Processes with perf events would already write out a perfcore.PID file
to the current directory on death, but since we may want to profile
a process and then let it continue running, recorded perf events can
now be accessed at any time via /proc/PID/perf_events.

This patch also adds information about process memory regions to the
perfcore JSON format. This removes the need to supply a core dump to
the Profiler app for symbolication, and so the "profiler coredump"
mechanism is removed entirely.

There's still a hard limit of 4MB worth of perf events per process,
so this is by no means a perfect final design, but it's a nice step
forward for both simplicity and stability.

Fixes #4848
Fixes #4849
This commit is contained in:
Andreas Kling 2021-01-11 09:52:18 +01:00
parent f259d96871
commit 5dafb72370
20 changed files with 195 additions and 310 deletions

View file

@ -31,6 +31,8 @@
namespace Kernel {
class KBufferBuilder;
struct [[gnu::packed]] MallocPerformanceEvent {
size_t size;
FlatPtr ptr;
@ -44,12 +46,14 @@ struct [[gnu::packed]] FreePerformanceEvent {
struct [[gnu::packed]] PerformanceEvent {
u8 type { 0 };
u8 stack_size { 0 };
u32 tid { 0 };
u64 timestamp;
union {
MallocPerformanceEvent malloc;
FreePerformanceEvent free;
} data;
FlatPtr stack[32];
static constexpr size_t max_stack_frame_count = 32;
FlatPtr stack[max_stack_frame_count];
};
class PerformanceEventBuffer {
@ -58,6 +62,11 @@ public:
KResult append(int type, FlatPtr arg1, FlatPtr arg2);
void clear()
{
m_count = 0;
}
size_t capacity() const
{
if (!m_buffer)
@ -71,6 +80,7 @@ public:
}
OwnPtr<KBuffer> to_json(ProcessID, const String& executable_path) const;
bool to_json(KBufferBuilder&, ProcessID, const String& executable_path) const;
private:
PerformanceEvent& at(size_t index);