aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-09-11 18:24:23 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-09-11 18:24:23 -0400
commit5555ded44698ed82ffa3d8742ec2994f695127bc (patch)
tree223aabd7b662345fbfc54caeb721c521fbe23968 /tools
parent0e9b07e574e544c1e840c59dabf39fef120620ae (diff)
perf evsel: Introduce perf_evsel__{str,int}val methods
Wrappers to the libtraceevent routines, so that we can further reduce the surface contact perf builtins have with it. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-rtmgzptvrifzjxqwb9vs6g1b@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/evsel.c35
-rw-r--r--tools/perf/util/evsel.h7
2 files changed, 42 insertions, 0 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 06f76441547..1506ba0453f 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -10,6 +10,7 @@
10#include <byteswap.h> 10#include <byteswap.h>
11#include <linux/bitops.h> 11#include <linux/bitops.h>
12#include "asm/bug.h" 12#include "asm/bug.h"
13#include "event-parse.h"
13#include "evsel.h" 14#include "evsel.h"
14#include "evlist.h" 15#include "evlist.h"
15#include "util.h" 16#include "util.h"
@@ -1000,3 +1001,37 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
1000 1001
1001 return 0; 1002 return 0;
1002} 1003}
1004
1005char *perf_evsel__strval(struct perf_evsel *evsel, struct perf_sample *sample,
1006 const char *name)
1007{
1008 struct format_field *field = pevent_find_field(evsel->tp_format, name);
1009 int offset;
1010
1011 if (!field)
1012 return NULL;
1013
1014 offset = field->offset;
1015
1016 if (field->flags & FIELD_IS_DYNAMIC) {
1017 offset = *(int *)(sample->raw_data + field->offset);
1018 offset &= 0xffff;
1019 }
1020
1021 return sample->raw_data + offset;
1022}
1023
1024u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
1025 const char *name)
1026{
1027 struct format_field *field = pevent_find_field(evsel->tp_format, name);
1028 u64 val;
1029
1030 if (!field)
1031 return 0;
1032
1033 val = pevent_read_number(evsel->tp_format->pevent,
1034 sample->raw_data + field->offset, field->size);
1035 return val;
1036
1037}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 390690eb878..dc40fe32210 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -120,6 +120,13 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
120 struct thread_map *threads); 120 struct thread_map *threads);
121void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads); 121void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
122 122
123struct perf_sample;
124
125char *perf_evsel__strval(struct perf_evsel *evsel, struct perf_sample *sample,
126 const char *name);
127u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
128 const char *name);
129
123#define perf_evsel__match(evsel, t, c) \ 130#define perf_evsel__match(evsel, t, c) \
124 (evsel->attr.type == PERF_TYPE_##t && \ 131 (evsel->attr.type == PERF_TYPE_##t && \
125 evsel->attr.config == PERF_COUNT_##c) 132 evsel->attr.config == PERF_COUNT_##c)