perf evlist: Refactor evlist__scnprintf_evsels()
authorIan Rogers <irogers@google.com>
Wed, 2 Apr 2025 20:15:47 +0000 (13:15 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 8 May 2025 15:47:46 +0000 (12:47 -0300)
commitf0f245eaa2bca3595a0e775e9abdf7de909c0450
tree62599aaf0331bff0d57b1a0a98cc909ac1ae4b8c
parenta5efaf90089e6dc50dc1f03174cbba3da37af986
perf evlist: Refactor evlist__scnprintf_evsels()

Switch output to using a strbuf so the storage can be resized.

Add a maximum size argument to avoid too much output that may happen for
uncore events.

Rename as scnprintf is no longer used.

Committer testing:

  With the patch applied:

  root@number:~# perf probe -x ~/bin/perf evlist__format_evsels
  Added new event:
    probe_perf:evlist_format_evsels (on evlist__format_evsels in /home/acme/bin/perf)

  You can now use it in all perf tools, such as:

   perf record -e probe_perf:evlist_format_evsels -aR sleep 1

  root@number:~# perf probe -l
    probe_perf:evlist_format_evsels (on evlist__format_evsels@util/evlist.c in /home/acme/bin/perf)
  root@number:~# perf trace -e probe_perf:*/max-stack=10/ perf record -e cycles,instructions,cache-misses /tmp/bla
  Failed to collect 'cycles,instructions,cache-misses' for the '/tmp/bla' workload: Permission denied
       0.000 perf/3893011 probe_perf:evlist_format_evsels(__probe_ip: 6183397)
                                         evlist__format_evsels (/home/acme/bin/perf)
                                         __cmd_record (/home/acme/bin/perf)
                                         cmd_record (/home/acme/bin/perf)
                                         run_builtin (/home/acme/bin/perf)
                                         handle_internal_command (/home/acme/bin/perf)
                                         run_argv (/home/acme/bin/perf)
                                         main (/home/acme/bin/perf)
                                         __libc_start_call_main (/usr/lib64/libc.so.6)
                                         __libc_start_main@@GLIBC_2.34 (/usr/lib64/libc.so.6)
                                         _start (/home/acme/bin/perf)
  root@number:~#

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Levi Yun <yeoreum.yun@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20250402201549.4090305-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-record.c
tools/perf/util/evlist.c
tools/perf/util/evlist.h