perf/core improvements and fixes
From: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit 0fbdad078a70ed72248c3d30fe32e45e83be00d1:
perf/x86: Allow for architecture specific RDPMC indexes (2013-02-06 19:45:24 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux tags/perf-core-for-mingo
for you to fetch changes up to 88fd2b6a76264e9e14463f532caae09d82a53207:
perf python: Link with sysfs.o (2013-02-06 18:09:28 -0300)
----------------------------------------------------------------
perf/core improvements and fixes
. Check for flex and bison before continuing building, from Borislav Petkov.
. Make event_copy local to mmaps, fixing buffer wrap around problems, from
David Ahern.
. Add option for runtime switching perf data file in perf report, just press
's' and a menu with the valid files found in the current directory will be presented, from Feng Tang.
. Add support to display whole group data for raw columns, from Jiri Olsa.
. Fix SIGALRM and pipe read race for the rwtop perl script. from Jiri Olsa.
. Fix perf_evsel::exclude_GH handling and add a test to catch regressions, from
Jiri Olsa.
. Error checking fixes, from Namhyung Kim.
. Fix calloc argument ordering, from Paul Gortmaker.
. Fix set event list leader, from Stephane Eranian.
. Add per processor socket count aggregation in perf stat, from Stephane Eranian.
. Fix perf python binding breakage.
----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf evlist: Pass the event_group info via perf_attr_details perf python: Link with sysfs.o
Borislav Petkov (1):
perf tools: Check for flex and bison before continuing building
David Ahern (1):
perf evlist: Make event_copy local to mmaps
Feng Tang (2):
perf hists browser: Add option for runtime switching perf data file perf report: Enable the runtime switching of perf data file
Jiri Olsa (4):
perf hists browser: Add support to display whole group data for raw columns perf perl scripts: Fix SIGALRM and pipe read race for rwtop perf tools: Fix perf_evsel::exclude_GH handling
perf tests: Adding automated parsing tests for group :GH modifiers
Namhyung Kim (3):
perf sort: Drop ip_[lr] arguments from _sort__sym_cmp() perf sort: Make setup_sorting returns an error code perf sort: Check return value of strdup()
Paul Gortmaker (1):
perf tools: Fix calloc argument ordering
Stephane Eranian (3):
perf evlist: Fix set event list leader
perf tools: Add cpu_map processor socket level functions perf stat: Add per processor socket count aggregation
tools/perf/Documentation/perf-stat.txt | 9 +- tools/perf/Makefile | 13 ++- tools/perf/builtin-annotate.c | 3 +- tools/perf/builtin-diff.c | 4 +- tools/perf/builtin-evlist.c | 4 +- tools/perf/builtin-report.c | 41 +++++--- tools/perf/builtin-stat.c | 126 +++++++++++++++++++++-- tools/perf/builtin-top.c | 3 +- tools/perf/perf.h | 26 ----- tools/perf/scripts/perl/rwtop.pl | 6 +- tools/perf/tests/hists_link.c | 3 +- tools/perf/tests/parse-events.c | 178 ++++++++++++++++++++++++++++++++- tools/perf/ui/browsers/hists.c | 112 ++++++++++++++++++++- tools/perf/ui/hist.c | 53 +++++----- tools/perf/ui/keysyms.h | 1 + tools/perf/util/callchain.c | 2 +- tools/perf/util/cpumap.c | 54 ++++++++++ tools/perf/util/cpumap.h | 9 ++ tools/perf/util/evlist.c | 7 +- tools/perf/util/evlist.h | 29 +++++- tools/perf/util/evsel.c | 2 +- tools/perf/util/evsel.h | 1 + tools/perf/util/header.c | 4 +- tools/perf/util/parse-events.c | 8 -- tools/perf/util/python-ext-sources | 1 + tools/perf/util/sort.c | 38 ++++--- tools/perf/util/sort.h | 2 +- 27 files changed, 611 insertions(+), 128 deletions(-)
PATCH 1/17 perf hists browser: Add option for runtime switching perf data file
From: Feng Tang <[email protected]>
Based on perf report/top/scripts browser integration idea from acme.
This will enable user to runtime switch the data file, when this option is selected, it will popup all the legal data files in current working directory, and the filename selected by user is saved in the global variable "input_name", and a new key 'K_SWITCH_INPUT_DATA' will be passed back to the built-in command which will perform the switch.
This initial version only enables it for 'perf report'.
v2: rebase to latest 'perf/core' branch (6e1d4dd) of acme's perf tree
--- tools/perf/ui/browsers/hists.c | 112 ++++++++++++++++++++++++++++++++++++++++- tools/perf/ui/keysyms.h | 1 + 2 files changed, 112 insertions(+), 1 deletion(-)
tools/perf/ui/browsers/hists.c +111 -1
@@ -1241,6 +1241,96 @@ static inline bool is_report_browser(void *timer)return timer ==NULL ; } +/* +* Only runtime switching of perf data file will make "input_name" point +* to a malloced buffer. So add "is_input_name_malloced" flag to decide +* whether we need to call free() for current "input_name" during the switch. +*/ +static bool is_input_name_malloced = false; + +static int switch_data_file (void ) +{ +char *pwd, *options[32 ], *abs_path[32 ], *tmp; +DIR *pwd_dir; +int nr_options =0 , choice =-1 , ret =-1 ; +struct dirent *dent; + + pwd =getenv ("PWD" ); +if (!pwd) +return ret; + + pwd_dir =opendir (pwd); +if (!pwd_dir) +return ret; + +memset (options,0 ,sizeof (options)); +memset (options,0 ,sizeof (abs_path)); + +while ((dent =readdir (pwd_dir))) { +char path[PATH_MAX ]; +u64 magic; +char *name = dent->d_name; +FILE *file; + +if (!(dent->d_type ==DT_REG )) +continue ; + +snprintf (path,sizeof (path),"%s/%s" , pwd, name); + + file =fopen (path,"r" ); +if (!file) +continue ; + +if (fread (&magic,1 ,8 , file) <8 ) + goto close_file_and_continue; + +if (is_perf_magic (magic)) { + options[nr_options] =strdup (name); +if (!options[nr_options]) + goto close_file_and_continue; + + abs_path[nr_options] =strdup (path); +if (!abs_path[nr_options]) { +free (options[nr_options]); +ui__warning ("Can't search all data files due to memory shortage.\n" ); +fclose (file); +break ; + } + + nr_options++; + } + +close_file_and_continue: +fclose (file); +if (nr_options >=32 ) { +ui__warning ("Too many perf data files in PWD!\n" +"Only the first 32 files will be listed.\n" ); +break ; + } + } +closedir (pwd_dir); + +if (nr_options) { + choice =ui__popup_menu (nr_options, options); +if (choice < nr_options && choice >=0 ) { + tmp =strdup (abs_path[choice]); +if (tmp) { +if (is_input_name_malloced) +free ((void *)input_name); + input_name = tmp; + is_input_name_malloced = true; + ret =0 ; + }else +ui__warning ("Data switch failed due to memory shortage!\n" ); + } + } + +free_popup_options (options, nr_options); +free_popup_options (abs_path, nr_options); +return ret; +} + + static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, const char *helpline, const char *ev_name, bool left_exits,
@@ -1275,7 +1365,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,int choice =0 , annotate =-2 , zoom_dso =-2 , zoom_thread =-2 , annotate_f =-2 , annotate_t =-2 , browse_map =-2 ; -int scripts_comm =-2 , scripts_symbol =-2 , scripts_all =-2 ; +int scripts_comm =-2 , scripts_symbol =-2 , + scripts_all =-2 , switch_data =-2 ; nr_options =0 ;
@@ -1332,6 +1423,10 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,if (is_report_browser (hbt)) goto do_scripts;continue ; +case 's' : +if (is_report_browser (hbt)) + goto do_data_switch; +continue ;case K_F1 :case 'h' :case '?' :
@@ -1351,6 +1446,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,"d Zoom into current DSO\n" "t Zoom into current Thread\n" "r Run available scripts('perf report' only)\n" +"s Switch to another data file in PWD ('perf report' only)\n" "P Print histograms to perf.hist.N\n" "V Verbose (DSO names in callchains, etc)\n" "/ Filter symbol by name");
@@ -1458,6 +1554,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,if (asprintf (&options[nr_options],"Run scripts for all samples" ) >0 ) scripts_all = nr_options++; +if (is_report_browser (hbt) &&asprintf (&options[nr_options], +"Switch to another data file in PWD" ) >0 ) + switch_data = nr_options++; add_exit_option: options[nr_options++] = (char *)"Exit" ; retry_popup_menu:
@@ -1568,6 +1667,16 @@ do_scripts:script_browse (script_opt); } +/* Switch to another data file */ +else if (choice == switch_data) { +do_data_switch: +if (!switch_data_file ()) { + key =K_SWITCH_INPUT_DATA ; +break ; + }else +ui__warning ("Won't switch the data files due to\n" +"no valid data file get selected!\n" ); + } } out_free_stack:pstack__delete (fstack);
@@ -1694,6 +1803,7 @@ browse_hists: "Do you really want to exit?"))continue ;/* Fall thru */ +case K_SWITCH_INPUT_DATA :case 'q' :case CTRL ('c' ): goto out;
tools/perf/ui/keysyms.h +1 -0
@@ -23,5 +23,6 @@#define K_TIMER -1#define K_ERROR -2#define K_RESIZE -3 +#define K_SWITCH_INPUT_DATA -4#endif /* _PERF_KEYSYMS_H_ */
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 2/17 perf report: Enable the runtime switching of perf data file
In reply to Arnaldo Carvalho de MeloFrom: Feng Tang <[email protected]>
This is for tui browser only. This patch will check the returned key of tui hists browser, if it's K_SWITH_INPUT_DATA, then recreate a session for the new selected data file.
V2: Move the setup_brower() before the "repeat" jump point.
--- tools/perf/builtin-report.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
tools/perf/builtin-report.c +27 -11
@@ -468,9 +468,17 @@ static int __cmd_report(struct perf_report *rep)if (use_browser >0 ) {if (use_browser ==1 ) { -perf_evlist__tui_browse_hists (session->evlist, help, -NULL , - &session->header.env); + ret =perf_evlist__tui_browse_hists (session->evlist, + help, +NULL , + &session->header.env); +/* +* Usually "ret" is the last pressed key, and we only +* care if the key notifies us to switch data file. +*/ +if (ret !=K_SWITCH_INPUT_DATA ) + ret =0 ; + }else if (use_browser ==2 ) {perf_evlist__gtk_browse_hists (session->evlist, help,NULL );
@@ -708,6 +716,16 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)else input_name ="perf.data" ; } + +if (strcmp (input_name,"-" ) !=0 ) +setup_browser (true); +else { + use_browser =0 ; +perf_hpp__column_enable (PERF_HPP__OVERHEAD ); +perf_hpp__init (); + } + +repeat: session =perf_session__new (input_name,O_RDONLY , report.force, false, &report.tool);if (session ==NULL )
@@ -733,14 +751,6 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) } -if (strcmp (input_name,"-" ) !=0 ) -setup_browser (true); -else { - use_browser =0 ; -perf_hpp__column_enable (PERF_HPP__OVERHEAD ); -perf_hpp__init (); - } -setup_sorting (report_usage, options);/*
@@ -809,6 +819,12 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) } ret =__cmd_report (&report); +if (ret ==K_SWITCH_INPUT_DATA ) { +perf_session__delete (session); + goto repeat; + }else + ret =0 ; + error:perf_session__delete (session);return ret;
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 3/17 perf evlist: Fix set event list leader
In reply to Arnaldo Carvalho de MeloFrom: Stephane Eranian <[email protected]>
The __perf_evlist__set_leader() was setting the leader for all events in the list except the first. Which means it assumed the first event already had event->leader = event.
Seems like this should be the role of the function to also do this. This is a requirement for an upcoming patch set.
--- tools/perf/util/evlist.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/evlist.c +1 -2
@@ -122,8 +122,7 @@ void __perf_evlist__set_leader(struct list_head *list) leader->nr_members = evsel->idx - leader->idx +1 ;list_for_each_entry (evsel, list, node) { -if (evsel != leader) - evsel->leader = leader; + evsel->leader = leader; } }
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 4/17 perf tools: Check for flex and bison before continuing building
In reply to Arnaldo Carvalho de MeloFrom: Borislav Petkov <[email protected]>
Check whether both executables are present on the system before continuing with the build instead of failing halfway, if either are missing.
--- tools/perf/Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tools/perf/Makefile +10 -3
@@ -149,6 +149,8 @@ RM = rm -f MKDIR = mkdir FIND = find INSTALL = install +FLEX = flex +BISON= bison # sparse is architecture-neutral, which means that we need to tell it # explicitly what architecture to check for. Fix this up for yours..
@@ -158,6 +160,14 @@ ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),tags) -include config/feature-tests.mak +ifeq ($(call get-executable,$(FLEX)),) + dummy := $(error Error: $(FLEX) is missing on this system, please install it) +endif + +ifeq ($(call get-executable,$(BISON)),) + dummy := $(error Error: $(BISON) is missing on this system, please install it) +endif + ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y) CFLAGS := $(CFLAGS) -fstack-protector-all endif
@@ -282,9 +292,6 @@ endif export PERL_PATH -FLEX = flex -BISON= bison - $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c $(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/parse-events-flex.h $(PARSER_DEBUG_FLEX) -t util/parse-events.l > $(OUTPUT)util/parse-events-flex.c
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 5/17 perf sort: Drop ip_[lr] arguments from _sort__sym_cmp()
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Current _sort__sym_cmp() function is used for comparing symbols between two hist entries on symbol, symbol_from and symbol_to sort keys. Those functions pass addresses of symbols but it's meaningless since it gets over-written inside of the _sort__sym_cmp function to a start address of the symbol. So just get rid of them.
This might cause a difference than prior output for branch stacks since it seems not using start address of the symbol but branch address. However AFAICS it'd be same as it gets overwritten anyway.
Also remove redundant part of code in sort__sym_cmp().
--- tools/perf/util/sort.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
tools/perf/util/sort.c +6 -17
@@ -160,9 +160,10 @@ struct sort_entry sort_dso = {/* --sort symbol */ -static int64_t _sort__sym_cmp (struct symbol *sym_l,struct symbol *sym_r, -u64 ip_l,u64 ip_r) +static int64_t _sort__sym_cmp (struct symbol *sym_l,struct symbol *sym_r) { +u64 ip_l, ip_r; +if (!sym_l || !sym_r)return cmp_null (sym_l, sym_r);
@@ -178,21 +179,10 @@ static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r,static int64_t sort__sym_cmp (struct hist_entry *left,struct hist_entry *right) { -u64 ip_l, ip_r; -if (!left->ms.sym && !right->ms.sym)return right->level - left->level; -if (!left->ms.sym || !right->ms.sym) -return cmp_null (left->ms.sym, right->ms.sym); - -if (left->ms.sym == right->ms.sym) -return 0 ; - - ip_l = left->ms.sym->start; - ip_r = right->ms.sym->start; - -return _sort__sym_cmp (left->ms.sym, right->ms.sym, ip_l, ip_r); +return _sort__sym_cmp (left->ms.sym, right->ms.sym); } static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
@@ -383,8 +373,7 @@ sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right)if (!from_l->sym && !from_r->sym)return right->level - left->level; -return _sort__sym_cmp (from_l->sym, from_r->sym, from_l->addr, - from_r->addr); +return _sort__sym_cmp (from_l->sym, from_r->sym); } static int64_t
@@ -396,7 +385,7 @@ sort__sym_to_cmp(struct hist_entry *left, struct hist_entry *right)if (!to_l->sym && !to_r->sym)return right->level - left->level; -return _sort__sym_cmp (to_l->sym, to_r->sym, to_l->addr, to_r->addr); +return _sort__sym_cmp (to_l->sym, to_r->sym); } static int hist_entry__sym_from_snprintf(struct hist_entry *self, char *bf,
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 6/17 perf sort: Make setup_sorting returns an error code
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Currently the setup_sorting() is called for parsing sort keys and exits if it failed to add the sort key. As it's included in libperf it'd be better returning an error code rather than exiting application inside of the library.
--- tools/perf/builtin-annotate.c | 3 ++- tools/perf/builtin-diff.c | 4 +++- tools/perf/builtin-report.c | 3 ++- tools/perf/builtin-top.c | 3 ++- tools/perf/tests/hists_link.c | 3 ++- tools/perf/util/sort.c | 10 ++++++---- tools/perf/util/sort.h | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-)
tools/perf/builtin-annotate.c +2 -1
@@ -309,7 +309,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)if (symbol__init () <0 )return -1 ; -setup_sorting (annotate_usage, options); +if (setup_sorting () <0 ) +usage_with_options (annotate_usage, options);if (argc) {/*
tools/perf/builtin-diff.c +3 -1
@@ -605,7 +605,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)ui_init (); -setup_sorting (diff_usage, options); +if (setup_sorting () <0 ) +usage_with_options (diff_usage, options); +setup_pager ();sort_entry__setup_elide (&sort_dso, symbol_conf.dso_list,"dso" ,NULL );
tools/perf/builtin-report.c +2 -1
@@ -751,7 +751,8 @@ repeat: } -setup_sorting (report_usage, options); +if (setup_sorting () <0 ) +usage_with_options (report_usage, options);/* * Only in the newt browser we are doing integrated annotation,
tools/perf/builtin-top.c +2 -1
@@ -1129,7 +1129,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)if (sort_order == default_sort_order) sort_order ="dso,symbol" ; -setup_sorting (top_usage, options); +if (setup_sorting () <0 ) +usage_with_options (top_usage, options);if (top.use_stdio) use_browser =0 ;
tools/perf/tests/hists_link.c +2 -1
@@ -449,7 +449,8 @@ int test__hists_link(void) goto out;/* default sort order (comm,dso,sym) will be used */ -setup_sorting (NULL ,NULL ); +if (setup_sorting () <0 ) + goto out;machines__init (&machines);
tools/perf/util/sort.c +6 -4
@@ -565,23 +565,25 @@ int sort_dimension__add(const char *tok)return -ESRCH ; } -void setup_sorting (const char *const usagestr[],const struct option *opts) +int setup_sorting (void ) {char *tmp, *tok, *str =strdup (sort_order); +int ret =0 ;for (tok =strtok_r (str,", " , &tmp); tok; tok =strtok_r (NULL ,", " , &tmp)) { -int ret =sort_dimension__add (tok); + ret =sort_dimension__add (tok);if (ret == -EINVAL ) {error ("Invalid --sort key: `%s'" , tok); -usage_with_options (usagestr, opts); +break ; }else if (ret == -ESRCH ) {error ("Unknown --sort key: `%s'" , tok); -usage_with_options (usagestr, opts); +break ; } }free (str); +return ret; } void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
tools/perf/util/sort.h +1 -1
@@ -160,7 +160,7 @@ struct sort_entry {extern struct sort_entry sort_thread;extern struct list_head hist_entry__sort_list; -void setup_sorting (const char *const usagestr[],const struct option *opts); +int setup_sorting (void );extern int sort_dimension__add (const char *);void sort_entry__setup_elide (struct sort_entry *self,struct strlist *list,const char *list_name,FILE *fp);
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 7/17 perf sort: Check return value of strdup()
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
When setup_sorting() is called, 'str' is passed to strtok_r() but it's not checked to have a valid pointer. As strtok_r() accepts NULL pointer on a first argument and use the third argument in that case, it can cause a trouble since our third argument, tmp, is not initialized.
--- tools/perf/util/sort.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/util/sort.c +5 -0
@@ -570,6 +570,11 @@ int setup_sorting(void)char *tmp, *tok, *str =strdup (sort_order);int ret =0 ; +if (str ==NULL ) { +error ("Not enough memory to setup sort keys" ); +return -ENOMEM ; + } +for (tok =strtok_r (str,", " , &tmp); tok; tok =strtok_r (NULL ,", " , &tmp)) { ret =sort_dimension__add (tok);
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 8/17 perf evlist: Make event_copy local to mmaps
In reply to Arnaldo Carvalho de MeloFrom: David Ahern <[email protected]>
I am getting segfaults *after* the time sorting of perf samples where the event type is off the charts:
(gdb) bt
\#0 0x0807b1b2 in hists__inc_nr_events (hists=0x80a99c4, type=1163281902) at util/hist.c:1225
\#1 0x08070795 in perf_session_deliver_event (session=0x80a9b90, event=0xf7a6aff8, sample=0xffffc318, tool=0xffffc520,
file_offset=0) at util/session.c:884
\#2 0x0806f9b9 in flush_sample_queue (s=0x80a9b90, tool=0xffffc520) at util/session.c:555 \#3 0x0806fc53 in process_finished_round (tool=0xffffc520, event=0x0, session=0x80a9b90) at util/session.c:645
This is bizarre because the event has already been processed once -- before it was added to the samples queue -- and the event was found to be sane at that time.
There seem to be 2 causes:
1. perf_evlist__mmap_read updates the read location even though there are outstanding references to events sitting in the mmap buffers via the ordered samples queue.
2. There is a single evlist->event_copy for all evlist entries. event_copy is used to handle an event wrapping at the mmap buffer boundary.
This patch addresses the second problem - making event_copy local to each perf_mmap. With this change my highly repeatable use case no longer fails.
The first problem is much more complicated and will be the subject of a future patch.
--- tools/perf/perf.h | 26 -------------------------- tools/perf/util/evlist.c | 4 ++-- tools/perf/util/evlist.h | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 29 deletions(-)
tools/perf/perf.h +0 -26
@@ -103,32 +103,6 @@#include "util/types.h" #include <stdbool.h> -struct perf_mmap { -void *base; -int mask; -unsigned int prev; -}; - -static inline unsigned int perf_mmap__read_head (struct perf_mmap *mm) -{ -struct perf_event_mmap_page *pc = mm->base; -int head = pc->data_head; -rmb (); -return head; -} - -static inline void perf_mmap__write_tail (struct perf_mmap *md, -unsigned long tail) -{ -struct perf_event_mmap_page *pc = md->base; - -/* -* ensure all reads are done before we write the tail out. -*/ -/* mb(); */ - pc->data_tail = tail; -} -/* * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all * counters in the current task.
tools/perf/util/evlist.c +2 -2
@@ -375,7 +375,7 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)if ((old & md->mask) + size != ((old + size) & md->mask)) {unsigned int offset = old;unsigned int len =min (sizeof (*event), size), cpy; -void *dst = &evlist->event_copy; +void *dst = &md->event_copy; do { cpy = min(md->mask + 1 - (offset & md->mask), len);
@@ -385,7 +385,7 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx) len -= cpy; }while (len); - event = &evlist->event_copy; + event = &md->event_copy; } old += size;
tools/perf/util/evlist.h +28 -1
@@ -17,6 +17,13 @@ struct perf_record_opts;#define PERF_EVLIST__HLIST_BITS 8#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS) +struct perf_mmap { +void *base; +int mask; +unsigned int prev; +union perf_event event_copy; +}; +struct perf_evlist {struct list_head entries;struct hlist_head heads[PERF_EVLIST__HLIST_SIZE ];
@@ -30,7 +37,6 @@ struct perf_evlist {pid_t pid; } workload;bool overwrite; -union perf_event event_copy;struct perf_mmap *mmap;struct pollfd *pollfd;struct thread_map *threads;
@@ -136,4 +142,25 @@ static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist) }size_t perf_evlist__fprintf (struct perf_evlist *evlist,FILE *fp); + +static inline unsigned int perf_mmap__read_head (struct perf_mmap *mm) +{ +struct perf_event_mmap_page *pc = mm->base; +int head = pc->data_head; +rmb (); +return head; +} + +static inline void perf_mmap__write_tail (struct perf_mmap *md, +unsigned long tail) +{ +struct perf_event_mmap_page *pc = md->base; + +/* +* ensure all reads are done before we write the tail out. +*/ +/* mb(); */ + pc->data_tail = tail; +} +#endif /* __PERF_EVLIST_H */
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 9/17 perf tools: Add cpu_map processor socket level functions
In reply to Arnaldo Carvalho de MeloFrom: Stephane Eranian <[email protected]>
This patch adds:
- cpu_map__get_socket: get socked id from cpu
- cpu_map__build_socket_map: build socket map
- cpu_map__socket: gets acutal socket from logical socket
Those functions are used by uncore and processor socket-level aggregation modes.
--- tools/perf/util/cpumap.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/cpumap.h | 9 ++++++++ 2 files changed, 63 insertions(+)
tools/perf/util/cpumap.c +54 -0
@@ -1,4 +1,5 @@#include "util.h" +#include "sysfs.h" #include "../perf.h" #include "cpumap.h" #include <assert.h>
@@ -201,3 +202,56 @@ void cpu_map__delete(struct cpu_map *map) {free (map); } + +int cpu_map__get_socket (struct cpu_map *map,int idx) +{ +FILE *fp; +const char *mnt; +char path[PATH_MAX ]; +int cpu, ret; + +if (idx > map->nr) +return -1 ; + + cpu = map->map[idx]; + + mnt =sysfs_find_mountpoint (); +if (!mnt) +return -1 ; + +sprintf (path, +"%s/devices/system/cpu/cpu%d/topology/physical_package_id" , + mnt, cpu); + + fp =fopen (path,"r" ); +if (!fp) +return -1 ; + ret =fscanf (fp,"%d" , &cpu); +fclose (fp); +return ret ==1 ? cpu :-1 ; +} + +int cpu_map__build_socket_map (struct cpu_map *cpus,struct cpu_map **sockp) +{ +struct cpu_map *sock; +int nr = cpus->nr; +int cpu, s1, s2; + + sock =calloc (1 ,sizeof (*sock) + nr *sizeof (int )); +if (!sock) +return -1 ; + +for (cpu =0 ; cpu < nr; cpu++) { + s1 =cpu_map__get_socket (cpus, cpu); +for (s2 =0 ; s2 < sock->nr; s2++) { +if (s1 == sock->map[s2]) +break ; + } +if (s2 == sock->nr) { + sock->map[sock->nr] = s1; + sock->nr++; + } + } + *sockp = sock; +return 0 ; +}
tools/perf/util/cpumap.h +9 -0
@@ -14,6 +14,15 @@ struct cpu_map *cpu_map__dummy_new(void);void cpu_map__delete (struct cpu_map *map);struct cpu_map *cpu_map__read (FILE *file);size_t cpu_map__fprintf (struct cpu_map *map,FILE *fp); +int cpu_map__get_socket (struct cpu_map *map,int idx); +int cpu_map__build_socket_map (struct cpu_map *cpus,struct cpu_map **sockp); + +static inline int cpu_map__socket (struct cpu_map *sock,int s) +{ +if (!sock || s > sock->nr || s <0 ) +return 0 ; +return sock->map[s]; +}static inline int cpu_map__nr (const struct cpu_map *map) {
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 10/17 perf stat: Add per processor socket count aggregation
In reply to Arnaldo Carvalho de MeloFrom: Stephane Eranian <[email protected]>
This patch adds per-processor socket count aggregation for system-wide mode measurements. This is a useful mode to detect imbalance between sockets.
To enable this mode, use --aggr-socket in addition to -a. (system-wide).
The output includes the socket number and the number of online processors on that socket. This is useful to gauge the amount of aggregation.
# ./perf stat -I 1000 -a --aggr-socket -e cycles sleep 2
# time socket cpus counts events
1.000097680 S0 4 5,788,785 cycles
2.000379943 S0 4 27,361,546 cycles
2.001167808 S0 4 818,275 cycles--- tools/perf/Documentation/perf-stat.txt | 9 ++- tools/perf/builtin-stat.c | 126 ++++++++++++++++++++++++++++++--- 2 files changed, 123 insertions(+), 12 deletions(-)
tools/perf/Documentation/perf-stat.txt +8 -1
@@ -116,9 +116,16 @@ perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' -- m -I msecs:: --interval-print msecs:: - print count deltas every N milliseconds (minimum: 100ms) + Print count deltas every N milliseconds (minimum: 100ms) example: perf stat -I 1000 -e cycles -a sleep 5 +--aggr-socket:: +Aggregate counts per processor socket for system-wide mode measurements. This +is a useful mode to detect imbalance between sockets. To enable this mode, +use --aggr-socket in addition to -a. (system-wide). The output includes the +socket number and the number of online processors on that socket. This is +useful to gauge the amount of aggregation. + EXAMPLES --------
tools/perf/builtin-stat.c +115 -11
223 lines not on this page · raw message
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 11/17 perf hists browser: Add support to display whole group data for raw columns
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Currently we don't display group members' values for raw columns like 'Samples' and 'Period' when in group report mode.
Uniting '__hpp__percent_fmt' and '__hpp__raw_fmt' function under new function __hpp__fmt. It's basically '__hpp__percent_fmt' code with new 'fmt_percent' bool parameter added saying whether raw number or percentage should be printed.
This way raw columns print out all the group members when in group report mode, like:
$ perf record -e '{cycles,cache-misses}' ls
...
$ perf report --group --show-total-period --stdio
...
# Overhead Period Command Shared Object Symbol
# ................ ........................ ....... ................. .................................
#
23.63% 11.24% 3331335 317 ls [kernel.kallsyms] [k] __lock_acquire
12.72% 0.00% 1793100 0 ls [kernel.kallsyms] [k] native_sched_clock
9.72% 0.00% 1369920 0 ls libc-2.14.90.so [.] _nl_find_locale
0.03% 0.07% 4476 2 ls [kernel.kallsyms] [k] intel_pmu_enable_all
0.00% 11.73% 0 331 ls ld-2.14.90.so [.] _dl_cache_libcmp
0.00% 11.06% 0 312 ls [kernel.kallsyms] [k] vma_interval_tree_insert--- tools/perf/ui/hist.c | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-)
tools/perf/ui/hist.c +26 -27
@@ -9,18 +9,24 @@typedef int (*hpp_snprint_fn )(char *buf,size_t size,const char *fmt, ...); -static int __hpp__percent_fmt (struct perf_hpp *hpp,struct hist_entry *he, -u64 (*get_field)(struct hist_entry *), -const char *fmt,hpp_snprint_fn print_fn) +static int __hpp__fmt (struct perf_hpp *hpp,struct hist_entry *he, +u64 (*get_field)(struct hist_entry *), +const char *fmt,hpp_snprint_fn print_fn, +bool fmt_percent) {int ret; -double percent =0.0 ;struct hists *hists = he->hists; -if (hists->stats.total_period) - percent =100.0 *get_field (he) / hists->stats.total_period; +if (fmt_percent) { +double percent =0.0 ; + +if (hists->stats.total_period) + percent =100.0 *get_field (he) / + hists->stats.total_period; - ret =print_fn (hpp->buf, hpp->size, fmt, percent); + ret =print_fn (hpp->buf, hpp->size, fmt, percent); + }else + ret =print_fn (hpp->buf, hpp->size, fmt,get_field (he));if (symbol_conf.event_group) {int prev_idx, idx_delta;
@@ -49,11 +55,15 @@ static int __hpp__percent_fmt(struct perf_hpp *hpp, struct hist_entry *he,* have no sample */ ret +=print_fn (hpp->buf + ret, hpp->size - ret, - fmt,0.0 ); + fmt,0 ); } - ret +=print_fn (hpp->buf + ret, hpp->size - ret, - fmt,100.0 * period / total); +if (fmt_percent) + ret +=print_fn (hpp->buf + ret, hpp->size - ret, + fmt,100.0 * period / total); +else + ret +=print_fn (hpp->buf + ret, hpp->size - ret, + fmt, period); prev_idx =perf_evsel__group_idx (evsel); }
@@ -65,23 +75,12 @@ static int __hpp__percent_fmt(struct perf_hpp *hpp, struct hist_entry *he,* zero-fill group members at last which have no sample */ ret +=print_fn (hpp->buf + ret, hpp->size - ret, - fmt,0.0 ); + fmt,0 ); } }return ret; } -static int __hpp__raw_fmt (struct perf_hpp *hpp,struct hist_entry *he, -u64 (*get_field)(struct hist_entry *), -const char *fmt,hpp_snprint_fn print_fn) -{ -int ret; - - ret =print_fn (hpp->buf, hpp->size, fmt,get_field (he)); -return ret; -} - -#define __HPP_HEADER_FN (_type, _str, _min_width, _unit_width) \ static int hpp__header_##_type(struct perf_hpp *hpp) \ { \
@@ -116,16 +115,16 @@ static u64 he_get_##_field(struct hist_entry *he) \ \ static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) \ { \ - return __hpp__percent_fmt(hpp, he, he_get_##_field, " %6.2f%%", \ - (hpp_snprint_fn )percent_color_snprintf); \ + return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \ + (hpp_snprint_fn )percent_color_snprintf, true); \ }#define __HPP_ENTRY_PERCENT_FN (_type, _field) \ static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \ { \ const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ - return __hpp__percent_fmt(hpp, he, he_get_##_field, fmt, \ - scnprintf); \ + return __hpp__fmt(hpp, he, he_get_##_field, fmt, \ + scnprintf, true); \ }#define __HPP_ENTRY_RAW_FN (_type, _field) \
@@ -137,7 +136,7 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \ static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \ { \const char *fmt = symbol_conf.field_sep ?" %" PRIu64 :" %11" PRIu64; \ - return __hpp__raw_fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf); \ + return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf, false); \ }#define HPP_PERCENT_FNS (_type, _str, _field, _min_width, _unit_width) \
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 12/17 perf perl scripts: Fix SIGALRM and pipe read race for rwtop
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Fixing rwtop script race. The issue is caused by rwtop script triggering SIGALRM and underneath pipe reading layer reporting error when interrupted.
Fixing this by setting SA_RESTART for rwtop SIGALRM handler, which avoids interruption of the pipe reading layer.
The discussion for this issue & fix is here:
https://lkml.org/lkml/2012/9/18/123
--- tools/perf/scripts/perl/rwtop.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/scripts/perl/rwtop.pl +5 -1
@@ -17,6 +17,7 @@ use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib"; use lib "./Perf-Trace-Util/lib"; use Perf::Trace::Core; use Perf::Trace::Util; +use POSIX qw/SIGALRM SA_RESTART/; my $default_interval = 3; my $nlines = 20;
@@ -90,7 +91,10 @@ sub syscalls::sys_enter_write sub trace_begin { - $SIG{ALRM} = \&set_print_pending; + my $sa = POSIX::SigAction->new(\&set_print_pending); + $sa->flags(SA_RESTART); + $sa->safe(1); + POSIX::sigaction(SIGALRM, $sa) or die "Can't set SIGALRM handler: $!\n"; alarm 1; }
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 13/17 perf tools: Fix perf_evsel::exclude_GH handling
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Let the perf_evsel::exclude_GH only prevent the reset of exclude_host and exclude_guest attributes in case they were already set.
We cannot reset their values to 0, because they might have other defaults set by event_attr_init.
--- tools/perf/util/parse-events.c | 8 -------- 1 file changed, 8 deletions(-)
tools/perf/util/parse-events.c +0 -8
@@ -699,14 +699,6 @@ static int get_event_modifier(struct event_modifier *mod, char *str,int exclude = eu | ek | eh;int exclude_GH = evsel ? evsel->exclude_GH :0 ; -/* -* We are here for group and 'GH' was not set as event -* modifier and whatever event/group modifier override -* default 'GH' setup. -*/ -if (evsel && !exclude_GH) - eH = eG =0 ; -memset (mod,0 ,sizeof (*mod));while (*str) {
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 14/17 perf tests: Adding automated parsing tests for group :GH modifiers
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
The ':GH' group modifier handling was just recently fixed, adding some autommated tests to keep it that way. Adding tests for following events:
"{cycles,cache-misses:G}:H"
"{cycles,cache-misses:H}:G"
"{cycles:G,cache-misses:H}:u"
"{cycles:G,cache-misses:H}:uG"
Plus fixing test__group2 test.
--- tools/perf/tests/parse-events.c | 178 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 177 insertions(+), 1 deletion(-)
tools/perf/tests/parse-events.c +177 -1
@@ -577,7 +577,7 @@ static int test__group2(struct perf_evlist *evlist)TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user);TEST_ASSERT_VAL ("wrong exclude_kernel" , evsel->attr.exclude_kernel);TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); -TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude guest" , evsel->attr.exclude_guest);TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host);TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip);TEST_ASSERT_VAL ("wrong leader" , evsel->leader == leader);
@@ -811,6 +811,166 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)return 0 ; } +static int test__group_gh1 (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel, *leader; + +TEST_ASSERT_VAL ("wrong number of entries" ,2 == evlist->nr_entries); +TEST_ASSERT_VAL ("wrong number of groups" ,1 == evlist->nr_groups); + +/* cycles + :H group modifier */ + evsel = leader =perf_evlist__first (evlist); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , !evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name); +TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); +TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 ); + +/* cache-misses:G + :H group modifier */ + evsel =perf_evsel__next (evsel); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , !evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong leader" , evsel->leader == leader); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==1 ); + +return 0 ; +} + +static int test__group_gh2 (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel, *leader; + +TEST_ASSERT_VAL ("wrong number of entries" ,2 == evlist->nr_entries); +TEST_ASSERT_VAL ("wrong number of groups" ,1 == evlist->nr_groups); + +/* cycles + :G group modifier */ + evsel = leader =perf_evlist__first (evlist); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , !evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name); +TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); +TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 ); + +/* cache-misses:H + :G group modifier */ + evsel =perf_evsel__next (evsel); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , !evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , !evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong leader" , evsel->leader == leader); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==1 ); + +return 0 ; +} + +static int test__group_gh3 (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel, *leader; + +TEST_ASSERT_VAL ("wrong number of entries" ,2 == evlist->nr_entries); +TEST_ASSERT_VAL ("wrong number of groups" ,1 == evlist->nr_groups); + +/* cycles:G + :u group modifier */ + evsel = leader =perf_evlist__first (evlist); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name); +TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); +TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 ); + +/* cache-misses:H + :u group modifier */ + evsel =perf_evsel__next (evsel); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong leader" , evsel->leader == leader); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==1 ); + +return 0 ; +} + +static int test__group_gh4 (struct perf_evlist *evlist) +{ +struct perf_evsel *evsel, *leader; + +TEST_ASSERT_VAL ("wrong number of entries" ,2 == evlist->nr_entries); +TEST_ASSERT_VAL ("wrong number of groups" ,1 == evlist->nr_groups); + +/* cycles:G + :uG group modifier */ + evsel = leader =perf_evlist__first (evlist); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong group name" , !evsel->group_name); +TEST_ASSERT_VAL ("wrong leader" ,perf_evsel__is_group_leader (evsel)); +TEST_ASSERT_VAL ("wrong nr_members" , evsel->nr_members ==2 ); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==0 ); + +/* cache-misses:H + :uG group modifier */ + evsel =perf_evsel__next (evsel); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HARDWARE == evsel->attr.type); +TEST_ASSERT_VAL ("wrong config" , +PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); +TEST_ASSERT_VAL ("wrong exclude_user" , !evsel->attr.exclude_user); +TEST_ASSERT_VAL ("wrong exclude_kernel" , evsel->attr.exclude_kernel); +TEST_ASSERT_VAL ("wrong exclude_hv" , evsel->attr.exclude_hv); +TEST_ASSERT_VAL ("wrong exclude guest" , !evsel->attr.exclude_guest); +TEST_ASSERT_VAL ("wrong exclude host" , !evsel->attr.exclude_host); +TEST_ASSERT_VAL ("wrong precise_ip" , !evsel->attr.precise_ip); +TEST_ASSERT_VAL ("wrong leader" , evsel->leader == leader); +TEST_ASSERT_VAL ("wrong group_idx" ,perf_evsel__group_idx (evsel) ==1 ); + +return 0 ; +} +static int count_tracepoints (void ) {char events_path[PATH_MAX ];
@@ -1011,6 +1171,22 @@ static struct evlist_test test__events[] = { .name = "*:*", .check = test__all_tracepoints, }, + [34] = { + .name = "{cycles,cache-misses:G}:H", + .check = test__group_gh1, + }, + [35] = { + .name = "{cycles,cache-misses:H}:G", + .check = test__group_gh2, + }, + [36] = { + .name = "{cycles:G,cache-misses:H}:u", + .check = test__group_gh3, + }, + [37] = { + .name = "{cycles:G,cache-misses:H}:uG", + .check = test__group_gh4, + }, };static struct evlist_test test__events_pmu[] = {
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 15/17 perf tools: Fix calloc argument ordering
In reply to Arnaldo Carvalho de MeloFrom: Paul Gortmaker <[email protected]>
A sweep of the kernel for regex "kcalloc(sizeof" turned up 2 reversed args, fixed in commit d3d09e18203dba16a9dbdb2b4cc673d90748cdd1 ("EDAC:
Fix kcalloc argument order") and also fixed in the networking commit a1b1add07fa794974573d93483d68e373edfe7bd ("gro: Fix kcalloc argument order").
I know that was the regex used, because on seeing the 1st of these changes, I wondered "how many other instances of this are there" and I happened to just use "calloc(sizeof" as a regex and it in turn found these additional reversed args instances in the perf code.
In the kcalloc cases, the changes are cosmetic, since the numbers are simply multiplied. I had no desire to go data mining in userspace to see if the same thing held true there, however.
--- tools/perf/util/callchain.c | 2 +- tools/perf/util/header.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/callchain.c +1 -1
@@ -444,7 +444,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,struct callchain_cursor_node *node = *cursor->last;if (!node) { - node =calloc (sizeof (*node),1 ); + node =calloc (1 ,sizeof (*node));if (!node)return -ENOMEM ;
tools/perf/util/header.c +2 -2
@@ -2253,7 +2253,7 @@ static int perf_header__adds_write(struct perf_header *header,if (!nr_sections)return 0 ; - feat_sec = p =calloc (sizeof (*feat_sec), nr_sections); + feat_sec = p =calloc (nr_sections,sizeof (*feat_sec));if (feat_sec ==NULL )return -ENOMEM ;
@@ -2425,7 +2425,7 @@ int perf_header__process_sections(struct perf_header *header, int fd,if (!nr_sections)return 0 ; - feat_sec = sec =calloc (sizeof (*feat_sec), nr_sections); + feat_sec = sec =calloc (nr_sections,sizeof (*feat_sec));if (!feat_sec)return -1 ;
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 16/17 perf evlist: Pass the event_group info via perf_attr_details
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
So that we avoid dragging symbol.o into the python binding.
--- tools/perf/builtin-evlist.c | 4 ++-- tools/perf/util/evsel.c | 2 +- tools/perf/util/evsel.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-)
tools/perf/builtin-evlist.c +2 -2
@@ -39,7 +39,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('F' ,"freq" , &details.freq,"Show the sample frequency" ),OPT_BOOLEAN ('v' ,"verbose" , &details.verbose,"Show all event attr details" ), -OPT_BOOLEAN ('g' ,"group" , &symbol_conf.event_group, +OPT_BOOLEAN ('g' ,"group" , &details.event_group,"Show event group information" ), OPT_END() };
@@ -52,7 +52,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)if (argc)usage_with_options (evlist_usage, options); -if (symbol_conf.event_group && (details.verbose || details.freq)) { +if (details.event_group && (details.verbose || details.freq)) {pr_err ("--group option is not compatible with other options\n" );usage_with_options (evlist_usage, options); }
tools/perf/util/evsel.c +1 -1
@@ -1391,7 +1391,7 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,bool first = true;int printed =0 ; -if (symbol_conf.event_group) { +if (details->event_group) {struct perf_evsel *pos;if (!perf_evsel__is_group_leader (evsel))
tools/perf/util/evsel.h +1 -0
@@ -254,6 +254,7 @@ static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)struct perf_attr_details {bool freq;bool verbose; +bool event_group; }; int perf_evsel__fprintf(struct perf_evsel *evsel,
Signature · 1 line
1.8.1.1.361.gec3ae6e
PATCH 17/17 perf python: Link with sysfs.o
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
So that we fix this regression:
[root@sandy linux]# perf test -v 15
15: Try 'use perf' in python, checking link problems :
--- start ---
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/acme/git/build/perf/python/perf.so: undefined symbol: sysfs_find_mountpoint ---- end ----
Try 'use perf' in python, checking link problems: FAILED!
[root@sandy linux]#
--- tools/perf/util/python-ext-sources | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/python-ext-sources +1 -0
@@ -18,4 +18,5 @@ util/cgroup.c util/debugfs.c util/rblist.c util/strlist.c +util/sysfs.c ../../lib/rbtree.c
Signature · 1 line
1.8.1.1.361.gec3ae6e
Quoted 105 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit
0fbdad078a70ed72248c3d30fe32e45e83be00d1:perf/x86: Allow for architecture specific RDPMC indexes (2013-02-06 19:45:24 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxtags/perf-core-for-mingofor you to fetch changes up to
88fd2b6a76264e9e14463f532caae09d82a53207:perf python: Link with sysfs.o (2013-02-06 18:09:28 -0300)
----------------------------------------------------------------
perf/core improvements and fixes. Check for flex and bison before continuing building, from Borislav Petkov.
. Make
event_copylocal to mmaps, fixing buffer wrap around problems, from
David Ahern.. Add option for runtime switching perf data file in perf report, just press
's' and a menu with the valid files found in the current directory will be presented, from Feng Tang.. Add support to display whole group data for raw columns, from Jiri Olsa.
. Fix SIGALRM and pipe read race for the rwtop perl script. from Jiri Olsa.
. Fix
perf_evsel::exclude_GHhandling and add a test to catch regressions, from
Jiri Olsa.. Error checking fixes, from Namhyung Kim.
. Fix calloc argument ordering, from Paul Gortmaker.
. Fix set event list leader, from Stephane Eranian.
. Add per processor socket count aggregation in perf stat, from Stephane Eranian.
. Fix perf python binding breakage.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf evlist: Pass theevent_groupinfo viaperf_attr_detailsperf python: Link with sysfs.oBorislav Petkov (1):
perf tools: Check for flex and bison before continuing buildingDavid Ahern (1):
perf evlist: Makeevent_copylocal to mmapsFeng Tang (2):
perf hists browser: Add option for runtime switching perf data file perf report: Enable the runtime switching of perf data fileJiri Olsa (4):
perf hists browser: Add support to display whole group data for raw columns perf perl scripts: Fix SIGALRM and pipe read race for rwtop perf tools: Fixperf_evsel::exclude_GHhandling
perf tests: Adding automated parsing tests for group :GH modifiersNamhyung Kim (3):
perf sort: Drop ip_[lr] arguments from_sort__sym_cmp()perf sort: Makesetup_sortingreturns an error code perf sort: Check return value ofstrdup()Paul Gortmaker (1):
perf tools: Fix calloc argument orderingStephane Eranian (3):
perf evlist: Fix set event list leader
perf tools: Addcpu_mapprocessor socket level functions perf stat: Add per processor socket count aggregationtools/perf/Documentation/perf-stat.txt | 9 +- tools/perf/Makefile | 13 ++- tools/perf/builtin-annotate.c | 3 +- tools/perf/builtin-diff.c | 4 +- tools/perf/builtin-evlist.c | 4 +- tools/perf/builtin-report.c | 41 +++++--- tools/perf/builtin-stat.c | 126 +++++++++++++++++++++-- tools/perf/builtin-top.c | 3 +- tools/perf/perf.h | 26 ----- tools/perf/scripts/perl/rwtop.pl | 6 +- tools/perf/tests/hists_link.c | 3 +- tools/perf/tests/parse-events.c | 178 ++++++++++++++++++++++++++++++++- tools/perf/ui/browsers/hists.c | 112 ++++++++++++++++++++- tools/perf/ui/hist.c | 53 +++++----- tools/perf/ui/keysyms.h | 1 + tools/perf/util/callchain.c | 2 +- tools/perf/util/cpumap.c | 54 ++++++++++ tools/perf/util/cpumap.h | 9 ++ tools/perf/util/evlist.c | 7 +- tools/perf/util/evlist.h | 29 +++++-
Quoted 8 lines
tools/perf/util/evsel.c | 2 +- tools/perf/util/evsel.h | 1 + tools/perf/util/header.c | 4 +- tools/perf/util/parse-events.c | 8 -- tools/perf/util/python-ext-sources | 1 + tools/perf/util/sort.c | 38 ++++--- tools/perf/util/sort.h | 2 +- 27 files changed, 611 insertions(+), 128 deletions(-)
Pulled, thanks a lot Arnaldo!
Ingo