From 29a0fc9b2b6084e7a8810481df62a0fa496d8957 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 28 Sep 2012 18:31:59 +0900 Subject: perf tools: Convert to LIBELF_SUPPORT For building perf without libelf, we can set NO_LIBELF=1 as a argument of make. It then defines NO_LIBELF_SUPPORT macro for C code to do the proper handling. However it usually used in a negative semantics - e.g. #ifndef - so we saw double negations which can be misleading. Convert it to a positive form to make it more readable. Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1348824728-14025-4-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/generate-cmdlist.sh | 4 ++-- tools/perf/util/map.c | 2 +- tools/perf/util/symbol.h | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/generate-cmdlist.sh b/tools/perf/util/generate-cmdlist.sh index 389590c1ad2..3ac38031d53 100755 --- a/tools/perf/util/generate-cmdlist.sh +++ b/tools/perf/util/generate-cmdlist.sh @@ -22,7 +22,7 @@ do }' "Documentation/perf-$cmd.txt" done -echo "#ifndef NO_LIBELF_SUPPORT" +echo "#ifdef LIBELF_SUPPORT" sed -n -e 's/^perf-\([^ ]*\)[ ].* full.*/\1/p' command-list.txt | sort | while read cmd @@ -35,5 +35,5 @@ do p }' "Documentation/perf-$cmd.txt" done -echo "#endif /* NO_LIBELF_SUPPORT */" +echo "#endif /* LIBELF_SUPPORT */" echo "};" diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index ead5316b3f8..6109fa4d14c 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -162,7 +162,7 @@ int map__load(struct map *self, symbol_filter_t filter) pr_warning(", continuing without symbols\n"); return -1; } else if (nr == 0) { -#ifndef NO_LIBELF_SUPPORT +#ifdef LIBELF_SUPPORT const size_t len = strlen(name); const size_t real_len = len - sizeof(DSO__DELETED); diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index b441b07172b..8b6ef7fac74 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -12,7 +12,7 @@ #include #include -#ifndef NO_LIBELF_SUPPORT +#ifdef LIBELF_SUPPORT #include #include #include @@ -46,10 +46,10 @@ char *strxfrchar(char *s, char from, char to); * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; * for newer versions we can use mmap to reduce memory usage: */ -#ifdef LIBELF_NO_MMAP -# define PERF_ELF_C_READ_MMAP ELF_C_READ -#else +#ifdef LIBELF_MMAP # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP +#else +# define PERF_ELF_C_READ_MMAP ELF_C_READ #endif #ifndef DMGL_PARAMS @@ -233,7 +233,7 @@ struct symsrc { int fd; enum dso_binary_type type; -#ifndef NO_LIBELF_SUPPORT +#ifdef LIBELF_SUPPORT Elf *elf; GElf_Ehdr ehdr; -- cgit v1.2.3-70-g09d2 From 95485b1cda827e4db7102ad5fde1791087a0f4c5 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 28 Sep 2012 18:32:00 +0900 Subject: perf tools: Convert to LIBUNWIND_SUPPORT For building perf without libunwind, we can set NO_LIBUNWIND=1 as a argument of make. It then defines NO_LIBUNWIND_SUPPORT macro for C code to do the proper handling. However it usually used in a negative semantics - e.g. #ifndef - so we saw double negations which can be misleading. Convert it to a positive form to make it more readable. Also change NO_PERF_REGS macro to HAVE_PERF_REGS for the same reason. Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa Cc: Ingo Molnar Cc: Jiri Olsa Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1348824728-14025-5-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 8 +++----- tools/perf/builtin-record.c | 14 +++++++------- tools/perf/util/perf_regs.h | 4 ++-- tools/perf/util/unwind.h | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 1df09175d8d..676302441e1 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -535,9 +535,8 @@ endif # PERF_HAVE_DWARF_REGS endif # NO_DWARF endif # NO_LIBELF -ifdef NO_LIBUNWIND - BASIC_CFLAGS += -DNO_LIBUNWIND_SUPPORT -else +ifndef NO_LIBUNWIND + BASIC_CFLAGS += -DLIBUNWIND_SUPPORT EXTLIBS += $(LIBUNWIND_LIBS) BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS) BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS) @@ -747,8 +746,7 @@ ifeq ($(NO_PERF_REGS),0) ifeq ($(ARCH),x86) LIB_H += arch/x86/include/perf_regs.h endif -else - BASIC_CFLAGS += -DNO_PERF_REGS + BASIC_CFLAGS += -DHAVE_PERF_REGS endif ifdef NO_STRLCPY diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f14cb5fdb91..8c029fe2e22 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -33,11 +33,11 @@ #define CALLCHAIN_HELP "do call-graph (stack chain/backtrace) recording: " -#ifdef NO_LIBUNWIND_SUPPORT -static char callchain_help[] = CALLCHAIN_HELP "[fp]"; -#else +#ifdef LIBUNWIND_SUPPORT static unsigned long default_stack_dump_size = 8192; static char callchain_help[] = CALLCHAIN_HELP "[fp] dwarf"; +#else +static char callchain_help[] = CALLCHAIN_HELP "[fp]"; #endif enum write_mode_t { @@ -800,7 +800,7 @@ error: return ret; } -#ifndef NO_LIBUNWIND_SUPPORT +#ifdef LIBUNWIND_SUPPORT static int get_stack_size(char *str, unsigned long *_size) { char *endptr; @@ -826,7 +826,7 @@ static int get_stack_size(char *str, unsigned long *_size) max_size, str); return -1; } -#endif /* !NO_LIBUNWIND_SUPPORT */ +#endif /* LIBUNWIND_SUPPORT */ static int parse_callchain_opt(const struct option *opt __maybe_unused, const char *arg, @@ -865,7 +865,7 @@ parse_callchain_opt(const struct option *opt __maybe_unused, const char *arg, "needed for -g fp\n"); break; -#ifndef NO_LIBUNWIND_SUPPORT +#ifdef LIBUNWIND_SUPPORT /* Dwarf style */ } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { ret = 0; @@ -883,7 +883,7 @@ parse_callchain_opt(const struct option *opt __maybe_unused, const char *arg, if (!ret) pr_debug("callchain: stack dump size %d\n", rec->opts.stack_dump_size); -#endif /* !NO_LIBUNWIND_SUPPORT */ +#endif /* LIBUNWIND_SUPPORT */ } else { pr_err("callchain: Unknown -g option " "value: %s\n", arg); diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h index 316dbe7f86e..5a4f2b6f373 100644 --- a/tools/perf/util/perf_regs.h +++ b/tools/perf/util/perf_regs.h @@ -1,7 +1,7 @@ #ifndef __PERF_REGS_H #define __PERF_REGS_H -#ifndef NO_PERF_REGS +#ifdef HAVE_PERF_REGS #include #else #define PERF_REGS_MASK 0 @@ -10,5 +10,5 @@ static inline const char *perf_reg_name(int id __maybe_unused) { return NULL; } -#endif /* NO_PERF_REGS */ +#endif /* HAVE_PERF_REGS */ #endif /* __PERF_REGS_H */ diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h index a78c8b303bb..cb6bc503a79 100644 --- a/tools/perf/util/unwind.h +++ b/tools/perf/util/unwind.h @@ -13,7 +13,7 @@ struct unwind_entry { typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); -#ifndef NO_LIBUNWIND_SUPPORT +#ifdef LIBUNWIND_SUPPORT int unwind__get_entries(unwind_entry_cb_t cb, void *arg, struct machine *machine, struct thread *thread, @@ -31,5 +31,5 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, { return 0; } -#endif /* NO_LIBUNWIND_SUPPORT */ +#endif /* LIBUNWIND_SUPPORT */ #endif /* __UNWIND_H */ -- cgit v1.2.3-70-g09d2 From 1254b51e32649f2d34ec6b070ed36717c5a6b825 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 28 Sep 2012 18:32:02 +0900 Subject: perf tools: Convert to NEWT_SUPPORT For building perf without libnewt, we can set NO_NEWT=1 as a argument of make. It then defines NO_NEWT_SUPPORT macro for C code to do the proper handling. However it usually used in a negative semantics - e.g. #ifndef - so we saw double negations which can be misleading. Convert it to a positive form to make it more readable. Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1348824728-14025-7-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 8 +++----- tools/perf/ui/gtk/util.c | 2 +- tools/perf/ui/helpline.h | 10 +++++----- tools/perf/util/annotate.h | 8 ++++---- tools/perf/util/cache.h | 12 ++++++------ tools/perf/util/debug.c | 2 +- tools/perf/util/debug.h | 6 +++--- tools/perf/util/hist.h | 18 +++++++++--------- 8 files changed, 32 insertions(+), 34 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 99b2bb371bc..3d2181c5750 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -554,16 +554,14 @@ ifndef NO_LIBAUDIT endif endif -ifdef NO_NEWT - BASIC_CFLAGS += -DNO_NEWT_SUPPORT -else +ifndef NO_NEWT FLAGS_NEWT=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lnewt ifneq ($(call try-cc,$(SOURCE_NEWT),$(FLAGS_NEWT)),y) msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev); - BASIC_CFLAGS += -DNO_NEWT_SUPPORT else # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h BASIC_CFLAGS += -I/usr/include/slang + BASIC_CFLAGS += -DNEWT_SUPPORT EXTLIBS += -lnewt -lslang LIB_OBJS += $(OUTPUT)ui/setup.o LIB_OBJS += $(OUTPUT)ui/browser.o @@ -603,7 +601,7 @@ else LIB_OBJS += $(OUTPUT)ui/gtk/util.o LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o # Make sure that it'd be included only once. - ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),) + ifeq ($(findstring -DNEWT_SUPPORT,$(BASIC_CFLAGS)),) LIB_OBJS += $(OUTPUT)ui/setup.o LIB_OBJS += $(OUTPUT)ui/util.o endif diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c index 8aada5b3c04..ccb046aac98 100644 --- a/tools/perf/ui/gtk/util.c +++ b/tools/perf/ui/gtk/util.c @@ -116,7 +116,7 @@ struct perf_error_ops perf_gtk_eops = { * FIXME: Functions below should be implemented properly. * For now, just add stubs for NO_NEWT=1 build. */ -#ifdef NO_NEWT_SUPPORT +#ifndef NEWT_SUPPORT void ui_progress__update(u64 curr __maybe_unused, u64 total __maybe_unused, const char *title __maybe_unused) { diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h index 2b667ee454c..e1f126ba069 100644 --- a/tools/perf/ui/helpline.h +++ b/tools/perf/ui/helpline.h @@ -23,16 +23,16 @@ void ui_helpline__puts(const char *msg); extern char ui_helpline__current[512]; -#ifdef NO_NEWT_SUPPORT +#ifdef NEWT_SUPPORT +extern char ui_helpline__last_msg[]; +int ui_helpline__show_help(const char *format, va_list ap); +#else static inline int ui_helpline__show_help(const char *format __maybe_unused, va_list ap __maybe_unused) { return 0; } -#else -extern char ui_helpline__last_msg[]; -int ui_helpline__show_help(const char *format, va_list ap); -#endif /* NO_NEWT_SUPPORT */ +#endif /* NEWT_SUPPORT */ #ifdef NO_GTK2_SUPPORT static inline int perf_gtk__show_helpline(const char *format __maybe_unused, diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 9b5b21e7b03..39242dcee8f 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -138,7 +138,10 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx, bool print_lines, bool full_paths, int min_pcnt, int max_lines); -#ifdef NO_NEWT_SUPPORT +#ifdef NEWT_SUPPORT +int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, + void(*timer)(void *arg), void *arg, int delay_secs); +#else static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, struct map *map __maybe_unused, int evidx __maybe_unused, @@ -148,9 +151,6 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, { return 0; } -#else -int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, - void(*timer)(void *arg), void *arg, int delay_secs); #endif extern const char *disassembler_style; diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index ab176942654..70f318dc1d9 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h @@ -33,7 +33,7 @@ extern int pager_use_color; extern int use_browser; -#if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) +#if !defined(NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) static inline void setup_browser(bool fallback_to_pager) { if (fallback_to_pager) @@ -44,15 +44,15 @@ static inline void exit_browser(bool wait_for_ok __maybe_unused) {} void setup_browser(bool fallback_to_pager); void exit_browser(bool wait_for_ok); -#ifdef NO_NEWT_SUPPORT +#ifdef NEWT_SUPPORT +int ui__init(void); +void ui__exit(bool wait_for_ok); +#else static inline int ui__init(void) { return -1; } static inline void ui__exit(bool wait_for_ok __maybe_unused) {} -#else -int ui__init(void); -void ui__exit(bool wait_for_ok); #endif #ifdef NO_GTK2_SUPPORT @@ -65,7 +65,7 @@ static inline void perf_gtk__exit(bool wait_for_ok __maybe_unused) {} int perf_gtk__init(void); void perf_gtk__exit(bool wait_for_ok); #endif -#endif /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */ +#endif /* !NEWT_SUPPORT && NO_GTK2_SUPPORT */ char *alias_lookup(const char *alias); int split_cmdline(char *cmdline, const char ***argv); diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 66eb3828ceb..0f6ad7037d9 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -49,7 +49,7 @@ int dump_printf(const char *fmt, ...) return ret; } -#if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) +#if !defined(NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) int ui__warning(const char *format, ...) { va_list args; diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index bb2e7d1007a..3fe9ade7a2c 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -15,7 +15,7 @@ void trace_event(union perf_event *event); struct ui_progress; struct perf_error_ops; -#if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) +#if !defined(NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) static inline void ui_progress__update(u64 curr __maybe_unused, u64 total __maybe_unused, const char *title __maybe_unused) {} @@ -34,13 +34,13 @@ perf_error__unregister(struct perf_error_ops *eops __maybe_unused) return 0; } -#else /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */ +#else /* !NEWT_SUPPORT && NO_GTK2_SUPPORT */ #include "../ui/progress.h" int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); #include "../ui/util.h" -#endif /* NO_NEWT_SUPPORT && NO_GTK2_SUPPORT */ +#endif /* !NEWT_SUPPORT && NO_GTK2_SUPPORT */ int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); int ui__error_paranoid(void); diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index f011ad4756e..843638d0287 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -154,7 +154,15 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, struct perf_evlist; -#ifdef NO_NEWT_SUPPORT +#ifdef NEWT_SUPPORT +#include "../ui/keysyms.h" +int hist_entry__tui_annotate(struct hist_entry *he, int evidx, + void(*timer)(void *arg), void *arg, int delay_secs); + +int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, + void(*timer)(void *arg), void *arg, + int refresh); +#else static inline int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, const char *help __maybe_unused, @@ -177,14 +185,6 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self } #define K_LEFT -1 #define K_RIGHT -2 -#else -#include "../ui/keysyms.h" -int hist_entry__tui_annotate(struct hist_entry *he, int evidx, - void(*timer)(void *arg), void *arg, int delay_secs); - -int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, - void(*timer)(void *arg), void *arg, - int refresh); #endif #ifdef NO_GTK2_SUPPORT -- cgit v1.2.3-70-g09d2 From f9f526ecdc09a851f4f5567ebcf9bc553778f6c2 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 28 Sep 2012 18:32:03 +0900 Subject: perf tools: Convert to GTK2_SUPPORT For building perf without gtk+2, we can set NO_GTK2=1 as a argument of make. It then defines NO_GTK2_SUPPORT macro for C code to do the proper handling. However it usually used in a negative semantics - e.g. #ifndef - so we saw double negations which can be misleading. Convert it to a positive form to make it more readable. Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1348824728-14025-8-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 6 ++---- tools/perf/ui/helpline.h | 8 ++++---- tools/perf/util/cache.h | 28 +++++++++++++++------------- tools/perf/util/debug.c | 2 +- tools/perf/util/debug.h | 17 +++++++++-------- tools/perf/util/hist.h | 11 +++++------ 6 files changed, 36 insertions(+), 36 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 3d2181c5750..31a07f95fd9 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -583,17 +583,15 @@ ifndef NO_NEWT endif endif -ifdef NO_GTK2 - BASIC_CFLAGS += -DNO_GTK2_SUPPORT -else +ifndef NO_GTK2 FLAGS_GTK2=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null) ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2)),y) msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev); - BASIC_CFLAGS += -DNO_GTK2_SUPPORT else ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2)),y) BASIC_CFLAGS += -DHAVE_GTK_INFO_BAR endif + BASIC_CFLAGS += -DGTK2_SUPPORT BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null) EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null) LIB_OBJS += $(OUTPUT)ui/gtk/browser.o diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h index e1f126ba069..baa28a4d16b 100644 --- a/tools/perf/ui/helpline.h +++ b/tools/perf/ui/helpline.h @@ -34,14 +34,14 @@ static inline int ui_helpline__show_help(const char *format __maybe_unused, } #endif /* NEWT_SUPPORT */ -#ifdef NO_GTK2_SUPPORT +#ifdef GTK2_SUPPORT +int perf_gtk__show_helpline(const char *format, va_list ap); +#else static inline int perf_gtk__show_helpline(const char *format __maybe_unused, va_list ap __maybe_unused) { return 0; } -#else -int perf_gtk__show_helpline(const char *format, va_list ap); -#endif /* NO_GTK2_SUPPORT */ +#endif /* GTK2_SUPPORT */ #endif /* _PERF_UI_HELPLINE_H_ */ diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 70f318dc1d9..07aec06e444 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h @@ -33,14 +33,7 @@ extern int pager_use_color; extern int use_browser; -#if !defined(NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) -static inline void setup_browser(bool fallback_to_pager) -{ - if (fallback_to_pager) - setup_pager(); -} -static inline void exit_browser(bool wait_for_ok __maybe_unused) {} -#else +#if defined(NEWT_SUPPORT) || defined(GTK2_SUPPORT) void setup_browser(bool fallback_to_pager); void exit_browser(bool wait_for_ok); @@ -55,17 +48,26 @@ static inline int ui__init(void) static inline void ui__exit(bool wait_for_ok __maybe_unused) {} #endif -#ifdef NO_GTK2_SUPPORT +#ifdef GTK2_SUPPORT +int perf_gtk__init(void); +void perf_gtk__exit(bool wait_for_ok); +#else static inline int perf_gtk__init(void) { return -1; } static inline void perf_gtk__exit(bool wait_for_ok __maybe_unused) {} -#else -int perf_gtk__init(void); -void perf_gtk__exit(bool wait_for_ok); #endif -#endif /* !NEWT_SUPPORT && NO_GTK2_SUPPORT */ + +#else /* NEWT_SUPPORT || GTK2_SUPPORT */ + +static inline void setup_browser(bool fallback_to_pager) +{ + if (fallback_to_pager) + setup_pager(); +} +static inline void exit_browser(bool wait_for_ok __maybe_unused) {} +#endif /* NEWT_SUPPORT || GTK2_SUPPORT */ char *alias_lookup(const char *alias); int split_cmdline(char *cmdline, const char ***argv); diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 0f6ad7037d9..03f830b4814 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -49,7 +49,7 @@ int dump_printf(const char *fmt, ...) return ret; } -#if !defined(NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) +#if !defined(NEWT_SUPPORT) && !defined(GTK2_SUPPORT) int ui__warning(const char *format, ...) { va_list args; diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 3fe9ade7a2c..dec98750b48 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -15,7 +15,14 @@ void trace_event(union perf_event *event); struct ui_progress; struct perf_error_ops; -#if !defined(NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT) +#if defined(NEWT_SUPPORT) || defined(GTK2_SUPPORT) + +#include "../ui/progress.h" +int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); +#include "../ui/util.h" + +#else + static inline void ui_progress__update(u64 curr __maybe_unused, u64 total __maybe_unused, const char *title __maybe_unused) {} @@ -34,13 +41,7 @@ perf_error__unregister(struct perf_error_ops *eops __maybe_unused) return 0; } -#else /* !NEWT_SUPPORT && NO_GTK2_SUPPORT */ - -#include "../ui/progress.h" -int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); -#include "../ui/util.h" - -#endif /* !NEWT_SUPPORT && NO_GTK2_SUPPORT */ +#endif /* NEWT_SUPPORT || GTK2_SUPPORT */ int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); int ui__error_paranoid(void); diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 843638d0287..6ca74079d5c 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -187,7 +187,11 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self #define K_RIGHT -2 #endif -#ifdef NO_GTK2_SUPPORT +#ifdef GTK2_SUPPORT +int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help, + void(*timer)(void *arg), void *arg, + int refresh); +#else static inline int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused, const char *help __maybe_unused, @@ -197,11 +201,6 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused, { return 0; } - -#else -int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help, - void(*timer)(void *arg), void *arg, - int refresh); #endif unsigned int hists__sort_list_width(struct hists *self); -- cgit v1.2.3-70-g09d2 From d6e66832a710c0e6d1376e8d39ee108636a177e7 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 28 Sep 2012 18:32:08 +0900 Subject: perf tools: Convert to HAVE_STRLCPY For similar reason of previous patches, convert NO_STRLCPY to positive HAVE_STRLCPY. Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1348824728-14025-13-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 8 +++----- tools/perf/util/cache.h | 2 +- tools/perf/util/path.c | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 31a07f95fd9..5216ade909d 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -743,11 +743,9 @@ ifeq ($(NO_PERF_REGS),0) BASIC_CFLAGS += -DHAVE_PERF_REGS endif -ifdef NO_STRLCPY - BASIC_CFLAGS += -DNO_STRLCPY -else - ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y) - BASIC_CFLAGS += -DNO_STRLCPY +ifndef NO_STRLCPY + ifeq ($(call try-cc,$(SOURCE_STRLCPY),),y) + BASIC_CFLAGS += -DHAVE_STRLCPY endif endif diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 07aec06e444..2bd51370ad2 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h @@ -107,7 +107,7 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2 extern char *perf_pathdup(const char *fmt, ...) __attribute__((format (printf, 1, 2))); -#ifdef NO_STRLCPY +#ifndef HAVE_STRLCPY extern size_t strlcpy(char *dest, const char *src, size_t size); #endif diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index bd749771142..a8c49548ca4 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c @@ -22,7 +22,7 @@ static const char *get_perf_dir(void) return "."; } -#ifdef NO_STRLCPY +#ifndef HAVE_STRLCPY size_t strlcpy(char *dest, const char *src, size_t size) { size_t ret = strlen(src); -- cgit v1.2.3-70-g09d2 From 4d8061faca7a50010f037374410f0c3647c3ecf8 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Wed, 3 Oct 2012 00:21:34 +0900 Subject: perf tools: Long option completion support for each subcommands Add internal --list-opts option to print all of long option names to stdout so that it can be used for bash completion engine. Signed-off-by: Namhyung Kim Acked-by: Frederic Weisbecker Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1349191294-6926-4-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 9 +++++++-- tools/perf/util/parse-options.c | 8 ++++++++ tools/perf/util/parse-options.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index bef06f0deeb..5c355ababf8 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -33,8 +33,13 @@ _perf() fi # List possible events for -e option elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then - cmds=$($cmd list --raw-dump) - COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + evts=$($cmd list --raw-dump) + COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) ) + # List long option names + elif [[ $cur == --* ]]; then + subcmd=${COMP_WORDS[1]} + opts=$($cmd $subcmd --list-opts) + COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) ) # Fall down to list regular files else _filedir diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 443fc116512..2bc9e70df7e 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c @@ -384,6 +384,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, return usage_with_options_internal(usagestr, options, 1); if (internal_help && !strcmp(arg + 2, "help")) return parse_options_usage(usagestr, options); + if (!strcmp(arg + 2, "list-opts")) + return PARSE_OPT_LIST; switch (parse_long_opt(ctx, arg + 2, options)) { case -1: return parse_options_usage(usagestr, options); @@ -422,6 +424,12 @@ int parse_options(int argc, const char **argv, const struct option *options, exit(129); case PARSE_OPT_DONE: break; + case PARSE_OPT_LIST: + while (options->type != OPTION_END) { + printf("--%s ", options->long_name); + options++; + } + exit(130); default: /* PARSE_OPT_UNKNOWN */ if (ctx.argv[0][1] == '-') { error("unknown option `%s'", ctx.argv[0] + 2); diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index abc31a1dac1..7bb5999940c 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h @@ -140,6 +140,7 @@ extern NORETURN void usage_with_options(const char * const *usagestr, enum { PARSE_OPT_HELP = -1, PARSE_OPT_DONE, + PARSE_OPT_LIST, PARSE_OPT_UNKNOWN, }; -- cgit v1.2.3-70-g09d2 From 4e34d9588b46f44a4dba718606913133f15e4b21 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Tue, 2 Oct 2012 01:32:51 +0900 Subject: perf tools: Convert to BACKTRACE_SUPPORT For building perf without stack backtrace debug, we can set NO_BACKTRACE=1 as a argument of make. It then defines NO_BACKTRACE macro for C code to do the proper handling. However it usually used in a negative semantics - e.g. #ifndef - so we saw double negations which can be misleading. Convert it to a positive form to make it more readable and add _SUPPORT suffix for consistency. Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Irina Tirdea Cc: Irina Tirdea Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1349109171-1942-1-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 10 +++++----- tools/perf/util/util.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 5216ade909d..f9126f89efe 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -45,6 +45,8 @@ include config/utilities.mak # # Define NO_LIBUNWIND if you do not want libunwind dependency for dwarf # backtrace post unwind. +# +# Define NO_BACKTRACE if you do not want stack backtrace debug feature $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) @@ -749,11 +751,9 @@ ifndef NO_STRLCPY endif endif -ifdef NO_BACKTRACE - BASIC_CFLAGS += -DNO_BACKTRACE -else - ifneq ($(call try-cc,$(SOURCE_BACKTRACE),),y) - BASIC_CFLAGS += -DNO_BACKTRACE +ifndef NO_BACKTRACE + ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y) + BASIC_CFLAGS += -DBACKTRACE_SUPPORT endif endif diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 2055cf38041..99664598bc1 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -1,7 +1,7 @@ #include "../perf.h" #include "util.h" #include -#ifndef NO_BACKTRACE +#ifdef BACKTRACE_SUPPORT #include #endif #include @@ -165,7 +165,7 @@ size_t hex_width(u64 v) } /* Obtain a backtrace and print it to stdout. */ -#ifndef NO_BACKTRACE +#ifdef BACKTRACE_SUPPORT void dump_stack(void) { void *array[16]; -- cgit v1.2.3-70-g09d2 From 39876e7dd385e0f0a438ee0ab13cf75a4f5e0e3b Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 3 Oct 2012 11:40:22 -0300 Subject: perf evlist: Introduce add_newtp method To reduce the boilerplate of creating and adding a new tracepoint to an evlist. Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-4z90i79gnmsza2czv2dhdrb7@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 18 +++--------------- tools/perf/util/evlist.c | 14 ++++++++++++++ tools/perf/util/evlist.h | 3 +++ 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 76b1202c03c..dec8ced61fb 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -200,24 +200,12 @@ static int trace__run(struct trace *trace) goto out; } - evsel = perf_evsel__newtp("raw_syscalls", "sys_enter", 0); - if (evsel == NULL) { - printf("Couldn't read the raw_syscalls:sys_enter tracepoint information!\n"); + if (perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_enter", trace__sys_enter) || + perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit)) { + printf("Couldn't read the raw_syscalls tracepoints information!\n"); goto out_delete_evlist; } - evsel->handler.func = trace__sys_enter; - perf_evlist__add(evlist, evsel); - - evsel = perf_evsel__newtp("raw_syscalls", "sys_exit", 1); - if (evsel == NULL) { - printf("Couldn't read the raw_syscalls:sys_exit tracepoint information!\n"); - goto out_delete_evlist; - } - - evsel->handler.func = trace__sys_exit; - perf_evlist__add(evlist, evsel); - err = perf_evlist__create_maps(evlist, &trace->opts.target); if (err < 0) { printf("Problems parsing the target to trace, check your options!\n"); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ae89686102f..6a2809fd257 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -285,6 +285,20 @@ out: return err; } +int perf_evlist__add_newtp(struct perf_evlist *evlist, + const char *sys, const char *name, void *handler) +{ + struct perf_evsel *evsel; + + evsel = perf_evsel__newtp(sys, name, evlist->nr_entries); + if (evsel == NULL) + return -1; + + evsel->handler.func = handler; + perf_evlist__add(evlist, evsel); + return 0; +} + void perf_evlist__disable(struct perf_evlist *evlist) { int cpu, thread; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 3f1fb66be02..ac98b010f1c 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -72,6 +72,9 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) +int perf_evlist__add_newtp(struct perf_evlist *evlist, + const char *sys, const char *name, void *handler); + int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter); struct perf_evsel * -- cgit v1.2.3-70-g09d2 From e60fc847cefa34d9b7a60f8fbbe3f7dc68fbd75e Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 3 Oct 2012 11:50:55 -0300 Subject: perf evlist: Remove some unused methods Those were introduced in a previous attempt at implementing 'trace', but are not being used anywhere, ditch them. Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-ruhm5gocoh32pb7gnr0ai6gh@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 86 ++---------------------------------------------- tools/perf/util/evlist.h | 17 +--------- 2 files changed, 3 insertions(+), 100 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 6a2809fd257..186b8773039 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -154,8 +154,8 @@ error: return -ENOMEM; } -int perf_evlist__add_attrs(struct perf_evlist *evlist, - struct perf_event_attr *attrs, size_t nr_attrs) +static int perf_evlist__add_attrs(struct perf_evlist *evlist, + struct perf_event_attr *attrs, size_t nr_attrs) { struct perf_evsel *evsel, *n; LIST_HEAD(head); @@ -189,60 +189,6 @@ int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, return perf_evlist__add_attrs(evlist, attrs, nr_attrs); } -static int trace_event__id(const char *evname) -{ - char *filename, *colon; - int err = -1, fd; - - if (asprintf(&filename, "%s/%s/id", tracing_events_path, evname) < 0) - return -1; - - colon = strrchr(filename, ':'); - if (colon != NULL) - *colon = '/'; - - fd = open(filename, O_RDONLY); - if (fd >= 0) { - char id[16]; - if (read(fd, id, sizeof(id)) > 0) - err = atoi(id); - close(fd); - } - - free(filename); - return err; -} - -int perf_evlist__add_tracepoints(struct perf_evlist *evlist, - const char *tracepoints[], - size_t nr_tracepoints) -{ - int err; - size_t i; - struct perf_event_attr *attrs = zalloc(nr_tracepoints * sizeof(*attrs)); - - if (attrs == NULL) - return -1; - - for (i = 0; i < nr_tracepoints; i++) { - err = trace_event__id(tracepoints[i]); - - if (err < 0) - goto out_free_attrs; - - attrs[i].type = PERF_TYPE_TRACEPOINT; - attrs[i].config = err; - attrs[i].sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | - PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD); - attrs[i].sample_period = 1; - } - - err = perf_evlist__add_attrs(evlist, attrs, nr_tracepoints); -out_free_attrs: - free(attrs); - return err; -} - struct perf_evsel * perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id) { @@ -257,34 +203,6 @@ perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id) return NULL; } -int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, - const struct perf_evsel_str_handler *assocs, - size_t nr_assocs) -{ - struct perf_evsel *evsel; - int err; - size_t i; - - for (i = 0; i < nr_assocs; i++) { - err = trace_event__id(assocs[i].name); - if (err < 0) - goto out; - - evsel = perf_evlist__find_tracepoint_by_id(evlist, err); - if (evsel == NULL) - continue; - - err = -EEXIST; - if (evsel->handler.func != NULL) - goto out; - evsel->handler.func = assocs[i].handler; - } - - err = 0; -out: - return err; -} - int perf_evlist__add_newtp(struct perf_evlist *evlist, const char *sys, const char *name, void *handler) { diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index ac98b010f1c..56003f779e6 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -51,27 +51,12 @@ void perf_evlist__delete(struct perf_evlist *evlist); void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); int perf_evlist__add_default(struct perf_evlist *evlist); -int perf_evlist__add_attrs(struct perf_evlist *evlist, - struct perf_event_attr *attrs, size_t nr_attrs); int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); -int perf_evlist__add_tracepoints(struct perf_evlist *evlist, - const char *tracepoints[], size_t nr_tracepoints); -int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, - const struct perf_evsel_str_handler *assocs, - size_t nr_assocs); - -#define perf_evlist__add_attrs_array(evlist, array) \ - perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array)) + #define perf_evlist__add_default_attrs(evlist, array) \ __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) -#define perf_evlist__add_tracepoints_array(evlist, array) \ - perf_evlist__add_tracepoints(evlist, array, ARRAY_SIZE(array)) - -#define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ - perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) - int perf_evlist__add_newtp(struct perf_evlist *evlist, const char *sys, const char *name, void *handler); -- cgit v1.2.3-70-g09d2 From ae359f193a80e19166efaed7d400d1476057b865 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:35 +0900 Subject: perf hists: Add struct hists pointer to struct hist_entry Adding pointer back to the parent struct hists for struct hists_entry. This will be useful in future for any hist_entry's data computation, that depends on total data of its parent hists. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-2-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/hist.c | 2 ++ tools/perf/util/sort.h | 1 + 2 files changed, 3 insertions(+) (limited to 'tools/perf/util') diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 236bc9d98ff..040f34c79a5 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -325,6 +325,7 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), .branch_info = bi, + .hists = self, }; return add_hist_entry(self, &entry, al, period); @@ -346,6 +347,7 @@ struct hist_entry *__hists__add_entry(struct hists *self, .period = period, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), + .hists = self, }; return add_hist_entry(self, &entry, al, period); diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 12d634792de..eb3959b8e9d 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -79,6 +79,7 @@ struct hist_entry { struct rb_root sorted_chain; }; struct branch_info *branch_info; + struct hists *hists; struct callchain_root callchain[0]; }; -- cgit v1.2.3-70-g09d2 From dd464345f330c1103f93daad309e8b44845e96cf Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:36 +0900 Subject: perf diff: Refactor diff displacement possition info Moving the position calculation into the diff command, so the position as prepared inside struct hist_entry data and there's no need to compute in the output display path. Removing 'displacement' from struct perf_hpp as it is no longer needed. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-3-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-diff.c | 49 +++++++++++++++++++++++++++++---------------- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/hist.c | 8 +++++--- tools/perf/ui/stdio/hist.c | 17 +++------------- tools/perf/util/hist.h | 4 +--- tools/perf/util/sort.h | 2 +- 7 files changed, 44 insertions(+), 40 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 761f4197a9e..5cb577a3c5b 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -70,8 +70,8 @@ static struct perf_tool tool = { .ordering_requires_timestamps = true, }; -static void perf_session__insert_hist_entry_by_name(struct rb_root *root, - struct hist_entry *he) +static void insert_hist_entry_by_name(struct rb_root *root, + struct hist_entry *he) { struct rb_node **p = &root->rb_node; struct rb_node *parent = NULL; @@ -90,7 +90,7 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root, rb_insert_color(&he->rb_node, root); } -static void hists__resort_entries(struct hists *self) +static void hists__name_resort(struct hists *self, bool sort) { unsigned long position = 1; struct rb_root tmp = RB_ROOT; @@ -100,12 +100,16 @@ static void hists__resort_entries(struct hists *self) struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); next = rb_next(&n->rb_node); - rb_erase(&n->rb_node, &self->entries); n->position = position++; - perf_session__insert_hist_entry_by_name(&tmp, n); + + if (sort) { + rb_erase(&n->rb_node, &self->entries); + insert_hist_entry_by_name(&tmp, n); + } } - self->entries = tmp; + if (sort) + self->entries = tmp; } static struct hist_entry *hists__find_entry(struct hists *self, @@ -121,7 +125,7 @@ static struct hist_entry *hists__find_entry(struct hists *self, n = n->rb_left; else if (cmp > 0) n = n->rb_right; - else + else return iter; } @@ -150,6 +154,24 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel, return NULL; } +static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name) +{ + struct perf_evsel *evsel; + + list_for_each_entry(evsel, &evlist->entries, node) { + struct hists *hists = &evsel->hists; + + hists__output_resort(hists); + + /* + * The hists__name_resort only sets possition + * if name is false. + */ + if (name || ((!name) && show_displacement)) + hists__name_resort(hists, name); + } +} + static int __cmd_diff(void) { int ret, i; @@ -176,15 +198,8 @@ static int __cmd_diff(void) evlist_old = older->evlist; evlist_new = newer->evlist; - list_for_each_entry(evsel, &evlist_new->entries, node) - hists__output_resort(&evsel->hists); - - list_for_each_entry(evsel, &evlist_old->entries, node) { - hists__output_resort(&evsel->hists); - - if (show_displacement) - hists__resort_entries(&evsel->hists); - } + perf_evlist__resort_hists(evlist_old, true); + perf_evlist__resort_hists(evlist_new, false); list_for_each_entry(evsel, &evlist_new->entries, node) { struct perf_evsel *evsel_old; @@ -200,7 +215,7 @@ static int __cmd_diff(void) hists__match(&evsel_old->hists, &evsel->hists); hists__fprintf(&evsel->hists, &evsel_old->hists, - show_displacement, true, 0, 0, stdout); + true, 0, 0, stdout); } out_delete: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1da243dfbc3..6748cac919d 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, const char *evname = perf_evsel__name(pos); hists__fprintf_nr_sample_events(hists, evname, stdout); - hists__fprintf(hists, NULL, false, true, 0, 0, stdout); + hists__fprintf(hists, NULL, true, 0, 0, stdout); fprintf(stdout, "\n\n"); } diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index f0c1c4f4692..357115874b7 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -316,7 +316,7 @@ static void perf_top__print_sym_table(struct perf_top *top) hists__output_recalc_col_len(&top->sym_evsel->hists, top->winsize.ws_row - 3); putchar('\n'); - hists__fprintf(&top->sym_evsel->hists, NULL, false, false, + hists__fprintf(&top->sym_evsel->hists, NULL, false, top->winsize.ws_row - 4 - printed, win_width, stdout); } diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index e3f8cd46e7d..55b9ca8f084 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -244,13 +244,15 @@ static int hpp__width_displ(struct perf_hpp *hpp __maybe_unused) } static int hpp__entry_displ(struct perf_hpp *hpp, - struct hist_entry *he __maybe_unused) + struct hist_entry *he) { + struct hist_entry *pair = he->pair; + long displacement = pair ? pair->position - he->position : 0; const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s"; char buf[32] = " "; - if (hpp->displacement) - scnprintf(buf, sizeof(buf), "%+4ld", hpp->displacement); + if (displacement) + scnprintf(buf, sizeof(buf), "%+4ld", displacement); return scnprintf(hpp->buf, hpp->size, fmt, buf); } diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 882461a4283..d7405f064e8 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -308,7 +308,7 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, static int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists, struct hists *pair_hists, - long displacement, u64 total_period, FILE *fp) + u64 total_period, FILE *fp) { char bf[512]; int ret; @@ -316,7 +316,6 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, .buf = bf, .size = size, .total_period = total_period, - .displacement = displacement, .ptr = pair_hists, }; bool color = !symbol_conf.field_sep; @@ -337,15 +336,13 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, } size_t hists__fprintf(struct hists *hists, struct hists *pair, - bool show_displacement, bool show_header, int max_rows, + bool show_header, int max_rows, int max_cols, FILE *fp) { struct sort_entry *se; struct rb_node *nd; size_t ret = 0; u64 total_period; - unsigned long position = 1; - long displacement = 0; unsigned int width; const char *sep = symbol_conf.field_sep; const char *col_width = symbol_conf.col_width_list_str; @@ -449,15 +446,7 @@ print_entries: if (h->filtered) continue; - if (show_displacement) { - if (h->pair != NULL) - displacement = ((long)h->pair->position - - (long)position); - else - displacement = 0; - ++position; - } - ret += hist_entry__fprintf(h, max_cols, hists, pair, displacement, + ret += hist_entry__fprintf(h, max_cols, hists, pair, total_period, fp); if (max_rows && ++nr_rows >= max_rows) diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 6ca74079d5c..efb8fc8a4d2 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -99,8 +99,7 @@ void hists__inc_nr_events(struct hists *self, u32 type); size_t hists__fprintf_nr_events(struct hists *self, FILE *fp); size_t hists__fprintf(struct hists *self, struct hists *pair, - bool show_displacement, bool show_header, - int max_rows, int max_cols, FILE *fp); + bool show_header, int max_rows, int max_cols, FILE *fp); int hist_entry__inc_addr_samples(struct hist_entry *self, int evidx, u64 addr); int hist_entry__annotate(struct hist_entry *self, size_t privsize); @@ -120,7 +119,6 @@ struct perf_hpp { size_t size; u64 total_period; const char *sep; - long displacement; void *ptr; }; diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index eb3959b8e9d..f070b523c81 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -73,8 +73,8 @@ struct hist_entry { u8 filtered; char *srcline; struct symbol *parent; + unsigned long position; union { - unsigned long position; struct hist_entry *pair; struct rb_root sorted_chain; }; -- cgit v1.2.3-70-g09d2 From 5395a04841fcdd9220177f2c21353fe6d4cd0729 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:37 +0900 Subject: perf hists: Separate overhead and baseline columns Currently the overhead and baseline columns are handled within single function and the distinction is made by 'baseline hists' pointer passed by 'struct perf_hpp::ptr'. Since hists pointer is now part of each hist_entry, it's possible to locate paired hists pointer directly from the passed struct hist_entry pointer. Also separating those 2 columns makes the code more obvious. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-4-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/hist.c | 74 ++++++++++++++++++++++++++++++---------------- tools/perf/ui/stdio/hist.c | 11 +++++-- tools/perf/util/hist.h | 1 + 3 files changed, 58 insertions(+), 28 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 55b9ca8f084..532a60177c3 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -8,9 +8,7 @@ /* hist period print (hpp) functions */ static int hpp__header_overhead(struct perf_hpp *hpp) { - const char *fmt = hpp->ptr ? "Baseline" : "Overhead"; - - return scnprintf(hpp->buf, hpp->size, fmt); + return scnprintf(hpp->buf, hpp->size, "Overhead"); } static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) @@ -22,17 +20,6 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) { double percent = 100.0 * he->period / hpp->total_period; - if (hpp->ptr) { - struct hists *old_hists = hpp->ptr; - u64 total_period = old_hists->stats.total_period; - u64 base_period = he->pair ? he->pair->period : 0; - - if (total_period) - percent = 100.0 * base_period / total_period; - else - percent = 0.0; - } - return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); } @@ -41,17 +28,6 @@ static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) double percent = 100.0 * he->period / hpp->total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; - if (hpp->ptr) { - struct hists *old_hists = hpp->ptr; - u64 total_period = old_hists->stats.total_period; - u64 base_period = he->pair ? he->pair->period : 0; - - if (total_period) - percent = 100.0 * base_period / total_period; - else - percent = 0.0; - } - return scnprintf(hpp->buf, hpp->size, fmt, percent); } @@ -159,6 +135,47 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, return scnprintf(hpp->buf, hpp->size, fmt, percent); } +static int hpp__header_baseline(struct perf_hpp *hpp) +{ + return scnprintf(hpp->buf, hpp->size, "Baseline"); +} + +static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused) +{ + return 8; +} + +static double baseline_percent(struct hist_entry *he) +{ + struct hist_entry *pair = he->pair; + struct hists *pair_hists = pair ? pair->hists : NULL; + double percent = 0.0; + + if (pair) { + u64 total_period = pair_hists->stats.total_period; + u64 base_period = pair->period; + + percent = 100.0 * base_period / total_period; + } + + return percent; +} + +static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he) +{ + double percent = baseline_percent(he); + + return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); +} + +static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he) +{ + double percent = baseline_percent(he); + const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; + + return scnprintf(hpp->buf, hpp->size, fmt, percent); +} + static int hpp__header_samples(struct perf_hpp *hpp) { const char *fmt = symbol_conf.field_sep ? "%s" : "%11s"; @@ -269,6 +286,7 @@ static int hpp__entry_displ(struct perf_hpp *hpp, .entry = hpp__entry_ ## _name struct perf_hpp_fmt perf_hpp__format[] = { + { .cond = false, HPP__COLOR_PRINT_FNS(baseline) }, { .cond = true, HPP__COLOR_PRINT_FNS(overhead) }, { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) }, { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) }, @@ -302,6 +320,8 @@ void perf_hpp__init(bool need_pair, bool show_displacement) perf_hpp__format[PERF_HPP__PERIOD].cond = true; if (need_pair) { + perf_hpp__format[PERF_HPP__OVERHEAD].cond = false; + perf_hpp__format[PERF_HPP__BASELINE].cond = true; perf_hpp__format[PERF_HPP__DELTA].cond = true; if (show_displacement) @@ -321,6 +341,7 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, const char *sep = symbol_conf.field_sep; char *start = hpp->buf; int i, ret; + bool first = true; if (symbol_conf.exclude_other && !he->parent) return 0; @@ -329,9 +350,10 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, if (!perf_hpp__format[i].cond) continue; - if (!sep || i > 0) { + if (!sep || !first) { ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); advance_hpp(hpp, ret); + first = false; } if (color && perf_hpp__format[i].color) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index d7405f064e8..0aa6776caba 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -353,6 +353,7 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, .size = sizeof(bf), .ptr = pair, }; + bool first = true; init_rem_hits(); @@ -364,8 +365,10 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, if (!perf_hpp__format[idx].cond) continue; - if (idx) + if (!first) fprintf(fp, "%s", sep ?: " "); + else + first = false; perf_hpp__format[idx].header(&dummy_hpp); fprintf(fp, "%s", bf); @@ -400,6 +403,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, if (sep) goto print_entries; + first = true; + fprintf(fp, "# "); for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) { unsigned int i; @@ -407,8 +412,10 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, if (!perf_hpp__format[idx].cond) continue; - if (idx) + if (!first) fprintf(fp, "%s", sep ?: " "); + else + first = false; width = perf_hpp__format[idx].width(&dummy_hpp); for (i = 0; i < width; i++) diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index efb8fc8a4d2..b1a2b9d9b65 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -133,6 +133,7 @@ struct perf_hpp_fmt { extern struct perf_hpp_fmt perf_hpp__format[]; enum { + PERF_HPP__BASELINE, PERF_HPP__OVERHEAD, PERF_HPP__OVERHEAD_SYS, PERF_HPP__OVERHEAD_US, -- cgit v1.2.3-70-g09d2 From 41724e4cf6c443d2dc575669b8555f0e2ae427a9 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:38 +0900 Subject: perf tools: Removing hists pair argument from output path The hists pointer is now part of the 'struct hist_entry'. And since the overhead and baseline columns are split now, there's no reason to pass it through the output path. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-5-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/hist.c | 9 +++++---- tools/perf/ui/stdio/hist.c | 10 +++------- tools/perf/util/hist.h | 4 ++-- 6 files changed, 13 insertions(+), 17 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 5cb577a3c5b..413c65a1ba3 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -214,8 +214,7 @@ static int __cmd_diff(void) first = false; hists__match(&evsel_old->hists, &evsel->hists); - hists__fprintf(&evsel->hists, &evsel_old->hists, - true, 0, 0, stdout); + hists__fprintf(&evsel->hists, true, 0, 0, stdout); } out_delete: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 6748cac919d..95e7ea879b8 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, const char *evname = perf_evsel__name(pos); hists__fprintf_nr_sample_events(hists, evname, stdout); - hists__fprintf(hists, NULL, true, 0, 0, stdout); + hists__fprintf(hists, true, 0, 0, stdout); fprintf(stdout, "\n\n"); } diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 357115874b7..ff6db808680 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -316,7 +316,7 @@ static void perf_top__print_sym_table(struct perf_top *top) hists__output_recalc_col_len(&top->sym_evsel->hists, top->winsize.ws_row - 3); putchar('\n'); - hists__fprintf(&top->sym_evsel->hists, NULL, false, + hists__fprintf(&top->sym_evsel->hists, false, top->winsize.ws_row - 4 - printed, win_width, stdout); } diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 532a60177c3..6b0138e5f33 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -228,16 +228,17 @@ static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused) static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) { - struct hists *pair_hists = hpp->ptr; + struct hist_entry *pair = he->pair; + struct hists *pair_hists = pair ? pair->hists : NULL; u64 old_total, new_total; double old_percent = 0, new_percent = 0; double diff; const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; char buf[32] = " "; - old_total = pair_hists->stats.total_period; - if (old_total > 0 && he->pair) - old_percent = 100.0 * he->pair->period / old_total; + old_total = pair_hists ? pair_hists->stats.total_period : 0; + if (old_total > 0 && pair) + old_percent = 100.0 * pair->period / old_total; new_total = hpp->total_period; if (new_total > 0) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 0aa6776caba..1340c93aa61 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -307,8 +307,7 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, } static int hist_entry__fprintf(struct hist_entry *he, size_t size, - struct hists *hists, struct hists *pair_hists, - u64 total_period, FILE *fp) + struct hists *hists, u64 total_period, FILE *fp) { char bf[512]; int ret; @@ -316,7 +315,6 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, .buf = bf, .size = size, .total_period = total_period, - .ptr = pair_hists, }; bool color = !symbol_conf.field_sep; @@ -335,8 +333,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, return ret; } -size_t hists__fprintf(struct hists *hists, struct hists *pair, - bool show_header, int max_rows, +size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, int max_cols, FILE *fp) { struct sort_entry *se; @@ -351,7 +348,6 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, struct perf_hpp dummy_hpp = { .buf = bf, .size = sizeof(bf), - .ptr = pair, }; bool first = true; @@ -453,7 +449,7 @@ print_entries: if (h->filtered) continue; - ret += hist_entry__fprintf(h, max_cols, hists, pair, + ret += hist_entry__fprintf(h, max_cols, hists, total_period, fp); if (max_rows && ++nr_rows >= max_rows) diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index b1a2b9d9b65..b83a2268b5d 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -98,8 +98,8 @@ void hists__output_recalc_col_len(struct hists *hists, int max_rows); void hists__inc_nr_events(struct hists *self, u32 type); size_t hists__fprintf_nr_events(struct hists *self, FILE *fp); -size_t hists__fprintf(struct hists *self, struct hists *pair, - bool show_header, int max_rows, int max_cols, FILE *fp); +size_t hists__fprintf(struct hists *self, bool show_header, int max_rows, + int max_cols, FILE *fp); int hist_entry__inc_addr_samples(struct hist_entry *self, int evidx, u64 addr); int hist_entry__annotate(struct hist_entry *self, size_t privsize); -- cgit v1.2.3-70-g09d2 From 1d77822ea6245e89149872405a3844e0778a004a Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:39 +0900 Subject: perf tool: Add hpp interface to enable/disable hpp column Adding perf_hpp__column_enable function to enable/disable hists column and removing diff command specific stuff 'need_pair and show_displacement' from hpp code. The diff command now enables/disables columns separately according to the user arguments. This will be helpful in future patches where more columns are added into diff output. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-6-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-diff.c | 18 +++++++++++++++++- tools/perf/builtin-report.c | 2 +- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/gtk/browser.c | 2 +- tools/perf/ui/hist.c | 15 ++++++--------- tools/perf/ui/setup.c | 2 +- tools/perf/util/hist.h | 3 ++- 7 files changed, 29 insertions(+), 15 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 413c65a1ba3..a0b531c14b9 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -256,6 +256,21 @@ static const struct option options[] = { OPT_END() }; +static void ui_init(void) +{ + perf_hpp__init(); + + /* No overhead column. */ + perf_hpp__column_enable(PERF_HPP__OVERHEAD, false); + + /* Display baseline/delta/displacement columns. */ + perf_hpp__column_enable(PERF_HPP__BASELINE, true); + perf_hpp__column_enable(PERF_HPP__DELTA, true); + + if (show_displacement) + perf_hpp__column_enable(PERF_HPP__DISPL, true); +} + int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused) { sort_order = diff__default_sort_order; @@ -278,7 +293,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused) if (symbol__init() < 0) return -1; - perf_hpp__init(true, show_displacement); + ui_init(); + setup_sorting(diff_usage, options); setup_pager(); diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 95e7ea879b8..a61725d89d3 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -691,7 +691,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) setup_browser(true); else { use_browser = 0; - perf_hpp__init(false, false); + perf_hpp__init(); } setup_sorting(report_usage, options); diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index a21f40bebba..bbd11c2f69d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -584,7 +584,7 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us) void hist_browser__init_hpp(void) { - perf_hpp__init(false, false); + perf_hpp__init(); perf_hpp__format[PERF_HPP__OVERHEAD].color = hist_browser__hpp_color_overhead; diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 7ff99ec1d95..2bc08f6af71 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c @@ -73,7 +73,7 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us) void perf_gtk__init_hpp(void) { - perf_hpp__init(false, false); + perf_hpp__init(); perf_hpp__format[PERF_HPP__OVERHEAD].color = perf_gtk__hpp_color_overhead; diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 6b0138e5f33..e8853f7780a 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -302,7 +302,7 @@ struct perf_hpp_fmt perf_hpp__format[] = { #undef HPP__COLOR_PRINT_FNS #undef HPP__PRINT_FNS -void perf_hpp__init(bool need_pair, bool show_displacement) +void perf_hpp__init(void) { if (symbol_conf.show_cpu_utilization) { perf_hpp__format[PERF_HPP__OVERHEAD_SYS].cond = true; @@ -319,15 +319,12 @@ void perf_hpp__init(bool need_pair, bool show_displacement) if (symbol_conf.show_total_period) perf_hpp__format[PERF_HPP__PERIOD].cond = true; +} - if (need_pair) { - perf_hpp__format[PERF_HPP__OVERHEAD].cond = false; - perf_hpp__format[PERF_HPP__BASELINE].cond = true; - perf_hpp__format[PERF_HPP__DELTA].cond = true; - - if (show_displacement) - perf_hpp__format[PERF_HPP__DISPL].cond = true; - } +void perf_hpp__column_enable(unsigned col, bool enable) +{ + BUG_ON(col >= PERF_HPP__MAX_INDEX); + perf_hpp__format[col].cond = enable; } static inline void advance_hpp(struct perf_hpp *hpp, int inc) diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c index bd7d460f844..ebb4cc10787 100644 --- a/tools/perf/ui/setup.c +++ b/tools/perf/ui/setup.c @@ -30,7 +30,7 @@ void setup_browser(bool fallback_to_pager) if (fallback_to_pager) setup_pager(); - perf_hpp__init(false, false); + perf_hpp__init(); break; } } diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index b83a2268b5d..a7f69d69dc6 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -147,7 +147,8 @@ enum { PERF_HPP__MAX_INDEX }; -void perf_hpp__init(bool need_pair, bool show_displacement); +void perf_hpp__init(void); +void perf_hpp__column_enable(unsigned col, bool enable); int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, bool color); -- cgit v1.2.3-70-g09d2 From b5ff71c3bab10a7a4b321b5de072ac5bd73ef9a4 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:40 +0900 Subject: perf diff: Removing the total_period argument from output code The total_period is available in struct hists data via the 'struct hist_entry::hists' pointer. There's no need to carry it through the output code path. Removing 'struct perf_hpp::total_period' pointer, because it's no longer needed. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-7-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 4 ++-- tools/perf/ui/gtk/browser.c | 4 ++-- tools/perf/ui/hist.c | 37 ++++++++++++++++++++++++++----------- tools/perf/ui/stdio/hist.c | 15 +++++---------- tools/perf/util/hist.h | 1 - 5 files changed, 35 insertions(+), 26 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index bbd11c2f69d..d359795454d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -569,7 +569,8 @@ static int hist_browser__show_callchain(struct hist_browser *browser, static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - double percent = 100.0 * he->_field / hpp->total_period; \ + struct hists *hists = he->hists; \ + double percent = 100.0 * he->_field / hists->stats.total_period;\ *(double *)hpp->ptr = percent; \ return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \ } @@ -624,7 +625,6 @@ static int hist_browser__show_entry(struct hist_browser *browser, struct perf_hpp hpp = { .buf = s, .size = sizeof(s), - .total_period = browser->hists->stats.total_period, }; ui_browser__gotorc(&browser->b, row, 0); diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 2bc08f6af71..3cbb1d622ed 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c @@ -49,7 +49,8 @@ static const char *perf_gtk__get_percent_color(double percent) static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - double percent = 100.0 * he->_field / hpp->total_period; \ + struct hists *hists = he->hists; \ + double percent = 100.0 * he->_field / hists->stats.total_period; \ const char *markup; \ int ret = 0; \ \ @@ -102,7 +103,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) struct perf_hpp hpp = { .buf = s, .size = sizeof(s), - .total_period = hists->stats.total_period, }; nr_cols = 0; diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index e8853f7780a..7f043394bef 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -18,14 +18,16 @@ static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); } static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -45,13 +47,16 @@ static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_sys / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -71,13 +76,16 @@ static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_us / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -96,14 +104,17 @@ static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -122,14 +133,17 @@ static int hpp__width_overhead_guest_us(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_us / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -230,6 +244,7 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) { struct hist_entry *pair = he->pair; struct hists *pair_hists = pair ? pair->hists : NULL; + struct hists *hists = he->hists; u64 old_total, new_total; double old_percent = 0, new_percent = 0; double diff; @@ -240,7 +255,7 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) if (old_total > 0 && pair) old_percent = 100.0 * pair->period / old_total; - new_total = hpp->total_period; + new_total = hists->stats.total_period; if (new_total > 0) new_percent = 100.0 * he->period / new_total; diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 1340c93aa61..850c6d293f4 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -292,9 +292,10 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, static size_t hist_entry__callchain_fprintf(struct hist_entry *he, struct hists *hists, - u64 total_period, FILE *fp) + FILE *fp) { int left_margin = 0; + u64 total_period = hists->stats.total_period; if (sort__first_dimension == SORT_COMM) { struct sort_entry *se = list_first_entry(&hist_entry__sort_list, @@ -307,14 +308,13 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, } static int hist_entry__fprintf(struct hist_entry *he, size_t size, - struct hists *hists, u64 total_period, FILE *fp) + struct hists *hists, FILE *fp) { char bf[512]; int ret; struct perf_hpp hpp = { .buf = bf, .size = size, - .total_period = total_period, }; bool color = !symbol_conf.field_sep; @@ -327,8 +327,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ret = fprintf(fp, "%s\n", bf); if (symbol_conf.use_callchain) - ret += hist_entry__callchain_fprintf(he, hists, - total_period, fp); + ret += hist_entry__callchain_fprintf(he, hists, fp); return ret; } @@ -339,7 +338,6 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, struct sort_entry *se; struct rb_node *nd; size_t ret = 0; - u64 total_period; unsigned int width; const char *sep = symbol_conf.field_sep; const char *col_width = symbol_conf.col_width_list_str; @@ -441,16 +439,13 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, goto out; print_entries: - total_period = hists->stats.total_period; - for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); if (h->filtered) continue; - ret += hist_entry__fprintf(h, max_cols, hists, - total_period, fp); + ret += hist_entry__fprintf(h, max_cols, hists, fp); if (max_rows && ++nr_rows >= max_rows) goto out; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a7f69d69dc6..66cb31fe81d 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -117,7 +117,6 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *he); struct perf_hpp { char *buf; size_t size; - u64 total_period; const char *sep; void *ptr; }; -- cgit v1.2.3-70-g09d2 From b24c28f794e1821c1bba3ef7e9e948ab77ee00ac Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 4 Oct 2012 21:49:41 +0900 Subject: perf hists: Introduce struct he_stat The struct he_stat is for separating out statistics data of a hist entry. It is required for later changes. It's just a mechanical change and should have no functional differences. Signed-off-by: Namhyung Kim Cc: Arun Sharma Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-8-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 8 +++---- tools/perf/ui/gtk/browser.c | 2 +- tools/perf/ui/hist.c | 30 ++++++++++++------------ tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/hist.c | 52 +++++++++++++++++++++++------------------- tools/perf/util/sort.h | 16 ++++++++----- 6 files changed, 59 insertions(+), 51 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index d359795454d..0568536ecf6 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -570,7 +570,7 @@ static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ struct hists *hists = he->hists; \ - double percent = 100.0 * he->_field / hists->stats.total_period;\ + double percent = 100.0 * he->stat._field / hists->stats.total_period; \ *(double *)hpp->ptr = percent; \ return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \ } @@ -982,7 +982,7 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, folded_sign = hist_entry__folded(he); hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists); - percent = (he->period * 100.0) / browser->hists->stats.total_period; + percent = (he->stat.period * 100.0) / browser->hists->stats.total_period; if (symbol_conf.use_callchain) printed += fprintf(fp, "%c ", folded_sign); @@ -990,10 +990,10 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, printed += fprintf(fp, " %5.2f%%", percent); if (symbol_conf.show_nr_samples) - printed += fprintf(fp, " %11u", he->nr_events); + printed += fprintf(fp, " %11u", he->stat.nr_events); if (symbol_conf.show_total_period) - printed += fprintf(fp, " %12" PRIu64, he->period); + printed += fprintf(fp, " %12" PRIu64, he->stat.period); printed += fprintf(fp, "%s\n", rtrim(s)); diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 3cbb1d622ed..4125c628411 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c @@ -50,7 +50,7 @@ static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ struct hists *hists = he->hists; \ - double percent = 100.0 * he->_field / hists->stats.total_period; \ + double percent = 100.0 * he->stat._field / hists->stats.total_period; \ const char *markup; \ int ret = 0; \ \ diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 7f043394bef..f5a1e4f6526 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -19,7 +19,7 @@ static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period / hists->stats.total_period; + double percent = 100.0 * he->stat.period / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); } @@ -27,7 +27,7 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period / hists->stats.total_period; + double percent = 100.0 * he->stat.period / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -48,7 +48,7 @@ static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_sys / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } @@ -56,7 +56,7 @@ static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -77,7 +77,7 @@ static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_us / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } @@ -85,7 +85,7 @@ static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -105,7 +105,7 @@ static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } @@ -114,7 +114,7 @@ static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -134,7 +134,7 @@ static int hpp__color_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } @@ -143,7 +143,7 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -167,7 +167,7 @@ static double baseline_percent(struct hist_entry *he) if (pair) { u64 total_period = pair_hists->stats.total_period; - u64 base_period = pair->period; + u64 base_period = pair->stat.period; percent = 100.0 * base_period / total_period; } @@ -206,7 +206,7 @@ static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he) { const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64; - return scnprintf(hpp->buf, hpp->size, fmt, he->nr_events); + return scnprintf(hpp->buf, hpp->size, fmt, he->stat.nr_events); } static int hpp__header_period(struct perf_hpp *hpp) @@ -225,7 +225,7 @@ static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he) { const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64; - return scnprintf(hpp->buf, hpp->size, fmt, he->period); + return scnprintf(hpp->buf, hpp->size, fmt, he->stat.period); } static int hpp__header_delta(struct perf_hpp *hpp) @@ -253,11 +253,11 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) old_total = pair_hists ? pair_hists->stats.total_period : 0; if (old_total > 0 && pair) - old_percent = 100.0 * pair->period / old_total; + old_percent = 100.0 * pair->stat.period / old_total; new_total = hists->stats.total_period; if (new_total > 0) - new_percent = 100.0 * he->period / new_total; + new_percent = 100.0 * he->stat.period / new_total; diff = new_percent - old_percent; if (fabs(diff) >= 0.01) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 850c6d293f4..fbd4e32d074 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -271,7 +271,7 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, { switch (callchain_param.mode) { case CHAIN_GRAPH_REL: - return callchain__fprintf_graph(fp, &he->sorted_chain, he->period, + return callchain__fprintf_graph(fp, &he->sorted_chain, he->stat.period, left_margin); break; case CHAIN_GRAPH_ABS: diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 040f34c79a5..3197f3f5001 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -135,16 +135,16 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he, { switch (cpumode) { case PERF_RECORD_MISC_KERNEL: - he->period_sys += period; + he->stat.period_sys += period; break; case PERF_RECORD_MISC_USER: - he->period_us += period; + he->stat.period_us += period; break; case PERF_RECORD_MISC_GUEST_KERNEL: - he->period_guest_sys += period; + he->stat.period_guest_sys += period; break; case PERF_RECORD_MISC_GUEST_USER: - he->period_guest_us += period; + he->stat.period_guest_us += period; break; default: break; @@ -153,13 +153,13 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he, static void hist_entry__decay(struct hist_entry *he) { - he->period = (he->period * 7) / 8; - he->nr_events = (he->nr_events * 7) / 8; + he->stat.period = (he->stat.period * 7) / 8; + he->stat.nr_events = (he->stat.nr_events * 7) / 8; } static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) { - u64 prev_period = he->period; + u64 prev_period = he->stat.period; if (prev_period == 0) return true; @@ -167,9 +167,9 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) hist_entry__decay(he); if (!he->filtered) - hists->stats.total_period -= prev_period - he->period; + hists->stats.total_period -= prev_period - he->stat.period; - return he->period == 0; + return he->stat.period == 0; } static void __hists__decay_entries(struct hists *hists, bool zap_user, @@ -223,7 +223,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) if (he != NULL) { *he = *template; - he->nr_events = 1; + he->stat.nr_events = 1; if (he->ms.map) he->ms.map->referenced = true; if (symbol_conf.use_callchain) @@ -238,7 +238,7 @@ static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) if (!h->filtered) { hists__calc_col_len(hists, h); ++hists->nr_entries; - hists->stats.total_period += h->period; + hists->stats.total_period += h->stat.period; } } @@ -270,8 +270,8 @@ static struct hist_entry *add_hist_entry(struct hists *hists, cmp = hist_entry__cmp(entry, he); if (!cmp) { - he->period += period; - ++he->nr_events; + he->stat.period += period; + ++he->stat.nr_events; /* If the map of an existing hist_entry has * become out-of-date due to an exec() or @@ -321,7 +321,9 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self, .cpu = al->cpu, .ip = bi->to.addr, .level = al->level, - .period = period, + .stat = { + .period = period, + }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), .branch_info = bi, @@ -344,7 +346,9 @@ struct hist_entry *__hists__add_entry(struct hists *self, .cpu = al->cpu, .ip = al->addr, .level = al->level, - .period = period, + .stat = { + .period = period, + }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), .hists = self, @@ -412,12 +416,12 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, cmp = hist_entry__collapse(iter, he); if (!cmp) { - iter->period += he->period; - iter->period_sys += he->period_sys; - iter->period_us += he->period_us; - iter->period_guest_sys += he->period_guest_sys; - iter->period_guest_us += he->period_guest_us; - iter->nr_events += he->nr_events; + iter->stat.period += he->stat.period; + iter->stat.period_sys += he->stat.period_sys; + iter->stat.period_us += he->stat.period_us; + iter->stat.period_guest_sys += he->stat.period_guest_sys; + iter->stat.period_guest_us += he->stat.period_guest_us; + iter->stat.nr_events += he->stat.nr_events; if (symbol_conf.use_callchain) { callchain_cursor_reset(&callchain_cursor); @@ -520,7 +524,7 @@ static void __hists__insert_output_entry(struct rb_root *entries, parent = *p; iter = rb_entry(parent, struct hist_entry, rb_node); - if (he->period > iter->period) + if (he->stat.period > iter->stat.period) p = &(*p)->rb_left; else p = &(*p)->rb_right; @@ -581,8 +585,8 @@ static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h if (h->ms.unfolded) hists->nr_entries += h->nr_rows; h->row_offset = 0; - hists->stats.total_period += h->period; - hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; + hists->stats.total_period += h->stat.period; + hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events; hists__calc_col_len(hists, h); } diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index f070b523c81..5786f323b59 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -43,6 +43,15 @@ extern struct sort_entry sort_sym_from; extern struct sort_entry sort_sym_to; extern enum sort_type sort__first_dimension; +struct he_stat { + u64 period; + u64 period_sys; + u64 period_us; + u64 period_guest_sys; + u64 period_guest_us; + u32 nr_events; +}; + /** * struct hist_entry - histogram entry * @@ -52,16 +61,11 @@ extern enum sort_type sort__first_dimension; struct hist_entry { struct rb_node rb_node_in; struct rb_node rb_node; - u64 period; - u64 period_sys; - u64 period_us; - u64 period_guest_sys; - u64 period_guest_us; + struct he_stat stat; struct map_symbol ms; struct thread *thread; u64 ip; s32 cpu; - u32 nr_events; /* XXX These two should move to some tree widget lib */ u16 row_offset; -- cgit v1.2.3-70-g09d2 From c4b35351ef3145c9abad64999d1de0de1b8361ab Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 4 Oct 2012 21:49:42 +0900 Subject: perf hists: Move he->stat.nr_events initialization to a template Since it is set to 1 for a new hist entry, no need to set to separately. Move it to a template entry. Signed-off-by: Namhyung Kim Cc: Arun Sharma Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-9-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/hist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 3197f3f5001..02476cb3167 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -223,7 +223,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) if (he != NULL) { *he = *template; - he->stat.nr_events = 1; + if (he->ms.map) he->ms.map->referenced = true; if (symbol_conf.use_callchain) @@ -323,6 +323,7 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self, .level = al->level, .stat = { .period = period, + .nr_events = 1, }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), @@ -348,6 +349,7 @@ struct hist_entry *__hists__add_entry(struct hists *self, .level = al->level, .stat = { .period = period, + .nr_events = 1, }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), -- cgit v1.2.3-70-g09d2 From 139c0815903de1a7865fe1d6beac5e995fefdf46 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 4 Oct 2012 21:49:43 +0900 Subject: perf hists: Add more helpers for hist entry stat Add and use he_stat__add_{period,stat} for calculating hist entry's stat. It will be used for accumulated stats later as well. Signed-off-by: Namhyung Kim Cc: Arun Sharma Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-10-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/hist.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tools/perf/util') diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 02476cb3167..277947a669b 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -151,6 +151,22 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he, } } +static void he_stat__add_period(struct he_stat *he_stat, u64 period) +{ + he_stat->period += period; + he_stat->nr_events += 1; +} + +static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src) +{ + dest->period += src->period; + dest->period_sys += src->period_sys; + dest->period_us += src->period_us; + dest->period_guest_sys += src->period_guest_sys; + dest->period_guest_us += src->period_guest_us; + dest->nr_events += src->nr_events; +} + static void hist_entry__decay(struct hist_entry *he) { he->stat.period = (he->stat.period * 7) / 8; @@ -270,8 +286,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists, cmp = hist_entry__cmp(entry, he); if (!cmp) { - he->stat.period += period; - ++he->stat.nr_events; + he_stat__add_period(&he->stat, period); /* If the map of an existing hist_entry has * become out-of-date due to an exec() or @@ -418,12 +433,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, cmp = hist_entry__collapse(iter, he); if (!cmp) { - iter->stat.period += he->stat.period; - iter->stat.period_sys += he->stat.period_sys; - iter->stat.period_us += he->stat.period_us; - iter->stat.period_guest_sys += he->stat.period_guest_sys; - iter->stat.period_guest_us += he->stat.period_guest_us; - iter->stat.nr_events += he->stat.nr_events; + he_stat__add_stat(&iter->stat, &he->stat); if (symbol_conf.use_callchain) { callchain_cursor_reset(&callchain_cursor); -- cgit v1.2.3-70-g09d2