Commit 83a0944f authored by Ingo Molnar's avatar Ingo Molnar

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: default avatarIngo Molnar <mingo@elte.hu>
parent 6baa0a5a
...@@ -166,7 +166,12 @@ endif ...@@ -166,7 +166,12 @@ endif
# CFLAGS and LDFLAGS are for the users to override from the command line. # CFLAGS and LDFLAGS are for the users to override from the command line.
CFLAGS = $(M64) -ggdb3 -Wall -Wextra -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -std=gnu99 -Wdeclaration-after-statement -Werror -O6 #
# Include saner warnings here, which can catch bugs:
#
EXTRA_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
CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 $(EXTRA_WARNINGS)
LDFLAGS = -lpthread -lrt -lelf -lm LDFLAGS = -lpthread -lrt -lelf -lm
ALL_CFLAGS = $(CFLAGS) ALL_CFLAGS = $(CFLAGS)
ALL_LDFLAGS = $(LDFLAGS) ALL_LDFLAGS = $(LDFLAGS)
......
...@@ -81,7 +81,7 @@ struct hist_entry { ...@@ -81,7 +81,7 @@ struct hist_entry {
struct sort_entry { struct sort_entry {
struct list_head list; struct list_head list;
char *header; const char *header;
int64_t (*cmp)(struct hist_entry *, struct hist_entry *); int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
int64_t (*collapse)(struct hist_entry *, struct hist_entry *); int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
...@@ -225,7 +225,7 @@ static struct sort_entry sort_sym = { ...@@ -225,7 +225,7 @@ static struct sort_entry sort_sym = {
static int sort__need_collapse = 0; static int sort__need_collapse = 0;
struct sort_dimension { struct sort_dimension {
char *name; const char *name;
struct sort_entry *entry; struct sort_entry *entry;
int taken; int taken;
}; };
...@@ -723,7 +723,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len) ...@@ -723,7 +723,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
const char *path = NULL; const char *path = NULL;
unsigned int hits = 0; unsigned int hits = 0;
double percent = 0.0; double percent = 0.0;
char *color; const char *color;
struct sym_ext *sym_ext = sym->priv; struct sym_ext *sym_ext = sym->priv;
offset = line_ip - start; offset = line_ip - start;
...@@ -805,7 +805,7 @@ static void free_source_line(struct symbol *sym, int len) ...@@ -805,7 +805,7 @@ static void free_source_line(struct symbol *sym, int len)
/* Get the filename:line for the colored entries */ /* Get the filename:line for the colored entries */
static void static void
get_source_line(struct symbol *sym, u64 start, int len, char *filename) get_source_line(struct symbol *sym, u64 start, int len, const char *filename)
{ {
int i; int i;
char cmd[PATH_MAX * 2]; char cmd[PATH_MAX * 2];
...@@ -851,7 +851,7 @@ get_source_line(struct symbol *sym, u64 start, int len, char *filename) ...@@ -851,7 +851,7 @@ get_source_line(struct symbol *sym, u64 start, int len, char *filename)
} }
} }
static void print_summary(char *filename) static void print_summary(const char *filename)
{ {
struct sym_ext *sym_ext; struct sym_ext *sym_ext;
struct rb_node *node; struct rb_node *node;
...@@ -867,7 +867,7 @@ static void print_summary(char *filename) ...@@ -867,7 +867,7 @@ static void print_summary(char *filename)
node = rb_first(&root_sym_ext); node = rb_first(&root_sym_ext);
while (node) { while (node) {
double percent; double percent;
char *color; const char *color;
char *path; char *path;
sym_ext = rb_entry(node, struct sym_ext, node); sym_ext = rb_entry(node, struct sym_ext, node);
...@@ -882,7 +882,7 @@ static void print_summary(char *filename) ...@@ -882,7 +882,7 @@ static void print_summary(char *filename)
static void annotate_sym(struct dso *dso, struct symbol *sym) static void annotate_sym(struct dso *dso, struct symbol *sym)
{ {
char *filename = dso->name, *d_filename; const char *filename = dso->name, *d_filename;
u64 start, end, len; u64 start, end, len;
char command[PATH_MAX*2]; char command[PATH_MAX*2];
FILE *file; FILE *file;
...@@ -892,7 +892,7 @@ static void annotate_sym(struct dso *dso, struct symbol *sym) ...@@ -892,7 +892,7 @@ static void annotate_sym(struct dso *dso, struct symbol *sym)
if (sym->module) if (sym->module)
filename = sym->module->path; filename = sym->module->path;
else if (dso == kernel_dso) else if (dso == kernel_dso)
filename = vmlinux; filename = vmlinux_name;
start = sym->obj_start; start = sym->obj_start;
if (!start) if (!start)
...@@ -964,7 +964,7 @@ static int __cmd_annotate(void) ...@@ -964,7 +964,7 @@ static int __cmd_annotate(void)
int ret, rc = EXIT_FAILURE; int ret, rc = EXIT_FAILURE;
unsigned long offset = 0; unsigned long offset = 0;
unsigned long head = 0; unsigned long head = 0;
struct stat stat; struct stat input_stat;
event_t *event; event_t *event;
uint32_t size; uint32_t size;
char *buf; char *buf;
...@@ -977,13 +977,13 @@ static int __cmd_annotate(void) ...@@ -977,13 +977,13 @@ static int __cmd_annotate(void)
exit(-1); exit(-1);
} }
ret = fstat(input, &stat); ret = fstat(input, &input_stat);
if (ret < 0) { if (ret < 0) {
perror("failed to stat file"); perror("failed to stat file");
exit(-1); exit(-1);
} }
if (!stat.st_size) { if (!input_stat.st_size) {
fprintf(stderr, "zero-sized file, nothing to do!\n"); fprintf(stderr, "zero-sized file, nothing to do!\n");
exit(0); exit(0);
} }
...@@ -1010,10 +1010,10 @@ static int __cmd_annotate(void) ...@@ -1010,10 +1010,10 @@ static int __cmd_annotate(void)
if (head + event->header.size >= page_size * mmap_window) { if (head + event->header.size >= page_size * mmap_window) {
unsigned long shift = page_size * (head / page_size); unsigned long shift = page_size * (head / page_size);
int ret; int munmap_ret;
ret = munmap(buf, page_size * mmap_window); munmap_ret = munmap(buf, page_size * mmap_window);
assert(ret == 0); assert(munmap_ret == 0);
offset += shift; offset += shift;
head -= shift; head -= shift;
...@@ -1049,7 +1049,7 @@ static int __cmd_annotate(void) ...@@ -1049,7 +1049,7 @@ static int __cmd_annotate(void)
head += size; head += size;
if (offset + head < (unsigned long)stat.st_size) if (offset + head < (unsigned long)input_stat.st_size)
goto more; goto more;
rc = EXIT_SUCCESS; rc = EXIT_SUCCESS;
...@@ -1092,7 +1092,7 @@ static const struct option options[] = { ...@@ -1092,7 +1092,7 @@ static const struct option options[] = {
"be more verbose (show symbol address, etc)"), "be more verbose (show symbol address, etc)"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"), "dump raw trace in ASCII"),
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
OPT_BOOLEAN('m', "modules", &modules, OPT_BOOLEAN('m', "modules", &modules,
"load module symbols - WARNING: use only with -k and LIVE kernel"), "load module symbols - WARNING: use only with -k and LIVE kernel"),
OPT_BOOLEAN('l', "print-line", &print_line, OPT_BOOLEAN('l', "print-line", &print_line,
......
...@@ -456,6 +456,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __used) ...@@ -456,6 +456,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __used)
break; break;
case HELP_FORMAT_WEB: case HELP_FORMAT_WEB:
show_html_page(argv[0]); show_html_page(argv[0]);
default:
break; break;
} }
......
...@@ -97,6 +97,7 @@ static int repsep_fprintf(FILE *fp, const char *fmt, ...) ...@@ -97,6 +97,7 @@ static int repsep_fprintf(FILE *fp, const char *fmt, ...)
n = vasprintf(&bf, fmt, ap); n = vasprintf(&bf, fmt, ap);
if (n > 0) { if (n > 0) {
char *sep = bf; char *sep = bf;
while (1) { while (1) {
sep = strchr(sep, *field_sep); sep = strchr(sep, *field_sep);
if (sep == NULL) if (sep == NULL)
...@@ -144,7 +145,7 @@ struct hist_entry { ...@@ -144,7 +145,7 @@ struct hist_entry {
struct sort_entry { struct sort_entry {
struct list_head list; struct list_head list;
char *header; const char *header;
int64_t (*cmp)(struct hist_entry *, struct hist_entry *); int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
int64_t (*collapse)(struct hist_entry *, struct hist_entry *); int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
...@@ -328,7 +329,7 @@ static int sort__need_collapse = 0; ...@@ -328,7 +329,7 @@ static int sort__need_collapse = 0;
static int sort__has_parent = 0; static int sort__has_parent = 0;
struct sort_dimension { struct sort_dimension {
char *name; const char *name;
struct sort_entry *entry; struct sort_entry *entry;
int taken; int taken;
}; };
...@@ -343,7 +344,7 @@ static struct sort_dimension sort_dimensions[] = { ...@@ -343,7 +344,7 @@ static struct sort_dimension sort_dimensions[] = {
static LIST_HEAD(hist_entry__sort_list); static LIST_HEAD(hist_entry__sort_list);
static int sort_dimension__add(char *tok) static int sort_dimension__add(const char *tok)
{ {
unsigned int i; unsigned int i;
...@@ -602,6 +603,7 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, ...@@ -602,6 +603,7 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
case CHAIN_GRAPH_REL: case CHAIN_GRAPH_REL:
ret += callchain__fprintf_graph(fp, chain, ret += callchain__fprintf_graph(fp, chain,
total_samples, 1, 1); total_samples, 1, 1);
case CHAIN_NONE:
default: default:
break; break;
} }
...@@ -1290,7 +1292,7 @@ process_lost_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -1290,7 +1292,7 @@ process_lost_event(event_t *event, unsigned long offset, unsigned long head)
static void trace_event(event_t *event) static void trace_event(event_t *event)
{ {
unsigned char *raw_event = (void *)event; unsigned char *raw_event = (void *)event;
char *color = PERF_COLOR_BLUE; const char *color = PERF_COLOR_BLUE;
int i, j; int i, j;
if (!dump_trace) if (!dump_trace)
...@@ -1348,7 +1350,7 @@ process_read_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -1348,7 +1350,7 @@ process_read_event(event_t *event, unsigned long offset, unsigned long head)
struct perf_counter_attr *attr = perf_header__find_attr(event->read.id); struct perf_counter_attr *attr = perf_header__find_attr(event->read.id);
if (show_threads) { if (show_threads) {
char *name = attr ? __event_name(attr->type, attr->config) const char *name = attr ? __event_name(attr->type, attr->config)
: "unknown"; : "unknown";
perf_read_values_add_value(&show_threads_values, perf_read_values_add_value(&show_threads_values,
event->read.pid, event->read.tid, event->read.pid, event->read.tid,
...@@ -1411,19 +1413,19 @@ process_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -1411,19 +1413,19 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
static u64 perf_header__sample_type(void) static u64 perf_header__sample_type(void)
{ {
u64 sample_type = 0; u64 type = 0;
int i; int i;
for (i = 0; i < header->attrs; i++) { for (i = 0; i < header->attrs; i++) {
struct perf_header_attr *attr = header->attr[i]; struct perf_header_attr *attr = header->attr[i];
if (!sample_type) if (!type)
sample_type = attr->attr.sample_type; type = attr->attr.sample_type;
else if (sample_type != attr->attr.sample_type) else if (type != attr->attr.sample_type)
die("non matching sample_type"); die("non matching sample_type");
} }
return sample_type; return type;
} }
static int __cmd_report(void) static int __cmd_report(void)
...@@ -1431,7 +1433,7 @@ static int __cmd_report(void) ...@@ -1431,7 +1433,7 @@ static int __cmd_report(void)
int ret, rc = EXIT_FAILURE; int ret, rc = EXIT_FAILURE;
unsigned long offset = 0; unsigned long offset = 0;
unsigned long head, shift; unsigned long head, shift;
struct stat stat; struct stat input_stat;
event_t *event; event_t *event;
uint32_t size; uint32_t size;
char *buf; char *buf;
...@@ -1450,13 +1452,13 @@ static int __cmd_report(void) ...@@ -1450,13 +1452,13 @@ static int __cmd_report(void)
exit(-1); exit(-1);
} }
ret = fstat(input, &stat); ret = fstat(input, &input_stat);
if (ret < 0) { if (ret < 0) {
perror("failed to stat file"); perror("failed to stat file");
exit(-1); exit(-1);
} }
if (!stat.st_size) { if (!input_stat.st_size) {
fprintf(stderr, "zero-sized file, nothing to do!\n"); fprintf(stderr, "zero-sized file, nothing to do!\n");
exit(0); exit(0);
} }
...@@ -1524,12 +1526,12 @@ static int __cmd_report(void) ...@@ -1524,12 +1526,12 @@ static int __cmd_report(void)
size = 8; size = 8;
if (head + event->header.size >= page_size * mmap_window) { if (head + event->header.size >= page_size * mmap_window) {
int ret; int munmap_ret;
shift = page_size * (head / page_size); shift = page_size * (head / page_size);
ret = munmap(buf, page_size * mmap_window); munmap_ret = munmap(buf, page_size * mmap_window);
assert(ret == 0); assert(munmap_ret == 0);
offset += shift; offset += shift;
head -= shift; head -= shift;
...@@ -1568,7 +1570,7 @@ static int __cmd_report(void) ...@@ -1568,7 +1570,7 @@ static int __cmd_report(void)
if (offset + head >= header->data_offset + header->data_size) if (offset + head >= header->data_offset + header->data_size)
goto done; goto done;
if (offset + head < (unsigned long)stat.st_size) if (offset + head < (unsigned long)input_stat.st_size)
goto more; goto more;
done: done:
...@@ -1666,7 +1668,7 @@ static const struct option options[] = { ...@@ -1666,7 +1668,7 @@ static const struct option options[] = {
"be more verbose (show symbol address, etc)"), "be more verbose (show symbol address, etc)"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"), "dump raw trace in ASCII"),
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
OPT_BOOLEAN('m', "modules", &modules, OPT_BOOLEAN('m', "modules", &modules,
"load module symbols - WARNING: use only with -k and LIVE kernel"), "load module symbols - WARNING: use only with -k and LIVE kernel"),
OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples, OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
......
...@@ -120,7 +120,8 @@ static void parse_source(struct sym_entry *syme) ...@@ -120,7 +120,8 @@ static void parse_source(struct sym_entry *syme)
struct module *module; struct module *module;
struct section *section = NULL; struct section *section = NULL;
FILE *file; FILE *file;
char command[PATH_MAX*2], *path = vmlinux; char command[PATH_MAX*2];
const char *path = vmlinux_name;
u64 start, end, len; u64 start, end, len;
if (!syme) if (!syme)
...@@ -487,10 +488,12 @@ static void print_sym_table(void) ...@@ -487,10 +488,12 @@ static void print_sym_table(void)
); );
for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node); struct symbol *sym;
struct symbol *sym = (struct symbol *)(syme + 1);
double pcnt; double pcnt;
syme = rb_entry(nd, struct sym_entry, rb_node);
sym = (struct symbol *)(syme + 1);
if (++printed > print_entries || (int)syme->snap_count < count_filter) if (++printed > print_entries || (int)syme->snap_count < count_filter)
continue; continue;
...@@ -609,7 +612,7 @@ static void print_mapped_keys(void) ...@@ -609,7 +612,7 @@ static void print_mapped_keys(void)
fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter); fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
if (vmlinux) { if (vmlinux_name) {
fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter); fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL"); fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
fprintf(stdout, "\t[S] stop annotation.\n"); fprintf(stdout, "\t[S] stop annotation.\n");
...@@ -638,7 +641,9 @@ static int key_mapped(int c) ...@@ -638,7 +641,9 @@ static int key_mapped(int c)
case 'F': case 'F':
case 's': case 's':
case 'S': case 'S':
return vmlinux ? 1 : 0; return vmlinux_name ? 1 : 0;
default:
break;
} }
return 0; return 0;
...@@ -724,6 +729,8 @@ static void handle_keypress(int c) ...@@ -724,6 +729,8 @@ static void handle_keypress(int c)
case 'z': case 'z':
zero = ~zero; zero = ~zero;
break; break;
default:
break;
} }
} }
...@@ -812,13 +819,13 @@ static int parse_symbols(void) ...@@ -812,13 +819,13 @@ static int parse_symbols(void)
{ {
struct rb_node *node; struct rb_node *node;
struct symbol *sym; struct symbol *sym;
int modules = vmlinux ? 1 : 0; int use_modules = vmlinux_name ? 1 : 0;
kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry)); kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry));
if (kernel_dso == NULL) if (kernel_dso == NULL)
return -1; return -1;
if (dso__load_kernel(kernel_dso, vmlinux, symbol_filter, verbose, modules) <= 0) if (dso__load_kernel(kernel_dso, vmlinux_name, symbol_filter, verbose, use_modules) <= 0)
goto out_delete_dso; goto out_delete_dso;
node = rb_first(&kernel_dso->syms); node = rb_first(&kernel_dso->syms);
...@@ -1114,7 +1121,7 @@ static const struct option options[] = { ...@@ -1114,7 +1121,7 @@ static const struct option options[] = {
"system-wide collection from all CPUs"), "system-wide collection from all CPUs"),
OPT_INTEGER('C', "CPU", &profile_cpu, OPT_INTEGER('C', "CPU", &profile_cpu,
"CPU to profile on"), "CPU to profile on"),
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
OPT_INTEGER('m', "mmap-pages", &mmap_pages, OPT_INTEGER('m', "mmap-pages", &mmap_pages,
"number of mmap data pages"), "number of mmap data pages"),
OPT_INTEGER('r', "realtime", &realtime_prio, OPT_INTEGER('r', "realtime", &realtime_prio,
......
...@@ -50,7 +50,8 @@ const char *make_absolute_path(const char *path) ...@@ -50,7 +50,8 @@ const char *make_absolute_path(const char *path)
die ("Could not get current working directory"); die ("Could not get current working directory");
if (last_elem) { if (last_elem) {
int len = strlen(buf); len = strlen(buf);
if (len + strlen(last_elem) + 2 > PATH_MAX) if (len + strlen(last_elem) + 2 > PATH_MAX)
die ("Too long path name: '%s/%s'", die ("Too long path name: '%s/%s'",
buf, last_elem); buf, last_elem);
......
...@@ -52,7 +52,6 @@ extern const char *perf_mailmap_file; ...@@ -52,7 +52,6 @@ extern const char *perf_mailmap_file;
extern void maybe_flush_or_die(FILE *, const char *); extern void maybe_flush_or_die(FILE *, const char *);
extern int copy_fd(int ifd, int ofd); extern int copy_fd(int ifd, int ofd);
extern int copy_file(const char *dst, const char *src, int mode); extern int copy_file(const char *dst, const char *src, int mode);
extern ssize_t read_in_full(int fd, void *buf, size_t count);
extern ssize_t write_in_full(int fd, const void *buf, size_t count); extern ssize_t write_in_full(int fd, const void *buf, size_t count);
extern void write_or_die(int fd, const void *buf, size_t count); extern void write_or_die(int fd, const void *buf, size_t count);
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
......
...@@ -50,6 +50,7 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain, ...@@ -50,6 +50,7 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,
else else
p = &(*p)->rb_right; p = &(*p)->rb_right;
break; break;
case CHAIN_NONE:
default: default:
break; break;
} }
...@@ -143,6 +144,7 @@ int register_callchain_param(struct callchain_param *param) ...@@ -143,6 +144,7 @@ int register_callchain_param(struct callchain_param *param)
case CHAIN_FLAT: case CHAIN_FLAT:
param->sort = sort_chain_flat; param->sort = sort_chain_flat;
break; break;
case CHAIN_NONE:
default: default:
return -1; return -1;
} }
......
...@@ -242,9 +242,9 @@ int color_fwrite_lines(FILE *fp, const char *color, ...@@ -242,9 +242,9 @@ int color_fwrite_lines(FILE *fp, const char *color,
return 0; return 0;
} }
char *get_percent_color(double percent) const char *get_percent_color(double percent)
{ {
char *color = PERF_COLOR_NORMAL; const char *color = PERF_COLOR_NORMAL;
/* /*
* We color high-overhead entries in red, mid-overhead * We color high-overhead entries in red, mid-overhead
...@@ -263,7 +263,7 @@ char *get_percent_color(double percent) ...@@ -263,7 +263,7 @@ char *get_percent_color(double percent)
int percent_color_fprintf(FILE *fp, const char *fmt, double percent) int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
{ {
int r; int r;
char *color; const char *color;
color = get_percent_color(percent); color = get_percent_color(percent);
r = color_fprintf(fp, color, fmt, percent); r = color_fprintf(fp, color, fmt, percent);
......
...@@ -36,6 +36,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); ...@@ -36,6 +36,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
int percent_color_fprintf(FILE *fp, const char *fmt, double percent); int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
char *get_percent_color(double percent); const char *get_percent_color(double percent);
#endif /* COLOR_H */ #endif /* COLOR_H */
...@@ -160,17 +160,18 @@ static int get_extended_base_var(char *name, int baselen, int c) ...@@ -160,17 +160,18 @@ static int get_extended_base_var(char *name, int baselen, int c)
name[baselen++] = '.'; name[baselen++] = '.';
for (;;) { for (;;) {
int c = get_next_char(); int ch = get_next_char();
if (c == '\n')
if (ch == '\n')
return -1; return -1;
if (c == '"') if (ch == '"')
break; break;
if (c == '\\') { if (ch == '\\') {
c = get_next_char(); ch = get_next_char();
if (c == '\n') if (ch == '\n')
return -1; return -1;
} }
name[baselen++] = c; name[baselen++] = ch;
if (baselen > MAXNAME / 2) if (baselen > MAXNAME / 2)
return -1; return -1;
} }
...@@ -530,6 +531,8 @@ static int store_aux(const char* key, const char* value, void *cb __used) ...@@ -530,6 +531,8 @@ static int store_aux(const char* key, const char* value, void *cb __used)
store.offset[store.seen] = ftell(config_file); store.offset[store.seen] = ftell(config_file);
} }
} }
default:
break;
} }
return 0; return 0;
} }
...@@ -619,6 +622,7 @@ static ssize_t find_beginning_of_line(const char* contents, size_t size, ...@@ -619,6 +622,7 @@ static ssize_t find_beginning_of_line(const char* contents, size_t size,
switch (contents[offset]) { switch (contents[offset]) {
case '=': equal_offset = offset; break; case '=': equal_offset = offset; break;
case ']': bracket_offset = offset; break; case ']': bracket_offset = offset; break;
default: break;
} }
if (offset > 0 && contents[offset-1] == '\\') { if (offset > 0 && contents[offset-1] == '\\') {
offset_ = offset; offset_ = offset;
...@@ -742,9 +746,9 @@ int perf_config_set_multivar(const char* key, const char* value, ...@@ -742,9 +746,9 @@ int perf_config_set_multivar(const char* key, const char* value,
goto write_err_out; goto write_err_out;
} else { } else {
struct stat st; struct stat st;
char* contents; char *contents;
ssize_t contents_sz, copy_begin, copy_end; ssize_t contents_sz, copy_begin, copy_end;
int i, new_line = 0; int new_line = 0;
if (value_regex == NULL) if (value_regex == NULL)
store.value_regex = NULL; store.value_regex = NULL;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define MAX_ARGS 32 #define MAX_ARGS 32
extern char **environ;
static const char *argv_exec_path; static const char *argv_exec_path;
static const char *argv0_path; static const char *argv0_path;
......
...@@ -436,9 +436,9 @@ static int mod_dso__load_module_paths(struct mod_dso *self) ...@@ -436,9 +436,9 @@ static int mod_dso__load_module_paths(struct mod_dso *self)
goto out_failure; goto out_failure;
while (!feof(file)) { while (!feof(file)) {
char *path, *name, *tmp; char *name, *tmp;
struct module *module; struct module *module;
int line_len, len; int line_len;
line_len = getline(&line, &n, file); line_len = getline(&line, &n, file);
if (line_len < 0) if (line_len < 0)
......
...@@ -16,8 +16,8 @@ struct perf_counter_attr attrs[MAX_COUNTERS]; ...@@ -16,8 +16,8 @@ struct perf_counter_attr attrs[MAX_COUNTERS];
struct event_symbol { struct event_symbol {
u8 type; u8 type;
u64 config; u64 config;
char *symbol; const char *symbol;
char *alias; const char *alias;
}; };
char debugfs_path[MAXPATHLEN]; char debugfs_path[MAXPATHLEN];
...@@ -51,7 +51,7 @@ static struct event_symbol event_symbols[] = { ...@@ -51,7 +51,7 @@ static struct event_symbol event_symbols[] = {
#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE) #define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE)
#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT) #define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT)
static char *hw_event_names[] = { static const char *hw_event_names[] = {
"cycles", "cycles",
"instructions", "instructions",
"cache-references", "cache-references",
...@@ -61,7 +61,7 @@ static char *hw_event_names[] = { ...@@ -61,7 +61,7 @@ static char *hw_event_names[] = {
"bus-cycles", "bus-cycles",
}; };
static char *sw_event_names[] = { static const char *sw_event_names[] = {
"cpu-clock-msecs", "cpu-clock-msecs",
"task-clock-msecs", "task-clock-msecs",
"page-faults", "page-faults",
...@@ -73,7 +73,7 @@ static char *sw_event_names[] = { ...@@ -73,7 +73,7 @@ static char *sw_event_names[] = {
#define MAX_ALIASES 8 #define MAX_ALIASES 8
static char *hw_cache[][MAX_ALIASES] = { static const char *hw_cache[][MAX_ALIASES] = {
{ "L1-dcache", "l1-d", "l1d", "L1-data", }, { "L1-dcache", "l1-d", "l1d", "L1-data", },
{ "L1-icache", "l1-i", "l1i", "L1-instruction", }, { "L1-icache", "l1-i", "l1i", "L1-instruction", },
{ "LLC", "L2" }, { "LLC", "L2" },
...@@ -82,13 +82,13 @@ static char *hw_cache[][MAX_ALIASES] = { ...@@ -82,13 +82,13 @@ static char *hw_cache[][MAX_ALIASES] = {
{ "branch", "branches", "bpu", "btb", "bpc", }, { "branch", "branches", "bpu", "btb", "bpc", },
}; };
static char *hw_cache_op[][MAX_ALIASES] = { static const char *hw_cache_op[][MAX_ALIASES] = {
{ "load", "loads", "read", }, { "load", "loads", "read", },
{ "store", "stores", "write", }, { "store", "stores", "write", },
{ "prefetch", "prefetches", "speculative-read", "speculative-load", }, { "prefetch", "prefetches", "speculative-read", "speculative-load", },
}; };
static char *hw_cache_result[][MAX_ALIASES] = { static const char *hw_cache_result[][MAX_ALIASES] = {
{ "refs", "Reference", "ops", "access", }, { "refs", "Reference", "ops", "access", },
{ "misses", "miss", }, { "misses", "miss", },
}; };
...@@ -158,7 +158,7 @@ int valid_debugfs_mount(const char *debugfs) ...@@ -158,7 +158,7 @@ int valid_debugfs_mount(const char *debugfs)
return 0; return 0;
} }
static char *tracepoint_id_to_name(u64 config) static const char *tracepoint_id_to_name(u64 config)
{ {
static char tracepoint_name[2 * MAX_EVENT_LENGTH]; static char tracepoint_name[2 * MAX_EVENT_LENGTH];
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
...@@ -235,7 +235,7 @@ static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) ...@@ -235,7 +235,7 @@ static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
return name; return name;
} }
char *event_name(int counter) const char *event_name(int counter)
{ {
u64 config = attrs[counter].config; u64 config = attrs[counter].config;
int type = attrs[counter].type; int type = attrs[counter].type;
...@@ -243,7 +243,7 @@ char *event_name(int counter) ...@@ -243,7 +243,7 @@ char *event_name(int counter)
return __event_name(type, config); return __event_name(type, config);
} }
char *__event_name(int type, u64 config) const char *__event_name(int type, u64 config)
{ {
static char buf[32]; static char buf[32];
...@@ -294,7 +294,7 @@ char *__event_name(int type, u64 config) ...@@ -294,7 +294,7 @@ char *__event_name(int type, u64 config)
return "unknown"; return "unknown";
} }
static int parse_aliases(const char **str, char *names[][MAX_ALIASES], int size) static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size)
{ {
int i, j; int i, j;
int n, longest = -1; int n, longest = -1;
......
...@@ -9,8 +9,8 @@ extern int nr_counters; ...@@ -9,8 +9,8 @@ extern int nr_counters;
extern struct perf_counter_attr attrs[MAX_COUNTERS]; extern struct perf_counter_attr attrs[MAX_COUNTERS];
extern char *event_name(int ctr); extern const char *event_name(int ctr);
extern char *__event_name(int type, u64 config); extern const char *__event_name(int type, u64 config);
extern int parse_events(const struct option *opt, const char *str, int unset); extern int parse_events(const struct option *opt, const char *str, int unset);
......
...@@ -53,6 +53,12 @@ static int get_value(struct parse_opt_ctx_t *p, ...@@ -53,6 +53,12 @@ static int get_value(struct parse_opt_ctx_t *p,
case OPTION_SET_INT: case OPTION_SET_INT:
case OPTION_SET_PTR: case OPTION_SET_PTR:
return opterror(opt, "takes no value", flags); return opterror(opt, "takes no value", flags);
case OPTION_END:
case OPTION_ARGUMENT:
case OPTION_GROUP:
case OPTION_STRING:
case OPTION_INTEGER:
case OPTION_LONG:
default: default:
break; break;
} }
...@@ -130,6 +136,9 @@ static int get_value(struct parse_opt_ctx_t *p, ...@@ -130,6 +136,9 @@ static int get_value(struct parse_opt_ctx_t *p,
return opterror(opt, "expects a numerical value", flags); return opterror(opt, "expects a numerical value", flags);
return 0; return 0;
case OPTION_END:
case OPTION_ARGUMENT:
case OPTION_GROUP:
default: default:
die("should not happen, someone must be hit on the forehead"); die("should not happen, someone must be hit on the forehead");
} }
...@@ -296,6 +305,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, ...@@ -296,6 +305,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
return parse_options_usage(usagestr, options); return parse_options_usage(usagestr, options);
case -2: case -2:
goto unknown; goto unknown;
default:
break;
} }
if (ctx->opt) if (ctx->opt)
check_typos(arg + 1, options); check_typos(arg + 1, options);
...@@ -314,6 +325,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, ...@@ -314,6 +325,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
ctx->argv[0] = strdup(ctx->opt - 1); ctx->argv[0] = strdup(ctx->opt - 1);
*(char *)ctx->argv[0] = '-'; *(char *)ctx->argv[0] = '-';
goto unknown; goto unknown;
default:
break;
} }
} }
continue; continue;
...@@ -336,6 +349,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, ...@@ -336,6 +349,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
return parse_options_usage(usagestr, options); return parse_options_usage(usagestr, options);
case -2: case -2:
goto unknown; goto unknown;
default:
break;
} }
continue; continue;
unknown: unknown:
...@@ -456,6 +471,13 @@ int usage_with_options_internal(const char * const *usagestr, ...@@ -456,6 +471,13 @@ int usage_with_options_internal(const char * const *usagestr,
} }
break; break;
default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */
case OPTION_END:
case OPTION_GROUP:
case OPTION_BIT:
case OPTION_BOOLEAN:
case OPTION_SET_INT:
case OPTION_SET_PTR:
case OPTION_LONG:
break; break;
} }
......
...@@ -17,7 +17,7 @@ static char bad_path[] = "/bad-path/"; ...@@ -17,7 +17,7 @@ static char bad_path[] = "/bad-path/";
* Two hacks: * Two hacks:
*/ */
static char *get_perf_dir(void) static const char *get_perf_dir(void)
{ {
return "."; return ".";
} }
...@@ -38,8 +38,9 @@ size_t strlcpy(char *dest, const char *src, size_t size) ...@@ -38,8 +38,9 @@ size_t strlcpy(char *dest, const char *src, size_t size)
static char *get_pathname(void) static char *get_pathname(void)
{ {
static char pathname_array[4][PATH_MAX]; static char pathname_array[4][PATH_MAX];
static int index; static int idx;
return pathname_array[3 & ++index];
return pathname_array[3 & ++idx];
} }
static char *cleanup_path(char *path) static char *cleanup_path(char *path)
...@@ -161,20 +162,24 @@ int perf_mkstemp(char *path, size_t len, const char *template) ...@@ -161,20 +162,24 @@ int perf_mkstemp(char *path, size_t len, const char *template)
} }
const char *make_relative_path(const char *abs, const char *base) const char *make_relative_path(const char *abs_path, const char *base)
{ {
static char buf[PATH_MAX + 1]; static char buf[PATH_MAX + 1];
int baselen; int baselen;
if (!base) if (!base)
return abs; return abs_path;
baselen = strlen(base); baselen = strlen(base);
if (prefixcmp(abs, base)) if (prefixcmp(abs_path, base))
return abs; return abs_path;
if (abs[baselen] == '/') if (abs_path[baselen] == '/')
baselen++; baselen++;
else if (base[baselen - 1] != '/') else if (base[baselen - 1] != '/')
return abs; return abs_path;
strcpy(buf, abs + baselen);
strcpy(buf, abs_path + baselen);
return buf; return buf;
} }
......
...@@ -262,7 +262,7 @@ int run_hook(const char *index_file, const char *name, ...) ...@@ -262,7 +262,7 @@ int run_hook(const char *index_file, const char *name, ...)
{ {
struct child_process hook; struct child_process hook;
const char **argv = NULL, *env[2]; const char **argv = NULL, *env[2];
char index[PATH_MAX]; char idx[PATH_MAX];
va_list args; va_list args;
int ret; int ret;
size_t i = 0, alloc = 0; size_t i = 0, alloc = 0;
...@@ -284,8 +284,8 @@ int run_hook(const char *index_file, const char *name, ...) ...@@ -284,8 +284,8 @@ int run_hook(const char *index_file, const char *name, ...)
hook.no_stdin = 1; hook.no_stdin = 1;
hook.stdout_to_stderr = 1; hook.stdout_to_stderr = 1;
if (index_file) { if (index_file) {
snprintf(index, sizeof(index), "PERF_INDEX_FILE=%s", index_file); snprintf(idx, sizeof(idx), "PERF_INDEX_FILE=%s", index_file);
env[0] = index; env[0] = idx;
env[1] = NULL; env[1] = NULL;
hook.env = env; hook.env = env;
} }
......
This diff is collapsed.
...@@ -55,7 +55,7 @@ struct dso { ...@@ -55,7 +55,7 @@ struct dso {
char name[0]; char name[0];
}; };
const char *sym_hist_filter; extern const char *sym_hist_filter;
typedef int (*symbol_filter_t)(struct dso *self, struct symbol *sym); typedef int (*symbol_filter_t)(struct dso *self, struct symbol *sym);
...@@ -87,6 +87,6 @@ extern struct list_head dsos; ...@@ -87,6 +87,6 @@ extern struct list_head dsos;
extern struct dso *kernel_dso; extern struct dso *kernel_dso;
extern struct dso *vdso; extern struct dso *vdso;
extern struct dso *hypervisor_dso; extern struct dso *hypervisor_dso;
extern char *vmlinux; extern const char *vmlinux_name;
extern int modules; extern int modules;
#endif /* _PERF_SYMBOL_ */ #endif /* _PERF_SYMBOL_ */
...@@ -96,7 +96,7 @@ static void perf_read_values__enlarge_counters(struct perf_read_values *values) ...@@ -96,7 +96,7 @@ static void perf_read_values__enlarge_counters(struct perf_read_values *values)
} }
static int perf_read_values__findnew_counter(struct perf_read_values *values, static int perf_read_values__findnew_counter(struct perf_read_values *values,
u64 rawid, char *name) u64 rawid, const char *name)
{ {
int i; int i;
...@@ -116,7 +116,7 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values, ...@@ -116,7 +116,7 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values,
void perf_read_values_add_value(struct perf_read_values *values, void perf_read_values_add_value(struct perf_read_values *values,
u32 pid, u32 tid, u32 pid, u32 tid,
u64 rawid, char *name, u64 value) u64 rawid, const char *name, u64 value)
{ {
int tindex, cindex; int tindex, cindex;
...@@ -221,8 +221,7 @@ static void perf_read_values__display_raw(FILE *fp, ...@@ -221,8 +221,7 @@ static void perf_read_values__display_raw(FILE *fp,
countwidth, values->value[i][j]); countwidth, values->value[i][j]);
} }
void perf_read_values_display(FILE *fp, struct perf_read_values *values, void perf_read_values_display(FILE *fp, struct perf_read_values *values, int raw)
int raw)
{ {
if (raw) if (raw)
perf_read_values__display_raw(fp, values); perf_read_values__display_raw(fp, values);
......
...@@ -19,7 +19,7 @@ void perf_read_values_destroy(struct perf_read_values *values); ...@@ -19,7 +19,7 @@ void perf_read_values_destroy(struct perf_read_values *values);
void perf_read_values_add_value(struct perf_read_values *values, void perf_read_values_add_value(struct perf_read_values *values,
u32 pid, u32 tid, u32 pid, u32 tid,
u64 rawid, char *name, u64 value); u64 rawid, const char *name, u64 value);
void perf_read_values_display(FILE *fp, struct perf_read_values *values, void perf_read_values_display(FILE *fp, struct perf_read_values *values,
int raw); int raw);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment