aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-buildid-list.c3
-rw-r--r--tools/perf/builtin-probe.c5
-rw-r--r--tools/perf/builtin-record.c6
-rw-r--r--tools/perf/util/header.c21
-rw-r--r--tools/perf/util/hist.c2
-rw-r--r--tools/perf/util/probe-event.c15
-rw-r--r--tools/perf/util/probe-finder.c85
-rw-r--r--tools/perf/util/string.c2
-rw-r--r--tools/perf/util/symbol.c63
-rw-r--r--tools/perf/util/symbol.h2
10 files changed, 150 insertions, 54 deletions
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 44a47e13bd67..c49837de7d3f 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -36,7 +36,6 @@ static const struct option options[] = {
36 36
37static int __cmd_buildid_list(void) 37static int __cmd_buildid_list(void)
38{ 38{
39 int err = -1;
40 struct perf_session *session; 39 struct perf_session *session;
41 40
42 session = perf_session__new(input_name, O_RDONLY, force, false); 41 session = perf_session__new(input_name, O_RDONLY, force, false);
@@ -49,7 +48,7 @@ static int __cmd_buildid_list(void)
49 perf_session__fprintf_dsos_buildid(session, stdout, with_hits); 48 perf_session__fprintf_dsos_buildid(session, stdout, with_hits);
50 49
51 perf_session__delete(session); 50 perf_session__delete(session);
52 return err; 51 return 0;
53} 52}
54 53
55int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) 54int cmd_buildid_list(int argc, const char **argv, const char *prefix __used)
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 2e000c068cc5..add163c9f0e7 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -249,6 +249,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
249 !params.show_lines)) 249 !params.show_lines))
250 usage_with_options(probe_usage, options); 250 usage_with_options(probe_usage, options);
251 251
252 /*
253 * Only consider the user's kernel image path if given.
254 */
255 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
256
252 if (params.list_events) { 257 if (params.list_events) {
253 if (params.mod_events) { 258 if (params.mod_events) {
254 pr_err(" Error: Don't use --list with --add/--del.\n"); 259 pr_err(" Error: Don't use --list with --add/--del.\n");
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e2c2de201eec..564491fa18b2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -197,7 +197,7 @@ static void sig_atexit(void)
197 if (child_pid > 0) 197 if (child_pid > 0)
198 kill(child_pid, SIGTERM); 198 kill(child_pid, SIGTERM);
199 199
200 if (signr == -1) 200 if (signr == -1 || signr == SIGUSR1)
201 return; 201 return;
202 202
203 signal(signr, SIG_DFL); 203 signal(signr, SIG_DFL);
@@ -515,6 +515,7 @@ static int __cmd_record(int argc, const char **argv)
515 atexit(sig_atexit); 515 atexit(sig_atexit);
516 signal(SIGCHLD, sig_handler); 516 signal(SIGCHLD, sig_handler);
517 signal(SIGINT, sig_handler); 517 signal(SIGINT, sig_handler);
518 signal(SIGUSR1, sig_handler);
518 519
519 if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) { 520 if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
520 perror("failed to create pipes"); 521 perror("failed to create pipes");
@@ -606,6 +607,7 @@ static int __cmd_record(int argc, const char **argv)
606 execvp(argv[0], (char **)argv); 607 execvp(argv[0], (char **)argv);
607 608
608 perror(argv[0]); 609 perror(argv[0]);
610 kill(getppid(), SIGUSR1);
609 exit(-1); 611 exit(-1);
610 } 612 }
611 613
@@ -762,7 +764,7 @@ static int __cmd_record(int argc, const char **argv)
762 } 764 }
763 } 765 }
764 766
765 if (quiet) 767 if (quiet || signr == SIGUSR1)
766 return 0; 768 return 0;
767 769
768 fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); 770 fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d7e67b167ea3..7cba0551a565 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -265,15 +265,16 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
265 const char *name, bool is_kallsyms) 265 const char *name, bool is_kallsyms)
266{ 266{
267 const size_t size = PATH_MAX; 267 const size_t size = PATH_MAX;
268 char *filename = malloc(size), 268 char *realname = realpath(name, NULL),
269 *filename = malloc(size),
269 *linkname = malloc(size), *targetname; 270 *linkname = malloc(size), *targetname;
270 int len, err = -1; 271 int len, err = -1;
271 272
272 if (filename == NULL || linkname == NULL) 273 if (realname == NULL || filename == NULL || linkname == NULL)
273 goto out_free; 274 goto out_free;
274 275
275 len = snprintf(filename, size, "%s%s%s", 276 len = snprintf(filename, size, "%s%s%s",
276 debugdir, is_kallsyms ? "/" : "", name); 277 debugdir, is_kallsyms ? "/" : "", realname);
277 if (mkdir_p(filename, 0755)) 278 if (mkdir_p(filename, 0755))
278 goto out_free; 279 goto out_free;
279 280
@@ -283,7 +284,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
283 if (is_kallsyms) { 284 if (is_kallsyms) {
284 if (copyfile("/proc/kallsyms", filename)) 285 if (copyfile("/proc/kallsyms", filename))
285 goto out_free; 286 goto out_free;
286 } else if (link(name, filename) && copyfile(name, filename)) 287 } else if (link(realname, filename) && copyfile(name, filename))
287 goto out_free; 288 goto out_free;
288 } 289 }
289 290
@@ -300,6 +301,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
300 if (symlink(targetname, linkname) == 0) 301 if (symlink(targetname, linkname) == 0)
301 err = 0; 302 err = 0;
302out_free: 303out_free:
304 free(realname);
303 free(filename); 305 free(filename);
304 free(linkname); 306 free(linkname);
305 return err; 307 return err;
@@ -946,11 +948,16 @@ perf_header__find_attr(u64 id, struct perf_header *header)
946 948
947 /* 949 /*
948 * We set id to -1 if the data file doesn't contain sample 950 * We set id to -1 if the data file doesn't contain sample
949 * ids. Check for this and avoid walking through the entire 951 * ids. This can happen when the data file contains one type
950 * list of ids which may be large. 952 * of event and in that case, the header can still store the
953 * event attribute information. Check for this and avoid
954 * walking through the entire list of ids which may be large.
951 */ 955 */
952 if (id == -1ULL) 956 if (id == -1ULL) {
957 if (header->attrs > 0)
958 return &header->attr[0]->attr;
953 return NULL; 959 return NULL;
960 }
954 961
955 for (i = 0; i < header->attrs; i++) { 962 for (i = 0; i < header->attrs; i++) {
956 struct perf_header_attr *attr = header->attr[i]; 963 struct perf_header_attr *attr = header->attr[i];
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 2022e8740994..76bcc35cf9b1 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -356,7 +356,7 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
356 356
357static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, 357static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
358 int depth, int depth_mask, int period, 358 int depth, int depth_mask, int period,
359 u64 total_samples, int hits, 359 u64 total_samples, u64 hits,
360 int left_margin) 360 int left_margin)
361{ 361{
362 int i; 362 int i;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 3b6a5297bf16..61191c6cbe7a 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -114,6 +114,8 @@ static struct symbol *__find_kernel_function_by_name(const char *name,
114const char *kernel_get_module_path(const char *module) 114const char *kernel_get_module_path(const char *module)
115{ 115{
116 struct dso *dso; 116 struct dso *dso;
117 struct map *map;
118 const char *vmlinux_name;
117 119
118 if (module) { 120 if (module) {
119 list_for_each_entry(dso, &machine.kernel_dsos, node) { 121 list_for_each_entry(dso, &machine.kernel_dsos, node) {
@@ -123,10 +125,17 @@ const char *kernel_get_module_path(const char *module)
123 } 125 }
124 pr_debug("Failed to find module %s.\n", module); 126 pr_debug("Failed to find module %s.\n", module);
125 return NULL; 127 return NULL;
128 }
129
130 map = machine.vmlinux_maps[MAP__FUNCTION];
131 dso = map->dso;
132
133 vmlinux_name = symbol_conf.vmlinux_name;
134 if (vmlinux_name) {
135 if (dso__load_vmlinux(dso, map, vmlinux_name, NULL) <= 0)
136 return NULL;
126 } else { 137 } else {
127 dso = machine.vmlinux_maps[MAP__FUNCTION]->dso; 138 if (dso__load_vmlinux_path(dso, map, NULL) <= 0) {
128 if (dso__load_vmlinux_path(dso,
129 machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) {
130 pr_debug("Failed to load kernel map.\n"); 139 pr_debug("Failed to load kernel map.\n");
131 return NULL; 140 return NULL;
132 } 141 }
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 3991d73d1cff..ddf4d4556321 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -117,28 +117,6 @@ static void line_list__free(struct list_head *head)
117} 117}
118 118
119/* Dwarf FL wrappers */ 119/* Dwarf FL wrappers */
120
121static int __linux_kernel_find_elf(Dwfl_Module *mod,
122 void **userdata,
123 const char *module_name,
124 Dwarf_Addr base,
125 char **file_name, Elf **elfp)
126{
127 int fd;
128 const char *path = kernel_get_module_path(module_name);
129
130 if (path) {
131 fd = open(path, O_RDONLY);
132 if (fd >= 0) {
133 *file_name = strdup(path);
134 return fd;
135 }
136 }
137 /* If failed, try to call standard method */
138 return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base,
139 file_name, elfp);
140}
141
142static char *debuginfo_path; /* Currently dummy */ 120static char *debuginfo_path; /* Currently dummy */
143 121
144static const Dwfl_Callbacks offline_callbacks = { 122static const Dwfl_Callbacks offline_callbacks = {
@@ -151,14 +129,6 @@ static const Dwfl_Callbacks offline_callbacks = {
151 .find_elf = dwfl_build_id_find_elf, 129 .find_elf = dwfl_build_id_find_elf,
152}; 130};
153 131
154static const Dwfl_Callbacks kernel_callbacks = {
155 .find_debuginfo = dwfl_standard_find_debuginfo,
156 .debuginfo_path = &debuginfo_path,
157
158 .find_elf = __linux_kernel_find_elf,
159 .section_address = dwfl_linux_kernel_module_section_address,
160};
161
162/* Get a Dwarf from offline image */ 132/* Get a Dwarf from offline image */
163static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias) 133static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias)
164{ 134{
@@ -185,6 +155,38 @@ error:
185 return dbg; 155 return dbg;
186} 156}
187 157
158#if _ELFUTILS_PREREQ(0, 148)
159/* This method is buggy if elfutils is older than 0.148 */
160static int __linux_kernel_find_elf(Dwfl_Module *mod,
161 void **userdata,
162 const char *module_name,
163 Dwarf_Addr base,
164 char **file_name, Elf **elfp)
165{
166 int fd;
167 const char *path = kernel_get_module_path(module_name);
168
169 pr_debug2("Use file %s for %s\n", path, module_name);
170 if (path) {
171 fd = open(path, O_RDONLY);
172 if (fd >= 0) {
173 *file_name = strdup(path);
174 return fd;
175 }
176 }
177 /* If failed, try to call standard method */
178 return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base,
179 file_name, elfp);
180}
181
182static const Dwfl_Callbacks kernel_callbacks = {
183 .find_debuginfo = dwfl_standard_find_debuginfo,
184 .debuginfo_path = &debuginfo_path,
185
186 .find_elf = __linux_kernel_find_elf,
187 .section_address = dwfl_linux_kernel_module_section_address,
188};
189
188/* Get a Dwarf from live kernel image */ 190/* Get a Dwarf from live kernel image */
189static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp, 191static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp,
190 Dwarf_Addr *bias) 192 Dwarf_Addr *bias)
@@ -205,11 +207,34 @@ static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp,
205 dbg = dwfl_addrdwarf(*dwflp, addr, bias); 207 dbg = dwfl_addrdwarf(*dwflp, addr, bias);
206 /* Here, check whether we could get a real dwarf */ 208 /* Here, check whether we could get a real dwarf */
207 if (!dbg) { 209 if (!dbg) {
210 pr_debug("Failed to find kernel dwarf at %lx\n",
211 (unsigned long)addr);
208 dwfl_end(*dwflp); 212 dwfl_end(*dwflp);
209 *dwflp = NULL; 213 *dwflp = NULL;
210 } 214 }
211 return dbg; 215 return dbg;
212} 216}
217#else
218/* With older elfutils, this just support kernel module... */
219static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr __used, Dwfl **dwflp,
220 Dwarf_Addr *bias)
221{
222 int fd;
223 const char *path = kernel_get_module_path("kernel");
224
225 if (!path) {
226 pr_err("Failed to find vmlinux path\n");
227 return NULL;
228 }
229
230 pr_debug2("Use file %s for debuginfo\n", path);
231 fd = open(path, O_RDONLY);
232 if (fd < 0)
233 return NULL;
234
235 return dwfl_init_offline_dwarf(fd, dwflp, bias);
236}
237#endif
213 238
214/* Dwarf wrappers */ 239/* Dwarf wrappers */
215 240
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 0409fc7c0058..8fc0bd3a3a4a 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -259,7 +259,7 @@ static bool __match_glob(const char *str, const char *pat, bool ignore_space)
259 if (!*pat) /* Tail wild card matches all */ 259 if (!*pat) /* Tail wild card matches all */
260 return true; 260 return true;
261 while (*str) 261 while (*str)
262 if (strglobmatch(str++, pat)) 262 if (__match_glob(str++, pat, ignore_space))
263 return true; 263 return true;
264 } 264 }
265 return !*str && !*pat; 265 return !*str && !*pat;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 0500895a45af..439ab947daf4 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -532,7 +532,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
532 struct machine *machine = kmaps->machine; 532 struct machine *machine = kmaps->machine;
533 struct map *curr_map = map; 533 struct map *curr_map = map;
534 struct symbol *pos; 534 struct symbol *pos;
535 int count = 0; 535 int count = 0, moved = 0;
536 struct rb_root *root = &self->symbols[map->type]; 536 struct rb_root *root = &self->symbols[map->type];
537 struct rb_node *next = rb_first(root); 537 struct rb_node *next = rb_first(root);
538 int kernel_range = 0; 538 int kernel_range = 0;
@@ -590,6 +590,11 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
590 char dso_name[PATH_MAX]; 590 char dso_name[PATH_MAX];
591 struct dso *dso; 591 struct dso *dso;
592 592
593 if (count == 0) {
594 curr_map = map;
595 goto filter_symbol;
596 }
597
593 if (self->kernel == DSO_TYPE_GUEST_KERNEL) 598 if (self->kernel == DSO_TYPE_GUEST_KERNEL)
594 snprintf(dso_name, sizeof(dso_name), 599 snprintf(dso_name, sizeof(dso_name),
595 "[guest.kernel].%d", 600 "[guest.kernel].%d",
@@ -615,7 +620,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
615 map_groups__insert(kmaps, curr_map); 620 map_groups__insert(kmaps, curr_map);
616 ++kernel_range; 621 ++kernel_range;
617 } 622 }
618 623filter_symbol:
619 if (filter && filter(curr_map, pos)) { 624 if (filter && filter(curr_map, pos)) {
620discard_symbol: rb_erase(&pos->rb_node, root); 625discard_symbol: rb_erase(&pos->rb_node, root);
621 symbol__delete(pos); 626 symbol__delete(pos);
@@ -623,8 +628,9 @@ discard_symbol: rb_erase(&pos->rb_node, root);
623 if (curr_map != map) { 628 if (curr_map != map) {
624 rb_erase(&pos->rb_node, root); 629 rb_erase(&pos->rb_node, root);
625 symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); 630 symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
626 } 631 ++moved;
627 count++; 632 } else
633 ++count;
628 } 634 }
629 } 635 }
630 636
@@ -634,7 +640,7 @@ discard_symbol: rb_erase(&pos->rb_node, root);
634 dso__set_loaded(curr_map->dso, curr_map->type); 640 dso__set_loaded(curr_map->dso, curr_map->type);
635 } 641 }
636 642
637 return count; 643 return count + moved;
638} 644}
639 645
640int dso__load_kallsyms(struct dso *self, const char *filename, 646int dso__load_kallsyms(struct dso *self, const char *filename,
@@ -1774,8 +1780,8 @@ out_failure:
1774 return -1; 1780 return -1;
1775} 1781}
1776 1782
1777static int dso__load_vmlinux(struct dso *self, struct map *map, 1783int dso__load_vmlinux(struct dso *self, struct map *map,
1778 const char *vmlinux, symbol_filter_t filter) 1784 const char *vmlinux, symbol_filter_t filter)
1779{ 1785{
1780 int err = -1, fd; 1786 int err = -1, fd;
1781 1787
@@ -2125,14 +2131,55 @@ static struct dso *machine__create_kernel(struct machine *self)
2125 return kernel; 2131 return kernel;
2126} 2132}
2127 2133
2134struct process_args {
2135 u64 start;
2136};
2137
2138static int symbol__in_kernel(void *arg, const char *name,
2139 char type __used, u64 start)
2140{
2141 struct process_args *args = arg;
2142
2143 if (strchr(name, '['))
2144 return 0;
2145
2146 args->start = start;
2147 return 1;
2148}
2149
2150/* Figure out the start address of kernel map from /proc/kallsyms */
2151static u64 machine__get_kernel_start_addr(struct machine *machine)
2152{
2153 const char *filename;
2154 char path[PATH_MAX];
2155 struct process_args args;
2156
2157 if (machine__is_host(machine)) {
2158 filename = "/proc/kallsyms";
2159 } else {
2160 if (machine__is_default_guest(machine))
2161 filename = (char *)symbol_conf.default_guest_kallsyms;
2162 else {
2163 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
2164 filename = path;
2165 }
2166 }
2167
2168 if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
2169 return 0;
2170
2171 return args.start;
2172}
2173
2128int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) 2174int __machine__create_kernel_maps(struct machine *self, struct dso *kernel)
2129{ 2175{
2130 enum map_type type; 2176 enum map_type type;
2177 u64 start = machine__get_kernel_start_addr(self);
2131 2178
2132 for (type = 0; type < MAP__NR_TYPES; ++type) { 2179 for (type = 0; type < MAP__NR_TYPES; ++type) {
2133 struct kmap *kmap; 2180 struct kmap *kmap;
2134 2181
2135 self->vmlinux_maps[type] = map__new2(0, kernel, type); 2182 self->vmlinux_maps[type] = map__new2(start, kernel, type);
2136 if (self->vmlinux_maps[type] == NULL) 2183 if (self->vmlinux_maps[type] == NULL)
2137 return -1; 2184 return -1;
2138 2185
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 038f2201ee09..6c6eafdb932d 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -166,6 +166,8 @@ void dso__sort_by_name(struct dso *self, enum map_type type);
166struct dso *__dsos__findnew(struct list_head *head, const char *name); 166struct dso *__dsos__findnew(struct list_head *head, const char *name);
167 167
168int dso__load(struct dso *self, struct map *map, symbol_filter_t filter); 168int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
169int dso__load_vmlinux(struct dso *self, struct map *map,
170 const char *vmlinux, symbol_filter_t filter);
169int dso__load_vmlinux_path(struct dso *self, struct map *map, 171int dso__load_vmlinux_path(struct dso *self, struct map *map,
170 symbol_filter_t filter); 172 symbol_filter_t filter);
171int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map, 173int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,