perf diff: Use perf_session__fprintf_hists just like 'perf record'
PATCH 1/1 perf diff: Use perf_session__fprintf_hists just like 'perf record'
From: Arnaldo Carvalho de Melo <[email protected]>
That means that almost everything you can do with 'perf report' can be done with 'perf diff', for instance:
$ perf record -f find / > /dev/null
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.062 MB perf.data (~2699 samples) ]
$ perf record -f find / > /dev/null
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.062 MB perf.data (~2687 samples) ]
perf diff | head -8
9.02% +1.00% find libc-2.10.1.so [.] _IO_vfprintf_internal
2.91% -1.00% find [kernel] [k] __kmalloc
2.85% -1.00% find [kernel] [k] ext4_htree_store_dirent
1.99% -1.00% find [kernel] [k] _atomic_dec_and_lock
2.44% find [kernel] [k] half_md4_transform
$So if you want to zoom into libc:
$ perf diff --dsos libc-2.10.1.so | head -8
37.34% find [.] _IO_vfprintf_internal
10.34% find [.] __GI_memmove
8.25% +2.00% find [.] _int_malloc
5.07% -1.00% find [.] __GI_mempcpy
7.62% +2.00% find [.] _int_free
$And if there were multiple commands using libc, it is also possible to aggregate them all by using --sort symbol:
$ perf diff --dsos libc-2.10.1.so --sort symbol | head -8
37.34% [.] _IO_vfprintf_internal
10.34% [.] __GI_memmove
8.25% +2.00% [.] _int_malloc
5.07% -1.00% [.] __GI_mempcpy
7.62% +2.00% [.] _int_free
$The displacement column now is off by default, to use it:
perf diff -m --dsos libc-2.10.1.so --sort symbol | head -8
37.34% [.] _IO_vfprintf_internal
10.34% [.] __GI_memmove
8.25% +2.00% [.] _int_malloc
5.07% -1.00% +2 [.] __GI_mempcpy
7.62% +2.00% -1 [.] _int_free$
Using -t/--field-separator can be used for scripting:
$ perf diff -t, -m --dsos libc-2.10.1.so --sort symbol | head -8 37.34, , ,[.] _IO_vfprintf_internal 10.34, , ,[.] __GI_memmove 8.25,+2.00%, ,[.] _int_malloc 5.07,-1.00%, +2,[.] __GI_mempcpy 7.62,+2.00%, -1,[.] _int_free 6.99,+1.00%, -1,[.] _IO_new_file_xsputn 1.89,-2.00%, +4,[.] __readdir64 $
Cc Frédéric Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/Documentation/perf-diff.txt | 29 ++++++- tools/perf/Documentation/perf-report.txt | 4 + tools/perf/builtin-diff.c | 90 +++++----------------- tools/perf/builtin-report.c | 12 +--- tools/perf/util/hist.c | 126 ++++++++++++++++++++++++------ tools/perf/util/hist.h | 5 +- tools/perf/util/sort.c | 11 +++ tools/perf/util/sort.h | 2 + 8 files changed, 169 insertions(+), 110 deletions(-)
tools/perf/Documentation/perf-diff.txt +26 -3
@@ -19,9 +19,32 @@ If no parameters are passed it will assume perf.data.old and perf.data. OPTIONS ------- --p:: ---percentage:: - Show percentages instead of raw counts +-d:: +--dsos=:: + Only consider symbols in these dsos. CSV that understands + file://filename entries. + +-C:: +--comms=:: + Only consider symbols in these comms. CSV that understands + file://filename entries. + +-S:: +--symbols=:: + Only consider these symbols. CSV that understands + file://filename entries. + +-s:: +--sort=:: + Sort by key(s): pid, comm, dso, symbol. + +-t:: +--field-separator=:: + + Use a special separator character and don't pad with spaces, replacing + all occurances of this separator in symbol names (and other output) + with a '.' character, that thus it's the only non valid separator. + -v:: --verbose:: Be verbose, for instance, show the raw counts in addition to the
tools/perf/Documentation/perf-report.txt +4 -0
@@ -39,6 +39,10 @@ OPTIONS Only consider these symbols. CSV that understands file://filename entries. +-s:: +--sort=:: + Sort by key(s): pid, comm, dso, symbol, parent. + -w:: --field-width=:: Force each column width to the provided list, for large terminal
tools/perf/builtin-diff.c +19 -71
135 lines not on this page · raw message
tools/perf/builtin-report.c +1 -11
@@ -225,7 +225,7 @@ static int __cmd_report(void)perf_session__collapse_resort (session);perf_session__output_resort (session, session->events_stats.total);fprintf (stdout,"# Samples: %ld\n#\n" , session->events_stats.total); -perf_session__fprintf_hists (session, stdout); +perf_session__fprintf_hists (session,NULL , false, stdout);if (sort_order == default_sort_order && parent_pattern == default_parent_pattern)fprintf (stdout,"#\n# (For a higher level overview, try: perf report --sort comm,dso)\n#\n" );
@@ -344,16 +344,6 @@ static const struct option options[] = { OPT_END() }; -static void sort_entry__setup_elide (struct sort_entry *self, -struct strlist *list, -const char *list_name,FILE *fp) -{ -if (list &&strlist__nr_entries (list) ==1 ) { -fprintf (fp,"# %s: %s\n" , list_name,strlist__entry (list,0 )->s); - self->elide = true; - } -} -int cmd_report (int argc,const char **argv,const char *prefix__used ) { argc =parse_options (argc, argv, options, report_usage,0 );
tools/perf/util/hist.c +103 -23
192 lines not on this page · raw message
tools/perf/util/hist.h +3 -2
@@ -21,6 +21,7 @@ void hist_entry__free(struct hist_entry *);void perf_session__output_resort (struct perf_session *self,u64 total_samples);void perf_session__collapse_resort (struct perf_session *self); -size_t perf_session__fprintf_hists (struct perf_session *self,FILE *fp); - +size_t perf_session__fprintf_hists (struct perf_session *self, +struct perf_session *pair, +bool show_displacement,FILE *fp);#endif /* __PERF_HIST_H */
tools/perf/util/sort.c +11 -0
@@ -303,3 +303,14 @@ void setup_sorting(const char * const usagestr[], const struct option *opts)free (str); } + +void sort_entry__setup_elide (struct sort_entry *self,struct strlist *list, +const char *list_name,FILE *fp) +{ +if (list &&strlist__nr_entries (list) ==1 ) { +if (fp !=NULL ) +fprintf (fp,"# %s: %s\n" , list_name, +strlist__entry (list,0 )->s); + self->elide = true; + } +}
tools/perf/util/sort.h +2 -0
@@ -101,5 +101,7 @@ extern int64_t sort__sym_cmp(struct hist_entry *, struct hist_entry *);extern int64_t sort__parent_cmp (struct hist_entry *,struct hist_entry *);extern size_t sort__parent_print (FILE *,struct hist_entry *,unsigned int );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);#endif /* __PERF_SORT_H */
Signature · 1 line
1.6.2.5