Skip to content

perf c2c: add a function view

Jiebin Sun linux-perf-users lkml 9 versions – Applied

Status from this message: Applied to perf-tools-next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest9 patches 13 repliesApplied
  2. v89 patches 11 repliesSuperseded
  3. v79 patches 2 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v69 patches6 repliesSuperseded
v59 patches0 repliesSuperseded
v49 patches5 repliesSuperseded
v314 patches5 repliesSuperseded
v214 patches0 repliesSuperseded
v114 patches6 repliesSuperseded

Changes in v9 from the cover letter

================

- Rebase onto perf-tools-next at 6ae6fb96ccd4.

- Move the function-view hierarchy construction, aggregation, sorting, and column formatting to util/c2c-function.c, as suggested by Namhyung. Keep only the TUI browser, key handling, and cacheline detail action in ui/browsers/c2c-function.c.

- Make the common model validate inputs before replacing existing state and keep its entries callchain-free during construction and teardown, independent of the caller's current callchain setting.

- Simplify three rbtree node-to-entry conversions by using rb_entry() directly with the nested hist_entry rb_node, as suggested by Namhyung.

- Clarify that Cycles % uses the surviving level-1 entries after pruning. No functional change.

Patches in v9 Applied

#Subject and filesSizeRepliesApplied
1/9perf c2c: extract shared data structures into util/c2c.htools/perf/builtin-c2c.c tools/perf/util/Build tools/perf/util/c2c.c +1 more+126 -1021 reply
2/9perf c2c: add function view model skeletontools/perf/util/Build tools/perf/util/c2c-function.c+67 -03 replies
3/9perf c2c: add column rendering for function viewtools/perf/util/c2c-function.c+353 -01 reply
4/9perf c2c: add HPP list parsing for function view columnstools/perf/util/c2c-function.c+266 -31 reply
5/9perf c2c: add function view stats merge and memory managementtools/perf/util/c2c-function.c+163 -01 reply
6/9perf c2c: add function view hierarchy entry creationtools/perf/util/c2c-function.c tools/perf/util/c2c.h+310 -111 reply
7/9perf c2c: build and finalize the function view hierarchytools/perf/util/c2c-function.c tools/perf/util/c2c.h+525 -151 reply
8/9perf c2c: add function view browser UI and cacheline detailtools/perf/builtin-c2c.c tools/perf/ui/browsers/Build tools/perf/ui/browsers/c2c-function.c +1 more+242 -01 reply
9/9perf c2c: document function view in perf-c2c man pagetools/perf/Documentation/perf-c2c.txt+71 -01 reply

Reviews trailers per patch

All 9 patches have a Reviewed-by or Acked-by.

PatchTianyou LiWangyang GuoIan Rogers
1/9R-b R-b R-b
2/9R-b R-b R-b
3/9R-b R-b R-b
4/9R-b R-b R-b
5/9R-b R-b R-b
6/9R-b R-b R-b
7/9R-b R-b R-b
8/9R-b R-b R-b
9/9R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v9 thread

Cover letter [PATCH v9 0/9] perf c2c: add a function view

The perf c2c cacheline view identifies hot shared lines, but it can be difficult to see which functions account for contention across those lines. This series adds a function-oriented view that groups the existing data as:

read-side function -> contending writer -> shared cacheline

Pressing TAB switches between the cacheline and function views. Existing cacheline-view data and operations remain unchanged.

v1: https://lore.kernel.org/linux-perf-users/[email protected]/
v2: https://lore.kernel.org/linux-perf-users/[email protected]/
v3: https://lore.kernel.org/linux-perf-users/[email protected]/
v4: https://lore.kernel.org/linux-perf-users/[email protected]/
v5: https://lore.kernel.org/linux-perf-users/[email protected]/
v6: https://lore.kernel.org/linux-perf-users/[email protected]/
v7: https://lore.kernel.org/linux-perf-users/[email protected]/
v8: https://lore.kernel.org/linux-perf-users/[email protected]/

Changes since v8
================

- Rebase onto perf-tools-next at 6ae6fb96ccd4.

- Move the function-view hierarchy construction, aggregation, sorting, and column formatting to util/c2c-function.c, as suggested by Namhyung. Keep only the TUI browser, key handling, and cacheline detail action in ui/browsers/c2c-function.c.

- Make the common model validate inputs before replacing existing state and keep its entries callchain-free during construction and teardown, independent of the caller's current callchain setting.

- Simplify three rbtree node-to-entry conversions by using rb_entry() directly with the nested hist_entry rb_node, as suggested by Namhyung.

- Clarify that Cycles % uses the surviving level-1 entries after pruning. No functional change.

Changes since v7
================

- Keep c2c-function.o in libperf-ui.a and drop the v7 tools/perf/Build change, as Namhyung suggested. builtin-c2c.c now passes the cacheline histograms, coalescing fields, symbol_full flag, and cacheline detail callback through struct c2c_function_view_args. The browser no longer references command-private state.

- Move the shared c2c types and the two column-formatting callbacks into new util/c2c.h and util/c2c.c. Keep struct perf_c2c, the command instance, and perf_c2c__browse_cacheline() private to builtin-c2c.c.

- Rebase onto perf-tools-next at bf10e6ee2ac3.

Changes since v6
================

- Link c2c-function.o directly into perf under CONFIG_SLANG instead of including it in libperf-ui.a. The browser depends on state and callbacks provided by builtin-c2c.o, which is not linked into python/perf.so, while libperf-ui.a is linked under --whole-archive. This fixes the unresolved symbols seen when importing the Python module and keeps the TUI-only object out of NO_SLANG builds.

