aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-report.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-08-15 06:26:57 -0400
committerIngo Molnar <mingo@elte.hu>2009-08-16 04:47:47 -0400
commit83a0944fa919fb2ebcfc1f8933d86e437b597ca6 (patch)
tree814906744656554a1bc07cdad6b84b3581565358 /tools/perf/builtin-report.c
parent6baa0a5ae0954fb2486c480a20556a9f1aee0965 (diff)
perf: Enable more compiler warnings
Related to a shadowed variable bug fix Valdis Kletnieks noticed that perf does not get built with -Wshadow, which could have helped us avoid the bug. So enable -Wshadow and also enable the following warnings on perf builds, in addition to the already enabled -Wall -Wextra -std=gnu99 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 And change/fix the perf code to build cleanly under GCC 4.3.2. The list of warnings enablement is rather arbitrary: it's based on my (quick) reading of the GCC manpages and trying them on perf. I categorized the warnings based on individually enabling them and looking whether they trigger something in the perf build. If i liked those warnings (i.e. if they trigger for something that arguably could be improved) i enabled the warning. If the warnings seemed to come from language laywers spamming the build with tons of nuisance warnings i generally kept them off. Most of the sign conversion related warnings were in this category. (A second patch enabling some of the sign warnings might be welcome - sign bugs can be nasty.) I also kept warnings that seem to make sense from their manpage description and which produced no actual warnings on our code base. These warnings might still be turned off if they end up being a nuisance. I also left out a few warnings that are not supported in older compilers. [ Note that these changes might break the build on older compilers i did not test, or on non-x86 architectures that produce different warnings, so more testing would be welcome. ] Reported-by: Valdis.Kletnieks@vt.edu Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-report.c')
-rw-r--r--tools/perf/builtin-report.c38
1 files changed, 20 insertions, 18 deletions
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,