Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf report: Add 'tgid' sort key

Sometimes we need to analyze the data in process level but current sort
keys only work on thread level. Let's add 'tgid' sort key for that as
'pid' is already taken for thread.

This will look mostly the same, but it only uses tgid instead of tid.
Here's an example of a process with two threads (thloop).

$ perf record -- perf test -w thloop

$ perf report --stdio -s tgid,pid -H
...
#
# Overhead Tgid:Command / Pid:Command
# ........... ..........................
#
100.00% 2018407:perf
50.34% 2018407:perf
49.66% 2018409:perf

Suggested-by: Stephane Eranian <eranian@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250509210421.197245-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
39922dc5 b9228817

+41
+1
tools/perf/Documentation/perf-report.txt
··· 94 94 95 95 - comm: command (name) of the task which can be read via /proc/<pid>/comm 96 96 - pid: command and tid of the task 97 + - tgid: command and tgid of the task 97 98 - dso: name of library or module executed at the time of sample 98 99 - dso_size: size of library or module executed at the time of sample 99 100 - symbol: name of function executed at the time of sample
+1
tools/perf/util/hist.h
··· 42 42 HISTC_TIME, 43 43 HISTC_DSO, 44 44 HISTC_THREAD, 45 + HISTC_TGID, 45 46 HISTC_COMM, 46 47 HISTC_CGROUP_ID, 47 48 HISTC_CGROUP,
+38
tools/perf/util/sort.c
··· 141 141 .se_width_idx = HISTC_THREAD, 142 142 }; 143 143 144 + /* --sort tgid */ 145 + 146 + static int64_t 147 + sort__tgid_cmp(struct hist_entry *left, struct hist_entry *right) 148 + { 149 + return thread__pid(right->thread) - thread__pid(left->thread); 150 + } 151 + 152 + static int hist_entry__tgid_snprintf(struct hist_entry *he, char *bf, 153 + size_t size, unsigned int width) 154 + { 155 + int tgid = thread__pid(he->thread); 156 + const char *comm = NULL; 157 + 158 + /* display comm of the thread-group leader */ 159 + if (thread__pid(he->thread) == thread__tid(he->thread)) { 160 + comm = thread__comm_str(he->thread); 161 + } else { 162 + struct maps *maps = thread__maps(he->thread); 163 + struct thread *leader = machine__find_thread(maps__machine(maps), 164 + tgid, tgid); 165 + if (leader) { 166 + comm = thread__comm_str(leader); 167 + thread__put(leader); 168 + } 169 + } 170 + width = max(7U, width) - 8; 171 + return repsep_snprintf(bf, size, "%7d:%-*.*s", tgid, width, width, comm ?: ""); 172 + } 173 + 174 + struct sort_entry sort_tgid = { 175 + .se_header = " Tgid:Command", 176 + .se_cmp = sort__tgid_cmp, 177 + .se_snprintf = hist_entry__tgid_snprintf, 178 + .se_width_idx = HISTC_TGID, 179 + }; 180 + 144 181 /* --sort simd */ 145 182 146 183 static int64_t ··· 2545 2508 2546 2509 static struct sort_dimension common_sort_dimensions[] = { 2547 2510 DIM(SORT_PID, "pid", sort_thread), 2511 + DIM(SORT_TGID, "tgid", sort_tgid), 2548 2512 DIM(SORT_COMM, "comm", sort_comm), 2549 2513 DIM(SORT_DSO, "dso", sort_dso), 2550 2514 DIM(SORT_SYM, "symbol", sort_sym),
+1
tools/perf/util/sort.h
··· 73 73 SORT_SYM_OFFSET, 74 74 SORT_ANNOTATE_DATA_TYPE_CACHELINE, 75 75 SORT_PARALLELISM, 76 + SORT_TGID, 76 77 77 78 /* branch stack specific sort keys */ 78 79 __SORT_BRANCH_STACK,