Skip to content

Commit

Permalink
Kernel+LibC: Add PERF_EVENT_SIGNPOST
Browse files Browse the repository at this point in the history
This event will be used by userspace programs wanting to mark
interesting high-level events in the profile. :^)
  • Loading branch information
awesomekling committed Aug 11, 2021
1 parent 8405381 commit 0d997d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Kernel/PerformanceEventBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ KResult PerformanceEventBuffer::append_with_ip_and_bp(ProcessID pid, ThreadID ti
break;
case PERF_EVENT_SYSCALL:
break;
case PERF_EVENT_SIGNPOST:
event.data.signpost.arg1 = arg1;
event.data.signpost.arg2 = arg2;
break;
default:
return EINVAL;
}
Expand Down Expand Up @@ -231,6 +235,11 @@ bool PerformanceEventBuffer::to_json_impl(Serializer& object) const
case PERF_EVENT_SYSCALL:
event_object.add("type", "syscall");
break;
case PERF_EVENT_SIGNPOST:
event_object.add("type"sv, "signpost"sv);
event_object.add("arg1"sv, event.data.signpost.arg1);
event_object.add("arg2"sv, event.data.signpost.arg2);
break;
}
event_object.add("pid", event.pid);
event_object.add("tid", event.tid);
Expand Down
6 changes: 6 additions & 0 deletions Kernel/PerformanceEventBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ struct [[gnu::packed]] KFreePerformanceEvent {
FlatPtr ptr;
};

struct [[gnu::packed]] SignpostPerformanceEvent {
FlatPtr arg1;
FlatPtr arg2;
};

struct [[gnu::packed]] PerformanceEvent {
u16 type { 0 };
u8 stack_size { 0 };
Expand All @@ -80,6 +85,7 @@ struct [[gnu::packed]] PerformanceEvent {
ContextSwitchPerformanceEvent context_switch;
KMallocPerformanceEvent kmalloc;
KFreePerformanceEvent kfree;
SignpostPerformanceEvent signpost;
} data;
static constexpr size_t max_stack_frame_count = 64;
FlatPtr stack[max_stack_frame_count];
Expand Down
1 change: 1 addition & 0 deletions Kernel/UnixTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum {
PERF_EVENT_KFREE = 4096,
PERF_EVENT_PAGE_FAULT = 8192,
PERF_EVENT_SYSCALL = 16384,
PERF_EVENT_SIGNPOST = 32768,
};

#define WNOHANG 1
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibC/serenity.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ enum {
PERF_EVENT_KFREE = 4096,
PERF_EVENT_PAGE_FAULT = 8192,
PERF_EVENT_SYSCALL = 16384,
PERF_EVENT_SIGNPOST = 32768,
};

#define PERF_EVENT_MASK_ALL (~0ull)
Expand Down

0 comments on commit 0d997d4

Please sign in to comment.