perf evsel: Introduce perf_evsel__{str, int}val methods
Commit-ID: 5555ded44698ed82ffa3d8742ec2994f695127bc Gitweb: http://git.kernel.org/tip/5555ded44698ed82ffa3d8742ec2994f695127bc Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 11 Sep 2012 19:24:23 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 11 Sep 2012 19:24:23 -0300
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 <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/evsel.c | 35 +++++++++++++++++++++++++++++++++++ tools/perf/util/evsel.h | 7 +++++++ 2 files changed, 42 insertions(+), 0 deletions(-)
tools/perf/util/evsel.c +35 -0
@@ -10,6 +10,7 @@#include <byteswap.h> #include <linux/bitops.h> #include "asm/bug.h" +#include "event-parse.h" #include "evsel.h" #include "evlist.h" #include "util.h"
@@ -1000,3 +1001,37 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,return 0 ; } + +char *perf_evsel__strval (struct perf_evsel *evsel,struct perf_sample *sample, +const char *name) +{ +struct format_field *field =pevent_find_field (evsel->tp_format, name); +int offset; + +if (!field) +return NULL ; + + offset = field->offset; + +if (field->flags &FIELD_IS_DYNAMIC ) { + offset = *(int *)(sample->raw_data + field->offset); + offset &=0xffff ; + } + +return sample->raw_data + offset; +} + +u64 perf_evsel__intval (struct perf_evsel *evsel,struct perf_sample *sample, +const char *name) +{ +struct format_field *field =pevent_find_field (evsel->tp_format, name); +u64 val; + +if (!field) +return 0 ; + + val =pevent_read_number (evsel->tp_format->pevent, + sample->raw_data + field->offset, field->size); +return val; + +}
tools/perf/util/evsel.h +7 -0
@@ -120,6 +120,13 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, struct thread_map *threads);void perf_evsel__close (struct perf_evsel *evsel,int ncpus,int nthreads); +struct perf_sample ; + +char *perf_evsel__strval (struct perf_evsel *evsel,struct perf_sample *sample, +const char *name); +u64 perf_evsel__intval (struct perf_evsel *evsel,struct perf_sample *sample, +const char *name); +#define perf_evsel__match (evsel, t, c) \ (evsel->attr.type == PERF_TYPE_##t && \ evsel->attr.config == PERF_COUNT_##c)