aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-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
17 files changed, 136 insertions, 105 deletions
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);