[PATCH 1/8] perf tools: Add thread_map__has function

From: Jiri Olsa
Date: Tue Apr 12 2016 - 09:29:45 EST


Adding thread_map__has function to return bool
of pid presence in threads map.

Link: http://lkml.kernel.org/n/tip-f3ilapuk59z22pi7qs7b0qw9@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/thread_map.c | 12 ++++++++++++
tools/perf/util/thread_map.h | 1 +
2 files changed, 13 insertions(+)

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 267112b4e3db..878ac0687b0a 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -436,3 +436,15 @@ struct thread_map *thread_map__new_event(struct thread_map_event *event)

return threads;
}
+
+bool thread_map__has(struct thread_map *threads, pid_t pid)
+{
+ int i;
+
+ for (i = 0; i < threads->nr; ++i) {
+ if (threads->map[i].pid == pid)
+ return true;
+ }
+
+ return false;
+}
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 85e4c7c4fbde..9a065ea69ff1 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -55,4 +55,5 @@ static inline char *thread_map__comm(struct thread_map *map, int thread)
}

void thread_map__read_comms(struct thread_map *threads);
+bool thread_map__has(struct thread_map *threads, pid_t pid);
#endif /* __PERF_THREAD_MAP_H */
--
2.4.11