From 8353b1eb9c1f4c1fd63ab543cbe0a397e7cf32fe Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 25 May 2023 11:16:08 -0700 Subject: [PATCH] libsysprof-analyze: account kernel stacks to the kernel If our entire stack was in kernel address context, inject the "- - Kernel - -" symbol at the top of the stack trace so that accounting gets properly assigned to the kernel. This is typical with kernel processes such as kworker. --- src/libsysprof-analyze/sysprof-callgraph.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-callgraph.c b/src/libsysprof-analyze/sysprof-callgraph.c index b6bff950..f77c7e9f 100644 --- a/src/libsysprof-analyze/sysprof-callgraph.c +++ b/src/libsysprof-analyze/sysprof-callgraph.c @@ -225,7 +225,7 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self, if (stack_depth == 0 || stack_depth > MAX_STACK_DEPTH) return; - symbols = g_newa (SysprofSymbol *, stack_depth + 2); + symbols = g_newa (SysprofSymbol *, stack_depth + 3); n_symbols = sysprof_document_symbolize_traceable (self->document, traceable, symbols, @@ -235,9 +235,14 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self, g_assert (n_symbols > 0); g_assert (n_symbols <= stack_depth); - /* We saved 2 extra spaces for these above so that we can + /* We saved 3 extra spaces for these above so that we can * tack on the "Process" symbol and the "Everything" symbol. + * If the final address context places us in Kernel, we want + * to add a "- - Kernel - -" symbol to ensure that we are + * accounting cost to the kernel for the process. */ + if (final_context == SYSPROF_ADDRESS_CONTEXT_KERNEL) + symbols[n_symbols++] = _sysprof_document_kernel_symbol (self->document); symbols[n_symbols++] = _sysprof_document_process_symbol (self->document, pid); symbols[n_symbols++] = self->everything;