Skip to content

Add PMU performance counters to LTTng execution events table - #139

Open
Hani Nemati (Nemati) wants to merge 1 commit into
developfrom
user/hanemati/lttng-pmu-counters
Open

Hani Nemati (Nemati) wants to merge 1 commit into
developfrom
user/hanemati/lttng-pmu-counters

Conversation

@Nemati

Copy link
Copy Markdown

Adds per-thread CPU performance counter (PMU) deltas to the LTTng Execution Events table.

When a kernel trace is recorded with perf counter contexts (lttng add-context -k -t perf:cpu:...), each sched_switch carries the current counter values. This change:

  • Captures the integer perf context fields on each context switch (ContextSwitch)
  • Computes, for each execution event, how much each counter changed between switch-in and switch-out (ExecutionEvent.PerformanceCountersDiffByName, exposed on IExecutionEvent)
  • Adds Instruction Count, LLC Misses, CPU Cycle and Cache Misses columns (0 when a counter wasn't recorded)

Existing behavior is unchanged for traces without counters: the thread state/timing columns are computed exactly as before, and missed context switches produce zero-length events with no counter deltas.

Record with, e.g.:

lttng add-context -k -t perf:cpu:instructions -t perf:cpu:cpu-cycles -t perf:cpu:cache-misses -t perf:cpu:LLC-load-misses

Testing: LTTngDataExtensions builds; all LTTngDataExtUnitTest tests pass.

Ports the performance counter support from 560cd2f onto develop:
- Capture integer perf context fields on each sched_switch
- Compute per-execution-event counter deltas between switch-in and switch-out
- Add Instruction Count, LLC Misses, CPU Cycle and Cache Misses columns

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new columns are hidden from every table configuration, and the PMU calculation path lacks coverage.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Adds per-thread PMU counter deltas to LTTng execution events and exposes them in the Execution Events table.

Changes:

  • Captures perf context values during context switches.
  • Computes counter deltas across execution intervals.
  • Registers four PMU counter columns.
File Description
ExecutionEventTable.cs Registers PMU counter columns.
LTTngThreadDataCooker.cs Associates switch-in and switch-out contexts.
ExecutionEvent.cs Computes and exposes counter deltas.
ContextSwitch.cs Captures perf context fields.
IExecutionEvent.cs Adds the counter-delta output contract.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +294 to +297
table.AddColumn(instructionCountColumn, Projection.CreateUsingFuncAdaptor((i) => GetPerformanceCounterDiff(threads[i], "_perf_cpu_instructions")));
table.AddColumn(lastLevelCacheMissesColumn, Projection.CreateUsingFuncAdaptor((i) => GetPerformanceCounterDiff(threads[i], "_perf_cpu_LLC_load_misses")));
table.AddColumn(cpuCycleColumn, Projection.CreateUsingFuncAdaptor((i) => GetPerformanceCounterDiff(threads[i], "_perf_cpu_cpu_cycles")));
table.AddColumn(cacheMissesColumn, Projection.CreateUsingFuncAdaptor((i) => GetPerformanceCounterDiff(threads[i], "_perf_cpu_cache_misses")));
Comment on lines +61 to +63
if (switchOutContextSwitch.PerformanceCountersByName.TryGetValue(counter.Key, out long switchOutValue))
{
this.performanceCountersDiffByName[counter.Key] = switchOutValue - counter.Value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants