aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/perf-report.txt15
-rw-r--r--tools/perf/Makefile2
-rw-r--r--tools/perf/builtin-annotate.c24
-rw-r--r--tools/perf/builtin-record.c13
-rw-r--r--tools/perf/builtin-report.c255
-rw-r--r--tools/perf/builtin-stat.c3
-rw-r--r--tools/perf/builtin-top.c6
-rw-r--r--tools/perf/perf.c77
-rw-r--r--tools/perf/perf.h8
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/header.h2
-rw-r--r--tools/perf/util/include/linux/kernel.h8
-rw-r--r--tools/perf/util/parse-events.c182
-rw-r--r--tools/perf/util/parse-events.h5
-rw-r--r--tools/perf/util/string.h3
-rw-r--r--tools/perf/util/strlist.c20
-rw-r--r--tools/perf/util/strlist.h11
-rw-r--r--tools/perf/util/symbol.c145
-rw-r--r--tools/perf/util/symbol.h1
-rw-r--r--tools/perf/util/util.h2
20 files changed, 616 insertions, 167 deletions
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 8aa3f8c88707..e72e93110782 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -24,6 +24,9 @@ OPTIONS
24--dsos=:: 24--dsos=::
25 Only consider symbols in these dsos. CSV that understands 25 Only consider symbols in these dsos. CSV that understands
26 file://filename entries. 26 file://filename entries.
27-n
28--show-nr-samples
29 Show the number of samples for each symbol
27-C:: 30-C::
28--comms=:: 31--comms=::
29 Only consider symbols in these comms. CSV that understands 32 Only consider symbols in these comms. CSV that understands
@@ -33,6 +36,18 @@ OPTIONS
33 Only consider these symbols. CSV that understands 36 Only consider these symbols. CSV that understands
34 file://filename entries. 37 file://filename entries.
35 38
39-w::
40--field-width=::
41 Force each column width to the provided list, for large terminal
42 readability.
43
44-t::
45--field-separator=::
46
47 Use a special separator character and don't pad with spaces, replacing
48 all occurances of this separator in symbol names (and other output)
49 with a '.' character, that thus it's the only non valid separator.
50
36SEE ALSO 51SEE ALSO
37-------- 52--------
38linkperf:perf-stat[1] 53linkperf:perf-stat[1]
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 7822b3d6baca..a5e9b876ca09 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -345,7 +345,7 @@ BUILTIN_OBJS += builtin-stat.o
345BUILTIN_OBJS += builtin-top.o 345BUILTIN_OBJS += builtin-top.o
346 346
347PERFLIBS = $(LIB_FILE) 347PERFLIBS = $(LIB_FILE)
348EXTLIBS = 348EXTLIBS = -lbfd
349 349
350# 350#
351# Platform specific tweaks 351# Platform specific tweaks
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 5f9eefecc574..1dba568e1941 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -74,20 +74,12 @@ struct fork_event {
74 u32 pid, ppid; 74 u32 pid, ppid;
75}; 75};
76 76
77struct period_event {
78 struct perf_event_header header;
79 u64 time;
80 u64 id;
81 u64 sample_period;
82};
83
84typedef union event_union { 77typedef union event_union {
85 struct perf_event_header header; 78 struct perf_event_header header;
86 struct ip_event ip; 79 struct ip_event ip;
87 struct mmap_event mmap; 80 struct mmap_event mmap;
88 struct comm_event comm; 81 struct comm_event comm;
89 struct fork_event fork; 82 struct fork_event fork;
90 struct period_event period;
91} event_t; 83} event_t;
92 84
93 85
@@ -998,19 +990,6 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head)
998} 990}
999 991
1000static int 992static int
1001process_period_event(event_t *event, unsigned long offset, unsigned long head)
1002{
1003 dprintf("%p [%p]: PERF_EVENT_PERIOD: time:%Ld, id:%Ld: period:%Ld\n",
1004 (void *)(offset + head),
1005 (void *)(long)(event->header.size),
1006 event->period.time,
1007 event->period.id,
1008 event->period.sample_period);
1009
1010 return 0;
1011}
1012
1013static int
1014process_event(event_t *event, unsigned long offset, unsigned long head) 993process_event(event_t *event, unsigned long offset, unsigned long head)
1015{ 994{
1016 switch (event->header.type) { 995 switch (event->header.type) {
@@ -1025,9 +1004,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1025 1004
1026 case PERF_EVENT_FORK: 1005 case PERF_EVENT_FORK:
1027 return process_fork_event(event, offset, head); 1006 return process_fork_event(event, offset, head);
1028
1029 case PERF_EVENT_PERIOD:
1030 return process_period_event(event, offset, head);
1031 /* 1007 /*
1032 * We dont process them right now but they are fine: 1008 * We dont process them right now but they are fine:
1033 */ 1009 */
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4ef78a5e6f32..6da09928130f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -43,6 +43,7 @@ static int call_graph = 0;
43static int verbose = 0; 43static int verbose = 0;
44static int inherit_stat = 0; 44static int inherit_stat = 0;
45static int no_samples = 0; 45static int no_samples = 0;
46static int sample_address = 0;
46 47
47static long samples; 48static long samples;
48static struct timeval last_read; 49static struct timeval last_read;
@@ -313,6 +314,10 @@ static void pid_synthesize_mmap_samples(pid_t pid)
313 if (*pbf == 'x') { /* vm_exec */ 314 if (*pbf == 'x') { /* vm_exec */
314 char *execname = strchr(bf, '/'); 315 char *execname = strchr(bf, '/');
315 316
317 /* Catch VDSO */
318 if (execname == NULL)
319 execname = strstr(bf, "[vdso]");
320
316 if (execname == NULL) 321 if (execname == NULL)
317 continue; 322 continue;
318 323
@@ -401,6 +406,9 @@ static void create_counter(int counter, int cpu, pid_t pid)
401 if (inherit_stat) 406 if (inherit_stat)
402 attr->inherit_stat = 1; 407 attr->inherit_stat = 1;
403 408
409 if (sample_address)
410 attr->sample_type |= PERF_SAMPLE_ADDR;
411
404 if (call_graph) 412 if (call_graph)
405 attr->sample_type |= PERF_SAMPLE_CALLCHAIN; 413 attr->sample_type |= PERF_SAMPLE_CALLCHAIN;
406 414
@@ -645,6 +653,8 @@ static const struct option options[] = {
645 "be more verbose (show counter open errors, etc)"), 653 "be more verbose (show counter open errors, etc)"),
646 OPT_BOOLEAN('s', "stat", &inherit_stat, 654 OPT_BOOLEAN('s', "stat", &inherit_stat,
647 "per thread counts"), 655 "per thread counts"),
656 OPT_BOOLEAN('d', "data", &sample_address,
657 "Sample addresses"),
648 OPT_BOOLEAN('n', "no-samples", &no_samples, 658 OPT_BOOLEAN('n', "no-samples", &no_samples,
649 "don't sample"), 659 "don't sample"),
650 OPT_END() 660 OPT_END()
@@ -654,7 +664,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
654{ 664{
655 int counter; 665 int counter;
656 666
657 argc = parse_options(argc, argv, options, record_usage, 0); 667 argc = parse_options(argc, argv, options, record_usage,
668 PARSE_OPT_STOP_AT_NON_OPTION);
658 if (!argc && target_pid == -1 && !system_wide) 669 if (!argc && target_pid == -1 && !system_wide)
659 usage_with_options(record_usage, options); 670 usage_with_options(record_usage, options);
660 671
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 4e5cc266311e..b20a4b6e31b7 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -33,8 +33,10 @@ static char *vmlinux = NULL;
33 33
34static char default_sort_order[] = "comm,dso"; 34static char default_sort_order[] = "comm,dso";
35static char *sort_order = default_sort_order; 35static char *sort_order = default_sort_order;
36static char *dso_list_str, *comm_list_str, *sym_list_str; 36static char *dso_list_str, *comm_list_str, *sym_list_str,
37 *col_width_list_str;
37static struct strlist *dso_list, *comm_list, *sym_list; 38static struct strlist *dso_list, *comm_list, *sym_list;
39static char *field_sep;
38 40
39static int input; 41static int input;
40static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; 42static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
@@ -49,6 +51,7 @@ static int verbose;
49static int modules; 51static int modules;
50 52
51static int full_paths; 53static int full_paths;
54static int show_nr_samples;
52 55
53static unsigned long page_size; 56static unsigned long page_size;
54static unsigned long mmap_window = 32; 57static unsigned long mmap_window = 32;
@@ -98,13 +101,6 @@ struct fork_event {
98 u32 pid, ppid; 101 u32 pid, ppid;
99}; 102};
100 103
101struct period_event {
102 struct perf_event_header header;
103 u64 time;
104 u64 id;
105 u64 sample_period;
106};
107
108struct lost_event { 104struct lost_event {
109 struct perf_event_header header; 105 struct perf_event_header header;
110 u64 id; 106 u64 id;
@@ -124,11 +120,37 @@ typedef union event_union {
124 struct mmap_event mmap; 120 struct mmap_event mmap;
125 struct comm_event comm; 121 struct comm_event comm;
126 struct fork_event fork; 122 struct fork_event fork;
127 struct period_event period;
128 struct lost_event lost; 123 struct lost_event lost;
129 struct read_event read; 124 struct read_event read;
130} event_t; 125} event_t;
131 126
127static int repsep_fprintf(FILE *fp, const char *fmt, ...)
128{
129 int n;
130 va_list ap;
131
132 va_start(ap, fmt);
133 if (!field_sep)
134 n = vfprintf(fp, fmt, ap);
135 else {
136 char *bf = NULL;
137 n = vasprintf(&bf, fmt, ap);
138 if (n > 0) {
139 char *sep = bf;
140 while (1) {
141 sep = strchr(sep, *field_sep);
142 if (sep == NULL)
143 break;
144 *sep = '.';
145 }
146 }
147 fputs(bf, fp);
148 free(bf);
149 }
150 va_end(ap);
151 return n;
152}
153
132static LIST_HEAD(dsos); 154static LIST_HEAD(dsos);
133static struct dso *kernel_dso; 155static struct dso *kernel_dso;
134static struct dso *vdso; 156static struct dso *vdso;
@@ -360,12 +382,28 @@ static struct thread *thread__new(pid_t pid)
360 return self; 382 return self;
361} 383}
362 384
385static unsigned int dsos__col_width,
386 comms__col_width,
387 threads__col_width;
388
363static int thread__set_comm(struct thread *self, const char *comm) 389static int thread__set_comm(struct thread *self, const char *comm)
364{ 390{
365 if (self->comm) 391 if (self->comm)
366 free(self->comm); 392 free(self->comm);
367 self->comm = strdup(comm); 393 self->comm = strdup(comm);
368 return self->comm ? 0 : -ENOMEM; 394 if (!self->comm)
395 return -ENOMEM;
396
397 if (!col_width_list_str && !field_sep &&
398 (!comm_list || strlist__has_entry(comm_list, comm))) {
399 unsigned int slen = strlen(comm);
400 if (slen > comms__col_width) {
401 comms__col_width = slen;
402 threads__col_width = slen + 6;
403 }
404 }
405
406 return 0;
369} 407}
370 408
371static size_t thread__fprintf(struct thread *self, FILE *fp) 409static size_t thread__fprintf(struct thread *self, FILE *fp)
@@ -536,7 +574,9 @@ struct sort_entry {
536 574
537 int64_t (*cmp)(struct hist_entry *, struct hist_entry *); 575 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
538 int64_t (*collapse)(struct hist_entry *, struct hist_entry *); 576 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
539 size_t (*print)(FILE *fp, struct hist_entry *); 577 size_t (*print)(FILE *fp, struct hist_entry *, unsigned int width);
578 unsigned int *width;
579 bool elide;
540}; 580};
541 581
542static int64_t cmp_null(void *l, void *r) 582static int64_t cmp_null(void *l, void *r)
@@ -558,15 +598,17 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
558} 598}
559 599
560static size_t 600static size_t
561sort__thread_print(FILE *fp, struct hist_entry *self) 601sort__thread_print(FILE *fp, struct hist_entry *self, unsigned int width)
562{ 602{
563 return fprintf(fp, "%16s:%5d", self->thread->comm ?: "", self->thread->pid); 603 return repsep_fprintf(fp, "%*s:%5d", width - 6,
604 self->thread->comm ?: "", self->thread->pid);
564} 605}
565 606
566static struct sort_entry sort_thread = { 607static struct sort_entry sort_thread = {
567 .header = " Command: Pid", 608 .header = "Command: Pid",
568 .cmp = sort__thread_cmp, 609 .cmp = sort__thread_cmp,
569 .print = sort__thread_print, 610 .print = sort__thread_print,
611 .width = &threads__col_width,
570}; 612};
571 613
572/* --sort comm */ 614/* --sort comm */
@@ -590,16 +632,17 @@ sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
590} 632}
591 633
592static size_t 634static size_t
593sort__comm_print(FILE *fp, struct hist_entry *self) 635sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width)
594{ 636{
595 return fprintf(fp, "%16s", self->thread->comm); 637 return repsep_fprintf(fp, "%*s", width, self->thread->comm);
596} 638}
597 639
598static struct sort_entry sort_comm = { 640static struct sort_entry sort_comm = {
599 .header = " Command", 641 .header = "Command",
600 .cmp = sort__comm_cmp, 642 .cmp = sort__comm_cmp,
601 .collapse = sort__comm_collapse, 643 .collapse = sort__comm_collapse,
602 .print = sort__comm_print, 644 .print = sort__comm_print,
645 .width = &comms__col_width,
603}; 646};
604 647
605/* --sort dso */ 648/* --sort dso */
@@ -617,18 +660,19 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
617} 660}
618 661
619static size_t 662static size_t
620sort__dso_print(FILE *fp, struct hist_entry *self) 663sort__dso_print(FILE *fp, struct hist_entry *self, unsigned int width)
621{ 664{
622 if (self->dso) 665 if (self->dso)
623 return fprintf(fp, "%-25s", self->dso->name); 666 return repsep_fprintf(fp, "%-*s", width, self->dso->name);
624 667
625 return fprintf(fp, "%016llx ", (u64)self->ip); 668 return repsep_fprintf(fp, "%*llx", width, (u64)self->ip);
626} 669}
627 670
628static struct sort_entry sort_dso = { 671static struct sort_entry sort_dso = {
629 .header = "Shared Object ", 672 .header = "Shared Object",
630 .cmp = sort__dso_cmp, 673 .cmp = sort__dso_cmp,
631 .print = sort__dso_print, 674 .print = sort__dso_print,
675 .width = &dsos__col_width,
632}; 676};
633 677
634/* --sort symbol */ 678/* --sort symbol */
@@ -648,22 +692,22 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
648} 692}
649 693
650static size_t 694static size_t
651sort__sym_print(FILE *fp, struct hist_entry *self) 695sort__sym_print(FILE *fp, struct hist_entry *self, unsigned int width __used)
652{ 696{
653 size_t ret = 0; 697 size_t ret = 0;
654 698
655 if (verbose) 699 if (verbose)
656 ret += fprintf(fp, "%#018llx ", (u64)self->ip); 700 ret += repsep_fprintf(fp, "%#018llx ", (u64)self->ip);
657 701
702 ret += repsep_fprintf(fp, "[%c] ", self->level);
658 if (self->sym) { 703 if (self->sym) {
659 ret += fprintf(fp, "[%c] %s", 704 ret += repsep_fprintf(fp, "%s", self->sym->name);
660 self->dso == kernel_dso ? 'k' :
661 self->dso == hypervisor_dso ? 'h' : '.', self->sym->name);
662 705
663 if (self->sym->module) 706 if (self->sym->module)
664 ret += fprintf(fp, "\t[%s]", self->sym->module->name); 707 ret += repsep_fprintf(fp, "\t[%s]",
708 self->sym->module->name);
665 } else { 709 } else {
666 ret += fprintf(fp, "%#016llx", (u64)self->ip); 710 ret += repsep_fprintf(fp, "%#016llx", (u64)self->ip);
667 } 711 }
668 712
669 return ret; 713 return ret;
@@ -690,19 +734,19 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
690} 734}
691 735
692static size_t 736static size_t
693sort__parent_print(FILE *fp, struct hist_entry *self) 737sort__parent_print(FILE *fp, struct hist_entry *self, unsigned int width)
694{ 738{
695 size_t ret = 0; 739 return repsep_fprintf(fp, "%-*s", width,
696 740 self->parent ? self->parent->name : "[other]");
697 ret += fprintf(fp, "%-20s", self->parent ? self->parent->name : "[other]");
698
699 return ret;
700} 741}
701 742
743static unsigned int parent_symbol__col_width;
744
702static struct sort_entry sort_parent = { 745static struct sort_entry sort_parent = {
703 .header = "Parent symbol ", 746 .header = "Parent symbol",
704 .cmp = sort__parent_cmp, 747 .cmp = sort__parent_cmp,
705 .print = sort__parent_print, 748 .print = sort__parent_print,
749 .width = &parent_symbol__col_width,
706}; 750};
707 751
708static int sort__need_collapse = 0; 752static int sort__need_collapse = 0;
@@ -967,17 +1011,25 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
967 return 0; 1011 return 0;
968 1012
969 if (total_samples) 1013 if (total_samples)
970 ret = percent_color_fprintf(fp, " %6.2f%%", 1014 ret = percent_color_fprintf(fp,
971 (self->count * 100.0) / total_samples); 1015 field_sep ? "%.2f" : " %6.2f%%",
1016 (self->count * 100.0) / total_samples);
972 else 1017 else
973 ret = fprintf(fp, "%12Ld ", self->count); 1018 ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count);
1019
1020 if (show_nr_samples) {
1021 if (field_sep)
1022 fprintf(fp, "%c%lld", *field_sep, self->count);
1023 else
1024 fprintf(fp, "%11lld", self->count);
1025 }
974 1026
975 list_for_each_entry(se, &hist_entry__sort_list, list) { 1027 list_for_each_entry(se, &hist_entry__sort_list, list) {
976 if (exclude_other && (se == &sort_parent)) 1028 if (se->elide)
977 continue; 1029 continue;
978 1030
979 fprintf(fp, " "); 1031 fprintf(fp, "%s", field_sep ?: " ");
980 ret += se->print(fp, self); 1032 ret += se->print(fp, self, se->width ? *se->width : 0);
981 } 1033 }
982 1034
983 ret += fprintf(fp, "\n"); 1035 ret += fprintf(fp, "\n");
@@ -992,6 +1044,18 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
992 * 1044 *
993 */ 1045 */
994 1046
1047static void dso__calc_col_width(struct dso *self)
1048{
1049 if (!col_width_list_str && !field_sep &&
1050 (!dso_list || strlist__has_entry(dso_list, self->name))) {
1051 unsigned int slen = strlen(self->name);
1052 if (slen > dsos__col_width)
1053 dsos__col_width = slen;
1054 }
1055
1056 self->slen_calculated = 1;
1057}
1058
995static struct symbol * 1059static struct symbol *
996resolve_symbol(struct thread *thread, struct map **mapp, 1060resolve_symbol(struct thread *thread, struct map **mapp,
997 struct dso **dsop, u64 *ipp) 1061 struct dso **dsop, u64 *ipp)
@@ -1011,6 +1075,14 @@ resolve_symbol(struct thread *thread, struct map **mapp,
1011 1075
1012 map = thread__find_map(thread, ip); 1076 map = thread__find_map(thread, ip);
1013 if (map != NULL) { 1077 if (map != NULL) {
1078 /*
1079 * We have to do this here as we may have a dso
1080 * with no symbol hit that has a name longer than
1081 * the ones with symbols sampled.
1082 */
1083 if (!sort_dso.elide && !map->dso->slen_calculated)
1084 dso__calc_col_width(map->dso);
1085
1014 if (mapp) 1086 if (mapp)
1015 *mapp = map; 1087 *mapp = map;
1016got_map: 1088got_map:
@@ -1282,35 +1354,67 @@ static size_t output__fprintf(FILE *fp, u64 total_samples)
1282 struct sort_entry *se; 1354 struct sort_entry *se;
1283 struct rb_node *nd; 1355 struct rb_node *nd;
1284 size_t ret = 0; 1356 size_t ret = 0;
1357 unsigned int width;
1358 char *col_width = col_width_list_str;
1285 1359
1286 fprintf(fp, "\n"); 1360 fprintf(fp, "# Samples: %Ld\n", (u64)total_samples);
1287 fprintf(fp, "#\n");
1288 fprintf(fp, "# (%Ld samples)\n", (u64)total_samples);
1289 fprintf(fp, "#\n"); 1361 fprintf(fp, "#\n");
1290 1362
1291 fprintf(fp, "# Overhead"); 1363 fprintf(fp, "# Overhead");
1364 if (show_nr_samples) {
1365 if (field_sep)
1366 fprintf(fp, "%cSamples", *field_sep);
1367 else
1368 fputs(" Samples ", fp);
1369 }
1292 list_for_each_entry(se, &hist_entry__sort_list, list) { 1370 list_for_each_entry(se, &hist_entry__sort_list, list) {
1293 if (exclude_other && (se == &sort_parent)) 1371 if (se->elide)
1294 continue; 1372 continue;
1295 fprintf(fp, " %s", se->header); 1373 if (field_sep) {
1374 fprintf(fp, "%c%s", *field_sep, se->header);
1375 continue;
1376 }
1377 width = strlen(se->header);
1378 if (se->width) {
1379 if (col_width_list_str) {
1380 if (col_width) {
1381 *se->width = atoi(col_width);
1382 col_width = strchr(col_width, ',');
1383 if (col_width)
1384 ++col_width;
1385 }
1386 }
1387 width = *se->width = max(*se->width, width);
1388 }
1389 fprintf(fp, " %*s", width, se->header);
1296 } 1390 }
1297 fprintf(fp, "\n"); 1391 fprintf(fp, "\n");
1298 1392
1393 if (field_sep)
1394 goto print_entries;
1395
1299 fprintf(fp, "# ........"); 1396 fprintf(fp, "# ........");
1397 if (show_nr_samples)
1398 fprintf(fp, " ..........");
1300 list_for_each_entry(se, &hist_entry__sort_list, list) { 1399 list_for_each_entry(se, &hist_entry__sort_list, list) {
1301 unsigned int i; 1400 unsigned int i;
1302 1401
1303 if (exclude_other && (se == &sort_parent)) 1402 if (se->elide)
1304 continue; 1403 continue;
1305 1404
1306 fprintf(fp, " "); 1405 fprintf(fp, " ");
1307 for (i = 0; i < strlen(se->header); i++) 1406 if (se->width)
1407 width = *se->width;
1408 else
1409 width = strlen(se->header);
1410 for (i = 0; i < width; i++)
1308 fprintf(fp, "."); 1411 fprintf(fp, ".");
1309 } 1412 }
1310 fprintf(fp, "\n"); 1413 fprintf(fp, "\n");
1311 1414
1312 fprintf(fp, "#\n"); 1415 fprintf(fp, "#\n");
1313 1416
1417print_entries:
1314 for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { 1418 for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) {
1315 pos = rb_entry(nd, struct hist_entry, rb_node); 1419 pos = rb_entry(nd, struct hist_entry, rb_node);
1316 ret += hist_entry__fprintf(fp, pos, total_samples); 1420 ret += hist_entry__fprintf(fp, pos, total_samples);
@@ -1524,19 +1628,6 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head)
1524} 1628}
1525 1629
1526static int 1630static int
1527process_period_event(event_t *event, unsigned long offset, unsigned long head)
1528{
1529 dprintf("%p [%p]: PERF_EVENT_PERIOD: time:%Ld, id:%Ld: period:%Ld\n",
1530 (void *)(offset + head),
1531 (void *)(long)(event->header.size),
1532 event->period.time,
1533 event->period.id,
1534 event->period.sample_period);
1535
1536 return 0;
1537}
1538
1539static int
1540process_lost_event(event_t *event, unsigned long offset, unsigned long head) 1631process_lost_event(event_t *event, unsigned long offset, unsigned long head)
1541{ 1632{
1542 dprintf("%p [%p]: PERF_EVENT_LOST: id:%Ld: lost:%Ld\n", 1633 dprintf("%p [%p]: PERF_EVENT_LOST: id:%Ld: lost:%Ld\n",
@@ -1617,9 +1708,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1617 case PERF_EVENT_FORK: 1708 case PERF_EVENT_FORK:
1618 return process_fork_event(event, offset, head); 1709 return process_fork_event(event, offset, head);
1619 1710
1620 case PERF_EVENT_PERIOD:
1621 return process_period_event(event, offset, head);
1622
1623 case PERF_EVENT_LOST: 1711 case PERF_EVENT_LOST:
1624 return process_lost_event(event, offset, head); 1712 return process_lost_event(event, offset, head);
1625 1713
@@ -1883,6 +1971,8 @@ static const struct option options[] = {
1883 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), 1971 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
1884 OPT_BOOLEAN('m', "modules", &modules, 1972 OPT_BOOLEAN('m', "modules", &modules,
1885 "load module symbols - WARNING: use only with -k and LIVE kernel"), 1973 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1974 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
1975 "Show a column with the number of samples"),
1886 OPT_STRING('s', "sort", &sort_order, "key[,key2...]", 1976 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1887 "sort by key(s): pid, comm, dso, symbol, parent"), 1977 "sort by key(s): pid, comm, dso, symbol, parent"),
1888 OPT_BOOLEAN('P', "full-paths", &full_paths, 1978 OPT_BOOLEAN('P', "full-paths", &full_paths,
@@ -1891,15 +1981,21 @@ static const struct option options[] = {
1891 "regex filter to identify parent, see: '--sort parent'"), 1981 "regex filter to identify parent, see: '--sort parent'"),
1892 OPT_BOOLEAN('x', "exclude-other", &exclude_other, 1982 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
1893 "Only display entries with parent-match"), 1983 "Only display entries with parent-match"),
1894 OPT_CALLBACK_DEFAULT('c', "callchain", NULL, "output_type,min_percent", 1984 OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent",
1895 "Display callchains using output_type and min percent threshold. " 1985 "Display callchains using output_type and min percent threshold. "
1896 "Default: flat,0", &parse_callchain_opt, callchain_default_opt), 1986 "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt),
1897 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]", 1987 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
1898 "only consider symbols in these dsos"), 1988 "only consider symbols in these dsos"),
1899 OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]", 1989 OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]",
1900 "only consider symbols in these comms"), 1990 "only consider symbols in these comms"),
1901 OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]", 1991 OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]",
1902 "only consider these symbols"), 1992 "only consider these symbols"),
1993 OPT_STRING('w', "column-widths", &col_width_list_str,
1994 "width[,width...]",
1995 "don't try to adjust column width, use these fixed values"),
1996 OPT_STRING('t', "field-separator", &field_sep, "separator",
1997 "separator for columns, no spaces will be added between "
1998 "columns '.' is reserved."),
1903 OPT_END() 1999 OPT_END()
1904}; 2000};
1905 2001
@@ -1919,7 +2015,8 @@ static void setup_sorting(void)
1919} 2015}
1920 2016
1921static void setup_list(struct strlist **list, const char *list_str, 2017static void setup_list(struct strlist **list, const char *list_str,
1922 const char *list_name) 2018 struct sort_entry *se, const char *list_name,
2019 FILE *fp)
1923{ 2020{
1924 if (list_str) { 2021 if (list_str) {
1925 *list = strlist__new(true, list_str); 2022 *list = strlist__new(true, list_str);
@@ -1928,6 +2025,11 @@ static void setup_list(struct strlist **list, const char *list_str,
1928 list_name); 2025 list_name);
1929 exit(129); 2026 exit(129);
1930 } 2027 }
2028 if (strlist__nr_entries(*list) == 1) {
2029 fprintf(fp, "# %s: %s\n", list_name,
2030 strlist__entry(*list, 0)->s);
2031 se->elide = true;
2032 }
1931 } 2033 }
1932} 2034}
1933 2035
@@ -1941,9 +2043,10 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
1941 2043
1942 setup_sorting(); 2044 setup_sorting();
1943 2045
1944 if (parent_pattern != default_parent_pattern) 2046 if (parent_pattern != default_parent_pattern) {
1945 sort_dimension__add("parent"); 2047 sort_dimension__add("parent");
1946 else 2048 sort_parent.elide = 1;
2049 } else
1947 exclude_other = 0; 2050 exclude_other = 0;
1948 2051
1949 /* 2052 /*
@@ -1952,11 +2055,17 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
1952 if (argc) 2055 if (argc)
1953 usage_with_options(report_usage, options); 2056 usage_with_options(report_usage, options);
1954 2057
1955 setup_list(&dso_list, dso_list_str, "dso");
1956 setup_list(&comm_list, comm_list_str, "comm");
1957 setup_list(&sym_list, sym_list_str, "symbol");
1958
1959 setup_pager(); 2058 setup_pager();
1960 2059
2060 setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout);
2061 setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout);
2062 setup_list(&sym_list, sym_list_str, &sort_sym, "symbol", stdout);
2063
2064 if (field_sep && *field_sep == '.') {
2065 fputs("'.' is the only non valid --field-separator argument\n",
2066 stderr);
2067 exit(129);
2068 }
2069
1961 return __cmd_report(); 2070 return __cmd_report();
1962} 2071}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 27921a8ce1a9..f9510eeeb6c7 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -511,7 +511,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
511{ 511{
512 int status; 512 int status;
513 513
514 argc = parse_options(argc, argv, options, stat_usage, 0); 514 argc = parse_options(argc, argv, options, stat_usage,
515 PARSE_OPT_STOP_AT_NON_OPTION);
515 if (!argc) 516 if (!argc)
516 usage_with_options(stat_usage, options); 517 usage_with_options(stat_usage, options);
517 if (run_count <= 0 || run_count > MAX_RUN) 518 if (run_count <= 0 || run_count > MAX_RUN)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 95d5c0ae375a..c0a423004e15 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -58,6 +58,7 @@ static u64 count_filter = 5;
58static int print_entries = 15; 58static int print_entries = 15;
59 59
60static int target_pid = -1; 60static int target_pid = -1;
61static int inherit = 0;
61static int profile_cpu = -1; 62static int profile_cpu = -1;
62static int nr_cpus = 0; 63static int nr_cpus = 0;
63static unsigned int realtime_prio = 0; 64static unsigned int realtime_prio = 0;
@@ -549,7 +550,7 @@ int group_fd;
549static void start_counter(int i, int counter) 550static void start_counter(int i, int counter)
550{ 551{
551 struct perf_counter_attr *attr; 552 struct perf_counter_attr *attr;
552 unsigned int cpu; 553 int cpu;
553 554
554 cpu = profile_cpu; 555 cpu = profile_cpu;
555 if (target_pid == -1 && profile_cpu == -1) 556 if (target_pid == -1 && profile_cpu == -1)
@@ -559,6 +560,7 @@ static void start_counter(int i, int counter)
559 560
560 attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; 561 attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
561 attr->freq = freq; 562 attr->freq = freq;
563 attr->inherit = (cpu < 0) && inherit;
562 564
563try_again: 565try_again:
564 fd[i][counter] = sys_perf_counter_open(attr, target_pid, cpu, group_fd, 0); 566 fd[i][counter] = sys_perf_counter_open(attr, target_pid, cpu, group_fd, 0);
@@ -685,6 +687,8 @@ static const struct option options[] = {
685 "only display functions with more events than this"), 687 "only display functions with more events than this"),
686 OPT_BOOLEAN('g', "group", &group, 688 OPT_BOOLEAN('g', "group", &group,
687 "put the counters into a counter group"), 689 "put the counters into a counter group"),
690 OPT_BOOLEAN('i', "inherit", &inherit,
691 "child tasks inherit counters"),
688 OPT_STRING('s', "sym-filter", &sym_filter, "pattern", 692 OPT_STRING('s', "sym-filter", &sym_filter, "pattern",
689 "only display symbols matchig this pattern"), 693 "only display symbols matchig this pattern"),
690 OPT_BOOLEAN('z', "zero", &zero, 694 OPT_BOOLEAN('z', "zero", &zero,
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index c5656784c61d..31982ad064b4 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -12,6 +12,8 @@
12#include "util/cache.h" 12#include "util/cache.h"
13#include "util/quote.h" 13#include "util/quote.h"
14#include "util/run-command.h" 14#include "util/run-command.h"
15#include "util/parse-events.h"
16#include "util/string.h"
15 17
16const char perf_usage_string[] = 18const char perf_usage_string[] =
17 "perf [--version] [--help] COMMAND [ARGS]"; 19 "perf [--version] [--help] COMMAND [ARGS]";
@@ -25,6 +27,8 @@ struct pager_config {
25 int val; 27 int val;
26}; 28};
27 29
30static char debugfs_mntpt[MAXPATHLEN];
31
28static int pager_command_config(const char *var, const char *value, void *data) 32static int pager_command_config(const char *var, const char *value, void *data)
29{ 33{
30 struct pager_config *c = data; 34 struct pager_config *c = data;
@@ -56,6 +60,15 @@ static void commit_pager_choice(void) {
56 } 60 }
57} 61}
58 62
63static void set_debugfs_path(void)
64{
65 char *path;
66
67 path = getenv(PERF_DEBUGFS_ENVIRONMENT);
68 snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
69 "tracing/events");
70}
71
59static int handle_options(const char*** argv, int* argc, int* envchanged) 72static int handle_options(const char*** argv, int* argc, int* envchanged)
60{ 73{
61 int handled = 0; 74 int handled = 0;
@@ -122,6 +135,22 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
122 setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1); 135 setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
123 if (envchanged) 136 if (envchanged)
124 *envchanged = 1; 137 *envchanged = 1;
138 } else if (!strcmp(cmd, "--debugfs-dir")) {
139 if (*argc < 2) {
140 fprintf(stderr, "No directory given for --debugfs-dir.\n");
141 usage(perf_usage_string);
142 }
143 strncpy(debugfs_mntpt, (*argv)[1], MAXPATHLEN);
144 debugfs_mntpt[MAXPATHLEN - 1] = '\0';
145 if (envchanged)
146 *envchanged = 1;
147 (*argv)++;
148 (*argc)--;
149 } else if (!prefixcmp(cmd, "--debugfs-dir=")) {
150 strncpy(debugfs_mntpt, cmd + 14, MAXPATHLEN);
151 debugfs_mntpt[MAXPATHLEN - 1] = '\0';
152 if (envchanged)
153 *envchanged = 1;
125 } else { 154 } else {
126 fprintf(stderr, "Unknown option: %s\n", cmd); 155 fprintf(stderr, "Unknown option: %s\n", cmd);
127 usage(perf_usage_string); 156 usage(perf_usage_string);
@@ -228,6 +257,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
228 if (use_pager == -1 && p->option & USE_PAGER) 257 if (use_pager == -1 && p->option & USE_PAGER)
229 use_pager = 1; 258 use_pager = 1;
230 commit_pager_choice(); 259 commit_pager_choice();
260 set_debugfs_path();
231 261
232 status = p->fn(argc, argv, prefix); 262 status = p->fn(argc, argv, prefix);
233 if (status) 263 if (status)
@@ -346,6 +376,49 @@ static int run_argv(int *argcp, const char ***argv)
346 return done_alias; 376 return done_alias;
347} 377}
348 378
379/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
380static void get_debugfs_mntpt(void)
381{
382 FILE *file;
383 char fs_type[100];
384 char debugfs[MAXPATHLEN];
385
386 /*
387 * try the standard location
388 */
389 if (valid_debugfs_mount("/sys/kernel/debug/") == 0) {
390 strcpy(debugfs_mntpt, "/sys/kernel/debug/");
391 return;
392 }
393
394 /*
395 * try the sane location
396 */
397 if (valid_debugfs_mount("/debug/") == 0) {
398 strcpy(debugfs_mntpt, "/debug/");
399 return;
400 }
401
402 /*
403 * give up and parse /proc/mounts
404 */
405 file = fopen("/proc/mounts", "r");
406 if (file == NULL)
407 return;
408
409 while (fscanf(file, "%*s %"
410 STR(MAXPATHLEN)
411 "s %99s %*s %*d %*d\n",
412 debugfs, fs_type) == 2) {
413 if (strcmp(fs_type, "debugfs") == 0)
414 break;
415 }
416 fclose(file);
417 if (strcmp(fs_type, "debugfs") == 0) {
418 strncpy(debugfs_mntpt, debugfs, MAXPATHLEN);
419 debugfs_mntpt[MAXPATHLEN - 1] = '\0';
420 }
421}
349 422
350int main(int argc, const char **argv) 423int main(int argc, const char **argv)
351{ 424{
@@ -354,7 +427,8 @@ int main(int argc, const char **argv)
354 cmd = perf_extract_argv0_path(argv[0]); 427 cmd = perf_extract_argv0_path(argv[0]);
355 if (!cmd) 428 if (!cmd)
356 cmd = "perf-help"; 429 cmd = "perf-help";
357 430 /* get debugfs mount point from /proc/mounts */
431 get_debugfs_mntpt();
358 /* 432 /*
359 * "perf-xxxx" is the same as "perf xxxx", but we obviously: 433 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
360 * 434 *
@@ -377,6 +451,7 @@ int main(int argc, const char **argv)
377 argc--; 451 argc--;
378 handle_options(&argv, &argc, NULL); 452 handle_options(&argv, &argc, NULL);
379 commit_pager_choice(); 453 commit_pager_choice();
454 set_debugfs_path();
380 if (argc > 0) { 455 if (argc > 0) {
381 if (!prefixcmp(argv[0], "--")) 456 if (!prefixcmp(argv[0], "--"))
382 argv[0] += 2; 457 argv[0] += 2;
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 63e67cc5487b..e5148e2b6134 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -1,7 +1,13 @@
1#ifndef _PERF_PERF_H 1#ifndef _PERF_PERF_H
2#define _PERF_PERF_H 2#define _PERF_PERF_H
3 3
4#if defined(__x86_64__) || defined(__i386__) 4#if defined(__i386__)
5#include "../../arch/x86/include/asm/unistd.h"
6#define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
7#define cpu_relax() asm volatile("rep; nop" ::: "memory");
8#endif
9
10#if defined(__x86_64__)
5#include "../../arch/x86/include/asm/unistd.h" 11#include "../../arch/x86/include/asm/unistd.h"
6#define rmb() asm volatile("lfence" ::: "memory") 12#define rmb() asm volatile("lfence" ::: "memory")
7#define cpu_relax() asm volatile("rep; nop" ::: "memory"); 13#define cpu_relax() asm volatile("rep; nop" ::: "memory");
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 161d5f413e28..4b50c412b9c5 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -18,6 +18,7 @@
18#define PERFATTRIBUTES_FILE ".perfattributes" 18#define PERFATTRIBUTES_FILE ".perfattributes"
19#define INFOATTRIBUTES_FILE "info/attributes" 19#define INFOATTRIBUTES_FILE "info/attributes"
20#define ATTRIBUTE_MACRO_PREFIX "[attr]" 20#define ATTRIBUTE_MACRO_PREFIX "[attr]"
21#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
21 22
22typedef int (*config_fn_t)(const char *, const char *, void *); 23typedef int (*config_fn_t)(const char *, const char *, void *);
23extern int perf_default_config(const char *, const char *, void *); 24extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index b5ef53ad4c7a..bf280449fcfd 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -16,7 +16,7 @@ struct perf_header {
16 int frozen; 16 int frozen;
17 int attrs, size; 17 int attrs, size;
18 struct perf_header_attr **attr; 18 struct perf_header_attr **attr;
19 off_t attr_offset; 19 s64 attr_offset;
20 u64 data_offset; 20 u64 data_offset;
21 u64 data_size; 21 u64 data_size;
22}; 22};
diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h
index 99c1b3d1edd9..a6b87390cb52 100644
--- a/tools/perf/util/include/linux/kernel.h
+++ b/tools/perf/util/include/linux/kernel.h
@@ -18,4 +18,12 @@
18 (type *)((char *)__mptr - offsetof(type, member)); }) 18 (type *)((char *)__mptr - offsetof(type, member)); })
19#endif 19#endif
20 20
21#ifndef max
22#define max(x, y) ({ \
23 typeof(x) _max1 = (x); \
24 typeof(y) _max2 = (y); \
25 (void) (&_max1 == &_max2); \
26 _max1 > _max2 ? _max1 : _max2; })
27#endif
28
21#endif 29#endif
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5184959e0615..7bdad8df22a6 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -5,6 +5,7 @@
5#include "parse-events.h" 5#include "parse-events.h"
6#include "exec_cmd.h" 6#include "exec_cmd.h"
7#include "string.h" 7#include "string.h"
8#include "cache.h"
8 9
9extern char *strcasestr(const char *haystack, const char *needle); 10extern char *strcasestr(const char *haystack, const char *needle);
10 11
@@ -19,6 +20,8 @@ struct event_symbol {
19 char *alias; 20 char *alias;
20}; 21};
21 22
23char debugfs_path[MAXPATHLEN];
24
22#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x 25#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
23#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x 26#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
24 27
@@ -71,8 +74,8 @@ static char *sw_event_names[] = {
71#define MAX_ALIASES 8 74#define MAX_ALIASES 8
72 75
73static char *hw_cache[][MAX_ALIASES] = { 76static char *hw_cache[][MAX_ALIASES] = {
74 { "L1-d$", "l1-d", "l1d", "L1-data", }, 77 { "L1-dcache", "l1-d", "l1d", "L1-data", },
75 { "L1-i$", "l1-i", "l1i", "L1-instruction", }, 78 { "L1-icache", "l1-i", "l1i", "L1-instruction", },
76 { "LLC", "L2" }, 79 { "LLC", "L2" },
77 { "dTLB", "d-tlb", "Data-TLB", }, 80 { "dTLB", "d-tlb", "Data-TLB", },
78 { "iTLB", "i-tlb", "Instruction-TLB", }, 81 { "iTLB", "i-tlb", "Instruction-TLB", },
@@ -110,6 +113,88 @@ static unsigned long hw_cache_stat[C(MAX)] = {
110 [C(BPU)] = (CACHE_READ), 113 [C(BPU)] = (CACHE_READ),
111}; 114};
112 115
116#define for_each_subsystem(sys_dir, sys_dirent, sys_next, file, st) \
117 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
118 if (snprintf(file, MAXPATHLEN, "%s/%s", debugfs_path, \
119 sys_dirent.d_name) && \
120 (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \
121 (strcmp(sys_dirent.d_name, ".")) && \
122 (strcmp(sys_dirent.d_name, "..")))
123
124#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, file, st) \
125 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
126 if (snprintf(file, MAXPATHLEN, "%s/%s/%s", debugfs_path, \
127 sys_dirent.d_name, evt_dirent.d_name) && \
128 (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \
129 (strcmp(evt_dirent.d_name, ".")) && \
130 (strcmp(evt_dirent.d_name, "..")))
131
132#define MAX_EVENT_LENGTH 30
133
134int valid_debugfs_mount(const char *debugfs)
135{
136 struct statfs st_fs;
137
138 if (statfs(debugfs, &st_fs) < 0)
139 return -ENOENT;
140 else if (st_fs.f_type != (long) DEBUGFS_MAGIC)
141 return -ENOENT;
142 return 0;
143}
144
145static char *tracepoint_id_to_name(u64 config)
146{
147 static char tracepoint_name[2 * MAX_EVENT_LENGTH];
148 DIR *sys_dir, *evt_dir;
149 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
150 struct stat st;
151 char id_buf[4];
152 int fd;
153 u64 id;
154 char evt_path[MAXPATHLEN];
155
156 if (valid_debugfs_mount(debugfs_path))
157 return "unkown";
158
159 sys_dir = opendir(debugfs_path);
160 if (!sys_dir)
161 goto cleanup;
162
163 for_each_subsystem(sys_dir, sys_dirent, sys_next, evt_path, st) {
164 evt_dir = opendir(evt_path);
165 if (!evt_dir)
166 goto cleanup;
167 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next,
168 evt_path, st) {
169 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id",
170 debugfs_path, sys_dirent.d_name,
171 evt_dirent.d_name);
172 fd = open(evt_path, O_RDONLY);
173 if (fd < 0)
174 continue;
175 if (read(fd, id_buf, sizeof(id_buf)) < 0) {
176 close(fd);
177 continue;
178 }
179 close(fd);
180 id = atoll(id_buf);
181 if (id == config) {
182 closedir(evt_dir);
183 closedir(sys_dir);
184 snprintf(tracepoint_name, 2 * MAX_EVENT_LENGTH,
185 "%s:%s", sys_dirent.d_name,
186 evt_dirent.d_name);
187 return tracepoint_name;
188 }
189 }
190 closedir(evt_dir);
191 }
192
193cleanup:
194 closedir(sys_dir);
195 return "unkown";
196}
197
113static int is_cache_op_valid(u8 cache_type, u8 cache_op) 198static int is_cache_op_valid(u8 cache_type, u8 cache_op)
114{ 199{
115 if (hw_cache_stat[cache_type] & COP(cache_op)) 200 if (hw_cache_stat[cache_type] & COP(cache_op))
@@ -177,6 +262,9 @@ char *event_name(int counter)
177 return sw_event_names[config]; 262 return sw_event_names[config];
178 return "unknown-software"; 263 return "unknown-software";
179 264
265 case PERF_TYPE_TRACEPOINT:
266 return tracepoint_id_to_name(config);
267
180 default: 268 default:
181 break; 269 break;
182 } 270 }
@@ -265,6 +353,53 @@ parse_generic_hw_event(const char **str, struct perf_counter_attr *attr)
265 return 1; 353 return 1;
266} 354}
267 355
356static int parse_tracepoint_event(const char **strp,
357 struct perf_counter_attr *attr)
358{
359 const char *evt_name;
360 char sys_name[MAX_EVENT_LENGTH];
361 char id_buf[4];
362 int fd;
363 unsigned int sys_length, evt_length;
364 u64 id;
365 char evt_path[MAXPATHLEN];
366
367 if (valid_debugfs_mount(debugfs_path))
368 return 0;
369
370 evt_name = strchr(*strp, ':');
371 if (!evt_name)
372 return 0;
373
374 sys_length = evt_name - *strp;
375 if (sys_length >= MAX_EVENT_LENGTH)
376 return 0;
377
378 strncpy(sys_name, *strp, sys_length);
379 sys_name[sys_length] = '\0';
380 evt_name = evt_name + 1;
381 evt_length = strlen(evt_name);
382 if (evt_length >= MAX_EVENT_LENGTH)
383 return 0;
384
385 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
386 sys_name, evt_name);
387 fd = open(evt_path, O_RDONLY);
388 if (fd < 0)
389 return 0;
390
391 if (read(fd, id_buf, sizeof(id_buf)) < 0) {
392 close(fd);
393 return 0;
394 }
395 close(fd);
396 id = atoll(id_buf);
397 attr->config = id;
398 attr->type = PERF_TYPE_TRACEPOINT;
399 *strp = evt_name + evt_length;
400 return 1;
401}
402
268static int check_events(const char *str, unsigned int i) 403static int check_events(const char *str, unsigned int i)
269{ 404{
270 int n; 405 int n;
@@ -374,7 +509,8 @@ parse_event_modifier(const char **strp, struct perf_counter_attr *attr)
374 */ 509 */
375static int parse_event_symbols(const char **str, struct perf_counter_attr *attr) 510static int parse_event_symbols(const char **str, struct perf_counter_attr *attr)
376{ 511{
377 if (!(parse_raw_event(str, attr) || 512 if (!(parse_tracepoint_event(str, attr) ||
513 parse_raw_event(str, attr) ||
378 parse_numeric_event(str, attr) || 514 parse_numeric_event(str, attr) ||
379 parse_symbolic_event(str, attr) || 515 parse_symbolic_event(str, attr) ||
380 parse_generic_hw_event(str, attr))) 516 parse_generic_hw_event(str, attr)))
@@ -423,6 +559,42 @@ static const char * const event_type_descriptors[] = {
423}; 559};
424 560
425/* 561/*
562 * Print the events from <debugfs_mount_point>/tracing/events
563 */
564
565static void print_tracepoint_events(void)
566{
567 DIR *sys_dir, *evt_dir;
568 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
569 struct stat st;
570 char evt_path[MAXPATHLEN];
571
572 if (valid_debugfs_mount(debugfs_path))
573 return;
574
575 sys_dir = opendir(debugfs_path);
576 if (!sys_dir)
577 goto cleanup;
578
579 for_each_subsystem(sys_dir, sys_dirent, sys_next, evt_path, st) {
580 evt_dir = opendir(evt_path);
581 if (!evt_dir)
582 goto cleanup;
583 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next,
584 evt_path, st) {
585 snprintf(evt_path, MAXPATHLEN, "%s:%s",
586 sys_dirent.d_name, evt_dirent.d_name);
587 fprintf(stderr, " %-40s [%s]\n", evt_path,
588 event_type_descriptors[PERF_TYPE_TRACEPOINT+1]);
589 }
590 closedir(evt_dir);
591 }
592
593cleanup:
594 closedir(sys_dir);
595}
596
597/*
426 * Print the help text for the event symbols: 598 * Print the help text for the event symbols:
427 */ 599 */
428void print_events(void) 600void print_events(void)
@@ -436,7 +608,7 @@ void print_events(void)
436 608
437 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { 609 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
438 type = syms->type + 1; 610 type = syms->type + 1;
439 if (type > ARRAY_SIZE(event_type_descriptors)) 611 if (type >= ARRAY_SIZE(event_type_descriptors))
440 type = 0; 612 type = 0;
441 613
442 if (type != prev_type) 614 if (type != prev_type)
@@ -472,5 +644,7 @@ void print_events(void)
472 "rNNN"); 644 "rNNN");
473 fprintf(stderr, "\n"); 645 fprintf(stderr, "\n");
474 646
647 print_tracepoint_events();
648
475 exit(129); 649 exit(129);
476} 650}
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index e3d552908e60..1ea5d09b6eb1 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -3,6 +3,8 @@
3 * Parse symbolic events/counts passed in as options: 3 * Parse symbolic events/counts passed in as options:
4 */ 4 */
5 5
6struct option;
7
6extern int nr_counters; 8extern int nr_counters;
7 9
8extern struct perf_counter_attr attrs[MAX_COUNTERS]; 10extern struct perf_counter_attr attrs[MAX_COUNTERS];
@@ -15,3 +17,6 @@ extern int parse_events(const struct option *opt, const char *str, int unset);
15 17
16extern void print_events(void); 18extern void print_events(void);
17 19
20extern char debugfs_path[];
21extern int valid_debugfs_mount(const char *debugfs);
22
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
index 3dca2f654cd0..bf39dfadfd24 100644
--- a/tools/perf/util/string.h
+++ b/tools/perf/util/string.h
@@ -5,4 +5,7 @@
5 5
6int hex2u64(const char *ptr, u64 *val); 6int hex2u64(const char *ptr, u64 *val);
7 7
8#define _STR(x) #x
9#define STR(x) _STR(x)
10
8#endif 11#endif
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 025a78edfffe..7ad38171dc2b 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -64,6 +64,7 @@ int strlist__add(struct strlist *self, const char *new_entry)
64 64
65 rb_link_node(&sn->rb_node, parent, p); 65 rb_link_node(&sn->rb_node, parent, p);
66 rb_insert_color(&sn->rb_node, &self->entries); 66 rb_insert_color(&sn->rb_node, &self->entries);
67 ++self->nr_entries;
67 68
68 return 0; 69 return 0;
69} 70}
@@ -155,8 +156,9 @@ struct strlist *strlist__new(bool dupstr, const char *slist)
155 struct strlist *self = malloc(sizeof(*self)); 156 struct strlist *self = malloc(sizeof(*self));
156 157
157 if (self != NULL) { 158 if (self != NULL) {
158 self->entries = RB_ROOT; 159 self->entries = RB_ROOT;
159 self->dupstr = dupstr; 160 self->dupstr = dupstr;
161 self->nr_entries = 0;
160 if (slist && strlist__parse_list(self, slist) != 0) 162 if (slist && strlist__parse_list(self, slist) != 0)
161 goto out_error; 163 goto out_error;
162 } 164 }
@@ -182,3 +184,17 @@ void strlist__delete(struct strlist *self)
182 free(self); 184 free(self);
183 } 185 }
184} 186}
187
188struct str_node *strlist__entry(const struct strlist *self, unsigned int idx)
189{
190 struct rb_node *nd;
191
192 for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
193 struct str_node *pos = rb_entry(nd, struct str_node, rb_node);
194
195 if (!idx--)
196 return pos;
197 }
198
199 return NULL;
200}
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index 2fdcfee87586..921818e44a54 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -11,7 +11,8 @@ struct str_node {
11 11
12struct strlist { 12struct strlist {
13 struct rb_root entries; 13 struct rb_root entries;
14 bool dupstr; 14 unsigned int nr_entries;
15 bool dupstr;
15}; 16};
16 17
17struct strlist *strlist__new(bool dupstr, const char *slist); 18struct strlist *strlist__new(bool dupstr, const char *slist);
@@ -21,11 +22,17 @@ void strlist__remove(struct strlist *self, struct str_node *sn);
21int strlist__load(struct strlist *self, const char *filename); 22int strlist__load(struct strlist *self, const char *filename);
22int strlist__add(struct strlist *self, const char *str); 23int strlist__add(struct strlist *self, const char *str);
23 24
25struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
24bool strlist__has_entry(struct strlist *self, const char *entry); 26bool strlist__has_entry(struct strlist *self, const char *entry);
25 27
26static inline bool strlist__empty(const struct strlist *self) 28static inline bool strlist__empty(const struct strlist *self)
27{ 29{
28 return rb_first(&self->entries) == NULL; 30 return self->nr_entries == 0;
31}
32
33static inline unsigned int strlist__nr_entries(const struct strlist *self)
34{
35 return self->nr_entries;
29} 36}
30 37
31int strlist__parse_list(struct strlist *self, const char *s); 38int strlist__parse_list(struct strlist *self, const char *s);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 4683b67b5ee4..28106059bf12 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -6,9 +6,15 @@
6#include <libelf.h> 6#include <libelf.h>
7#include <gelf.h> 7#include <gelf.h>
8#include <elf.h> 8#include <elf.h>
9#include <bfd.h>
9 10
10const char *sym_hist_filter; 11const char *sym_hist_filter;
11 12
13#ifndef DMGL_PARAMS
14#define DMGL_PARAMS (1 << 0) /* Include function args */
15#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
16#endif
17
12static struct symbol *symbol__new(u64 start, u64 len, 18static struct symbol *symbol__new(u64 start, u64 len,
13 const char *name, unsigned int priv_size, 19 const char *name, unsigned int priv_size,
14 u64 obj_start, int verbose) 20 u64 obj_start, int verbose)
@@ -65,6 +71,7 @@ struct dso *dso__new(const char *name, unsigned int sym_priv_size)
65 self->syms = RB_ROOT; 71 self->syms = RB_ROOT;
66 self->sym_priv_size = sym_priv_size; 72 self->sym_priv_size = sym_priv_size;
67 self->find_symbol = dso__find_symbol; 73 self->find_symbol = dso__find_symbol;
74 self->slen_calculated = 0;
68 } 75 }
69 76
70 return self; 77 return self;
@@ -373,36 +380,61 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
373 idx < nr_entries; \ 380 idx < nr_entries; \
374 ++idx, pos = gelf_getrela(reldata, idx, &pos_mem)) 381 ++idx, pos = gelf_getrela(reldata, idx, &pos_mem))
375 382
376static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf, 383/*
377 GElf_Ehdr *ehdr, Elf_Scn *scn_dynsym, 384 * We need to check if we have a .dynsym, so that we can handle the
378 GElf_Shdr *shdr_dynsym, 385 * .plt, synthesizing its symbols, that aren't on the symtabs (be it
379 size_t dynsym_idx, int verbose) 386 * .dynsym or .symtab).
387 * And always look at the original dso, not at debuginfo packages, that
388 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS).
389 */
390static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
380{ 391{
381 uint32_t nr_rel_entries, idx; 392 uint32_t nr_rel_entries, idx;
382 GElf_Sym sym; 393 GElf_Sym sym;
383 u64 plt_offset; 394 u64 plt_offset;
384 GElf_Shdr shdr_plt; 395 GElf_Shdr shdr_plt;
385 struct symbol *f; 396 struct symbol *f;
386 GElf_Shdr shdr_rel_plt; 397 GElf_Shdr shdr_rel_plt, shdr_dynsym;
387 Elf_Data *reldata, *syms, *symstrs; 398 Elf_Data *reldata, *syms, *symstrs;
388 Elf_Scn *scn_plt_rel, *scn_symstrs; 399 Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym;
400 size_t dynsym_idx;
401 GElf_Ehdr ehdr;
389 char sympltname[1024]; 402 char sympltname[1024];
390 int nr = 0, symidx; 403 Elf *elf;
404 int nr = 0, symidx, fd, err = 0;
405
406 fd = open(self->name, O_RDONLY);
407 if (fd < 0)
408 goto out;
409
410 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
411 if (elf == NULL)
412 goto out_close;
413
414 if (gelf_getehdr(elf, &ehdr) == NULL)
415 goto out_elf_end;
416
417 scn_dynsym = elf_section_by_name(elf, &ehdr, &shdr_dynsym,
418 ".dynsym", &dynsym_idx);
419 if (scn_dynsym == NULL)
420 goto out_elf_end;
391 421
392 scn_plt_rel = elf_section_by_name(elf, ehdr, &shdr_rel_plt, 422 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
393 ".rela.plt", NULL); 423 ".rela.plt", NULL);
394 if (scn_plt_rel == NULL) { 424 if (scn_plt_rel == NULL) {
395 scn_plt_rel = elf_section_by_name(elf, ehdr, &shdr_rel_plt, 425 scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
396 ".rel.plt", NULL); 426 ".rel.plt", NULL);
397 if (scn_plt_rel == NULL) 427 if (scn_plt_rel == NULL)
398 return 0; 428 goto out_elf_end;
399 } 429 }
400 430
431 err = -1;
432
401 if (shdr_rel_plt.sh_link != dynsym_idx) 433 if (shdr_rel_plt.sh_link != dynsym_idx)
402 return 0; 434 goto out_elf_end;
403 435
404 if (elf_section_by_name(elf, ehdr, &shdr_plt, ".plt", NULL) == NULL) 436 if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL)
405 return 0; 437 goto out_elf_end;
406 438
407 /* 439 /*
408 * Fetch the relocation section to find the indexes to the GOT 440 * Fetch the relocation section to find the indexes to the GOT
@@ -410,19 +442,19 @@ static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf,
410 */ 442 */
411 reldata = elf_getdata(scn_plt_rel, NULL); 443 reldata = elf_getdata(scn_plt_rel, NULL);
412 if (reldata == NULL) 444 if (reldata == NULL)
413 return -1; 445 goto out_elf_end;
414 446
415 syms = elf_getdata(scn_dynsym, NULL); 447 syms = elf_getdata(scn_dynsym, NULL);
416 if (syms == NULL) 448 if (syms == NULL)
417 return -1; 449 goto out_elf_end;
418 450
419 scn_symstrs = elf_getscn(elf, shdr_dynsym->sh_link); 451 scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link);
420 if (scn_symstrs == NULL) 452 if (scn_symstrs == NULL)
421 return -1; 453 goto out_elf_end;
422 454
423 symstrs = elf_getdata(scn_symstrs, NULL); 455 symstrs = elf_getdata(scn_symstrs, NULL);
424 if (symstrs == NULL) 456 if (symstrs == NULL)
425 return -1; 457 goto out_elf_end;
426 458
427 nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize; 459 nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize;
428 plt_offset = shdr_plt.sh_offset; 460 plt_offset = shdr_plt.sh_offset;
@@ -441,7 +473,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf,
441 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 473 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
442 sympltname, self->sym_priv_size, 0, verbose); 474 sympltname, self->sym_priv_size, 0, verbose);
443 if (!f) 475 if (!f)
444 return -1; 476 goto out_elf_end;
445 477
446 dso__insert_symbol(self, f); 478 dso__insert_symbol(self, f);
447 ++nr; 479 ++nr;
@@ -459,19 +491,25 @@ static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf,
459 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 491 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
460 sympltname, self->sym_priv_size, 0, verbose); 492 sympltname, self->sym_priv_size, 0, verbose);
461 if (!f) 493 if (!f)
462 return -1; 494 goto out_elf_end;
463 495
464 dso__insert_symbol(self, f); 496 dso__insert_symbol(self, f);
465 ++nr; 497 ++nr;
466 } 498 }
467 } else {
468 /*
469 * TODO: There are still one more shdr_rel_plt.sh_type
470 * I have to investigate, but probably should be ignored.
471 */
472 } 499 }
473 500
474 return nr; 501 err = 0;
502out_elf_end:
503 elf_end(elf);
504out_close:
505 close(fd);
506
507 if (err == 0)
508 return nr;
509out:
510 fprintf(stderr, "%s: problems reading %s PLT info.\n",
511 __func__, self->name);
512 return 0;
475} 513}
476 514
477static int dso__load_sym(struct dso *self, int fd, const char *name, 515static int dso__load_sym(struct dso *self, int fd, const char *name,
@@ -485,10 +523,9 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
485 GElf_Shdr shdr; 523 GElf_Shdr shdr;
486 Elf_Data *syms; 524 Elf_Data *syms;
487 GElf_Sym sym; 525 GElf_Sym sym;
488 Elf_Scn *sec, *sec_dynsym, *sec_strndx; 526 Elf_Scn *sec, *sec_strndx;
489 Elf *elf; 527 Elf *elf;
490 size_t dynsym_idx; 528 int nr = 0, kernel = !strcmp("[kernel]", self->name);
491 int nr = 0;
492 529
493 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); 530 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
494 if (elf == NULL) { 531 if (elf == NULL) {
@@ -504,32 +541,11 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
504 goto out_elf_end; 541 goto out_elf_end;
505 } 542 }
506 543
507 /*
508 * We need to check if we have a .dynsym, so that we can handle the
509 * .plt, synthesizing its symbols, that aren't on the symtabs (be it
510 * .dynsym or .symtab)
511 */
512 sec_dynsym = elf_section_by_name(elf, &ehdr, &shdr,
513 ".dynsym", &dynsym_idx);
514 if (sec_dynsym != NULL) {
515 nr = dso__synthesize_plt_symbols(self, elf, &ehdr,
516 sec_dynsym, &shdr,
517 dynsym_idx, verbose);
518 if (nr < 0)
519 goto out_elf_end;
520 }
521
522 /*
523 * But if we have a full .symtab (that is a superset of .dynsym) we
524 * should add the symbols not in the .dynsyn
525 */
526 sec = elf_section_by_name(elf, &ehdr, &shdr, ".symtab", NULL); 544 sec = elf_section_by_name(elf, &ehdr, &shdr, ".symtab", NULL);
527 if (sec == NULL) { 545 if (sec == NULL) {
528 if (sec_dynsym == NULL) 546 sec = elf_section_by_name(elf, &ehdr, &shdr, ".dynsym", NULL);
547 if (sec == NULL)
529 goto out_elf_end; 548 goto out_elf_end;
530
531 sec = sec_dynsym;
532 gelf_getshdr(sec, &shdr);
533 } 549 }
534 550
535 syms = elf_getdata(sec, NULL); 551 syms = elf_getdata(sec, NULL);
@@ -555,12 +571,17 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
555 nr_syms = shdr.sh_size / shdr.sh_entsize; 571 nr_syms = shdr.sh_size / shdr.sh_entsize;
556 572
557 memset(&sym, 0, sizeof(sym)); 573 memset(&sym, 0, sizeof(sym));
558 self->adjust_symbols = (ehdr.e_type == ET_EXEC || 574 if (!kernel) {
575 self->adjust_symbols = (ehdr.e_type == ET_EXEC ||
559 elf_section_by_name(elf, &ehdr, &shdr, 576 elf_section_by_name(elf, &ehdr, &shdr,
560 ".gnu.prelink_undo", 577 ".gnu.prelink_undo",
561 NULL) != NULL); 578 NULL) != NULL);
579 } else self->adjust_symbols = 0;
580
562 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { 581 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) {
563 struct symbol *f; 582 struct symbol *f;
583 const char *name;
584 char *demangled;
564 u64 obj_start; 585 u64 obj_start;
565 struct section *section = NULL; 586 struct section *section = NULL;
566 int is_label = elf_sym__is_label(&sym); 587 int is_label = elf_sym__is_label(&sym);
@@ -599,10 +620,19 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
599 goto out_elf_end; 620 goto out_elf_end;
600 } 621 }
601 } 622 }
623 /*
624 * We need to figure out if the object was created from C++ sources
625 * DWARF DW_compile_unit has this, but we don't always have access
626 * to it...
627 */
628 name = elf_sym__name(&sym, symstrs);
629 demangled = bfd_demangle(NULL, name, DMGL_PARAMS | DMGL_ANSI);
630 if (demangled != NULL)
631 name = demangled;
602 632
603 f = symbol__new(sym.st_value, sym.st_size, 633 f = symbol__new(sym.st_value, sym.st_size, name,
604 elf_sym__name(&sym, symstrs),
605 self->sym_priv_size, obj_start, verbose); 634 self->sym_priv_size, obj_start, verbose);
635 free(demangled);
606 if (!f) 636 if (!f)
607 goto out_elf_end; 637 goto out_elf_end;
608 638
@@ -668,6 +698,11 @@ more:
668 if (!ret) 698 if (!ret)
669 goto more; 699 goto more;
670 700
701 if (ret > 0) {
702 int nr_plt = dso__synthesize_plt_symbols(self, verbose);
703 if (nr_plt > 0)
704 ret += nr_plt;
705 }
671out: 706out:
672 free(name); 707 free(name);
673 return ret; 708 return ret;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 7918cffb23cd..2f92b21c712d 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -25,6 +25,7 @@ struct dso {
25 struct symbol *(*find_symbol)(struct dso *, u64 ip); 25 struct symbol *(*find_symbol)(struct dso *, u64 ip);
26 unsigned int sym_priv_size; 26 unsigned int sym_priv_size;
27 unsigned char adjust_symbols; 27 unsigned char adjust_symbols;
28 unsigned char slen_calculated;
28 char name[0]; 29 char name[0];
29}; 30};
30 31
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index b4be6071c105..68fe157d72fb 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -50,6 +50,7 @@
50#include <unistd.h> 50#include <unistd.h>
51#include <stdio.h> 51#include <stdio.h>
52#include <sys/stat.h> 52#include <sys/stat.h>
53#include <sys/statfs.h>
53#include <fcntl.h> 54#include <fcntl.h>
54#include <stddef.h> 55#include <stddef.h>
55#include <stdlib.h> 56#include <stdlib.h>
@@ -80,6 +81,7 @@
80#include <netdb.h> 81#include <netdb.h>
81#include <pwd.h> 82#include <pwd.h>
82#include <inttypes.h> 83#include <inttypes.h>
84#include "../../../include/linux/magic.h"
83 85
84#ifndef NO_ICONV 86#ifndef NO_ICONV
85#include <iconv.h> 87#include <iconv.h>