Skip to content

Commit

Permalink
perf_counter tools: Add more warnings and fix/annotate them
Browse files Browse the repository at this point in the history
Enable -Wextra. This found a few real bugs plus a number
of signed/unsigned type mismatches/uncleanlinesses. It
also required a few annotations

All things considered it was still worth it so lets try with
this enabled for now.

Cc: Peter Zijlstra <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Ingo Molnar committed Jul 1, 2009
1 parent 88a69df commit f37a291
Show file tree
Hide file tree
Showing 27 changed files with 151 additions and 128 deletions.
2 changes: 1 addition & 1 deletion tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ endif

# CFLAGS and LDFLAGS are for the users to override from the command line.

CFLAGS = $(M64) -ggdb3 -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -std=gnu99 -Wdeclaration-after-statement -Werror -O6
CFLAGS = $(M64) -ggdb3 -Wall -Wextra -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -std=gnu99 -Wdeclaration-after-statement -Werror -O6
LDFLAGS = -lpthread -lrt -lelf -lm
ALL_CFLAGS = $(CFLAGS)
ALL_LDFLAGS = $(LDFLAGS)
Expand Down
12 changes: 6 additions & 6 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void dsos__fprintf(FILE *fp)

static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
{
return dso__find_symbol(kernel_dso, ip);
return dso__find_symbol(dso, ip);
}

static int load_kernel(void)
Expand Down Expand Up @@ -203,7 +203,7 @@ static u64 map__map_ip(struct map *map, u64 ip)
return ip - map->start + map->pgoff;
}

static u64 vdso__map_ip(struct map *map, u64 ip)
static u64 vdso__map_ip(struct map *map __used, u64 ip)
{
return ip;
}
Expand Down Expand Up @@ -600,7 +600,7 @@ static LIST_HEAD(hist_entry__sort_list);

static int sort_dimension__add(char *tok)
{
int i;
unsigned int i;

for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
struct sort_dimension *sd = &sort_dimensions[i];
Expand Down Expand Up @@ -1069,7 +1069,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
static const char *prev_color;
unsigned int offset;
size_t line_len;
u64 line_ip;
s64 line_ip;
int ret;
char *c;

Expand Down Expand Up @@ -1428,7 +1428,7 @@ static int __cmd_annotate(void)

head += size;

if (offset + head < stat.st_size)
if (offset + head < (unsigned long)stat.st_size)
goto more;

rc = EXIT_SUCCESS;
Expand Down Expand Up @@ -1492,7 +1492,7 @@ static void setup_sorting(void)
free(str);
}

