aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Makefile7
-rw-r--r--tools/perf/builtin-annotate.c32
-rw-r--r--tools/perf/builtin-help.c1
-rw-r--r--tools/perf/builtin-report.c38
-rw-r--r--tools/perf/builtin-top.c23
-rw-r--r--tools/perf/util/abspath.c3
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/callchain.c2
-rw-r--r--tools/perf/util/color.c6
-rw-r--r--tools/perf/util/color.h2
-rw-r--r--tools/perf/util/config.c22
-rw-r--r--tools/perf/util/exec_cmd.c1
-rw-r--r--tools/perf/util/module.c4
-rw-r--r--tools/perf/util/parse-events.c26
-rw-r--r--tools/perf/util/parse-events.h4
-rw-r--r--tools/perf/util/parse-options.c22
-rw-r--r--tools/perf/util/path.c25
-rw-r--r--tools/perf/util/run-command.c6
-rw-r--r--tools/perf/util/symbol.c104
-rw-r--r--tools/perf/util/symbol.h4
-rw-r--r--tools/perf/util/values.c7
-rw-r--r--tools/perf/util/values.h2
22 files changed, 194 insertions, 148 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 0056405e4c93..8608c06f806e 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -166,7 +166,12 @@ endif
166 166
167# CFLAGS and LDFLAGS are for the users to override from the command line. 167# CFLAGS and LDFLAGS are for the users to override from the command line.
168 168
169CFLAGS = $(M64) -ggdb3 -Wall -Wextra -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -std=gnu99 -Wdeclaration-after-statement -Werror -O6 169#
170# Include saner warnings here, which can catch bugs:
171#
172EXTRA_WARNINGS = -Wcast-align -Wformat=2 -Wshadow -Winit-self -Wpacked -Wredundant-decls -Wstack-protector -Wstrict-aliasing=3 -Wswitch-default -Wswitch-enum -Wno-system-headers -Wundef -Wvolatile-register-var -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wdeclaration-after-statement
173
174CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 $(EXTRA_WARNINGS)
170LDFLAGS = -lpthread -lrt -lelf -lm 175LDFLAGS = -lpthread -lrt -lelf -lm
171ALL_CFLAGS = $(CFLAGS) 176ALL_CFLAGS = $(CFLAGS)
172ALL_LDFLAGS = $(LDFLAGS) 177ALL_LDFLAGS = $(LDFLAGS)
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 3bedaa5d21d2..32ff9838351e 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -81,7 +81,7 @@ struct hist_entry {
81struct sort_entry { 81struct sort_entry {
82 struct list_head list; 82 struct list_head list;
83 83
84 char *header; 84 const char *header;
85 85
86 int64_t (*cmp)(struct hist_entry *, struct hist_entry *); 86 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
87 int64_t (*collapse)(struct hist_entry *, struct hist_entry *); 87 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
@@ -225,7 +225,7 @@ static struct sort_entry sort_sym = {
225static int sort__need_collapse = 0; 225static int sort__need_collapse = 0;
226 226
227struct sort_dimension { 227struct sort_dimension {
228 char *name; 228 const char *name;
229 struct sort_entry *entry; 229 struct sort_entry *entry;
230 int taken; 230 int taken;
231}; 231};
@@ -723,7 +723,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
723 const char *path = NULL; 723 const char *path = NULL;
724 unsigned int hits = 0; 724 unsigned int hits = 0;
725 double percent = 0.0; 725 double percent = 0.0;
726 char *color; 726 const char *color;
727 struct sym_ext *sym_ext = sym->priv; 727 struct sym_ext *sym_ext = sym->priv;
728 728
729 offset = line_ip - start; 729 offset = line_ip - start;
@@ -805,7 +805,7 @@ static void free_source_line(struct symbol *sym, int len)
805 805
806/* Get the filename:line for the colored entries */ 806/* Get the filename:line for the colored entries */
807static void 807static void
808get_source_line(struct symbol *sym, u64 start, int len, char *filename) 808get_source_line(struct symbol *sym, u64 start, int len, const char *filename)
809{ 809{
810 int i; 810 int i;
811 char cmd[PATH_MAX * 2]; 811 char cmd[PATH_MAX * 2];
@@ -851,7 +851,7 @@ get_source_line(struct symbol *sym, u64 start, int len, char *filename)
851 } 851 }
852} 852}
853 853
854static void print_summary(char *filename) 854static void print_summary(const char *filename)
855{ 855{
856 struct sym_ext *sym_ext; 856 struct sym_ext *sym_ext;
857 struct rb_node *node; 857 struct rb_node *node;
@@ -867,7 +867,7 @@ static void print_summary(char *filename)
867 node = rb_first(&root_sym_ext); 867 node = rb_first(&root_sym_ext);
868 while (node) { 868 while (node) {
869 double percent; 869 double percent;
870 char *color; 870 const char *color;
871 char *path; 871 char *path;
872 872
873 sym_ext = rb_entry(node, struct sym_ext, node); 873 sym_ext = rb_entry(node, struct sym_ext, node);
@@ -882,7 +882,7 @@ static void print_summary(char *filename)
882 882
883static void annotate_sym(struct dso *dso, struct symbol *sym) 883static void annotate_sym(struct dso *dso, struct symbol *sym)
884{ 884{
885 char *filename = dso->name, *d_filename; 885 const char *filename = dso->name, *d_filename;
886 u64 start, end, len; 886 u64 start, end, len;
887 char command[PATH_MAX*2]; 887 char command[PATH_MAX*2];
888 FILE *file; 888 FILE *file;
@@ -892,7 +892,7 @@ static void annotate_sym(struct dso *dso, struct symbol *sym)
892 if (sym->module) 892 if (sym->module)
893 filename = sym->module->path; 893 filename = sym->module->path;
894 else if (dso == kernel_dso) 894 else if (dso == kernel_dso)
895 filename = vmlinux; 895 filename = vmlinux_name;
896 896
897 start = sym->obj_start; 897 start = sym->obj_start;
898 if (!start) 898 if (!start)
@@ -964,7 +964,7 @@ static int __cmd_annotate(void)
964 int ret, rc = EXIT_FAILURE; 964 int ret, rc = EXIT_FAILURE;
965 unsigned long offset = 0; 965 unsigned long offset = 0;
966 unsigned long head = 0; 966 unsigned long head = 0;
967 struct stat stat; 967 struct stat input_stat;
968 event_t *event; 968 event_t *event;
969 uint32_t size; 969 uint32_t size;
970 char *buf; 970 char *buf;
@@ -977,13 +977,13 @@ static int __cmd_annotate(void)
977 exit(-1); 977 exit(-1);
978 } 978 }
979 979
980 ret = fstat(input, &stat); 980 ret = fstat(input, &input_stat);
981 if (ret < 0) { 981 if (ret < 0) {
982 perror("failed to stat file"); 982 perror("failed to stat file");
983 exit(-1); 983 exit(-1);
984 } 984 }
985 985
986 if (!stat.st_size) { 986 if (!input_stat.st_size) {
987 fprintf(stderr, "zero-sized file, nothing to do!\n"); 987 fprintf(stderr, "zero-sized file, nothing to do!\n");
988 exit(0); 988 exit(0);
989 } 989 }
@@ -1010,10 +1010,10 @@ more:
1010 1010
1011 if (head + event->header.size >= page_size * mmap_window) { 1011 if (head + event->header.size >= page_size * mmap_window) {
1012 unsigned long shift = page_size * (head / page_size); 1012 unsigned long shift = page_size * (head / page_size);
1013 int ret; 1013 int munmap_ret;
1014 1014
1015 ret = munmap(buf, page_size * mmap_window); 1015 munmap_ret = munmap(buf, page_size * mmap_window);
1016 assert(ret == 0); 1016 assert(munmap_ret == 0);
1017 1017
1018 offset += shift; 1018 offset += shift;
1019 head -= shift; 1019 head -= shift;
@@ -1049,7 +1049,7 @@ more:
1049 1049
1050 head += size; 1050 head += size;
1051 1051
1052 if (offset + head < (unsigned long)stat.st_size) 1052 if (offset + head < (unsigned long)input_stat.st_size)
1053 goto more; 1053 goto more;
1054 1054
1055 rc = EXIT_SUCCESS; 1055 rc = EXIT_SUCCESS;
@@ -1092,7 +1092,7 @@ static const struct option options[] = {
1092 "be more verbose (show symbol address, etc)"), 1092 "be more verbose (show symbol address, etc)"),
1093 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, 1093 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1094 "dump raw trace in ASCII"), 1094 "dump raw trace in ASCII"),
1095 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), 1095 OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
1096 OPT_BOOLEAN('m', "modules", &modules, 1096 OPT_BOOLEAN('m', "modules", &modules,
1097 "load module symbols - WARNING: use only with -k and LIVE kernel"), 1097 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1098 OPT_BOOLEAN('l', "print-line", &print_line, 1098 OPT_BOOLEAN('l', "print-line", &print_line,
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 2599d86a733b..4fb8734a796e 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -456,6 +456,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __used)
456 break; 456 break;
457 case HELP_FORMAT_WEB: 457 case HELP_FORMAT_WEB:
458 show_html_page(argv[0]); 458 show_html_page(argv[0]);
459 default:
459 break; 460 break;
460 } 461 }
461 462
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 298f26b8ac78..3b9d24dc0eda 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -97,6 +97,7 @@ static int repsep_fprintf(FILE *fp, const char *fmt, ...)
97 n = vasprintf(&bf, fmt, ap); 97 n = vasprintf(&bf, fmt, ap);
98 if (n > 0) { 98 if (n > 0) {
99 char *sep = bf; 99 char *sep = bf;
100
100 while (1) { 101 while (1) {
101 sep = strchr(sep, *field_sep); 102 sep = strchr(sep, *field_sep);
102 if (sep == NULL) 103 if (sep == NULL)
@@ -144,7 +145,7 @@ struct hist_entry {
144struct sort_entry { 145struct sort_entry {
145 struct list_head list; 146 struct list_head list;
146 147
147 char *header; 148 const char *header;
148 149
149 int64_t (*cmp)(struct hist_entry *, struct hist_entry *); 150 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
150 int64_t (*collapse)(struct hist_entry *, struct hist_entry *); 151 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
@@ -328,7 +329,7 @@ static int sort__need_collapse = 0;
328static int sort__has_parent = 0; 329static int sort__has_parent = 0;
329 330
330struct sort_dimension { 331struct sort_dimension {
331 char *name; 332 const char *name;
332 struct sort_entry *entry; 333 struct sort_entry *entry;
333 int taken; 334 int taken;
334}; 335};
@@ -343,7 +344,7 @@ static struct sort_dimension sort_dimensions[] = {
343 344
344static LIST_HEAD(hist_entry__sort_list); 345static LIST_HEAD(hist_entry__sort_list);
345 346
346static int sort_dimension__add(char *tok) 347static int sort_dimension__add(const char *tok)
347{ 348{
348 unsigned int i; 349 unsigned int i;
349 350
@@ -602,6 +603,7 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
602 case CHAIN_GRAPH_REL: 603 case CHAIN_GRAPH_REL:
603 ret += callchain__fprintf_graph(fp, chain, 604 ret += callchain__fprintf_graph(fp, chain,
604 total_samples, 1, 1); 605 total_samples, 1, 1);
606 case CHAIN_NONE:
605 default: 607 default:
606 break; 608 break;
607 } 609 }
@@ -1290,7 +1292,7 @@ process_lost_event(event_t *event, unsigned long offset, unsigned long head)
1290static void trace_event(event_t *event) 1292static void trace_event(event_t *event)
1291{ 1293{
1292 unsigned char *raw_event = (void *)event; 1294 unsigned char *raw_event = (void *)event;
1293 char *color = PERF_COLOR_BLUE; 1295 const char *color = PERF_COLOR_BLUE;
1294 int i, j; 1296 int i, j;
1295 1297
1296 if (!dump_trace) 1298 if (!dump_trace)
@@ -1348,7 +1350,7 @@ process_read_event(event_t *event, unsigned long offset, unsigned long head)
1348 struct perf_counter_attr *attr = perf_header__find_attr(event->read.id); 1350 struct perf_counter_attr *attr = perf_header__find_attr(event->read.id);
1349 1351
1350 if (show_threads) { 1352 if (show_threads) {
1351 char *name = attr ? __event_name(attr->type, attr->config) 1353 const char *name = attr ? __event_name(attr->type, attr->config)
1352 : "unknown"; 1354 : "unknown";
1353 perf_read_values_add_value(&show_threads_values, 1355 perf_read_values_add_value(&show_threads_values,
1354 event->read.pid, event->read.tid, 1356 event->read.pid, event->read.tid,
@@ -1411,19 +1413,19 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1411 1413
1412static u64 perf_header__sample_type(void) 1414static u64 perf_header__sample_type(void)
1413{ 1415{
1414 u64 sample_type = 0; 1416 u64 type = 0;
1415 int i; 1417 int i;
1416 1418
1417 for (i = 0; i < header->attrs; i++) { 1419 for (i = 0; i < header->attrs; i++) {
1418 struct perf_header_attr *attr = header->attr[i]; 1420 struct perf_header_attr *attr = header->attr[i];
1419 1421
1420 if (!sample_type) 1422 if (!type)
1421 sample_type = attr->attr.sample_type; 1423 type = attr->attr.sample_type;
1422 else if (sample_type != attr->attr.sample_type) 1424 else if (type != attr->attr.sample_type)
1423 die("non matching sample_type"); 1425 die("non matching sample_type");
1424 } 1426 }
1425 1427
1426 return sample_type; 1428 return type;
1427} 1429}
1428 1430
1429static int __cmd_report(void) 1431static int __cmd_report(void)
@@ -1431,7 +1433,7 @@ static int __cmd_report(void)
1431 int ret, rc = EXIT_FAILURE; 1433 int ret, rc = EXIT_FAILURE;
1432 unsigned long offset = 0; 1434 unsigned long offset = 0;
1433 unsigned long head, shift; 1435 unsigned long head, shift;
1434 struct stat stat; 1436 struct stat input_stat;
1435 event_t *event; 1437 event_t *event;
1436 uint32_t size; 1438 uint32_t size;
1437 char *buf; 1439 char *buf;
@@ -1450,13 +1452,13 @@ static int __cmd_report(void)
1450 exit(-1); 1452 exit(-1);
1451 } 1453 }
1452 1454
1453 ret = fstat(input, &stat); 1455 ret = fstat(input, &input_stat);
1454 if (ret < 0) { 1456 if (ret < 0) {
1455 perror("failed to stat file"); 1457 perror("failed to stat file");
1456 exit(-1); 1458 exit(-1);
1457 } 1459 }
1458 1460
1459 if (!stat.st_size) { 1461 if (!input_stat.st_size) {
1460 fprintf(stderr, "zero-sized file, nothing to do!\n"); 1462 fprintf(stderr, "zero-sized file, nothing to do!\n");
1461 exit(0); 1463 exit(0);
1462 } 1464 }
@@ -1524,12 +1526,12 @@ more:
1524 size = 8; 1526 size = 8;
1525 1527
1526 if (head + event->header.size >= page_size * mmap_window) { 1528 if (head + event->header.size >= page_size * mmap_window) {
1527 int ret; 1529 int munmap_ret;
1528 1530
1529 shift = page_size * (head / page_size); 1531 shift = page_size * (head / page_size);
1530 1532
1531 ret = munmap(buf, page_size * mmap_window); 1533 munmap_ret = munmap(buf, page_size * mmap_window);
1532 assert(ret == 0); 1534 assert(munmap_ret == 0);
1533 1535
1534 offset += shift; 1536 offset += shift;
1535 head -= shift; 1537 head -= shift;
@@ -1568,7 +1570,7 @@ more:
1568 if (offset + head >= header->data_offset + header->data_size) 1570 if (offset + head >= header->data_offset + header->data_size)
1569 goto done; 1571 goto done;
1570 1572
1571 if (offset + head < (unsigned long)stat.st_size) 1573 if (offset + head < (unsigned long)input_stat.st_size)
1572 goto more; 1574 goto more;
1573 1575
1574done: 1576done:
@@ -1666,7 +1668,7 @@ static const struct option options[] = {
1666 "be more verbose (show symbol address, etc)"), 1668 "be more verbose (show symbol address, etc)"),
1667 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, 1669 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1668 "dump raw trace in ASCII"), 1670 "dump raw trace in ASCII"),
1669 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), 1671 OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
1670 OPT_BOOLEAN('m', "modules", &modules, 1672 OPT_BOOLEAN('m', "modules", &modules,
1671 "load module symbols - WARNING: use only with -k and LIVE kernel"), 1673 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1672 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples, 1674 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 9a6dbbff9a9f..06f763e4b35b 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -120,7 +120,8 @@ static void parse_source(struct sym_entry *syme)
120 struct module *module; 120 struct module *module;
121 struct section *section = NULL; 121 struct section *section = NULL;
122 FILE *file; 122 FILE *file;
123 char command[PATH_MAX*2], *path = vmlinux; 123 char command[PATH_MAX*2];
124 const char *path = vmlinux_name;
124 u64 start, end, len; 125 u64 start, end, len;
125 126
126 if (!syme) 127 if (!syme)
@@ -487,10 +488,12 @@ static void print_sym_table(void)
487 ); 488 );
488 489
489 for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { 490 for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
490 struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); 491 struct symbol *sym;
491 struct symbol *sym = (struct symbol *)(syme + 1);
492 double pcnt; 492 double pcnt;
493 493
494 syme = rb_entry(nd, struct sym_entry, rb_node);
495 sym = (struct symbol *)(syme + 1);
496
494 if (++printed > print_entries || (int)syme->snap_count < count_filter) 497 if (++printed > print_entries || (int)syme->snap_count < count_filter)
495 continue; 498 continue;
496 499
@@ -609,7 +612,7 @@ static void print_mapped_keys(void)
609 612
610 fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter); 613 fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
611 614
612 if (vmlinux) { 615 if (vmlinux_name) {
613 fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter); 616 fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
614 fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL"); 617 fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
615 fprintf(stdout, "\t[S] stop annotation.\n"); 618 fprintf(stdout, "\t[S] stop annotation.\n");
@@ -638,7 +641,9 @@ static int key_mapped(int c)
638 case 'F': 641 case 'F':
639 case 's': 642 case 's':
640 case 'S': 643 case 'S':
641 return vmlinux ? 1 : 0; 644 return vmlinux_name ? 1 : 0;
645 default:
646 break;
642 } 647 }
643 648
644 return 0; 649 return 0;
@@ -724,6 +729,8 @@ static void handle_keypress(int c)
724 case 'z': 729 case 'z':
725 zero = ~zero; 730 zero = ~zero;
726 break; 731 break;
732 default:
733 break;
727 } 734 }
728} 735}
729 736
@@ -812,13 +819,13 @@ static int parse_symbols(void)
812{ 819{
813 struct rb_node *node; 820 struct rb_node *node;
814 struct symbol *sym; 821 struct symbol *sym;
815 int modules = vmlinux ? 1 : 0; 822 int use_modules = vmlinux_name ? 1 : 0;
816 823
817 kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry)); 824 kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry));
818 if (kernel_dso == NULL) 825 if (kernel_dso == NULL)
819 return -1; 826 return -1;
820 827
821 if (dso__load_kernel(kernel_dso, vmlinux, symbol_filter, verbose, modules) <= 0) 828 if (dso__load_kernel(kernel_dso, vmlinux_name, symbol_filter, verbose, use_modules) <= 0)
822 goto out_delete_dso; 829 goto out_delete_dso;
823 830
824 node = rb_first(&kernel_dso->syms); 831 node = rb_first(&kernel_dso->syms);
@@ -1114,7 +1121,7 @@ static const struct option options[] = {
1114 "system-wide collection from all CPUs"), 1121 "system-wide collection from all CPUs"),
1115 OPT_INTEGER('C', "CPU", &profile_cpu, 1122 OPT_INTEGER('C', "CPU", &profile_cpu,
1116 "CPU to profile on"), 1123 "CPU to profile on"),
1117 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), 1124 OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
1118 OPT_INTEGER('m', "mmap-pages", &mmap_pages, 1125 OPT_INTEGER('m', "mmap-pages", &mmap_pages,
1119 "number of mmap data pages"), 1126 "number of mmap data pages"),
1120 OPT_INTEGER('r', "realtime", &realtime_prio, 1127 OPT_INTEGER('r', "realtime", &realtime_prio,
diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c
index 61d33b81fc97..a791dd467261 100644
--- a/tools/perf/util/abspath.c
+++ b/tools/perf/util/abspath.c
@@ -50,7 +50,8 @@ const char *make_absolute_path(const char *path)
50 die ("Could not get current working directory"); 50 die ("Could not get current working directory");
51 51
52 if (last_elem) { 52 if (last_elem) {
53 int len = strlen(buf); 53 len = strlen(buf);
54
54 if (len + strlen(last_elem) + 2 > PATH_MAX) 55 if (len + strlen(last_elem) + 2 > PATH_MAX)
55 die ("Too long path name: '%s/%s'", 56 die ("Too long path name: '%s/%s'",
56 buf, last_elem); 57 buf, last_elem);
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 4b50c412b9c5..6f8ea9d210b6 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -52,7 +52,6 @@ extern const char *perf_mailmap_file;
52extern void maybe_flush_or_die(FILE *, const char *); 52extern void maybe_flush_or_die(FILE *, const char *);
53extern int copy_fd(int ifd, int ofd); 53extern int copy_fd(int ifd, int ofd);
54extern int copy_file(const char *dst, const char *src, int mode); 54extern int copy_file(const char *dst, const char *src, int mode);
55extern ssize_t read_in_full(int fd, void *buf, size_t count);
56extern ssize_t write_in_full(int fd, const void *buf, size_t count); 55extern ssize_t write_in_full(int fd, const void *buf, size_t count);
57extern void write_or_die(int fd, const void *buf, size_t count); 56extern void write_or_die(int fd, const void *buf, size_t count);
58extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); 57extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 011473411642..3b8380f1b478 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -50,6 +50,7 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,
50 else 50 else
51 p = &(*p)->rb_right; 51 p = &(*p)->rb_right;
52 break; 52 break;
53 case CHAIN_NONE:
53 default: 54 default:
54 break; 55 break;
55 } 56 }
@@ -143,6 +144,7 @@ int register_callchain_param(struct callchain_param *param)
143 case CHAIN_FLAT: 144 case CHAIN_FLAT:
144 param->sort = sort_chain_flat; 145 param->sort = sort_chain_flat;
145 break; 146 break;
147 case CHAIN_NONE:
146 default: 148 default:
147 return -1; 149 return -1;
148 } 150 }
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index 90a044d1fe7d..e47fdeb85391 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -242,9 +242,9 @@ int color_fwrite_lines(FILE *fp, const char *color,
242 return 0; 242 return 0;
243} 243}
244 244
245char *get_percent_color(double percent) 245const char *get_percent_color(double percent)
246{ 246{
247 char *color = PERF_COLOR_NORMAL; 247 const char *color = PERF_COLOR_NORMAL;
248 248
249 /* 249 /*
250 * We color high-overhead entries in red, mid-overhead 250 * We color high-overhead entries in red, mid-overhead
@@ -263,7 +263,7 @@ char *get_percent_color(double percent)
263int percent_color_fprintf(FILE *fp, const char *fmt, double percent) 263int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
264{ 264{
265 int r; 265 int r;
266 char *color; 266 const char *color;
267 267
268 color = get_percent_color(percent); 268 color = get_percent_color(percent);
269 r = color_fprintf(fp, color, fmt, percent); 269 r = color_fprintf(fp, color, fmt, percent);
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h
index 706cec50bd25..43d0d1b67c45 100644
--- a/tools/perf/util/color.h
+++ b/tools/perf/util/color.h
@@ -36,6 +36,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
36int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); 36int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
37int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); 37int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
38int percent_color_fprintf(FILE *fp, const char *fmt, double percent); 38int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
39char *get_percent_color(double percent); 39const char *get_percent_color(double percent);
40 40
41#endif /* COLOR_H */ 41#endif /* COLOR_H */
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 780df541006d..8784649109ce 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -160,17 +160,18 @@ static int get_extended_base_var(char *name, int baselen, int c)
160 name[baselen++] = '.'; 160 name[baselen++] = '.';
161 161
162 for (;;) { 162 for (;;) {
163 int c = get_next_char(); 163 int ch = get_next_char();
164 if (c == '\n') 164
165 if (ch == '\n')
165 return -1; 166 return -1;
166 if (c == '"') 167 if (ch == '"')
167 break; 168 break;
168 if (c == '\\') { 169 if (ch == '\\') {
169 c = get_next_char(); 170 ch = get_next_char();
170 if (c == '\n') 171 if (ch == '\n')
171 return -1; 172 return -1;
172 } 173 }
173 name[baselen++] = c; 174 name[baselen++] = ch;
174 if (baselen > MAXNAME / 2) 175 if (baselen > MAXNAME / 2)
175 return -1; 176 return -1;
176 } 177 }
@@ -530,6 +531,8 @@ static int store_aux(const char* key, const char* value, void *cb __used)
530 store.offset[store.seen] = ftell(config_file); 531 store.offset[store.seen] = ftell(config_file);
531 } 532 }
532 } 533 }
534 default:
535 break;
533 } 536 }
534 return 0; 537 return 0;
535} 538}
@@ -619,6 +622,7 @@ contline:
619 switch (contents[offset]) { 622 switch (contents[offset]) {
620 case '=': equal_offset = offset; break; 623 case '=': equal_offset = offset; break;
621 case ']': bracket_offset = offset; break; 624 case ']': bracket_offset = offset; break;
625 default: break;
622 } 626 }
623 if (offset > 0 && contents[offset-1] == '\\') { 627 if (offset > 0 && contents[offset-1] == '\\') {
624 offset_ = offset; 628 offset_ = offset;
@@ -742,9 +746,9 @@ int perf_config_set_multivar(const char* key, const char* value,
742 goto write_err_out; 746 goto write_err_out;
743 } else { 747 } else {
744 struct stat st; 748 struct stat st;
745 char* contents; 749 char *contents;
746 ssize_t contents_sz, copy_begin, copy_end; 750 ssize_t contents_sz, copy_begin, copy_end;
747 int i, new_line = 0; 751 int new_line = 0;
748 752
749 if (value_regex == NULL) 753 if (value_regex == NULL)
750 store.value_regex = NULL; 754 store.value_regex = NULL;
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 34a352867382..2745605dba11 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -6,7 +6,6 @@
6 6
7#define MAX_ARGS 32 7#define MAX_ARGS 32
8 8
9extern char **environ;
10static const char *argv_exec_path; 9static const char *argv_exec_path;
11static const char *argv0_path; 10static const char *argv0_path;
12 11
diff --git a/tools/perf/util/module.c b/tools/perf/util/module.c
index ddabe925d65d..3d567fe59c79 100644
--- a/tools/perf/util/module.c
+++ b/tools/perf/util/module.c
@@ -436,9 +436,9 @@ static int mod_dso__load_module_paths(struct mod_dso *self)
436 goto out_failure; 436 goto out_failure;
437 437
438 while (!feof(file)) { 438 while (!feof(file)) {
439 char *path, *name, *tmp; 439 char *name, *tmp;
440 struct module *module; 440 struct module *module;
441 int line_len, len; 441 int line_len;
442 442
443 line_len = getline(&line, &n, file); 443 line_len = getline(&line, &n, file);
444 if (line_len < 0) 444 if (line_len < 0)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 044178408783..1cda97b39118 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -14,10 +14,10 @@ int nr_counters;
14struct perf_counter_attr attrs[MAX_COUNTERS]; 14struct perf_counter_attr attrs[MAX_COUNTERS];
15 15
16struct event_symbol { 16struct event_symbol {
17 u8 type; 17 u8 type;
18 u64 config; 18 u64 config;
19 char *symbol; 19 const char *symbol;
20 char *alias; 20 const char *alias;
21}; 21};
22 22
23char debugfs_path[MAXPATHLEN]; 23char debugfs_path[MAXPATHLEN];
@@ -51,7 +51,7 @@ static struct event_symbol event_symbols[] = {
51#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE) 51#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE)
52#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT) 52#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT)
53 53
54static char *hw_event_names[] = { 54static const char *hw_event_names[] = {
55 "cycles", 55 "cycles",
56 "instructions", 56 "instructions",
57 "cache-references", 57 "cache-references",
@@ -61,7 +61,7 @@ static char *hw_event_names[] = {
61 "bus-cycles", 61 "bus-cycles",
62}; 62};
63 63
64static char *sw_event_names[] = { 64static const char *sw_event_names[] = {
65 "cpu-clock-msecs", 65 "cpu-clock-msecs",
66 "task-clock-msecs", 66 "task-clock-msecs",
67 "page-faults", 67 "page-faults",
@@ -73,7 +73,7 @@ static char *sw_event_names[] = {
73 73
74#define MAX_ALIASES 8 74#define MAX_ALIASES 8
75 75
76static char *hw_cache[][MAX_ALIASES] = { 76static const char *hw_cache[][MAX_ALIASES] = {
77 { "L1-dcache", "l1-d", "l1d", "L1-data", }, 77 { "L1-dcache", "l1-d", "l1d", "L1-data", },
78 { "L1-icache", "l1-i", "l1i", "L1-instruction", }, 78 { "L1-icache", "l1-i", "l1i", "L1-instruction", },
79 { "LLC", "L2" }, 79 { "LLC", "L2" },
@@ -82,13 +82,13 @@ static char *hw_cache[][MAX_ALIASES] = {
82 { "branch", "branches", "bpu", "btb", "bpc", }, 82 { "branch", "branches", "bpu", "btb", "bpc", },
83}; 83};
84 84
85static char *hw_cache_op[][MAX_ALIASES] = { 85static const char *hw_cache_op[][MAX_ALIASES] = {
86 { "load", "loads", "read", }, 86 { "load", "loads", "read", },
87 { "store", "stores", "write", }, 87 { "store", "stores", "write", },
88 { "prefetch", "prefetches", "speculative-read", "speculative-load", }, 88 { "prefetch", "prefetches", "speculative-read", "speculative-load", },
89}; 89};
90 90
91static char *hw_cache_result[][MAX_ALIASES] = { 91static const char *hw_cache_result[][MAX_ALIASES] = {
92 { "refs", "Reference", "ops", "access", }, 92 { "refs", "Reference", "ops", "access", },
93 { "misses", "miss", }, 93 { "misses", "miss", },
94}; 94};
@@ -158,7 +158,7 @@ int valid_debugfs_mount(const char *debugfs)
158 return 0; 158 return 0;
159} 159}
160 160
161static char *tracepoint_id_to_name(u64 config) 161static const char *tracepoint_id_to_name(u64 config)
162{ 162{
163 static char tracepoint_name[2 * MAX_EVENT_LENGTH]; 163 static char tracepoint_name[2 * MAX_EVENT_LENGTH];
164 DIR *sys_dir, *evt_dir; 164 DIR *sys_dir, *evt_dir;
@@ -235,7 +235,7 @@ static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
235 return name; 235 return name;
236} 236}
237 237
238char *event_name(int counter) 238const char *event_name(int counter)
239{ 239{
240 u64 config = attrs[counter].config; 240 u64 config = attrs[counter].config;
241 int type = attrs[counter].type; 241 int type = attrs[counter].type;
@@ -243,7 +243,7 @@ char *event_name(int counter)
243 return __event_name(type, config); 243 return __event_name(type, config);
244} 244}
245 245
246char *__event_name(int type, u64 config) 246const char *__event_name(int type, u64 config)
247{ 247{
248 static char buf[32]; 248 static char buf[32];
249 249
@@ -294,7 +294,7 @@ char *__event_name(int type, u64 config)
294 return "unknown"; 294 return "unknown";
295} 295}
296 296
297static int parse_aliases(const char **str, char *names[][MAX_ALIASES], int size) 297static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size)
298{ 298{
299 int i, j; 299 int i, j;
300 int n, longest = -1; 300 int n, longest = -1;
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 192a962e3a0f..9b1aeea01636 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -9,8 +9,8 @@ extern int nr_counters;
9 9
10extern struct perf_counter_attr attrs[MAX_COUNTERS]; 10extern struct perf_counter_attr attrs[MAX_COUNTERS];
11 11
12extern char *event_name(int ctr); 12extern const char *event_name(int ctr);
13extern char *__event_name(int type, u64 config); 13extern const char *__event_name(int type, u64 config);
14 14
15extern int parse_events(const struct option *opt, const char *str, int unset); 15extern int parse_events(const struct option *opt, const char *str, int unset);
16 16
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 1bf67190c820..6d8af48c925e 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -53,6 +53,12 @@ static int get_value(struct parse_opt_ctx_t *p,
53 case OPTION_SET_INT: 53 case OPTION_SET_INT:
54 case OPTION_SET_PTR: 54 case OPTION_SET_PTR:
55 return opterror(opt, "takes no value", flags); 55 return opterror(opt, "takes no value", flags);
56 case OPTION_END:
57 case OPTION_ARGUMENT:
58 case OPTION_GROUP:
59 case OPTION_STRING:
60 case OPTION_INTEGER:
61 case OPTION_LONG:
56 default: 62 default:
57 break; 63 break;
58 } 64 }
@@ -130,6 +136,9 @@ static int get_value(struct parse_opt_ctx_t *p,
130 return opterror(opt, "expects a numerical value", flags); 136 return opterror(opt, "expects a numerical value", flags);
131 return 0; 137 return 0;
132 138
139 case OPTION_END:
140 case OPTION_ARGUMENT:
141 case OPTION_GROUP:
133 default: 142 default:
134 die("should not happen, someone must be hit on the forehead"); 143 die("should not happen, someone must be hit on the forehead");
135 } 144 }
@@ -296,6 +305,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
296 return parse_options_usage(usagestr, options); 305 return parse_options_usage(usagestr, options);
297 case -2: 306 case -2:
298 goto unknown; 307 goto unknown;
308 default:
309 break;
299 } 310 }
300 if (ctx->opt) 311 if (ctx->opt)
301 check_typos(arg + 1, options); 312 check_typos(arg + 1, options);
@@ -314,6 +325,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
314 ctx->argv[0] = strdup(ctx->opt - 1); 325 ctx->argv[0] = strdup(ctx->opt - 1);
315 *(char *)ctx->argv[0] = '-'; 326 *(char *)ctx->argv[0] = '-';
316 goto unknown; 327 goto unknown;
328 default:
329 break;
317 } 330 }
318 } 331 }
319 continue; 332 continue;
@@ -336,6 +349,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
336 return parse_options_usage(usagestr, options); 349 return parse_options_usage(usagestr, options);
337 case -2: 350 case -2:
338 goto unknown; 351 goto unknown;
352 default:
353 break;
339 } 354 }
340 continue; 355 continue;
341unknown: 356unknown:
@@ -456,6 +471,13 @@ int usage_with_options_internal(const char * const *usagestr,
456 } 471 }
457 break; 472 break;
458 default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ 473 default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */
474 case OPTION_END:
475 case OPTION_GROUP:
476 case OPTION_BIT:
477 case OPTION_BOOLEAN:
478 case OPTION_SET_INT:
479 case OPTION_SET_PTR:
480 case OPTION_LONG:
459 break; 481 break;
460 } 482 }
461 483
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index a501a40dd2cb..fd1f2faaade4 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -17,7 +17,7 @@ static char bad_path[] = "/bad-path/";
17 * Two hacks: 17 * Two hacks:
18 */ 18 */
19 19
20static char *get_perf_dir(void) 20static const char *get_perf_dir(void)
21{ 21{
22 return "."; 22 return ".";
23} 23}
@@ -38,8 +38,9 @@ size_t strlcpy(char *dest, const char *src, size_t size)
38static char *get_pathname(void) 38static char *get_pathname(void)
39{ 39{
40 static char pathname_array[4][PATH_MAX]; 40 static char pathname_array[4][PATH_MAX];
41 static int index; 41 static int idx;
42 return pathname_array[3 & ++index]; 42
43 return pathname_array[3 & ++idx];
43} 44}
44 45
45static char *cleanup_path(char *path) 46static char *cleanup_path(char *path)
@@ -161,20 +162,24 @@ int perf_mkstemp(char *path, size_t len, const char *template)
161} 162}
162 163
163 164
164const char *make_relative_path(const char *abs, const char *base) 165const char *make_relative_path(const char *abs_path, const char *base)
165{ 166{
166 static char buf[PATH_MAX + 1]; 167 static char buf[PATH_MAX + 1];
167 int baselen; 168 int baselen;
169
168 if (!base) 170 if (!base)
169 return abs; 171 return abs_path;
172
170 baselen = strlen(base); 173 baselen = strlen(base);
171 if (prefixcmp(abs, base)) 174 if (prefixcmp(abs_path, base))
172 return abs; 175 return abs_path;
173 if (abs[baselen] == '/') 176 if (abs_path[baselen] == '/')
174 baselen++; 177 baselen++;
175 else if (base[baselen - 1] != '/') 178 else if (base[baselen - 1] != '/')
176 return abs; 179 return abs_path;
177 strcpy(buf, abs + baselen); 180
181 strcpy(buf, abs_path + baselen);
182
178 return buf; 183 return buf;
179} 184}
180 185
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c
index a3935343091a..2b615acf94d7 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/perf/util/run-command.c
@@ -262,7 +262,7 @@ int run_hook(const char *index_file, const char *name, ...)
262{ 262{
263 struct child_process hook; 263 struct child_process hook;
264 const char **argv = NULL, *env[2]; 264 const char **argv = NULL, *env[2];
265 char index[PATH_MAX]; 265 char idx[PATH_MAX];
266 va_list args; 266 va_list args;
267 int ret; 267 int ret;
268 size_t i = 0, alloc = 0; 268 size_t i = 0, alloc = 0;
@@ -284,8 +284,8 @@ int run_hook(const char *index_file, const char *name, ...)
284 hook.no_stdin = 1; 284 hook.no_stdin = 1;
285 hook.stdout_to_stderr = 1; 285 hook.stdout_to_stderr = 1;
286 if (index_file) { 286 if (index_file) {
287 snprintf(index, sizeof(index), "PERF_INDEX_FILE=%s", index_file); 287 snprintf(idx, sizeof(idx), "PERF_INDEX_FILE=%s", index_file);
288 env[0] = index; 288 env[0] = idx;
289 env[1] = NULL; 289 env[1] = NULL;
290 hook.env = env; 290 hook.env = env;
291 } 291 }
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 0b9862351260..3159d47ae1cc 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -21,7 +21,7 @@ enum dso_origin {
21 21
22static struct symbol *symbol__new(u64 start, u64 len, 22static struct symbol *symbol__new(u64 start, u64 len,
23 const char *name, unsigned int priv_size, 23 const char *name, unsigned int priv_size,
24 u64 obj_start, int verbose) 24 u64 obj_start, int v)
25{ 25{
26 size_t namelen = strlen(name) + 1; 26 size_t namelen = strlen(name) + 1;
27 struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen); 27 struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen);
@@ -29,7 +29,7 @@ static struct symbol *symbol__new(u64 start, u64 len,
29 if (!self) 29 if (!self)
30 return NULL; 30 return NULL;
31 31
32 if (verbose >= 2) 32 if (v >= 2)
33 printf("new symbol: %016Lx [%08lx]: %s, hist: %p, obj_start: %p\n", 33 printf("new symbol: %016Lx [%08lx]: %s, hist: %p, obj_start: %p\n",
34 (u64)start, (unsigned long)len, name, self->hist, (void *)(unsigned long)obj_start); 34 (u64)start, (unsigned long)len, name, self->hist, (void *)(unsigned long)obj_start);
35 35
@@ -156,7 +156,7 @@ size_t dso__fprintf(struct dso *self, FILE *fp)
156 return ret; 156 return ret;
157} 157}
158 158
159static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int verbose) 159static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int v)
160{ 160{
161 struct rb_node *nd, *prevnd; 161 struct rb_node *nd, *prevnd;
162 char *line = NULL; 162 char *line = NULL;
@@ -198,7 +198,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int verb
198 * Well fix up the end later, when we have all sorted. 198 * Well fix up the end later, when we have all sorted.
199 */ 199 */
200 sym = symbol__new(start, 0xdead, line + len + 2, 200 sym = symbol__new(start, 0xdead, line + len + 2,
201 self->sym_priv_size, 0, verbose); 201 self->sym_priv_size, 0, v);
202 202
203 if (sym == NULL) 203 if (sym == NULL)
204 goto out_delete_line; 204 goto out_delete_line;
@@ -239,7 +239,7 @@ out_failure:
239 return -1; 239 return -1;
240} 240}
241 241
242static int dso__load_perf_map(struct dso *self, symbol_filter_t filter, int verbose) 242static int dso__load_perf_map(struct dso *self, symbol_filter_t filter, int v)
243{ 243{
244 char *line = NULL; 244 char *line = NULL;
245 size_t n; 245 size_t n;
@@ -277,7 +277,7 @@ static int dso__load_perf_map(struct dso *self, symbol_filter_t filter, int verb
277 continue; 277 continue;
278 278
279 sym = symbol__new(start, size, line + len, 279 sym = symbol__new(start, size, line + len,
280 self->sym_priv_size, start, verbose); 280 self->sym_priv_size, start, v);
281 281
282 if (sym == NULL) 282 if (sym == NULL)
283 goto out_delete_line; 283 goto out_delete_line;
@@ -305,13 +305,13 @@ out_failure:
305 * elf_symtab__for_each_symbol - iterate thru all the symbols 305 * elf_symtab__for_each_symbol - iterate thru all the symbols
306 * 306 *
307 * @self: struct elf_symtab instance to iterate 307 * @self: struct elf_symtab instance to iterate
308 * @index: uint32_t index 308 * @idx: uint32_t idx
309 * @sym: GElf_Sym iterator 309 * @sym: GElf_Sym iterator
310 */ 310 */
311#define elf_symtab__for_each_symbol(syms, nr_syms, index, sym) \ 311#define elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) \
312 for (index = 0, gelf_getsym(syms, index, &sym);\ 312 for (idx = 0, gelf_getsym(syms, idx, &sym);\
313 index < nr_syms; \ 313 idx < nr_syms; \
314 index++, gelf_getsym(syms, index, &sym)) 314 idx++, gelf_getsym(syms, idx, &sym))
315 315
316static inline uint8_t elf_sym__type(const GElf_Sym *sym) 316static inline uint8_t elf_sym__type(const GElf_Sym *sym)
317{ 317{
@@ -354,7 +354,7 @@ static inline const char *elf_sym__name(const GElf_Sym *sym,
354 354
355static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, 355static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
356 GElf_Shdr *shp, const char *name, 356 GElf_Shdr *shp, const char *name,
357 size_t *index) 357 size_t *idx)
358{ 358{
359 Elf_Scn *sec = NULL; 359 Elf_Scn *sec = NULL;
360 size_t cnt = 1; 360 size_t cnt = 1;
@@ -365,8 +365,8 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
365 gelf_getshdr(sec, shp); 365 gelf_getshdr(sec, shp);
366 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); 366 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
367 if (!strcmp(name, str)) { 367 if (!strcmp(name, str)) {
368 if (index) 368 if (idx)
369 *index = cnt; 369 *idx = cnt;
370 break; 370 break;
371 } 371 }
372 ++cnt; 372 ++cnt;
@@ -392,7 +392,7 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
392 * And always look at the original dso, not at debuginfo packages, that 392 * And always look at the original dso, not at debuginfo packages, that
393 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS). 393 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS).
394 */ 394 */
395static int dso__synthesize_plt_symbols(struct dso *self, int verbose) 395static int dso__synthesize_plt_symbols(struct dso *self, int v)
396{ 396{
397 uint32_t nr_rel_entries, idx; 397 uint32_t nr_rel_entries, idx;
398 GElf_Sym sym; 398 GElf_Sym sym;
@@ -442,7 +442,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
442 goto out_elf_end; 442 goto out_elf_end;
443 443
444 /* 444 /*
445 * Fetch the relocation section to find the indexes to the GOT 445 * Fetch the relocation section to find the idxes to the GOT
446 * and the symbols in the .dynsym they refer to. 446 * and the symbols in the .dynsym they refer to.
447 */ 447 */
448 reldata = elf_getdata(scn_plt_rel, NULL); 448 reldata = elf_getdata(scn_plt_rel, NULL);
@@ -476,7 +476,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
476 "%s@plt", elf_sym__name(&sym, symstrs)); 476 "%s@plt", elf_sym__name(&sym, symstrs));
477 477
478 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 478 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
479 sympltname, self->sym_priv_size, 0, verbose); 479 sympltname, self->sym_priv_size, 0, v);
480 if (!f) 480 if (!f)
481 goto out_elf_end; 481 goto out_elf_end;
482 482
@@ -494,7 +494,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
494 "%s@plt", elf_sym__name(&sym, symstrs)); 494 "%s@plt", elf_sym__name(&sym, symstrs));
495 495
496 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 496 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
497 sympltname, self->sym_priv_size, 0, verbose); 497 sympltname, self->sym_priv_size, 0, v);
498 if (!f) 498 if (!f)
499 goto out_elf_end; 499 goto out_elf_end;
500 500
@@ -518,12 +518,12 @@ out:
518} 518}
519 519
520static int dso__load_sym(struct dso *self, int fd, const char *name, 520static int dso__load_sym(struct dso *self, int fd, const char *name,
521 symbol_filter_t filter, int verbose, struct module *mod) 521 symbol_filter_t filter, int v, struct module *mod)
522{ 522{
523 Elf_Data *symstrs, *secstrs; 523 Elf_Data *symstrs, *secstrs;
524 uint32_t nr_syms; 524 uint32_t nr_syms;
525 int err = -1; 525 int err = -1;
526 uint32_t index; 526 uint32_t idx;
527 GElf_Ehdr ehdr; 527 GElf_Ehdr ehdr;
528 GElf_Shdr shdr; 528 GElf_Shdr shdr;
529 Elf_Data *syms; 529 Elf_Data *syms;
@@ -534,14 +534,14 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
534 534
535 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); 535 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
536 if (elf == NULL) { 536 if (elf == NULL) {
537 if (verbose) 537 if (v)
538 fprintf(stderr, "%s: cannot read %s ELF file.\n", 538 fprintf(stderr, "%s: cannot read %s ELF file.\n",
539 __func__, name); 539 __func__, name);
540 goto out_close; 540 goto out_close;
541 } 541 }
542 542
543 if (gelf_getehdr(elf, &ehdr) == NULL) { 543 if (gelf_getehdr(elf, &ehdr) == NULL) {
544 if (verbose) 544 if (v)
545 fprintf(stderr, "%s: cannot get elf header.\n", __func__); 545 fprintf(stderr, "%s: cannot get elf header.\n", __func__);
546 goto out_elf_end; 546 goto out_elf_end;
547 } 547 }
@@ -583,9 +583,9 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
583 NULL) != NULL); 583 NULL) != NULL);
584 } else self->adjust_symbols = 0; 584 } else self->adjust_symbols = 0;
585 585
586 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { 586 elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) {
587 struct symbol *f; 587 struct symbol *f;
588 const char *name; 588 const char *elf_name;
589 char *demangled; 589 char *demangled;
590 u64 obj_start; 590 u64 obj_start;
591 struct section *section = NULL; 591 struct section *section = NULL;
@@ -608,7 +608,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
608 obj_start = sym.st_value; 608 obj_start = sym.st_value;
609 609
610 if (self->adjust_symbols) { 610 if (self->adjust_symbols) {
611 if (verbose >= 2) 611 if (v >= 2)
612 printf("adjusting symbol: st_value: %Lx sh_addr: %Lx sh_offset: %Lx\n", 612 printf("adjusting symbol: st_value: %Lx sh_addr: %Lx sh_offset: %Lx\n",
613 (u64)sym.st_value, (u64)shdr.sh_addr, (u64)shdr.sh_offset); 613 (u64)sym.st_value, (u64)shdr.sh_addr, (u64)shdr.sh_offset);
614 614
@@ -630,13 +630,13 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
630 * DWARF DW_compile_unit has this, but we don't always have access 630 * DWARF DW_compile_unit has this, but we don't always have access
631 * to it... 631 * to it...
632 */ 632 */
633 name = elf_sym__name(&sym, symstrs); 633 elf_name = elf_sym__name(&sym, symstrs);
634 demangled = bfd_demangle(NULL, name, DMGL_PARAMS | DMGL_ANSI); 634 demangled = bfd_demangle(NULL, elf_name, DMGL_PARAMS | DMGL_ANSI);
635 if (demangled != NULL) 635 if (demangled != NULL)
636 name = demangled; 636 elf_name = demangled;
637 637
638 f = symbol__new(sym.st_value, sym.st_size, name, 638 f = symbol__new(sym.st_value, sym.st_size, elf_name,
639 self->sym_priv_size, obj_start, verbose); 639 self->sym_priv_size, obj_start, v);
640 free(demangled); 640 free(demangled);
641 if (!f) 641 if (!f)
642 goto out_elf_end; 642 goto out_elf_end;
@@ -659,7 +659,7 @@ out_close:
659 659
660#define BUILD_ID_SIZE 128 660#define BUILD_ID_SIZE 128
661 661
662static char *dso__read_build_id(struct dso *self, int verbose) 662static char *dso__read_build_id(struct dso *self, int v)
663{ 663{
664 int i; 664 int i;
665 GElf_Ehdr ehdr; 665 GElf_Ehdr ehdr;
@@ -676,14 +676,14 @@ static char *dso__read_build_id(struct dso *self, int verbose)
676 676
677 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); 677 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
678 if (elf == NULL) { 678 if (elf == NULL) {
679 if (verbose) 679 if (v)
680 fprintf(stderr, "%s: cannot read %s ELF file.\n", 680 fprintf(stderr, "%s: cannot read %s ELF file.\n",
681 __func__, self->name); 681 __func__, self->name);
682 goto out_close; 682 goto out_close;
683 } 683 }
684 684
685 if (gelf_getehdr(elf, &ehdr) == NULL) { 685 if (gelf_getehdr(elf, &ehdr) == NULL) {
686 if (verbose) 686 if (v)
687 fprintf(stderr, "%s: cannot get elf header.\n", __func__); 687 fprintf(stderr, "%s: cannot get elf header.\n", __func__);
688 goto out_elf_end; 688 goto out_elf_end;
689 } 689 }
@@ -706,7 +706,7 @@ static char *dso__read_build_id(struct dso *self, int verbose)
706 ++raw; 706 ++raw;
707 bid += 2; 707 bid += 2;
708 } 708 }
709 if (verbose >= 2) 709 if (v >= 2)
710 printf("%s(%s): %s\n", __func__, self->name, build_id); 710 printf("%s(%s): %s\n", __func__, self->name, build_id);
711out_elf_end: 711out_elf_end:
712 elf_end(elf); 712 elf_end(elf);
@@ -732,7 +732,7 @@ char dso__symtab_origin(const struct dso *self)
732 return origin[self->origin]; 732 return origin[self->origin];
733} 733}
734 734
735int dso__load(struct dso *self, symbol_filter_t filter, int verbose) 735int dso__load(struct dso *self, symbol_filter_t filter, int v)
736{ 736{
737 int size = PATH_MAX; 737 int size = PATH_MAX;
738 char *name = malloc(size), *build_id = NULL; 738 char *name = malloc(size), *build_id = NULL;
@@ -745,7 +745,7 @@ int dso__load(struct dso *self, symbol_filter_t filter, int verbose)
745 self->adjust_symbols = 0; 745 self->adjust_symbols = 0;
746 746
747 if (strncmp(self->name, "/tmp/perf-", 10) == 0) { 747 if (strncmp(self->name, "/tmp/perf-", 10) == 0) {
748 ret = dso__load_perf_map(self, filter, verbose); 748 ret = dso__load_perf_map(self, filter, v);
749 self->origin = ret > 0 ? DSO__ORIG_JAVA_JIT : 749 self->origin = ret > 0 ? DSO__ORIG_JAVA_JIT :
750 DSO__ORIG_NOT_FOUND; 750 DSO__ORIG_NOT_FOUND;
751 return ret; 751 return ret;
@@ -764,7 +764,7 @@ more:
764 snprintf(name, size, "/usr/lib/debug%s", self->name); 764 snprintf(name, size, "/usr/lib/debug%s", self->name);
765 break; 765 break;
766 case DSO__ORIG_BUILDID: 766 case DSO__ORIG_BUILDID:
767 build_id = dso__read_build_id(self, verbose); 767 build_id = dso__read_build_id(self, v);
768 if (build_id != NULL) { 768 if (build_id != NULL) {
769 snprintf(name, size, 769 snprintf(name, size,
770 "/usr/lib/debug/.build-id/%.2s/%s.debug", 770 "/usr/lib/debug/.build-id/%.2s/%s.debug",
@@ -785,7 +785,7 @@ more:
785 fd = open(name, O_RDONLY); 785 fd = open(name, O_RDONLY);
786 } while (fd < 0); 786 } while (fd < 0);
787 787
788 ret = dso__load_sym(self, fd, name, filter, verbose, NULL); 788 ret = dso__load_sym(self, fd, name, filter, v, NULL);
789 close(fd); 789 close(fd);
790 790
791 /* 791 /*
@@ -795,7 +795,7 @@ more:
795 goto more; 795 goto more;
796 796
797 if (ret > 0) { 797 if (ret > 0) {
798 int nr_plt = dso__synthesize_plt_symbols(self, verbose); 798 int nr_plt = dso__synthesize_plt_symbols(self, v);
799 if (nr_plt > 0) 799 if (nr_plt > 0)
800 ret += nr_plt; 800 ret += nr_plt;
801 } 801 }
@@ -807,7 +807,7 @@ out:
807} 807}
808 808
809static int dso__load_module(struct dso *self, struct mod_dso *mods, const char *name, 809static int dso__load_module(struct dso *self, struct mod_dso *mods, const char *name,
810 symbol_filter_t filter, int verbose) 810 symbol_filter_t filter, int v)
811{ 811{
812 struct module *mod = mod_dso__find_module(mods, name); 812 struct module *mod = mod_dso__find_module(mods, name);
813 int err = 0, fd; 813 int err = 0, fd;
@@ -820,13 +820,13 @@ static int dso__load_module(struct dso *self, struct mod_dso *mods, const char *
820 if (fd < 0) 820 if (fd < 0)
821 return err; 821 return err;
822 822
823 err = dso__load_sym(self, fd, name, filter, verbose, mod); 823 err = dso__load_sym(self, fd, name, filter, v, mod);
824 close(fd); 824 close(fd);
825 825
826 return err; 826 return err;
827} 827}
828 828
829int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose) 829int dso__load_modules(struct dso *self, symbol_filter_t filter, int v)
830{ 830{
831 struct mod_dso *mods = mod_dso__new_dso("modules"); 831 struct mod_dso *mods = mod_dso__new_dso("modules");
832 struct module *pos; 832 struct module *pos;
@@ -844,7 +844,7 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose)
844 next = rb_first(&mods->mods); 844 next = rb_first(&mods->mods);
845 while (next) { 845 while (next) {
846 pos = rb_entry(next, struct module, rb_node); 846 pos = rb_entry(next, struct module, rb_node);
847 err = dso__load_module(self, mods, pos->name, filter, verbose); 847 err = dso__load_module(self, mods, pos->name, filter, v);
848 848
849 if (err < 0) 849 if (err < 0)
850 break; 850 break;
@@ -887,14 +887,14 @@ static inline void dso__fill_symbol_holes(struct dso *self)
887} 887}
888 888
889static int dso__load_vmlinux(struct dso *self, const char *vmlinux, 889static int dso__load_vmlinux(struct dso *self, const char *vmlinux,
890 symbol_filter_t filter, int verbose) 890 symbol_filter_t filter, int v)
891{ 891{
892 int err, fd = open(vmlinux, O_RDONLY); 892 int err, fd = open(vmlinux, O_RDONLY);
893 893
894 if (fd < 0) 894 if (fd < 0)
895 return -1; 895 return -1;
896 896
897 err = dso__load_sym(self, fd, vmlinux, filter, verbose, NULL); 897 err = dso__load_sym(self, fd, vmlinux, filter, v, NULL);
898 898
899 if (err > 0) 899 if (err > 0)
900 dso__fill_symbol_holes(self); 900 dso__fill_symbol_holes(self);
@@ -905,18 +905,18 @@ static int dso__load_vmlinux(struct dso *self, const char *vmlinux,
905} 905}
906 906
907int dso__load_kernel(struct dso *self, const char *vmlinux, 907int dso__load_kernel(struct dso *self, const char *vmlinux,
908 symbol_filter_t filter, int verbose, int modules) 908 symbol_filter_t filter, int v, int use_modules)
909{ 909{
910 int err = -1; 910 int err = -1;
911 911
912 if (vmlinux) { 912 if (vmlinux) {
913 err = dso__load_vmlinux(self, vmlinux, filter, verbose); 913 err = dso__load_vmlinux(self, vmlinux, filter, v);
914 if (err > 0 && modules) 914 if (err > 0 && use_modules)
915 err = dso__load_modules(self, filter, verbose); 915 err = dso__load_modules(self, filter, v);
916 } 916 }
917 917
918 if (err <= 0) 918 if (err <= 0)
919 err = dso__load_kallsyms(self, filter, verbose); 919 err = dso__load_kallsyms(self, filter, v);
920 920
921 if (err > 0) 921 if (err > 0)
922 self->origin = DSO__ORIG_KERNEL; 922 self->origin = DSO__ORIG_KERNEL;
@@ -929,7 +929,7 @@ struct dso *kernel_dso;
929struct dso *vdso; 929struct dso *vdso;
930struct dso *hypervisor_dso; 930struct dso *hypervisor_dso;
931 931
932char *vmlinux = "vmlinux"; 932const char *vmlinux_name = "vmlinux";
933int modules; 933int modules;
934 934
935static void dsos__add(struct dso *dso) 935static void dsos__add(struct dso *dso)
@@ -997,7 +997,7 @@ int load_kernel(void)
997 if (!kernel_dso) 997 if (!kernel_dso)
998 return -1; 998 return -1;
999 999
1000 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules); 1000 err = dso__load_kernel(kernel_dso, vmlinux_name, NULL, verbose, modules);
1001 if (err <= 0) { 1001 if (err <= 0) {
1002 dso__delete(kernel_dso); 1002 dso__delete(kernel_dso);
1003 kernel_dso = NULL; 1003 kernel_dso = NULL;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 48b8e5759af9..6e8490716408 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -55,7 +55,7 @@ struct dso {
55 char name[0]; 55 char name[0];
56}; 56};
57 57
58const char *sym_hist_filter; 58extern const char *sym_hist_filter;
59 59
60typedef int (*symbol_filter_t)(struct dso *self, struct symbol *sym); 60typedef int (*symbol_filter_t)(struct dso *self, struct symbol *sym);
61 61
@@ -87,6 +87,6 @@ extern struct list_head dsos;
87extern struct dso *kernel_dso; 87extern struct dso *kernel_dso;
88extern struct dso *vdso; 88extern struct dso *vdso;
89extern struct dso *hypervisor_dso; 89extern struct dso *hypervisor_dso;
90extern char *vmlinux; 90extern const char *vmlinux_name;
91extern int modules; 91extern int modules;
92#endif /* _PERF_SYMBOL_ */ 92#endif /* _PERF_SYMBOL_ */
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 614cfaf4712a..1c15e39f99e3 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -96,7 +96,7 @@ static void perf_read_values__enlarge_counters(struct perf_read_values *values)
96} 96}
97 97
98static int perf_read_values__findnew_counter(struct perf_read_values *values, 98static int perf_read_values__findnew_counter(struct perf_read_values *values,
99 u64 rawid, char *name) 99 u64 rawid, const char *name)
100{ 100{
101 int i; 101 int i;
102 102
@@ -116,7 +116,7 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values,
116 116
117void perf_read_values_add_value(struct perf_read_values *values, 117void perf_read_values_add_value(struct perf_read_values *values,
118 u32 pid, u32 tid, 118 u32 pid, u32 tid,
119 u64 rawid, char *name, u64 value) 119 u64 rawid, const char *name, u64 value)
120{ 120{
121 int tindex, cindex; 121 int tindex, cindex;
122 122
@@ -221,8 +221,7 @@ static void perf_read_values__display_raw(FILE *fp,
221 countwidth, values->value[i][j]); 221 countwidth, values->value[i][j]);
222} 222}
223 223
224void perf_read_values_display(FILE *fp, struct perf_read_values *values, 224void perf_read_values_display(FILE *fp, struct perf_read_values *values, int raw)
225 int raw)
226{ 225{
227 if (raw) 226 if (raw)
228 perf_read_values__display_raw(fp, values); 227 perf_read_values__display_raw(fp, values);
diff --git a/tools/perf/util/values.h b/tools/perf/util/values.h
index f8960fde0547..cadf8cf2a590 100644
--- a/tools/perf/util/values.h
+++ b/tools/perf/util/values.h
@@ -19,7 +19,7 @@ void perf_read_values_destroy(struct perf_read_values *values);
19 19
20void perf_read_values_add_value(struct perf_read_values *values, 20void perf_read_values_add_value(struct perf_read_values *values,
21 u32 pid, u32 tid, 21 u32 pid, u32 tid,
22 u64 rawid, char *name, u64 value); 22 u64 rawid, const char *name, u64 value);
23 23
24void perf_read_values_display(FILE *fp, struct perf_read_values *values, 24void perf_read_values_display(FILE *fp, struct perf_read_values *values,
25 int raw); 25 int raw);