aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/perf/threadmap.c
diff options
context:
space:
mode:
authorIan Rogers <[email protected]>2025-05-19 19:51:39 +0000
committerArnaldo Carvalho de Melo <[email protected]>2025-05-21 18:07:13 +0000
commit3ee2255c4fc2b7d424d5f5c744364189b659f123 (patch)
tree0d633ea28360a63d778d17c5fb1e51f503eb5c92 /tools/lib/perf/threadmap.c
parentlibperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_ma... (diff)
downloadkernel-3ee2255c4fc2b7d424d5f5c744364189b659f123.tar.gz
kernel-3ee2255c4fc2b7d424d5f5c744364189b659f123.zip
libperf threadmap: Add perf_thread_map__idx()
Allow computation of thread map index from a PID. Note, with a 'struct perf_cpu_map' the sorted nature allows for a binary search to compute the index which isn't currently possible with a 'struct perf_thread_map' as they aren't guaranteed sorted. Signed-off-by: Ian Rogers <[email protected]> Acked-by: Gautam Menghani <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/lib/perf/threadmap.c')
-rw-r--r--tools/lib/perf/threadmap.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/lib/perf/threadmap.c b/tools/lib/perf/threadmap.c
index 3ca9ba4987fc..db431b036f57 100644
--- a/tools/lib/perf/threadmap.c
+++ b/tools/lib/perf/threadmap.c
@@ -104,3 +104,15 @@ pid_t perf_thread_map__pid(struct perf_thread_map *map, int idx)
return map->map[idx].pid;
}
+
+int perf_thread_map__idx(struct perf_thread_map *threads, pid_t pid)
+{
+ if (!threads)
+ return pid == -1 ? 0 : -1;
+
+ for (int i = 0; i < threads->nr; ++i) {
+ if (threads->map[i].pid == pid)
+ return i;
+ }
+ return -1;
+}