int cmd_annotate(int argc, const char **argv, const char *prefix)
int cmd_annotate(int argc, const char **argv, const char *prefix __used)
{
symbol__init();

Expand Down
6 changes: 4 additions & 2 deletions tools/perf/builtin-help.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Builtin help command
*/
#include "perf.h"
#include "util/cache.h"
#include "builtin.h"
#include "util/exec_cmd.h"
Expand Down Expand Up @@ -277,7 +278,7 @@ static struct cmdnames main_cmds, other_cmds;

void list_common_cmds_help(void)
{
int i, longest = 0;
unsigned int i, longest = 0;

for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
if (longest < strlen(common_cmds[i].name))
Expand Down Expand Up @@ -415,9 +416,10 @@ static void show_html_page(const char *perf_cmd)
open_html(page_path.buf);
}

int cmd_help(int argc, const char **argv, const char *prefix)
int cmd_help(int argc, const char **argv, const char *prefix __used)
{
const char *alias;

load_command_list("perf-", &main_cmds, &other_cmds);

perf_config(perf_help_config, NULL);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "util/parse-options.h"
#include "util/parse-events.h"

int cmd_list(int argc, const char **argv, const char *prefix)
int cmd_list(int argc __used, const char **argv __used, const char *prefix __used)
{
print_events();
return 0;
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static void pid_synthesize_mmap_samples(pid_t pid)
while (1) {
char bf[BUFSIZ], *pbf = bf;
struct mmap_event mmap_ev = {
.header.type = PERF_EVENT_MMAP,
.header = { .type = PERF_EVENT_MMAP },
};
int n;
size_t size;
Expand Down Expand Up @@ -650,7 +650,7 @@ static const struct option options[] = {
OPT_END()
};

int cmd_record(int argc, const char **argv, const char *prefix)
int cmd_record(int argc, const char **argv, const char *prefix __used)
{
int counter;

Expand Down
22 changes: 11 additions & 11 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void dsos__fprintf(FILE *fp)

static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
{
return dso__find_symbol(kernel_dso, ip);
return dso__find_symbol(dso, ip);
}

static int load_kernel(void)
Expand Down Expand Up @@ -239,7 +239,7 @@ static u64 map__map_ip(struct map *map, u64 ip)
return ip - map->start + map->pgoff;
}

static u64 vdso__map_ip(struct map *map, u64 ip)
static u64 vdso__map_ip(struct map *map __used, u64 ip)
{
return ip;
}
Expand Down Expand Up @@ -712,7 +712,7 @@ static LIST_HEAD(hist_entry__sort_list);

static int sort_dimension__add(char *tok)
{
int i;
unsigned int i;

for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
struct sort_dimension *sd = &sort_dimensions[i];
Expand Down Expand Up @@ -801,7 +801,7 @@ callchain__fprintf(FILE *fp, struct callchain_node *self, u64 total_samples)
ret += fprintf(fp, " %s\n", chain->sym->name);
else
ret += fprintf(fp, " %p\n",
(void *)chain->ip);
(void *)(long)chain->ip);
}

return ret;
Expand Down Expand Up @@ -938,12 +938,12 @@ static int call__match(struct symbol *sym)
}

static struct symbol **
resolve_callchain(struct thread *thread, struct map *map,
resolve_callchain(struct thread *thread, struct map *map __used,
struct ip_callchain *chain, struct hist_entry *entry)
{
int i;
struct symbol **syms;
u64 context = PERF_CONTEXT_MAX;
struct symbol **syms;
unsigned int i;

if (callchain) {
syms = calloc(chain->nr, sizeof(*syms));
Expand Down Expand Up @@ -1183,7 +1183,7 @@ static size_t output__fprintf(FILE *fp, u64 total_samples)

fprintf(fp, "# ........");
list_for_each_entry(se, &hist_entry__sort_list, list) {
int i;
unsigned int i;

if (exclude_other && (se == &sort_parent))
continue;
Expand Down Expand Up @@ -1271,7 +1271,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
(long long)period);

if (sample_type & PERF_SAMPLE_CALLCHAIN) {
int i;
unsigned int i;

chain = (void *)more_data;

Expand Down Expand Up @@ -1667,7 +1667,7 @@ static int __cmd_report(void)
if (offset + head >= header->data_offset + header->data_size)
goto done;

if (offset + head < stat.st_size)
if (offset + head < (unsigned long)stat.st_size)
goto more;

done:
Expand Down Expand Up @@ -1756,7 +1756,7 @@ static void setup_list(struct strlist **list, const char *list_str,
}
}

int cmd_report(int argc, const char **argv, const char *prefix)
int cmd_report(int argc, const char **argv, const char *prefix __used)
{
symbol__init();

Expand Down
18 changes: 10 additions & 8 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static struct perf_counter_attr default_attrs[] = {

static int system_wide = 0;
static int verbose = 0;
static int nr_cpus = 0;
static unsigned int nr_cpus = 0;
static int run_idx = 0;

static int run_count = 1;
Expand Down Expand Up @@ -108,7 +108,8 @@ static void create_perf_stat_counter(int counter, int pid)
PERF_FORMAT_TOTAL_TIME_RUNNING;

if (system_wide) {
int cpu;
unsigned int cpu;

for (cpu = 0; cpu < nr_cpus; cpu++) {
fd[cpu][counter] = sys_perf_counter_open(attr, -1, cpu, -1, 0);
if (fd[cpu][counter] < 0 && verbose)
Expand Down Expand Up @@ -150,8 +151,8 @@ static inline int nsec_counter(int counter)
static void read_counter(int counter)
{
u64 *count, single_count[3];
ssize_t res;
int cpu, nv;
unsigned int cpu;
size_t res, nv;
int scaled;

count = event_res[run_idx][counter];
Expand All @@ -165,6 +166,7 @@ static void read_counter(int counter)

res = read(fd[cpu][counter], single_count, nv * sizeof(u64));
assert(res == nv * sizeof(u64));

close(fd[cpu][counter]);
fd[cpu][counter] = -1;

Expand Down Expand Up @@ -200,7 +202,7 @@ static void read_counter(int counter)
runtime_cycles[run_idx] = count[0];
}

static int run_perf_stat(int argc, const char **argv)
static int run_perf_stat(int argc __used, const char **argv)
{
unsigned long long t0, t1;
int status = 0;
Expand Down Expand Up @@ -390,7 +392,7 @@ static void calc_avg(void)
event_res_avg[j]+1, event_res[i][j]+1);
update_avg("counter/2", j,
event_res_avg[j]+2, event_res[i][j]+2);
if (event_scaled[i][j] != -1)
if (event_scaled[i][j] != (u64)-1)
update_avg("scaled", j,
event_scaled_avg + j, event_scaled[i]+j);
else
Expand Down Expand Up @@ -510,7 +512,7 @@ static const struct option options[] = {
OPT_END()
};

int cmd_stat(int argc, const char **argv, const char *prefix)
int cmd_stat(int argc, const char **argv, const char *prefix __used)
{
int status;

Expand All @@ -528,7 +530,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix)

nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
assert(nr_cpus <= MAX_NR_CPUS);
assert(nr_cpus >= 0);
assert((int)nr_cpus >= 0);

/*
* We dont want to block the signals - that would cause
Expand Down
8 changes: 4 additions & 4 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static void print_sym_table(void)
}
}

static void *display_thread(void *arg)
static void *display_thread(void *arg __used)
{
struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
int delay_msecs = delay_secs * 1000;
Expand All @@ -287,7 +287,7 @@ static void *display_thread(void *arg)
}

/* Tag samples to be skipped. */
char *skip_symbols[] = {
static const char *skip_symbols[] = {
"default_idle",
"cpu_idle",
"enter_idle",
Expand Down Expand Up @@ -426,7 +426,7 @@ static void process_event(u64 ip, int counter, int user)
struct mmap_data {
int counter;
void *base;
unsigned int mask;
int mask;
unsigned int prev;
};

Expand Down Expand Up @@ -705,7 +705,7 @@ static const struct option options[] = {
OPT_END()
};

int cmd_top(int argc, const char **argv, const char *prefix)
int cmd_top(int argc, const char **argv, const char *prefix __used)
{
int counter;

Expand Down
5 changes: 1 addition & 4 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
use_pager = 1;
commit_pager_choice();

if (p->option & NEED_WORK_TREE)
/* setup_work_tree() */;

status = p->fn(argc, argv, prefix);
if (status)
return status & 0xff;
Expand Down Expand Up @@ -266,7 +263,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "annotate", cmd_annotate, 0 },
{ "version", cmd_version, 0 },
};
int i;
unsigned int i;
static const char ext[] = STRIP_EXTENSION;

if (sizeof(ext) > 1) {
Expand Down
2 changes: 2 additions & 0 deletions tools/perf/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ static inline unsigned long long rdclock(void)
#define __user
#define asmlinkage

#define __used __attribute__((__unused__))

#define unlikely(x) __builtin_expect(!!(x), 0)
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
static const char *alias_key;
static char *alias_val;

static int alias_lookup_cb(const char *k, const char *v, void *cb)
static int alias_lookup_cb(const char *k, const char *v, void *cb __used)
{
if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
if (!v)
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "util.h"
#include "strbuf.h"
#include "../perf.h"

#define PERF_DIR_ENVIRONMENT "PERF_DIR"
#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
Expand Down
Loading

0 comments on commit f37a291

Please sign in to comment.