[PATCH 11/13] perf tools: Add a new pmu interface to iterate over all events

From: Jiri Olsa
Date: Wed Jul 16 2014 - 16:04:53 EST


From: Andi Kleen <ak@xxxxxxxxxxxxxxx>

With calling a callback. To be used in test code added in the next
patch.

Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Link: http://lkml.kernel.org/n/1405123165-22666-10-git-send-email-andi@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/pmu.c | 18 ++++++++++++++++++
tools/perf/util/pmu.h | 2 ++
2 files changed, 20 insertions(+)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 8714f9a11abe..397e4004fcdf 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -869,3 +869,21 @@ bool pmu_have_event(const char *pname, const char *name)
}
return false;
}
+
+int pmu_iterate_events(int (*func)(const char *pmu, const char *name))
+{
+ int ret = 0;
+ struct perf_pmu *pmu;
+ struct perf_pmu_alias *alias;
+
+ perf_pmu__find("cpu"); /* Load PMUs */
+ pmu = NULL;
+ while ((pmu = perf_pmu__scan(pmu)) != NULL) {
+ list_for_each_entry(alias, &pmu->aliases, list) {
+ ret = func(pmu->name, alias->name);
+ if (ret != 0)
+ break;
+ }
+ }
+ return ret;
+}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 583d21e4cefb..87a1da471686 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -47,5 +47,7 @@ bool pmu_have_event(const char *pname, const char *name);

int perf_pmu__test(void);

+int pmu_iterate_events(int (*func)(const char *, const char *name));
+
extern const char *json_file;
#endif /* __PMU_H */
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/