Skip to content

Commit

Permalink
perf tools: Expose 'addr' functions so they can be reused
Browse files Browse the repository at this point in the history
Move some functions and functionality related to the use of
'addr' out of builtin-script so they can be reused.

The moved functions are: is_bts_event() and sample_addr_correlates_sym()
and a new function perf_event__preprocess_sample_addr() is created from
bits of print_sample_addr().

perf_event__preprocess_sample_addr() is the equivalent of
perf_event__preprocess_sample() but for 'addr' instead of 'ip'.

Signed-off-by: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
ahunter6 authored and acmel committed Jul 25, 2014
1 parent f1dd146 commit 9b0d2d8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
34 changes: 1 addition & 33 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,52 +358,20 @@ static void print_sample_start(struct perf_sample *sample,
}
}

static bool is_bts_event(struct perf_event_attr *attr)
{
return ((attr->type == PERF_TYPE_HARDWARE) &&
(attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
(attr->sample_period == 1));
}

static bool sample_addr_correlates_sym(struct perf_event_attr *attr)
{
if ((attr->type == PERF_TYPE_SOFTWARE) &&
((attr->config == PERF_COUNT_SW_PAGE_FAULTS) ||
(attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN) ||
(attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)))
return true;

if (is_bts_event(attr))
return true;

return false;
}

static void print_sample_addr(union perf_event *event,
struct perf_sample *sample,
struct machine *machine,
struct thread *thread,
struct perf_event_attr *attr)
{
struct addr_location al;
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

printf("%16" PRIx64, sample->addr);

if (!sample_addr_correlates_sym(attr))
return;

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
sample->addr, &al);
if (!al.map)
thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
sample->addr, &al);

al.cpu = sample->cpu;
al.sym = NULL;

if (al.map)
al.sym = map__find_symbol(al.map, al.addr, NULL);
perf_event__preprocess_sample_addr(event, sample, machine, thread, &al);

if (PRINT_FIELD(SYM)) {
printf(" ");
Expand Down
42 changes: 42 additions & 0 deletions tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,45 @@ int perf_event__preprocess_sample(const union perf_event *event,

return 0;
}

bool is_bts_event(struct perf_event_attr *attr)
{
return attr->type == PERF_TYPE_HARDWARE &&
(attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
attr->sample_period == 1;
}

bool sample_addr_correlates_sym(struct perf_event_attr *attr)
{
if (attr->type == PERF_TYPE_SOFTWARE &&
(attr->config == PERF_COUNT_SW_PAGE_FAULTS ||
attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN ||
attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ))
return true;

if (is_bts_event(attr))
return true;

return false;
}

void perf_event__preprocess_sample_addr(union perf_event *event,
struct perf_sample *sample,
struct machine *machine,
struct thread *thread,
struct addr_location *al)
{
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
sample->addr, al);
if (!al->map)
thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
sample->addr, al);

al->cpu = sample->cpu;
al->sym = NULL;

if (al->map)
al->sym = map__find_symbol(al->map, al->addr, NULL);
}
10 changes: 10 additions & 0 deletions tools/perf/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ int perf_event__preprocess_sample(const union perf_event *event,
struct addr_location *al,
struct perf_sample *sample);

struct thread;

bool is_bts_event(struct perf_event_attr *attr);
bool sample_addr_correlates_sym(struct perf_event_attr *attr);
void perf_event__preprocess_sample_addr(union perf_event *event,
struct perf_sample *sample,
struct machine *machine,
struct thread *thread,
struct addr_location *al);

const char *perf_event__name(unsigned int id);

size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
Expand Down

0 comments on commit 9b0d2d8

Please sign in to comment.