aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-07-22 09:17:39 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-07-25 11:08:34 -0400
commit9b0d2d875d57d85fdfb35ac27f89951520a8b473 (patch)
tree2b5007f4e01912ee107f28fa8e4fc16e4448db7f /tools
parentf1dd1460a40894b00bbeacd753025e9251ec11bd (diff)
perf tools: Expose 'addr' functions so they can be reused
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 <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> 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/r/1406035081-14301-31-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-script.c34
-rw-r--r--tools/perf/util/event.c42
-rw-r--r--tools/perf/util/event.h10
3 files changed, 53 insertions, 33 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 582da97872e5..f57035b89c15 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -358,27 +358,6 @@ static void print_sample_start(struct perf_sample *sample,
358 } 358 }
359} 359}
360 360
361static bool is_bts_event(struct perf_event_attr *attr)
362{
363 return ((attr->type == PERF_TYPE_HARDWARE) &&
364 (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
365 (attr->sample_period == 1));
366}
367
368static bool sample_addr_correlates_sym(struct perf_event_attr *attr)
369{
370 if ((attr->type == PERF_TYPE_SOFTWARE) &&
371 ((attr->config == PERF_COUNT_SW_PAGE_FAULTS) ||
372 (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN) ||
373 (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)))
374 return true;
375
376 if (is_bts_event(attr))
377 return true;
378
379 return false;
380}
381
382static void print_sample_addr(union perf_event *event, 361static void print_sample_addr(union perf_event *event,
383 struct perf_sample *sample, 362 struct perf_sample *sample,
384 struct machine *machine, 363 struct machine *machine,
@@ -386,24 +365,13 @@ static void print_sample_addr(union perf_event *event,
386 struct perf_event_attr *attr) 365 struct perf_event_attr *attr)
387{ 366{
388 struct addr_location al; 367 struct addr_location al;
389 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
390 368
391 printf("%16" PRIx64, sample->addr); 369 printf("%16" PRIx64, sample->addr);
392 370
393 if (!sample_addr_correlates_sym(attr)) 371 if (!sample_addr_correlates_sym(attr))
394 return; 372 return;
395 373
396 thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, 374 perf_event__preprocess_sample_addr(event, sample, machine, thread, &al);
397 sample->addr, &al);
398 if (!al.map)
399 thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
400 sample->addr, &al);
401
402 al.cpu = sample->cpu;
403 al.sym = NULL;
404
405 if (al.map)
406 al.sym = map__find_symbol(al.map, al.addr, NULL);
407 375
408 if (PRINT_FIELD(SYM)) { 376 if (PRINT_FIELD(SYM)) {
409 printf(" "); 377 printf(" ");
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 7e0e8ae568ec..1398c83d896d 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -874,3 +874,45 @@ int perf_event__preprocess_sample(const union perf_event *event,
874 874
875 return 0; 875 return 0;
876} 876}
877
878bool is_bts_event(struct perf_event_attr *attr)
879{
880 return attr->type == PERF_TYPE_HARDWARE &&
881 (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
882 attr->sample_period == 1;
883}
884
885bool sample_addr_correlates_sym(struct perf_event_attr *attr)
886{
887 if (attr->type == PERF_TYPE_SOFTWARE &&
888 (attr->config == PERF_COUNT_SW_PAGE_FAULTS ||
889 attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN ||
890 attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ))
891 return true;
892
893 if (is_bts_event(attr))
894 return true;
895
896 return false;
897}
898
899void perf_event__preprocess_sample_addr(union perf_event *event,
900 struct perf_sample *sample,
901 struct machine *machine,
902 struct thread *thread,
903 struct addr_location *al)
904{
905 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
906
907 thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
908 sample->addr, al);
909 if (!al->map)
910 thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
911 sample->addr, al);
912
913 al->cpu = sample->cpu;
914 al->sym = NULL;
915
916 if (al->map)
917 al->sym = map__find_symbol(al->map, al->addr, NULL);
918}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index e5dd40addb30..94d6976180da 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -288,6 +288,16 @@ int perf_event__preprocess_sample(const union perf_event *event,
288 struct addr_location *al, 288 struct addr_location *al,
289 struct perf_sample *sample); 289 struct perf_sample *sample);
290 290
291struct thread;
292
293bool is_bts_event(struct perf_event_attr *attr);
294bool sample_addr_correlates_sym(struct perf_event_attr *attr);
295void perf_event__preprocess_sample_addr(union perf_event *event,
296 struct perf_sample *sample,
297 struct machine *machine,
298 struct thread *thread,
299 struct addr_location *al);
300
291const char *perf_event__name(unsigned int id); 301const char *perf_event__name(unsigned int id);
292 302
293size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, 303size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,