- Rebase onto perf-tools-next at d74fb8c4c87f.

Changes since v5
================

- Give the function-view children their own references instead of borrowing them, as suggested by Namhyung. They set ops and take refs via map_symbol__copy() and thread__get(), so hist_entry__delete() frees them; the custom child destructor and the WARN_ON_ONCE(report_hierarchy) guard are gone.

- Add NO_SLANG stubs for the two TUI entry points declared in c2c.h, matching how util/hist.h declares its own.

- Spell out in the symbol renderer why the length returned by se_snprintf() cannot exceed the cell.

- Rebase onto perf-tools-next at d04ef71492fa.

No intended change to the rendered output, cacheline-view data, existing cacheline operations, or --stdio output.

Changes since v4
================

- Rebase onto perf-tools-next at 0d40fedcd1b9.

- Require iaddr in --coalesce before entering the function view; without it, coalesced samples cannot be reliably attributed.

- Reuse each source cacheline's existing index as the level-3 identity, so same-address sources no longer merge and 'd' finds the original entry, without adding fields to the shared C2C structures.

- Keep same-function reader/writer pairs, which the coalesced view cannot reliably tell apart from cross-thread contention.

- Robustness and cleanup: build the hierarchy only from filtered cachelines with a lightweight entry allocator; explicit mem_info__new() handling; a local bound in the symbol renderer; a NULL-map guard; deterministic tie-breaks; function-view-local row recounting; Ctrl-C as an exit key; and expanded man-page docs.

Changes since v3
================

Reworked the function view into a true function-centric hierarchy, as discussed with Namhyung:

- Level 1 is the read-side function itself, aggregating all of its code addresses into one entry and sorting by Cycles %.

- Level 2 is the contending function that writes the shared lines, aggregated across cachelines and sorted by store count. Level 3 is the specific cachelines.

- Dedicated code-address and offset columns were removed from the main view. Verbose function formatting can still include a representative code address, and full code-address information remains available in the per-cacheline detail view ('d').

- Lower-level entries are indented like the normal perf report hierarchy view, and entries with no contending writer are pruned.

- Reorganized the series from 14 mechanical patches into 9 logically self-contained patches.

Changes since v2
================

- Prefix helpers exported from builtin-c2c.c with c2c_, as suggested by Namhyung.

Changes since v1
================

- Add a worked man-page example, as suggested by Namhyung.

In the perf c2c TUI, press TAB in the cacheline view to switch to the function view. It presents a three-level hierarchy:

Level 1: read-side function, sorted by Cycles %
Level 2: functions writing the shared lines, sorted by store count Level 3: cachelines where the two functions contend

For example, with dequeue_pushable_task expanded to its level-2 writers and two of those writers expanded to their level-3 cachelines:

Shared Data Functions Table (19 entries, sorted on Cycles %)
Cycles Store
% count Function / Contending function / Cacheline
----------------------------------------------------------------------

  +  35.67%      876  + [k] cpupri_set
  +  24.31%      424  + [k] pull_rt_task
  -  16.53%      555  - [k] dequeue_pushable_task
                 145    - [k] pull_rt_task
                 145        0xff2d0082809da080
                 139    - [k] enqueue_pushable_task
                  70        0xff2d00a2071f9640
                  69        0xff2d0082809da000

A level-1 store count decomposes into its level-2 writers, and each writer's count decomposes into its level-3 cachelines (here 145 = 145, 139 = 70 + 69).

Keys in the function view:

  TAB/ESC/q/Ctrl-C   return to the cacheline view
  d                  show details for the selected level-3 cacheline
  e / +              expand / collapse the selected entry
  ?                  help

The common function-view model is in tools/perf/util/c2c-function.c. It constructs the hierarchy from the existing cacheline histograms into dedicated hists and provides the custom column formatters. The TUI front end remains in tools/perf/ui/browsers/c2c-function.c.

Testing: every commit builds with and without SLANG support. In both configurations python/perf.so has no unresolved symbols, the Python module imports successfully, and the full series passes perf test c2c and perf test 'import perf'. The cacheline-view --stdio output is byte-identical to the base commit. A TUI smoke test entered the function view and expanded its first level-1 entry; the rendered output was identical to the existing reference screen after trimming trailing spaces.

Jiebin Sun (9):
perf c2c: extract shared data structures into util/c2c.h perf c2c: add function view model skeleton
perf c2c: add column rendering for function view perf c2c: add HPP list parsing for function view columns perf c2c: add function view stats merge and memory management perf c2c: add function view hierarchy entry creation perf c2c: build and finalize the function view hierarchy perf c2c: add function view browser UI and cacheline detail perf c2c: document function view in perf-c2c man page

 tools/perf/Documentation/perf-c2c.txt |   71 ++
 tools/perf/builtin-c2c.c              |  115 +-
 tools/perf/ui/browsers/Build          |    1 +
 tools/perf/ui/browsers/c2c-function.c |  209 ++++
 tools/perf/util/Build                 |    2 +
 tools/perf/util/c2c-function.c        | 1642 +++++++++++++++++++++++++
 tools/perf/util/c2c.c                 |   21 +
 tools/perf/util/c2c.h                 |  135 ++
 8 files changed, 2094 insertions(+), 102 deletions(-)
 create mode 100644 tools/perf/ui/browsers/c2c-function.c
 create mode 100644 tools/perf/util/c2c-function.c
 create mode 100644 tools/perf/util/c2c.c
 create mode 100644 tools/perf/util/c2c.h
Signature · 1 line
2.52.0