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.
This commit is contained in:
Christian Hergert
2023-05-25 11:16:08 -07:00
parent 6f90a552e7
commit 8353b1eb9c

View File

@ -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;