perf tools: Add perf_pmu__format_bits()
authorAdrian Hunter <adrian.hunter@intel.com>
Fri, 17 Jul 2015 16:33:49 +0000 (19:33 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 6 Aug 2015 19:49:01 +0000 (16:49 -0300)
Add perf_pmu__format_bits() to get the format bits for a PMU config
term.  Intel PT will use this to validate terms and to record format
bits to enable later interpreting the config from the attribute stored
in the perf.data file.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1437150840-31811-15-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/pmu.c
tools/perf/util/pmu.h

index b615cdf211d6e241109ad66b988f93ab3e65c5af..c548ec89c8bcfda19a6ad83da4a598f87b558dcf 100644 (file)
@@ -542,7 +542,7 @@ struct perf_pmu *perf_pmu__find(const char *name)
 }
 
 static struct perf_pmu_format *
-pmu_find_format(struct list_head *formats, char *name)
+pmu_find_format(struct list_head *formats, const char *name)
 {
        struct perf_pmu_format *format;
 
@@ -553,6 +553,21 @@ pmu_find_format(struct list_head *formats, char *name)
        return NULL;
 }
 
+__u64 perf_pmu__format_bits(struct list_head *formats, const char *name)
+{
+       struct perf_pmu_format *format = pmu_find_format(formats, name);
+       __u64 bits = 0;
+       int fbit;
+
+       if (!format)
+               return 0;
+
+       for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS)
+               bits |= 1ULL << fbit;
+
+       return bits;
+}
+
 /*
  * Sets value based on the format definition (format parameter)
  * and unformated value (value parameter).
index 7b9c8cf8ae3e590578abb0f71a41739cb8fc968a..5d7e84466bee5a0124fe8c81db64e83a9f483e99 100644 (file)
@@ -54,6 +54,7 @@ int perf_pmu__config_terms(struct list_head *formats,
                           struct perf_event_attr *attr,
                           struct list_head *head_terms,
                           bool zero, struct parse_events_error *error);
+__u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
                          struct perf_pmu_info *info);
 struct list_head *perf_pmu__alias(struct perf_pmu *pmu,