From 863e451f69ddf255e877567e325298edd3b21519 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 6 Sep 2012 17:46:55 +0200 Subject: perf diff: Make diff command work with evsel hists Putting 'perf diff' command back on track with the 'latest' evsel hists changes. Each evsel has its own 'hists' object gathering stats for the particular event. While currently counts are accumulated for the whole session regardless of the events diversification within compared sessions. The 'perf diff' command now outputs all matching events within compared sessions (with event name specified). The per event diff output stays the same. $ ./perf diff # Event 'cycles' # # Baseline Delta Shared Object Symbol # ........ .......... ................. .............................. # 0.00% +15.14% [kernel.kallsyms] [k] __wake_up 0.00% +13.38% [kernel.kallsyms] [k] ext4fs_dirhash ... SNIP 0.00% +0.42% [kernel.kallsyms] [k] local_clock 0.17% -0.05% [kernel.kallsyms] [k] native_write_msr_safe # Event 'faults' # # Baseline Delta Shared Object Symbol # ........ .......... ................. .............................. # 0.00% +79.12% ld-2.15.so [.] _dl_relocate_object 0.00% +11.62% ld-2.15.so [.] openaux Signed-off-by: Jiri Olsa Cc: Andi Kleen Cc: Corey Ashford Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul E. McKenney Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1346946426-13496-2-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.h | 7 +++++++ tools/perf/util/session.h | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a3f562cec43..390690eb878 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -124,6 +124,13 @@ void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads); (evsel->attr.type == PERF_TYPE_##t && \ evsel->attr.config == PERF_COUNT_##c) +static inline bool perf_evsel__match2(struct perf_evsel *e1, + struct perf_evsel *e2) +{ + return (e1->attr.type == e2->attr.type) && + (e1->attr.config == e2->attr.config); +} + int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, int cpu, int thread, bool scale); diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 176a60902f5..aab414fbb64 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -36,9 +36,7 @@ struct perf_session { struct pevent *pevent; /* * FIXME: Need to split this up further, we need global - * stats + per event stats. 'perf diff' also needs - * to properly support multiple events in a single - * perf.data file. + * stats + per event stats. */ struct hists hists; int fd; -- cgit v1.2.3-70-g09d2 From 0ca0c130419a4aa05d28fbecc5d360f051944251 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 6 Sep 2012 17:46:56 +0200 Subject: perf tools: Replace sort's standalone field_sep with symbol_conf.field_sep The repsep_snprintf function was still using standalone field_sep, which not even set anymore. Replacing it with 'symbol_conf.field_sep'. Signed-off-by: Jiri Olsa Cc: Andi Kleen Cc: Corey Ashford Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul E. McKenney Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1346946426-13496-3-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/sort.c | 6 ++---- tools/perf/util/sort.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 0f5a0a496bc..7a2fbd8855b 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -12,8 +12,6 @@ int sort__branch_mode = -1; /* -1 = means not set */ enum sort_type sort__first_dimension; -char * field_sep; - LIST_HEAD(hist_entry__sort_list); static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) @@ -23,11 +21,11 @@ static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) va_start(ap, fmt); n = vsnprintf(bf, size, fmt, ap); - if (field_sep && n > 0) { + if (symbol_conf.field_sep && n > 0) { char *sep = bf; while (1) { - sep = strchr(sep, *field_sep); + sep = strchr(sep, *symbol_conf.field_sep); if (sep == NULL) break; *sep = '.'; diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index e724b26acd5..e459c981b03 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -32,7 +32,6 @@ extern const char default_sort_order[]; extern int sort__need_collapse; extern int sort__has_parent; extern int sort__branch_mode; -extern char *field_sep; extern struct sort_entry sort_comm; extern struct sort_entry sort_dso; extern struct sort_entry sort_sym; -- cgit v1.2.3-70-g09d2 From b771a8306205f0261496e93574a71bc7106844dc Mon Sep 17 00:00:00 2001 From: Irina Tirdea Date: Sat, 8 Sep 2012 03:43:17 +0300 Subject: perf tools: include basename for non-glibc systems perf uses the glibc version of basename(), by defining _GNU_SOURCE, including string.h and not including libgen.h. The glibc version of basename is better than the POSIX version since it does not modify its argument. Android has only one version of basename which is defined in libgen.h. This version is the same as the glibc version. Error on Android: util/annotate.c: In function 'symbol__annotate_printf': util/annotate.c:503:3: error: implicit declaration of function 'basename' [-Werror=implicit-function-declaration] util/annotate.c:503:3: error: nested extern declaration of 'basename' [-Werror=nested-externs] util/annotate.c:503:14: error: assignment makes pointer from integer without a cast [-Werror] On Android libgen.h should be included to define basename. Signed-off-by: Irina Tirdea Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1347065004-15306-6-git-send-email-irina.tirdea@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/symbol.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/perf/util') diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index fc4b1e630fd..d3b330cbc3e 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -10,6 +10,9 @@ #include #include #include +#if defined(__BIONIC__) +#include +#endif #ifndef NO_LIBELF_SUPPORT #include -- cgit v1.2.3-70-g09d2 From 57ec0a942d6855cd7a5711fcf4adb57c51259659 Mon Sep 17 00:00:00 2001 From: Irina Tirdea Date: Sat, 8 Sep 2012 03:43:18 +0300 Subject: perf tools: fix missing winsize definition In Android, struct winsize is not defined in the headers already included in help.c. This leads to a compile error. Including termios.h fixes the compilation error since it defines struct winsize. Signed-off-by: Irina Tirdea Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1347065004-15306-7-git-send-email-irina.tirdea@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/help.c | 1 + tools/perf/util/top.h | 1 + 2 files changed, 2 insertions(+) (limited to 'tools/perf/util') diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c index 6f2975a0035..4fa764d8f7d 100644 --- a/tools/perf/util/help.c +++ b/tools/perf/util/help.c @@ -3,6 +3,7 @@ #include "exec_cmd.h" #include "levenshtein.h" #include "help.h" +#include void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) { diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h index 33347ca89ee..86ff1b15059 100644 --- a/tools/perf/util/top.h +++ b/tools/perf/util/top.h @@ -5,6 +5,7 @@ #include "types.h" #include #include +#include struct perf_evlist; struct perf_evsel; -- cgit v1.2.3-70-g09d2 From 27683dc5cc9286ace82b6c900ab794428ed5e487 Mon Sep 17 00:00:00 2001 From: Irina Tirdea Date: Sat, 8 Sep 2012 03:43:19 +0300 Subject: perf tools: include missing pthread.h header pthread variables are used in some files without explicitely including pthread.h. This leads to compile errors on Android. e.g.: in annotate.h, error: unknown type name 'pthread_mutex_t' Including pthread.h explicitely in files that use it to have all definitions included. Signed-off-by: Irina Tirdea Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1347065004-15306-8-git-send-email-irina.tirdea@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/perf.c | 1 + tools/perf/util/annotate.h | 1 + 2 files changed, 2 insertions(+) (limited to 'tools/perf/util') diff --git a/tools/perf/perf.c b/tools/perf/perf.c index e7840e50071..fb8578cfa03 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -14,6 +14,7 @@ #include "util/run-command.h" #include "util/parse-events.h" #include "util/debugfs.h" +#include const char perf_usage_string[] = "perf [--version] [--help] COMMAND [ARGS]"; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index a6d6bc5d716..62a6e7a7365 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -7,6 +7,7 @@ #include "symbol.h" #include #include +#include struct ins; -- cgit v1.2.3-70-g09d2 From 7b45f21c2e42f265f6fd469e43857e98e2fdf01c Mon Sep 17 00:00:00 2001 From: Irina Tirdea Date: Sat, 8 Sep 2012 03:43:21 +0300 Subject: perf tools: replace mkostemp with mkstemp The mkostemp function is only available in glibc. This leads to compile error in Android, since bionic is derived from BSD. Replacing mkostemp with mkstemp. mkstemp is available on both glibc and bionic. Signed-off-by: Irina Tirdea Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1347065004-15306-10-git-send-email-irina.tirdea@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/dso-test-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/dso-test-data.c b/tools/perf/util/dso-test-data.c index 541cdc72c7d..c6caedeb1d6 100644 --- a/tools/perf/util/dso-test-data.c +++ b/tools/perf/util/dso-test-data.c @@ -23,7 +23,7 @@ static char *test_file(int size) int fd, i; unsigned char *buf; - fd = mkostemp(templ, O_CREAT|O_WRONLY|O_TRUNC); + fd = mkstemp(templ); buf = malloc(size); if (!buf) { -- cgit v1.2.3-70-g09d2 From c9f08bee50c71b06685ccff8110e56a7c05662b7 Mon Sep 17 00:00:00 2001 From: Irina Tirdea Date: Sat, 8 Sep 2012 03:43:23 +0300 Subject: perf tools: add NO_BACKTRACE for application self-debugging perf has support for self-debugging by defining dump_stack function. This function uses backtrace and backtrace_symbols functions defined as GNU extensions. In Android, bionic does not offer support for these functions and compilation will fail with the following error: target C: libperf <= tools/perf/util/util.c tools/perf/util/util.c:4:22: fatal error: execinfo.h: No such file or directory compilation terminated. Add a compile-time option (NO_BACKTRACE) to enable or disable self-debugging functionality in perf. This can also help in debugging since it offers the possibility to turn on/off printing the backtrace. Signed-off-by: Irina Tirdea Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1347065004-15306-12-git-send-email-irina.tirdea@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 8 ++++++++ tools/perf/config/feature-tests.mak | 14 ++++++++++++++ tools/perf/util/util.c | 6 ++++++ 3 files changed, 28 insertions(+) (limited to 'tools/perf/util') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index afd50757490..3eda4921573 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -755,6 +755,14 @@ else endif endif +ifdef NO_BACKTRACE + BASIC_CFLAGS += -DNO_BACKTRACE +else + ifneq ($(call try-cc,$(SOURCE_BACKTRACE),),y) + BASIC_CFLAGS += -DNO_BACKTRACE + endif +endif + ifdef ASCIIDOC8 export ASCIIDOC8 endif diff --git a/tools/perf/config/feature-tests.mak b/tools/perf/config/feature-tests.mak index 2f1156a62ab..116690a669d 100644 --- a/tools/perf/config/feature-tests.mak +++ b/tools/perf/config/feature-tests.mak @@ -179,3 +179,17 @@ int main(void) } endef endif + +ifndef NO_BACKTRACE +define SOURCE_BACKTRACE +#include +#include + +int main(void) +{ + backtrace(NULL, 0); + backtrace_symbols(NULL, 0); + return 0; +} +endef +endif diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 1b8775c3707..2055cf38041 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -1,7 +1,9 @@ #include "../perf.h" #include "util.h" #include +#ifndef NO_BACKTRACE #include +#endif #include #include @@ -163,6 +165,7 @@ size_t hex_width(u64 v) } /* Obtain a backtrace and print it to stdout. */ +#ifndef NO_BACKTRACE void dump_stack(void) { void *array[16]; @@ -177,3 +180,6 @@ void dump_stack(void) free(strings); } +#else +void dump_stack(void) {} +#endif -- cgit v1.2.3-70-g09d2 From b155a09015135cf59ada8d48109ccbd9891c1b42 Mon Sep 17 00:00:00 2001 From: Adrian Hunter Date: Fri, 31 Aug 2012 10:49:27 +0300 Subject: perf tools: Fix build for another rbtree.c change Fixes: ../../lib/rbtree.c: In function 'rb_insert_color': ../../lib/rbtree.c:95:9: error: 'true' undeclared (first use in this function) ../../lib/rbtree.c:95:9: note: each undeclared identifier is reported only once for each function it appears in ../../lib/rbtree.c: In function '__rb_erase_color': ../../lib/rbtree.c:216:9: error: 'true' undeclared (first use in this function) ../../lib/rbtree.c: In function 'rb_erase': ../../lib/rbtree.c:368:2: error: unknown type name 'bool' make: *** [util/rbtree.o] Error 1 Signed-off-by: Adrian Hunter Cc: Michel Lespinasse Cc: Andrew Morton Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/50406F60.5040707@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/include/linux/rbtree.h | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/perf/util') diff --git a/tools/perf/util/include/linux/rbtree.h b/tools/perf/util/include/linux/rbtree.h index 7a243a14303..2a030c5af3a 100644 --- a/tools/perf/util/include/linux/rbtree.h +++ b/tools/perf/util/include/linux/rbtree.h @@ -1 +1,2 @@ +#include #include "../../../../include/linux/rbtree.h" -- cgit v1.2.3-70-g09d2