summaryrefslogtreecommitdiff
path: root/tools/perf/util/c2c-function.c
AgeCommit message (Collapse)Author
2026-09-25perf c2c: Add stdio support for the function viewJiebin Sun
The function view is currently TUI-only, so it cannot be used by builds without SLANG support, when output is piped, or from a script. Add a --function option that prints the fully expanded three-level hierarchy to stdout. Keep the stdio renderer in builtin-c2c.c and reuse the common function-view model introduced by the merged series. Export only the coalescing-field capability check from the model, preserving the util/UI boundary and leaving the TUI object in libperf-ui.a. Stop padding the final identity column in symbol_view_entry(). The generic formatter pads non-final columns but deliberately leaves the final column unpadded, avoiding trailing whitespace in function-view table rows. The TUI remains unchanged because its browser clears the rest of each rendered row. --function implies --stdio and is rejected together with --stats. Validate the iaddr requirement before processing events. Return function-view build failures from the report command, and preserve TUI browser errors when converting the display helpers to return a status. Committer notes: root@x2:~# uname -r 7.2.5-200.fc44.x86_64 root@x2:~# rpm -q kernel-debuginfo kernel-debuginfo-7.2.5-200.fc44.x86_64 root@x2:~# perf c2c record perf bench futex hash -t 4 -r 1 -s > /dev/null 2>&1 root@x2:~# perf c2c report --stdio --function | grep "Functions Table" -A25 Shared Data Functions Table ================================================= # # Cycles Store # % count Function / Contending function / Cacheline # ......... ....... .............................. # - 47.89% 703 - [k] _raw_spin_lock 322 - [k] _raw_spin_lock 24 0xffff8b6dcbadf040 23 0xffff8b6dcbadf2c0 23 0xffff8b6dcbadf080 23 0xffff8b6dcbadf380 22 0xffff8b6dcbadf280 22 0xffff8b6dcbadf140 22 0xffff8b6dcbadf340 21 0xffff8b6dcbadf300 21 0xffff8b6dcbadf400 20 0xffff8b6dcbadf1c0 19 0xffff8b6dcbadf3c0 19 0xffff8b6dcbadf180 19 0xffff8b6dcbadf0c0 17 0xffff8b6dcbadf100 16 0xffff8b6dcbadf240 11 0xffff8b6dcbadf200 205 - [k] futex_q_unlock root@x2:~# Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-08-17perf c2c: build and finalize the function view hierarchyJiebin Sun
Add the builder that walks the top-level cacheline entries and, for each read-side function, correlates the functions that write the same lines (level 2) and the specific cachelines they contend over (level 3) within each retained detail histogram. Aggregate the write traffic per contending function, resort by store count, and prune writers/functions with no contention. The finalize pass then computes the Cycles % denominator from the surviving level-1 entries after pruning, so the column shows each function's share of the functions retained in the table rather than of the whole recording -- the semantics documented for Cycles % in perf-c2c.txt. Expose c2c_function__build() and c2c_function__reset() for the TUI front end added by the next patch. The builder requires iaddr in the cacheline coalescing fields and returns the completed hists through an output argument. Validate the inputs before replacing an existing model. Function-view entries do not carry callchains. Suppress callchain handling while building and tearing down the model so the common API does not depend on the caller's current callchain setting. Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-08-17perf c2c: add function view hierarchy entry creationJiebin Sun
Add the entry-creation layer: owned-reference child allocation and insertion, and the level-1/2/3 lookup-or-create functions keyed by function symbol (level 1 read-side, level 2 writer) and by the source cacheline's existing index (level 3). Give synthetic children normal entry operations and acquire their thread and map-symbol references. This lets the hierarchy teardown use hist_entry__delete() for the common fields while the function-view free callback handles the private child tree and containing allocation. Reuse cacheline_idx to preserve the source entry identity without adding function-view-only state. Add c2c_function__find_cacheline() to locate the original cacheline entry by the same index. These are driven by the hierarchy builder in the next patch and are __maybe_unused until then. Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-08-17perf c2c: add function view stats merge and memory managementJiebin Sun
Add the per-entry stats/cstats aggregation helpers and hierarchy teardown. Child common fields are released through hist_entry__delete(), while the function-view free callback handles the private child tree and containing allocation. Also add a helper for pruning writer entries with no stores or cacheline children. These are used by the entry-creation and builder patches that follow and are __maybe_unused until then. Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-08-17perf c2c: add HPP list parsing for function view columnsJiebin Sun
Add the parser that builds the function view's local HPP output and sort lists from field strings. This includes dimension lookup, comparator wrappers, c2c_fmt allocation, and the initialization entry points used by the hierarchy builder. The generic perf_hpp__setup_output_field() registers formats on the global perf_hpp_list. Using it here would leave the function view's local list without output columns and modify the cacheline view's list instead. Add c2c_function_hists__setup_output_field() to append sort keys to the local output list. Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-08-17perf c2c: add column rendering for function viewJiebin Sun
Add renderers for the function view's Cycles %, Store count, and hierarchy identity columns. The identity column renders the read-side function, contending writer, or cacheline, with indentation for the hierarchy level. Also add width and header helpers, estimated-cycle calculation, comparators, and the dimension table that ties them together. Clamp the identity renderer's returned length to its local buffer before using it for pointer and padding calculations. This handles snprintf-style would-have-been lengths without changing normal output. The next patch connects these dimensions to the view's HPP lists, so the symbols used only there are temporarily marked __maybe_unused. Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-08-17perf c2c: add function view model skeletonJiebin Sun
Add the initial common model for the c2c function view: model state and small helpers shared by the hierarchy construction and formatting added in later patches. Build the model from util/ so it remains independent of the TUI and command-private symbols. Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Reviewed-by: Tianyou Li <tianyou.li@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: James Clark <james.clark@linaro.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>