mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
Kernel: Don't log profile data before/after the process/thread lifetime
There were a few cases where we could end up logging profiling events before or after the associated process or thread exists in the profile: After enabling profiling we might end up with CPU samples before we had a chance to synthesize process/thread creation events. After a thread exits we would still log associated kmalloc/kfree events. Instead we now just ignore those events.
This commit is contained in:
parent
d24dd7a3df
commit
01c75e3a34
8 changed files with 39 additions and 22 deletions
|
@ -40,6 +40,8 @@ public:
|
|||
|
||||
inline static void add_thread_created_event(Thread& thread)
|
||||
{
|
||||
if (thread.is_profiling_suppressed())
|
||||
return;
|
||||
if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_CREATE, thread.tid().value(), 0, nullptr, &thread);
|
||||
}
|
||||
|
@ -47,6 +49,8 @@ public:
|
|||
|
||||
inline static void add_thread_exit_event(Thread& thread)
|
||||
{
|
||||
// As an exception this doesn't check whether profiling is suppressed for
|
||||
// the thread so we can record the thread_exit event anyway.
|
||||
if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto rc = event_buffer->append(PERF_EVENT_THREAD_EXIT, thread.tid().value(), 0, nullptr, &thread);
|
||||
}
|
||||
|
@ -54,6 +58,8 @@ public:
|
|||
|
||||
inline static void add_cpu_sample_event(Thread& current_thread, const RegisterState& regs, u32 lost_time)
|
||||
{
|
||||
if (current_thread.is_profiling_suppressed())
|
||||
return;
|
||||
if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto rc = event_buffer->append_with_eip_and_ebp(
|
||||
current_thread.pid(), current_thread.tid(),
|
||||
|
@ -77,27 +83,35 @@ public:
|
|||
|
||||
inline static void add_context_switch_perf_event(Thread& current_thread, Thread& next_thread)
|
||||
{
|
||||
if (current_thread.is_profiling_suppressed())
|
||||
return;
|
||||
if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_CONTEXT_SWITCH, next_thread.pid().value(), next_thread.tid().value(), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
inline static void add_kmalloc_perf_event(Process& current_process, size_t size, FlatPtr ptr)
|
||||
inline static void add_kmalloc_perf_event(Thread& current_thread, size_t size, FlatPtr ptr)
|
||||
{
|
||||
if (auto* event_buffer = current_process.current_perf_events_buffer()) {
|
||||
if (current_thread.is_profiling_suppressed())
|
||||
return;
|
||||
if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_KMALLOC, size, ptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
inline static void add_kfree_perf_event(Process& current_process, size_t size, FlatPtr ptr)
|
||||
inline static void add_kfree_perf_event(Thread& current_thread, size_t size, FlatPtr ptr)
|
||||
{
|
||||
if (auto* event_buffer = current_process.current_perf_events_buffer()) {
|
||||
if (current_thread.is_profiling_suppressed())
|
||||
return;
|
||||
if (auto* event_buffer = current_thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_KFREE, size, ptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
inline static void add_page_fault_event(Thread& thread, const RegisterState& regs)
|
||||
{
|
||||
if (thread.is_profiling_suppressed())
|
||||
return;
|
||||
if (auto* event_buffer = thread.process().current_perf_events_buffer()) {
|
||||
[[maybe_unused]] auto rc = event_buffer->append_with_eip_and_ebp(
|
||||
thread.pid(), thread.tid(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue