perf evlist: Add perf_evlist__id2sid method to get event ID related data
authorJiri Olsa <jolsa@redhat.com>
Thu, 11 Oct 2012 12:10:35 +0000 (14:10 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 7 Aug 2013 20:35:21 +0000 (17:35 -0300)
This will be helpful for PERF_FORMAT_GROUP samples where we need to
store ID related period value for each event.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-twmlgsbyim97p7cyohjwb1df@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index 10fcc0372aa9e457b3145c8a0d3774c10fc063e5..da2dd92d5b27ae58eee8650e090e54a92cd28eea 100644 (file)
@@ -337,21 +337,32 @@ static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
        return 0;
 }
 
-struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
+struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id)
 {
        struct hlist_head *head;
        struct perf_sample_id *sid;
        int hash;
 
-       if (evlist->nr_entries == 1)
-               return perf_evlist__first(evlist);
-
        hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
        head = &evlist->heads[hash];
 
        hlist_for_each_entry(sid, head, node)
                if (sid->id == id)
-                       return sid->evsel;
+                       return sid;
+
+       return NULL;
+}
+
+struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
+{
+       struct perf_sample_id *sid;
+
+       if (evlist->nr_entries == 1)
+               return perf_evlist__first(evlist);
+
+       sid = perf_evlist__id2sid(evlist, id);
+       if (sid)
+               return sid->evsel;
 
        if (!perf_evlist__sample_id_all(evlist))
                return perf_evlist__first(evlist);
index c7178b7b9951b6b070ca05f959bb8679f33d7132..327ababa67b6130991a0c6f32ea666c73b21babf 100644 (file)
@@ -78,6 +78,8 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
 
 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
 
+struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
+
 union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx);
 
 int perf_evlist__open(struct perf_evlist *evlist);