aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Makefile10
-rw-r--r--tools/perf/builtin-probe.c1
-rw-r--r--tools/perf/builtin-top.c13
-rw-r--r--tools/perf/util/probe-event.c2
-rw-r--r--tools/perf/util/probe-finder.c18
-rw-r--r--tools/perf/util/probe-finder.h1
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c17
-rw-r--r--tools/perf/util/symbol.c18
-rw-r--r--tools/perf/util/symbol.h3
9 files changed, 49 insertions, 34 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 8a8f52db7e38..bc0f670a8338 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -200,7 +200,7 @@ endif
200 200
201CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 201CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
202EXTLIBS = -lpthread -lrt -lelf -lm 202EXTLIBS = -lpthread -lrt -lelf -lm
203ALL_CFLAGS = $(CFLAGS) 203ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
204ALL_LDFLAGS = $(LDFLAGS) 204ALL_LDFLAGS = $(LDFLAGS)
205STRIP ?= strip 205STRIP ?= strip
206 206
@@ -492,19 +492,19 @@ ifeq ($(uname_S),Darwin)
492 PTHREAD_LIBS = 492 PTHREAD_LIBS =
493endif 493endif
494 494
495ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 495ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
496ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 496ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
497 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); 497 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
498endif 498endif
499 499
500 ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 500 ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
501 BASIC_CFLAGS += -DLIBELF_NO_MMAP 501 BASIC_CFLAGS += -DLIBELF_NO_MMAP
502 endif 502 endif
503else 503else
504 msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); 504 msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]);
505endif 505endif
506 506
507ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 507ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
508 msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev); 508 msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev);
509 BASIC_CFLAGS += -DNO_DWARF_SUPPORT 509 BASIC_CFLAGS += -DNO_DWARF_SUPPORT
510else 510else
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index c30a33592340..152d6c9b1fa4 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -47,7 +47,6 @@
47#include "util/probe-event.h" 47#include "util/probe-event.h"
48 48
49#define MAX_PATH_LEN 256 49#define MAX_PATH_LEN 256
50#define MAX_PROBES 128
51 50
52/* Session management structure */ 51/* Session management structure */
53static struct { 52static struct {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 0b719e3dde05..1f529321607e 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -455,7 +455,7 @@ static void print_sym_table(void)
455 struct sym_entry *syme, *n; 455 struct sym_entry *syme, *n;
456 struct rb_root tmp = RB_ROOT; 456 struct rb_root tmp = RB_ROOT;
457 struct rb_node *nd; 457 struct rb_node *nd;
458 int sym_width = 0, dso_width = 0, max_dso_width; 458 int sym_width = 0, dso_width = 0, dso_short_width = 0;
459 const int win_width = winsize.ws_col - 1; 459 const int win_width = winsize.ws_col - 1;
460 460
461 samples = userspace_samples = 0; 461 samples = userspace_samples = 0;
@@ -545,15 +545,20 @@ static void print_sym_table(void)
545 if (syme->map->dso->long_name_len > dso_width) 545 if (syme->map->dso->long_name_len > dso_width)
546 dso_width = syme->map->dso->long_name_len; 546 dso_width = syme->map->dso->long_name_len;
547 547
548 if (syme->map->dso->short_name_len > dso_short_width)
549 dso_short_width = syme->map->dso->short_name_len;
550
548 if (syme->name_len > sym_width) 551 if (syme->name_len > sym_width)
549 sym_width = syme->name_len; 552 sym_width = syme->name_len;
550 } 553 }
551 554
552 printed = 0; 555 printed = 0;
553 556
554 max_dso_width = winsize.ws_col - sym_width - 29; 557 if (sym_width + dso_width > winsize.ws_col - 29) {
555 if (dso_width > max_dso_width) 558 dso_width = dso_short_width;
556 dso_width = max_dso_width; 559 if (sym_width + dso_width > winsize.ws_col - 29)
560 sym_width = winsize.ws_col - dso_width - 29;
561 }
557 putchar('\n'); 562 putchar('\n');
558 if (nr_counters == 1) 563 if (nr_counters == 1)
559 printf(" samples pcnt"); 564 printf(" samples pcnt");
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 53181dbfe4a8..7c004b6ef24f 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -242,7 +242,7 @@ void parse_perf_probe_event(const char *str, struct probe_point *pp,
242 242
243 /* Parse probe point */ 243 /* Parse probe point */
244 parse_perf_probe_probepoint(argv[0], pp); 244 parse_perf_probe_probepoint(argv[0], pp);
245 if (pp->file || pp->line) 245 if (pp->file || pp->line || pp->lazy_line)
246 *need_dwarf = true; 246 *need_dwarf = true;
247 247
248 /* Copy arguments and ensure return probe has no C argument */ 248 /* Copy arguments and ensure return probe has no C argument */
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 1e6c65ebbd80..c171a243d05b 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -333,8 +333,8 @@ static void show_location(Dwarf_Op *op, struct probe_finder *pf)
333 die("%u exceeds max register number.", regn); 333 die("%u exceeds max register number.", regn);
334 334
335 if (deref) 335 if (deref)
336 ret = snprintf(pf->buf, pf->len, " %s=+%ju(%s)", 336 ret = snprintf(pf->buf, pf->len, " %s=%+jd(%s)",
337 pf->var, (uintmax_t)offs, regs); 337 pf->var, (intmax_t)offs, regs);
338 else 338 else
339 ret = snprintf(pf->buf, pf->len, " %s=%s", pf->var, regs); 339 ret = snprintf(pf->buf, pf->len, " %s=%s", pf->var, regs);
340 DIE_IF(ret < 0); 340 DIE_IF(ret < 0);
@@ -352,8 +352,7 @@ static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
352 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL) 352 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
353 goto error; 353 goto error;
354 /* TODO: handle more than 1 exprs */ 354 /* TODO: handle more than 1 exprs */
355 ret = dwarf_getlocation_addr(&attr, (pf->addr - pf->cu_base), 355 ret = dwarf_getlocation_addr(&attr, pf->addr, &expr, &nexpr, 1);
356 &expr, &nexpr, 1);
357 if (ret <= 0 || nexpr == 0) 356 if (ret <= 0 || nexpr == 0)
358 goto error; 357 goto error;
359 358
@@ -437,8 +436,7 @@ static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
437 436
438 /* Get the frame base attribute/ops */ 437 /* Get the frame base attribute/ops */
439 dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); 438 dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr);
440 ret = dwarf_getlocation_addr(&fb_attr, (pf->addr - pf->cu_base), 439 ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
441 &pf->fb_ops, &nops, 1);
442 if (ret <= 0 || nops == 0) 440 if (ret <= 0 || nops == 0)
443 pf->fb_ops = NULL; 441 pf->fb_ops = NULL;
444 442
@@ -455,6 +453,9 @@ static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
455 /* *pf->fb_ops will be cached in libdw. Don't free it. */ 453 /* *pf->fb_ops will be cached in libdw. Don't free it. */
456 pf->fb_ops = NULL; 454 pf->fb_ops = NULL;
457 455
456 if (pp->found == MAX_PROBES)
457 die("Too many( > %d) probe point found.\n", MAX_PROBES);
458
458 pp->probes[pp->found] = strdup(tmp); 459 pp->probes[pp->found] = strdup(tmp);
459 pp->found++; 460 pp->found++;
460} 461}
@@ -641,7 +642,6 @@ static void find_probe_point_by_func(struct probe_finder *pf)
641int find_probe_point(int fd, struct probe_point *pp) 642int find_probe_point(int fd, struct probe_point *pp)
642{ 643{
643 struct probe_finder pf = {.pp = pp}; 644 struct probe_finder pf = {.pp = pp};
644 int ret;
645 Dwarf_Off off, noff; 645 Dwarf_Off off, noff;
646 size_t cuhl; 646 size_t cuhl;
647 Dwarf_Die *diep; 647 Dwarf_Die *diep;
@@ -668,10 +668,6 @@ int find_probe_point(int fd, struct probe_point *pp)
668 pf.fname = NULL; 668 pf.fname = NULL;
669 669
670 if (!pp->file || pf.fname) { 670 if (!pp->file || pf.fname) {
671 /* Save CU base address (for frame_base) */
672 ret = dwarf_lowpc(&pf.cu_die, &pf.cu_base);
673 if (ret != 0)
674 pf.cu_base = 0;
675 if (pp->function) 671 if (pp->function)
676 find_probe_point_by_func(&pf); 672 find_probe_point_by_func(&pf);
677 else if (pp->lazy_line) 673 else if (pp->lazy_line)
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index d1a651793ba6..21f7354397b4 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -71,7 +71,6 @@ struct probe_finder {
71 71
72 /* For variable searching */ 72 /* For variable searching */
73 Dwarf_Op *fb_ops; /* Frame base attribute */ 73 Dwarf_Op *fb_ops; /* Frame base attribute */
74 Dwarf_Addr cu_base; /* Current CU base address */
75 const char *var; /* Current variable name */ 74 const char *var; /* Current variable name */
76 char *buf; /* Current output buffer */ 75 char *buf; /* Current output buffer */
77 int len; /* Length of output buffer */ 76 int len; /* Length of output buffer */
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 33a414bbba3e..6a72f14c5986 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -208,7 +208,7 @@ static void python_process_event(int cpu, void *data,
208 int size __unused, 208 int size __unused,
209 unsigned long long nsecs, char *comm) 209 unsigned long long nsecs, char *comm)
210{ 210{
211 PyObject *handler, *retval, *context, *t; 211 PyObject *handler, *retval, *context, *t, *obj;
212 static char handler_name[256]; 212 static char handler_name[256];
213 struct format_field *field; 213 struct format_field *field;
214 unsigned long long val; 214 unsigned long long val;
@@ -256,16 +256,23 @@ static void python_process_event(int cpu, void *data,
256 offset &= 0xffff; 256 offset &= 0xffff;
257 } else 257 } else
258 offset = field->offset; 258 offset = field->offset;
259 PyTuple_SetItem(t, n++, 259 obj = PyString_FromString((char *)data + offset);
260 PyString_FromString((char *)data + offset));
261 } else { /* FIELD_IS_NUMERIC */ 260 } else { /* FIELD_IS_NUMERIC */
262 val = read_size(data + field->offset, field->size); 261 val = read_size(data + field->offset, field->size);
263 if (field->flags & FIELD_IS_SIGNED) { 262 if (field->flags & FIELD_IS_SIGNED) {
264 PyTuple_SetItem(t, n++, PyInt_FromLong(val)); 263 if ((long long)val >= LONG_MIN &&
264 (long long)val <= LONG_MAX)
265 obj = PyInt_FromLong(val);
266 else
267 obj = PyLong_FromLongLong(val);
265 } else { 268 } else {
266 PyTuple_SetItem(t, n++, PyInt_FromLong(val)); 269 if (val <= LONG_MAX)
270 obj = PyInt_FromLong(val);
271 else
272 obj = PyLong_FromUnsignedLongLong(val);
267 } 273 }
268 } 274 }
275 PyTuple_SetItem(t, n++, obj);
269 } 276 }
270 277
271 if (_PyTuple_Resize(&t, n) == -1) 278 if (_PyTuple_Resize(&t, n) == -1)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 323c0aea0a91..c458c4a371d1 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -163,9 +163,17 @@ void dso__set_long_name(struct dso *self, char *name)
163 self->long_name_len = strlen(name); 163 self->long_name_len = strlen(name);
164} 164}
165 165
166static void dso__set_short_name(struct dso *self, const char *name)
167{
168 if (name == NULL)
169 return;
170 self->short_name = name;
171 self->short_name_len = strlen(name);
172}
173
166static void dso__set_basename(struct dso *self) 174static void dso__set_basename(struct dso *self)
167{ 175{
168 self->short_name = basename(self->long_name); 176 dso__set_short_name(self, basename(self->long_name));
169} 177}
170 178
171struct dso *dso__new(const char *name) 179struct dso *dso__new(const char *name)
@@ -176,7 +184,7 @@ struct dso *dso__new(const char *name)
176 int i; 184 int i;
177 strcpy(self->name, name); 185 strcpy(self->name, name);
178 dso__set_long_name(self, self->name); 186 dso__set_long_name(self, self->name);
179 self->short_name = self->name; 187 dso__set_short_name(self, self->name);
180 for (i = 0; i < MAP__NR_TYPES; ++i) 188 for (i = 0; i < MAP__NR_TYPES; ++i)
181 self->symbols[i] = self->symbol_names[i] = RB_ROOT; 189 self->symbols[i] = self->symbol_names[i] = RB_ROOT;
182 self->slen_calculated = 0; 190 self->slen_calculated = 0;
@@ -897,7 +905,6 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
897 struct kmap *kmap = self->kernel ? map__kmap(map) : NULL; 905 struct kmap *kmap = self->kernel ? map__kmap(map) : NULL;
898 struct map *curr_map = map; 906 struct map *curr_map = map;
899 struct dso *curr_dso = self; 907 struct dso *curr_dso = self;
900 size_t dso_name_len = strlen(self->short_name);
901 Elf_Data *symstrs, *secstrs; 908 Elf_Data *symstrs, *secstrs;
902 uint32_t nr_syms; 909 uint32_t nr_syms;
903 int err = -1; 910 int err = -1;
@@ -987,7 +994,8 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
987 char dso_name[PATH_MAX]; 994 char dso_name[PATH_MAX];
988 995
989 if (strcmp(section_name, 996 if (strcmp(section_name,
990 curr_dso->short_name + dso_name_len) == 0) 997 (curr_dso->short_name +
998 self->short_name_len)) == 0)
991 goto new_symbol; 999 goto new_symbol;
992 1000
993 if (strcmp(section_name, ".text") == 0) { 1001 if (strcmp(section_name, ".text") == 0) {
@@ -1782,7 +1790,7 @@ struct dso *dso__new_kernel(const char *name)
1782 struct dso *self = dso__new(name ?: "[kernel.kallsyms]"); 1790 struct dso *self = dso__new(name ?: "[kernel.kallsyms]");
1783 1791
1784 if (self != NULL) { 1792 if (self != NULL) {
1785 self->short_name = "[kernel]"; 1793 dso__set_short_name(self, "[kernel]");
1786 self->kernel = 1; 1794 self->kernel = 1;
1787 } 1795 }
1788 1796
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 280dadd32a08..f30a37428919 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -110,9 +110,10 @@ struct dso {
110 u8 sorted_by_name; 110 u8 sorted_by_name;
111 u8 loaded; 111 u8 loaded;
112 u8 build_id[BUILD_ID_SIZE]; 112 u8 build_id[BUILD_ID_SIZE];
113 u16 long_name_len;
114 const char *short_name; 113 const char *short_name;
115 char *long_name; 114 char *long_name;
115 u16 long_name_len;
116 u16 short_name_len;
116 char name[0]; 117 char name[0];
117}; 118};
118 119