perf/core improvements and fixes
From: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit caea6cf52139116e43e615d87fcbf9823e197fdf:
Merge branch 'uprobes/core' of git://git.kernel.org/pub/scm/linux/kernel/git/oleg/misc into perf/core (2013-11-11 09:44:16 +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 67c1e4a53b17894e6a24f95057cc374c4be051cb:
perf tests: Use lower sample_freq in sw clock event period test (2013-11-11 16:43:34 -0300)
----------------------------------------------------------------
perf/core improvements and fixes.
. Prevent condition that all sort keys are elided, fix from Namhyung Kim.
. Synthesize non-exec MMAP records when --data used, allowing the resolution of
data addresses to symbols (global variables, etc).
. Don't force a refresh during progress update in the TUI, greatly reducing
startup costs, fix from Patrick Palka.
. Fix sw clock event period test wrt not checking if using > max_sample_freq.
. Code cleanups by David Ahern and Adrian Hunter.
----------------------------------------------------------------
Adrian Hunter (1):
perf record: Use correct return type for write()
Arnaldo Carvalho de Melo (6):
perf evsel: Remove idx parm from constructor
perf record: Synthesize non-exec MMAP records when --data used perf machine: Introduce synthesize_threads method out of open coded equivalent perf machine: Simplify synthesize_threads method
perf tests: Check return of perf_evlist__open sw clock event period test perf tests: Use lower sample_freq in sw clock event period test
David Ahern (1):
perf record: Move existing write_output into helper function
Namhyung Kim (1):
perf tools: Prevent condition that all sort keys are elided
Patrick Palka (1):
perf ui tui progress: Don't force a refresh during progress update
tools/perf/builtin-kvm.c | 14 ++------- tools/perf/builtin-record.c | 21 ++++++------- tools/perf/builtin-top.c | 10 ++----- tools/perf/builtin-trace.c | 24 +++++---------- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/evsel-tp-sched.c | 4 +-- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/open-syscall-all-cpus.c | 2 +- tools/perf/tests/open-syscall-tp-fields.c | 2 +- tools/perf/tests/open-syscall.c | 2 +- tools/perf/tests/sw-clock.c | 13 ++++++-- tools/perf/ui/tui/progress.c | 3 +- tools/perf/util/event.c | 50 ++++++++++++++++++------------- tools/perf/util/event.h | 4 +-- tools/perf/util/evlist.c | 9 +++--- tools/perf/util/evsel.c | 4 +-- tools/perf/util/evsel.h | 15 ++++++++-- tools/perf/util/header.c | 4 +-- tools/perf/util/machine.c | 12 ++++++++ tools/perf/util/machine.h | 12 ++++++++ tools/perf/util/parse-events.c | 6 ++-- tools/perf/util/sort.c | 13 ++++++++ 22 files changed, 133 insertions(+), 95 deletions(-)
PATCH 1/10 perf ui tui progress: Don't force a refresh during progress update
From: Patrick Palka <[email protected]>
Each call to tui_progress__update() would forcibly refresh the entire screen. This is somewhat inefficient and causes noticable flickering during the startup of perf-report, especially on large/slow terminals.
It looks like the force-refresh in tui_progress__update() serves no purpose other than to clear the screen so that the progress bar of a previous operation does not subsume that of a subsequent operation. But we can do just that in a much more efficient manner by clearing only the region that a previous progress bar may have occupied before repainting the new progress bar. Then the force-refresh could be removed with no change in visuals.
This patch disables the slow force-refresh in tui_progress__update() and instead calls SLsmg_fill_region() on the entire area that the progress bar may occupy before repainting it. This change makes the startup of perf-report much faster and appear much "smoother".
It turns out that this was a big bottleneck in the startup speed of perf-report -- with this patch, perf-report starts up ~2x faster (1.1s vs 0.55s) on my machines. (These numbers were measured by running "time perf report" on an 8MB perf.data and pressing 'q' immediately.)
--- tools/perf/ui/tui/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/ui/tui/progress.c +2 -1
@@ -18,13 +18,14 @@ static void tui_progress__update(struct ui_progress *p)if (p->total ==0 )return ; -ui__refresh_dimensions (true); +ui__refresh_dimensions (false);pthread_mutex_lock (&ui__lock); y = SLtt_Screen_Rows /2 -2 ;SLsmg_set_color (0 );SLsmg_draw_box (y,0 ,3 , SLtt_Screen_Cols);SLsmg_gotorc (y++,1 );SLsmg_write_string ((char *)p->title); +SLsmg_fill_region (y,1 ,1 , SLtt_Screen_Cols -2 ,' ' );SLsmg_set_color (HE_COLORSET_SELECTED ); bar = ((SLtt_Screen_Cols -2 ) * p->curr) / p->total;SLsmg_fill_region (y,1 ,1 , bar,' ' );
Signature · 1 line
1.8.1.4
PATCH 2/10 perf evsel: Remove idx parm from constructor
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Most uses of the evsel constructor are followed by a call to perf_evlist__add with an idex of evlist->nr_entries, so make rename the current constructor to perf_evsel__new_idx and remove the need for passing the constructor for the common case.
We still need the new_idx variant because the way groups are handled, with evsel->nr_members holding the number of entries in an evlist, partitioning the evlist into sublists inside a single linked list.
This asks for a clarifying refactoring, but for now simplify the non parser cases, so that tool writers don't have to bother with evsel idx setting.
--- tools/perf/builtin-trace.c | 13 +++++-------- tools/perf/tests/evsel-tp-sched.c | 4 ++-- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/open-syscall-all-cpus.c | 2 +- tools/perf/tests/open-syscall-tp-fields.c | 2 +- tools/perf/tests/open-syscall.c | 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/util/evlist.c | 9 +++++---- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/evsel.h | 15 +++++++++++++-- tools/perf/util/header.c | 4 ++-- tools/perf/util/parse-events.c | 6 +++--- 12 files changed, 37 insertions(+), 28 deletions(-)
tools/perf/builtin-trace.c +5 -8
@@ -149,10 +149,9 @@ static void perf_evsel__delete_priv(struct perf_evsel *evsel)perf_evsel__delete (evsel); } -static struct perf_evsel *perf_evsel__syscall_newtp (const char *direction, -void *handler,int idx) +static struct perf_evsel *perf_evsel__syscall_newtp (const char *direction,void *handler) { -struct perf_evsel *evsel =perf_evsel__newtp ("raw_syscalls" , direction, idx); +struct perf_evsel *evsel =perf_evsel__newtp ("raw_syscalls" , direction);if (evsel) { evsel->priv =malloc (sizeof (struct syscall_tp ));
@@ -186,17 +185,16 @@ static int perf_evlist__add_syscall_newtp(struct perf_evlist *evlist, void *sys_exit_handler) {int ret =-1 ; -int idx = evlist->nr_entries;struct perf_evsel *sys_enter, *sys_exit; - sys_enter =perf_evsel__syscall_newtp ("sys_enter" , sys_enter_handler, idx++); + sys_enter =perf_evsel__syscall_newtp ("sys_enter" , sys_enter_handler);if (sys_enter ==NULL ) goto out;if (perf_evsel__init_sc_tp_ptr_field (sys_enter, args)) goto out_delete_sys_enter; - sys_exit =perf_evsel__syscall_newtp ("sys_exit" , sys_exit_handler, idx++); + sys_exit =perf_evsel__syscall_newtp ("sys_exit" , sys_exit_handler);if (sys_exit ==NULL ) goto out_delete_sys_enter;
@@ -1824,8 +1822,7 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);static void perf_evlist__add_vfs_getname (struct perf_evlist *evlist) { -struct perf_evsel *evsel =perf_evsel__newtp ("probe" ,"vfs_getname" , - evlist->nr_entries); +struct perf_evsel *evsel =perf_evsel__newtp ("probe" ,"vfs_getname" );if (evsel ==NULL )return ;
tools/perf/tests/evsel-tp-sched.c +2 -2
@@ -32,7 +32,7 @@ static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,int test__perf_evsel__tp_sched_test (void ) { -struct perf_evsel *evsel =perf_evsel__newtp ("sched" ,"sched_switch" ,0 ); +struct perf_evsel *evsel =perf_evsel__newtp ("sched" ,"sched_switch" );int ret =0 ;if (evsel ==NULL ) {
@@ -63,7 +63,7 @@ int test__perf_evsel__tp_sched_test(void)perf_evsel__delete (evsel); - evsel =perf_evsel__newtp ("sched" ,"sched_wakeup" ,0 ); + evsel =perf_evsel__newtp ("sched" ,"sched_wakeup" );if (perf_evsel__test_field (evsel,"comm" ,16 , true)) ret =-1 ;
tools/perf/tests/mmap-basic.c +1 -1
@@ -65,7 +65,7 @@ int test__basic_mmap(void)char name[64 ];snprintf (name,sizeof (name),"sys_enter_%s" , syscall_names[i]); - evsels[i] =perf_evsel__newtp ("syscalls" , name, i); + evsels[i] =perf_evsel__newtp ("syscalls" , name);if (evsels[i] ==NULL ) {pr_debug ("perf_evsel__new\n" ); goto out_free_evlist;
tools/perf/tests/open-syscall-all-cpus.c +1 -1
@@ -26,7 +26,7 @@ int test__open_syscall_event_on_all_cpus(void)CPU_ZERO (&cpu_set); - evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" ,0 ); + evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" );if (evsel ==NULL ) {pr_debug ("is debugfs mounted on /sys/kernel/debug?\n" ); goto out_thread_map_delete;
tools/perf/tests/open-syscall-tp-fields.c +1 -1
@@ -27,7 +27,7 @@ int test__syscall_open_tp_fields(void) goto out; } - evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" ,0 ); + evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" );if (evsel ==NULL ) {pr_debug ("%s: perf_evsel__newtp\n" , __func__); goto out_delete_evlist;
tools/perf/tests/open-syscall.c +1 -1
@@ -15,7 +15,7 @@ int test__open_syscall_event(void)return -1 ; } - evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" ,0 ); + evsel =perf_evsel__newtp ("syscalls" ,"sys_enter_open" );if (evsel ==NULL ) {pr_debug ("is debugfs mounted on /sys/kernel/debug?\n" ); goto out_thread_map_delete;
tools/perf/tests/sw-clock.c +1 -1
@@ -42,7 +42,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)return -1 ; } - evsel =perf_evsel__new (&attr,0 ); + evsel =perf_evsel__new (&attr);if (evsel ==NULL ) {pr_debug ("perf_evsel__new\n" ); goto out_free_evlist;
tools/perf/util/evlist.c +5 -4
@@ -117,6 +117,8 @@ void perf_evlist__delete(struct perf_evlist *evlist)void perf_evlist__add (struct perf_evlist *evlist,struct perf_evsel *entry) {list_add_tail (&entry->node, &evlist->entries); + entry->idx = evlist->nr_entries; +if (!evlist->nr_entries++)perf_evlist__set_id_pos (evlist); }
@@ -165,7 +167,7 @@ int perf_evlist__add_default(struct perf_evlist *evlist)event_attr_init (&attr); - evsel =perf_evsel__new (&attr,0 ); + evsel =perf_evsel__new (&attr);if (evsel ==NULL ) goto error;
@@ -190,7 +192,7 @@ static int perf_evlist__add_attrs(struct perf_evlist *evlist,size_t i;for (i =0 ; i < nr_attrs; i++) { - evsel =perf_evsel__new (attrs + i, evlist->nr_entries + i); + evsel =perf_evsel__new_idx (attrs + i, evlist->nr_entries + i);if (evsel ==NULL ) goto out_delete_partial_list;list_add_tail (&evsel->node, &head);
@@ -249,9 +251,8 @@ perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,int perf_evlist__add_newtp (struct perf_evlist *evlist,const char *sys,const char *name,void *handler) { -struct perf_evsel *evsel; +struct perf_evsel *evsel =perf_evsel__newtp (sys, name); - evsel =perf_evsel__newtp (sys, name, evlist->nr_entries);if (evsel ==NULL )return -1 ;
tools/perf/util/evsel.c +2 -2
@@ -168,7 +168,7 @@ void perf_evsel__init(struct perf_evsel *evsel,perf_evsel__calc_id_pos (evsel); } -struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr,int idx) +struct perf_evsel *perf_evsel__new_idx (struct perf_event_attr *attr,int idx) {struct perf_evsel *evsel =zalloc (sizeof (*evsel));
@@ -219,7 +219,7 @@ out:return format; } -struct perf_evsel *perf_evsel__newtp (const char *sys,const char *name,int idx) +struct perf_evsel *perf_evsel__newtp_idx (const char *sys,const char *name,int idx) {struct perf_evsel *evsel =zalloc (sizeof (*evsel));
tools/perf/util/evsel.h +13 -2
@@ -96,8 +96,19 @@ struct thread_map;struct perf_evlist ;struct perf_record_opts ; -struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr,int idx); -struct perf_evsel *perf_evsel__newtp (const char *sys,const char *name,int idx); +struct perf_evsel *perf_evsel__new_idx (struct perf_event_attr *attr,int idx); + +static inline struct perf_evsel *perf_evsel__new (struct perf_event_attr *attr) +{ +return perf_evsel__new_idx (attr,0 ); +} + +struct perf_evsel *perf_evsel__newtp_idx (const char *sys,const char *name,int idx); + +static inline struct perf_evsel *perf_evsel__newtp (const char *sys,const char *name) +{ +return perf_evsel__newtp_idx (sys, name,0 ); +}struct event_format *event_format__new (const char *sys,const char *name);
tools/perf/util/header.c +2 -2
@@ -2797,7 +2797,7 @@ int perf_session__read_header(struct perf_session *session)perf_event__attr_swap (&f_attr.attr); tmp =lseek (fd,0 ,SEEK_CUR ); - evsel =perf_evsel__new (&f_attr.attr, i); + evsel =perf_evsel__new (&f_attr.attr);if (evsel ==NULL ) goto out_delete_evlist;
@@ -2916,7 +2916,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused,return -ENOMEM ; } - evsel =perf_evsel__new (&event->attr.attr, evlist->nr_entries); + evsel =perf_evsel__new (&event->attr.attr);if (evsel ==NULL )return -ENOMEM ;
tools/perf/util/parse-events.c +3 -3
@@ -277,7 +277,7 @@ static int __add_event(struct list_head *list, int *idx,event_attr_init (attr); - evsel =perf_evsel__new (attr, (*idx)++); + evsel =perf_evsel__new_idx (attr, (*idx)++);if (!evsel)return -ENOMEM ;
@@ -378,7 +378,7 @@ static int add_tracepoint(struct list_head *list, int *idx, {struct perf_evsel *evsel; - evsel =perf_evsel__newtp (sys_name, evt_name, (*idx)++); + evsel =perf_evsel__newtp_idx (sys_name, evt_name, (*idx)++);if (!evsel)return -ENOMEM ;
@@ -1097,7 +1097,7 @@ static bool is_event_supported(u8 type, unsigned config) .threads = { 0 }, }; - evsel =perf_evsel__new (&attr,0 ); + evsel =perf_evsel__new (&attr);if (evsel) { ret =perf_evsel__open (evsel,NULL , &tmap.map) >=0 ;perf_evsel__delete (evsel);
Signature · 1 line
1.8.1.4
PATCH 3/10 perf record: Synthesize non-exec MMAP records when --data used
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
When perf_event_attr.mmap_data is set the kernel will generate PERF_RECORD_MMAP events when non-exec (data, SysV mem) mmaps are created, so we need to synthesize from /proc/pid/maps for existing threads, as we do for exec mmaps.
Right now just 'perf record' does it, but any other tool that uses perf_event__synthesize_thread(s|map) can request it.
--- tools/perf/builtin-kvm.c | 4 ++-- tools/perf/builtin-record.c | 6 ++--- tools/perf/builtin-top.c | 4 ++-- tools/perf/builtin-trace.c | 4 ++-- tools/perf/tests/code-reading.c | 2 +- tools/perf/util/event.c | 50 ++++++++++++++++++++++++----------------- tools/perf/util/event.h | 4 ++-- 7 files changed, 42 insertions(+), 32 deletions(-)
tools/perf/builtin-kvm.c +2 -2
@@ -1550,10 +1550,10 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,perf_event__synthesize_thread_map (&kvm->tool, kvm->evlist->threads, perf_event__process, - &kvm->session->machines.host); + &kvm->session->machines.host, false); else perf_event__synthesize_threads(&kvm->tool, perf_event__process, - &kvm->session->machines.host); + &kvm->session->machines.host, false); err =kvm_live_open_events (kvm);
tools/perf/builtin-record.c +3 -3
@@ -482,11 +482,11 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)if (perf_target__has_task (&opts->target)) err =perf_event__synthesize_thread_map (tool, evsel_list->threads, - process_synthesized_event, - machine); + process_synthesized_event, + machine, opts->sample_address);else if (perf_target__has_cpu (&opts->target)) err =perf_event__synthesize_threads (tool, process_synthesized_event, - machine); + machine, opts->sample_address);else /* command specified */ err =0 ;
tools/perf/builtin-top.c +2 -2
@@ -953,10 +953,10 @@ static int __cmd_top(struct perf_top *top)if (perf_target__has_task (&opts->target))perf_event__synthesize_thread_map (&top->tool, top->evlist->threads, perf_event__process, - &top->session->machines.host); + &top->session->machines.host, false);else perf_event__synthesize_threads (&top->tool, perf_event__process, - &top->session->machines.host); + &top->session->machines.host, false); ret =perf_top__start_counters (top);if (ret)
tools/perf/builtin-trace.c +2 -2
@@ -1343,10 +1343,10 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)if (perf_target__has_task (&trace->opts.target)) { err =perf_event__synthesize_thread_map (&trace->tool, evlist->threads, trace__tool_process, - trace->host); + trace->host, false); }else { err =perf_event__synthesize_threads (&trace->tool, trace__tool_process, - trace->host); + trace->host, false); }if (err)
tools/perf/tests/code-reading.c +1 -1
@@ -441,7 +441,7 @@ static int do_test_code_reading(bool try_kcore) } ret =perf_event__synthesize_thread_map (NULL , threads, - perf_event__process, machine); + perf_event__process, machine, false);if (ret <0 ) {pr_debug ("perf_event__synthesize_thread_map failed\n" ); goto out_err;
tools/perf/util/event.c +30 -20
126 lines not on this page · raw message
tools/perf/util/event.h +2 -2
@@ -208,10 +208,10 @@ typedef int (*perf_event__handler_t)(struct perf_tool *tool,int perf_event__synthesize_thread_map (struct perf_tool *tool,struct thread_map *threads,perf_event__handler_t process, -struct machine *machine); +struct machine *machine,bool mmap_data);int perf_event__synthesize_threads (struct perf_tool *tool,perf_event__handler_t process, -struct machine *machine); +struct machine *machine,bool mmap_data); int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine,
Signature · 1 line
1.8.1.4
Re: [PATCH 03/10] perf record: Synthesize non-exec MMAP records when --data used
[Added Vince]
Quoted 4 lines · Arnaldo Carvalho de Melo
When perf_event_attr.mmap_data is set the kernel will generate
PERF_RECORD_MMAPevents when non-exec (data, SysV mem) mmaps are created, so we need to synthesize from/proc/pid/mapsfor existing threads
Seems like that should be documented in the man pages:
[dsa@MacBook perf]$ egrep -r mmap_data Documentation/ [dsa@MacBook perf]$
Vince: where are you keeping the man page you are putting together?
David
Re: [PATCH 03/10] perf record: Synthesize non-exec MMAP records when --data used
Quoted 8 lines · David Ahern
[Added Vince]
Quoted 4 lines · Arnaldo Carvalho de Melo
When perf_event_attr.mmap_data is set the kernel will generate
PERF_RECORD_MMAPevents when non-exec (data, SysV mem) mmaps are created, so we need to synthesize from/proc/pid/mapsfor existing threads
Quoted 6 lines
Seems like that should be documented in the man pages:
[dsa@MacBook perf]$ egrep -r
mmap_dataDocumentation/[dsa@MacBook perf]$Vince: where are you keeping the man page you are putting together?
It's in the official linux manpage git tree (perf_event_open.2) and has been included in the last few manpage releases.
There is a blurb on PERF_RECORD_MMAP, though it definitely could use a bit more elaboration.
Vince
PATCH 4/10 perf machine: Introduce synthesize_threads method out of open coded equivalent
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Further simplifications to be done on following patch, as most tools don't use the callback, using instead just the canned machine__process_event one.
--- tools/perf/builtin-kvm.c | 15 +++------------ tools/perf/builtin-record.c | 12 ++---------- tools/perf/builtin-top.c | 11 +++-------- tools/perf/builtin-trace.c | 11 ++--------- tools/perf/util/machine.c | 12 ++++++++++++ tools/perf/util/machine.h | 4 ++++ 6 files changed, 26 insertions(+), 39 deletions(-)
tools/perf/builtin-kvm.c +3 -12
@@ -1544,18 +1544,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, } kvm->session->evlist = kvm->evlist;perf_session__set_id_hdr_size (kvm->session); - - -if (perf_target__has_task (&kvm->opts.target)) -perf_event__synthesize_thread_map (&kvm->tool, - kvm->evlist->threads, - perf_event__process, - &kvm->session->machines.host, false); -else -perf_event__synthesize_threads (&kvm->tool, perf_event__process, - &kvm->session->machines.host, false); - - +machine__synthesize_threads (&kvm->session->machines.host, &kvm->tool, + &kvm->opts.target, kvm->evlist->threads, + perf_event__process, false); err =kvm_live_open_events (kvm);if (err) goto out;
tools/perf/builtin-record.c +2 -10
@@ -480,16 +480,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) perf_event__synthesize_guest_os, tool); } -if (perf_target__has_task (&opts->target)) - err =perf_event__synthesize_thread_map (tool, evsel_list->threads, - process_synthesized_event, - machine, opts->sample_address); -else if (perf_target__has_cpu (&opts->target)) - err =perf_event__synthesize_threads (tool, process_synthesized_event, - machine, opts->sample_address); -else /* command specified */ - err =0 ; - + err =machine__synthesize_threads (machine, tool, &opts->target, evsel_list->threads, + process_synthesized_event, opts->sample_address);if (err !=0 ) goto out_delete_session;
tools/perf/builtin-top.c +3 -8
@@ -950,14 +950,9 @@ static int __cmd_top(struct perf_top *top)if (ret) goto out_delete; -if (perf_target__has_task (&opts->target)) -perf_event__synthesize_thread_map (&top->tool, top->evlist->threads, - perf_event__process, - &top->session->machines.host, false); -else -perf_event__synthesize_threads (&top->tool, perf_event__process, - &top->session->machines.host, false); - +machine__synthesize_threads (&top->session->machines.host, &top->tool, + &opts->target, top->evlist->threads, + perf_event__process, false); ret =perf_top__start_counters (top);if (ret) goto out_delete;
tools/perf/builtin-trace.c +2 -9
@@ -1340,15 +1340,8 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)if (trace->host ==NULL )return -ENOMEM ; -if (perf_target__has_task (&trace->opts.target)) { - err =perf_event__synthesize_thread_map (&trace->tool, evlist->threads, - trace__tool_process, - trace->host, false); - }else { - err =perf_event__synthesize_threads (&trace->tool, trace__tool_process, - trace->host, false); - } - + err =machine__synthesize_threads (trace->host, &trace->tool, &trace->opts.target, + evlist->threads, trace__tool_process, false);if (err)symbol__exit ();
tools/perf/util/machine.c +12 -0
@@ -1394,3 +1394,15 @@ int machine__for_each_thread(struct machine *machine, }return rc; } + +int machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, +struct perf_target *target,struct thread_map *threads, +perf_event__handler_t process,bool data_mmap) +{ +if (perf_target__has_task (target)) +return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap); +else if (perf_target__has_cpu (target)) +return perf_event__synthesize_threads (tool, process, machine, data_mmap); +/* command specified */ +return 0 ; +}
tools/perf/util/machine.h +4 -0
@@ -4,6 +4,7 @@#include <sys/types.h> #include <linux/rbtree.h> #include "map.h" +#include "event.h" struct addr_location ;struct branch_stack ;
@@ -178,4 +179,7 @@ int machine__for_each_thread(struct machine *machine,int (*fn)(struct thread *thread,void *p), void *priv); +int machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, +struct perf_target *target,struct thread_map *threads, +perf_event__handler_t process,bool data_mmap);#endif /* __PERF_MACHINE_H */
Signature · 1 line
1.8.1.4
Re: [PATCH 04/10] perf machine: Introduce synthesize_threads method out of open coded equivalent
tools/perf/util/machine.c int machine__for_each_thread(struct machine *machine, · line 1405
Quoted 4 lines · Arnaldo Carvalho de Melo
tools/perf/util/machine.c +4
-0+if (perf_target__has_task (target)) +return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap); +else if (perf_target__has_cpu (target)) +return perf_event__synthesize_threads (tool, process, machine, data_mmap);
Getting kind of long on the line lengths...
Re: [PATCH 04/10] perf machine: Introduce synthesize_threads method out of open coded equivalent
Quoted 8 lines · David Ahern
tools/perf/util/machine.c int machine__for_each_thread(struct machine *machine, · line 1405
Quoted 4 lines · Arnaldo Carvalho de Melo
tools/perf/util/machine.c +4
-0+if (perf_target__has_task (target)) +return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap); +else if (perf_target__has_cpu (target)) +return perf_event__synthesize_threads (tool, process, machine, data_mmap);Getting kind of long on the line lengths...
Maybe we could start losing most of the perf_ prefixes - it's all about perf here, so it does not really add much information, does it?
that would turn it into:
if (target__has_task(target)) return event__synthesize_thread_map(tool, threads, process, machine, data_mmap); else if (target__has_cpu(target)) return event__synthesize_threads(tool, process, machine, data_mmap);
Another trick would be to combine (tool, machine) into a single helper struct (struct context *ctx?), if that is mostly a constant combination describing tool environment, which gets passed deep inside the guts of functions.
Thanks,
Ingo
Re: [PATCH 04/10] perf machine: Introduce synthesize_threads method out of open coded equivalent
Em Mon, Nov 11, 2013 at 09:50:45PM +0100, Ingo Molnar escreveu:
Quoted 10 lines · David Ahern
Quoted 8 lines · Arnaldo Carvalho de Melo
tools/perf/util/machine.c int machine__for_each_thread(struct machine *machine, · line 1405
Quoted 4 lines
tools/perf/util/machine.c +4
-0+if (perf_target__has_task (target)) +return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap); +else if (perf_target__has_cpu (target)) +return perf_event__synthesize_threads (tool, process, machine, data_mmap);Getting kind of long on the line lengths...
Quoted 2 lines
Maybe we could start losing most of the
perf_prefixes - it's all about perf here, so it does not really add much information, does it?
In some cases that is ok, that is why I didn't call it 'perf_machine', just 'machine', in others, like 'perf_event', I thought 'event' would be too general when somebody tries to use this code together with other libraries.
In some cases, like 'perf_target', probably its ok to move to 'target', perhaps this is ok for this problem domain, i.e. monitoring/profiling/etc.
Quoted 11 lines
that would turn it into:
if (target__has_task(target)) return event__synthesize_thread_map(tool, threads, process, machine, data_mmap); else if (target__has_cpu(target)) return event__synthesize_threads(tool, process, machine, data_mmap);Another trick would be to combine (tool, machine) into a single helper struct (struct context *ctx?), if that is mostly a constant combination describing tool environment, which gets passed deep inside the guts of functions.
Reducing the function signature is something that may help as well, and was done in this series with machine__synthesize_threads, that avoids passing the tool and process arguments, since they were constanty anyway.
What you propose is used in some cases, like with symbol_conf, will try to work in that direction as time goes by, i.e. doing some refactoring work of this kind every once in a while, not to disrupt too much the patch flow.
- Arnaldo
Re: [PATCH 04/10] perf machine: Introduce synthesize_threads method out of open coded equivalent
Quoted 11 lines · Arnaldo Carvalho de Melo
Em Mon, Nov 11, 2013 at 09:50:45PM +0100, Ingo Molnar escreveu:
Quoted 9 lines · David Ahern
Quoted 8 lines · Arnaldo Carvalho de Melo
tools/perf/util/machine.c int machine__for_each_thread(struct machine *machine, · line 1405
Quoted 4 lines
tools/perf/util/machine.c +4
-0+if (perf_target__has_task (target)) +return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap); +else if (perf_target__has_cpu (target)) +return perf_event__synthesize_threads (tool, process, machine, data_mmap);Getting kind of long on the line lengths...
Quoted 7 lines
Quoted 2 lines
Maybe we could start losing most of the
perf_prefixes - it's all about perf here, so it does not really add much information, does it?In some cases that is ok, that is why I didn't call it '
perf_machine', just 'machine', in others, like 'perf_event', I thought 'event' would be too general when somebody tries to use this code together with other libraries.
I think 'event' as a variable name is generally unused by libraries, exactly because so much random code uses it.
The only unfortunate C library land grabs I've run into are 'time' [by glibc] and 'y0' [by libm].
What I was suggesting here was more like an event__*() namespace - there shouldn't be any collision with public functions from libraries, public functions are generally either well established, or prefixed with a library name.
These are perf-internal function names, so using event__*() should be fine
- assuming there are no counter arguments.
Thanks,
Ingo
tip-bot for Arnaldo Carvalho de Melo
merge bot[tip:perf/urgent] perf target: Shorten perf_target__ to target__
In reply to Arnaldo Carvalho de Meloperf target: Shorten perf_target__ to target__
Commit-ID: 602ad878d41ef097cc9aa2def7830d5bb27a15d8 Gitweb: http://git.kernel.org/tip/602ad878d41ef097cc9aa2def7830d5bb27a15d8 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 12 Nov 2013 16:46:16 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 12 Nov 2013 16:51:03 -0300
perf target: Shorten perf_target__ to target__
Getting unwieldly long, for this app domain should be descriptive enough and the use of __ to separate the class from the method names should help with avoiding clashes with other code bases.
--- tools/perf/builtin-kvm.c | 6 ++--- tools/perf/builtin-record.c | 14 ++++++------ tools/perf/builtin-stat.c | 21 ++++++++--------- tools/perf/builtin-top.c | 14 ++++++------ tools/perf/builtin-trace.c | 10 ++++---- tools/perf/perf.h | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/util/evlist.c | 12 ++++------ tools/perf/util/evlist.h | 5 ++-- tools/perf/util/evsel.c | 9 ++++---- tools/perf/util/evsel.h | 3 +-- tools/perf/util/machine.c | 6 ++--- tools/perf/util/machine.h | 4 ++-- tools/perf/util/target.c | 54 +++++++++++++++++++++----------------------- tools/perf/util/target.h | 44 +++++++++++++++++------------------- tools/perf/util/top.c | 2 +- 16 files changed, 99 insertions(+), 109 deletions(-)
tools/perf/builtin-kvm.c +3 -3
@@ -1510,13 +1510,13 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,/* * target related setups */ - err =perf_target__validate (&kvm->opts.target); + err =target__validate (&kvm->opts.target);if (err) { -perf_target__strerror (&kvm->opts.target, err, errbuf,BUFSIZ ); +target__strerror (&kvm->opts.target, err, errbuf,BUFSIZ );ui__warning ("%s" , errbuf); } -if (perf_target__none (&kvm->opts.target)) +if (target__none (&kvm->opts.target)) kvm->opts.target.system_wide = true;
tools/perf/builtin-record.c +7 -7
@@ -506,7 +506,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)* (apart from group members) have enable_on_exec=1 set, * so don't spoil it by prematurely enabling them. */ -if (!perf_target__none (&opts->target)) +if (!target__none (&opts->target))perf_evlist__enable (evsel_list);/*
@@ -535,7 +535,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)* die with the process and we wait for that. Thus no need to * disable events in this case. */ -if (done && !disabled && !perf_target__none (&opts->target)) { +if (done && !disabled && !target__none (&opts->target)) {perf_evlist__disable (evsel_list); disabled = true; }
@@ -906,7 +906,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) argc =parse_options (argc, argv, record_options, record_usage,PARSE_OPT_STOP_AT_NON_OPTION ); -if (!argc &&perf_target__none (&rec->opts.target)) +if (!argc &&target__none (&rec->opts.target))usage_with_options (record_usage, record_options);if (nr_cgroups && !rec->opts.target.system_wide) {
@@ -936,17 +936,17 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) goto out_symbol_exit; } - err =perf_target__validate (&rec->opts.target); + err =target__validate (&rec->opts.target);if (err) { -perf_target__strerror (&rec->opts.target, err, errbuf,BUFSIZ ); +target__strerror (&rec->opts.target, err, errbuf,BUFSIZ );ui__warning ("%s" , errbuf); } - err =perf_target__parse_uid (&rec->opts.target); + err =target__parse_uid (&rec->opts.target);if (err) {int saved_errno = errno; -perf_target__strerror (&rec->opts.target, err, errbuf,BUFSIZ ); +target__strerror (&rec->opts.target, err, errbuf,BUFSIZ );ui__error ("%s" , errbuf); err = -saved_errno;
tools/perf/builtin-stat.c +10 -11
@@ -108,7 +108,7 @@ enum {static struct perf_evlist *evsel_list; -static struct perf_target target = { +static struct target target = { .uid =UINT_MAX , };
@@ -294,11 +294,10 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->inherit = !no_inherit; -if (perf_target__has_cpu (&target)) +if (target__has_cpu (&target))return perf_evsel__open_per_cpu (evsel,perf_evsel__cpus (evsel)); -if (!perf_target__has_task (&target) && -perf_evsel__is_group_leader (evsel)) { +if (!target__has_task (&target) &&perf_evsel__is_group_leader (evsel)) { attr->disabled =1 ;if (!initial_delay) attr->enable_on_exec =1 ;
@@ -1236,7 +1235,7 @@ static void print_stat(int argc, const char **argv)fprintf (output,"\'system wide" ); else if (target.cpu_list) fprintf(output, "\'CPU(s) %s", target.cpu_list); - else if (!perf_target__has_task(&target)) { + else if (!target__has_task(&target)) { fprintf(output, "\'%s", argv[0]); for (i = 1; i < argc; i++) fprintf(output, " %s", argv[i]);
@@ -1667,7 +1666,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false; -if (!argc &&perf_target__none (&target)) +if (!argc &&target__none (&target))usage_with_options (stat_usage, options);if (run_count <0 ) {
@@ -1680,8 +1679,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }/* no_aggr, cgroup are for system-wide only */ -if ((aggr_mode !=AGGR_GLOBAL || nr_cgroups) - && !perf_target__has_cpu (&target)) { +if ((aggr_mode !=AGGR_GLOBAL || nr_cgroups) && + !target__has_cpu (&target)) {fprintf (stderr,"both cgroup and no-aggregation " "modes only available in system-wide mode\n" );
@@ -1694,14 +1693,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)if (add_default_attributes ()) goto out; -perf_target__validate (&target); +target__validate (&target);if (perf_evlist__create_maps (evsel_list, &target) <0 ) { -if (perf_target__has_task (&target)) { +if (target__has_task (&target)) {pr_err ("Problems finding threads of monitor\n" );parse_options_usage (stat_usage, options,"p" ,1 );parse_options_usage (NULL , options,"t" ,1 ); - }else if (perf_target__has_cpu (&target)) { + }else if (target__has_cpu (&target)) {perror ("failed to parse CPUs map" );parse_options_usage (stat_usage, options,"C" ,1 );parse_options_usage (NULL , options,"a" ,1 );
tools/perf/builtin-top.c +7 -7
@@ -967,7 +967,7 @@ static int __cmd_top(struct perf_top *top)* XXX 'top' still doesn't start workloads like record, trace, but should, * so leave the check here. */ -if (!perf_target__none (&opts->target)) +if (!target__none (&opts->target))perf_evlist__enable (top->evlist);/* Wait for a minimal set of events before starting the snapshot */
@@ -1053,7 +1053,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) .sym_pcnt_filter = 5, };struct perf_record_opts *opts = &top.record_opts; -struct perf_target *target = &opts->target; +struct target *target = &opts->target;const struct option options[] = { OPT_CALLBACK('e', "event", &top.evlist, "event", "event selector. use 'perf list' to list available events",
@@ -1169,24 +1169,24 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)setup_browser (false); - status =perf_target__validate (target); + status =target__validate (target);if (status) { -perf_target__strerror (target, status, errbuf,BUFSIZ ); +target__strerror (target, status, errbuf,BUFSIZ );ui__warning ("%s" , errbuf); } - status =perf_target__parse_uid (target); + status =target__parse_uid (target);if (status) {int saved_errno = errno; -perf_target__strerror (target, status, errbuf,BUFSIZ ); +target__strerror (target, status, errbuf,BUFSIZ );ui__error ("%s" , errbuf); status = -saved_errno; goto out_delete_evlist; } -if (perf_target__none (target)) +if (target__none (target)) target->system_wide = true;if (perf_evlist__create_maps (top.evlist, target) <0 )
tools/perf/builtin-trace.c +5 -5
@@ -2327,21 +2327,21 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) } } - err =perf_target__validate (&trace.opts.target); + err =target__validate (&trace.opts.target);if (err) { -perf_target__strerror (&trace.opts.target, err, bf,sizeof (bf)); +target__strerror (&trace.opts.target, err, bf,sizeof (bf));fprintf (trace.output,"%s" , bf); goto out_close; } - err =perf_target__parse_uid (&trace.opts.target); + err =target__parse_uid (&trace.opts.target);if (err) { -perf_target__strerror (&trace.opts.target, err, bf,sizeof (bf)); +target__strerror (&trace.opts.target, err, bf,sizeof (bf));fprintf (trace.output,"%s" , bf); goto out_close; } -if (!argc &&perf_target__none (&trace.opts.target)) +if (!argc &&target__none (&trace.opts.target)) trace.opts.target.system_wide = true;if (input_name)
tools/perf/perf.h +1 -1
@@ -248,7 +248,7 @@ enum perf_call_graph_mode { };struct perf_record_opts { -struct perf_target target; +struct target target;int call_graph;bool group;bool inherit_stat;
tools/perf/tests/task-exit.c +1 -1
@@ -28,7 +28,7 @@ int test__task_exit(void)union perf_event *event;struct perf_evsel *evsel;struct perf_evlist *evlist; -struct perf_target target = { +struct target target = { .uid =UINT_MAX , .uses_mmap = true, };
tools/perf/util/evlist.c +5 -7
@@ -811,8 +811,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,return perf_evlist__mmap_per_cpu (evlist, prot, mask); } -int perf_evlist__create_maps (struct perf_evlist *evlist, -struct perf_target *target) +int perf_evlist__create_maps (struct perf_evlist *evlist,struct target *target) { evlist->threads =thread_map__new_str (target->pid, target->tid, target->uid);
@@ -820,9 +819,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist,if (evlist->threads ==NULL )return -1 ; -if (perf_target__has_task (target)) +if (target__has_task (target)) evlist->cpus =cpu_map__dummy_new (); -else if (!perf_target__has_cpu (target) && !target->uses_mmap) +else if (!target__has_cpu (target) && !target->uses_mmap) evlist->cpus =cpu_map__dummy_new ();else evlist->cpus =cpu_map__new (target->cpu_list);
@@ -1031,8 +1030,7 @@ out_err:return err; } -int perf_evlist__prepare_workload (struct perf_evlist *evlist, -struct perf_target *target, +int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct target *target,const char *argv[],bool pipe_output,bool want_signal) {
@@ -1084,7 +1082,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,exit (-1 ); } -if (perf_target__none (target)) +if (target__none (target)) evlist->threads->map[0 ] = evlist->workload.pid;close (child_ready_pipe[1 ]);
tools/perf/util/evlist.h +2 -3
@@ -102,7 +102,7 @@ void perf_evlist__config(struct perf_evlist *evlist,int perf_record_opts__config (struct perf_record_opts *opts);int perf_evlist__prepare_workload (struct perf_evlist *evlist, -struct perf_target *target, +struct target *target,const char *argv[],bool pipe_output,bool want_signal);int perf_evlist__start_workload (struct perf_evlist *evlist);
@@ -134,8 +134,7 @@ static inline void perf_evlist__set_maps(struct perf_evlist *evlist, evlist->threads = threads; } -int perf_evlist__create_maps (struct perf_evlist *evlist, -struct perf_target *target); +int perf_evlist__create_maps (struct perf_evlist *evlist,struct target *target);void perf_evlist__delete_maps (struct perf_evlist *evlist);int perf_evlist__apply_filters (struct perf_evlist *evlist);
tools/perf/util/evsel.c +4 -5
@@ -645,7 +645,7 @@ void perf_evsel__config(struct perf_evsel *evsel, } } -if (perf_target__has_cpu (&opts->target)) +if (target__has_cpu (&opts->target))perf_evsel__set_sample_bit (evsel,CPU );if (opts->period)
@@ -653,7 +653,7 @@ void perf_evsel__config(struct perf_evsel *evsel,if (!perf_missing_features.sample_id_all && (opts->sample_time || !opts->no_inherit || -perf_target__has_cpu (&opts->target))) +target__has_cpu (&opts->target)))perf_evsel__set_sample_bit (evsel,TIME );if (opts->raw_samples) {
@@ -696,7 +696,7 @@ void perf_evsel__config(struct perf_evsel *evsel,* Setting enable_on_exec for independent events and * group leaders for traced executed by perf. */ -if (perf_target__none (&opts->target) &&perf_evsel__is_group_leader (evsel)) +if (target__none (&opts->target) &&perf_evsel__is_group_leader (evsel)) attr->enable_on_exec =1 ; }
@@ -2006,8 +2006,7 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,return false; } -int perf_evsel__open_strerror (struct perf_evsel *evsel, -struct perf_target *target, +int perf_evsel__open_strerror (struct perf_evsel *evsel,struct target *target,int err,char *msg,size_t size) {switch (err) {
tools/perf/util/evsel.h +1 -2
@@ -318,8 +318,7 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,bool perf_evsel__fallback (struct perf_evsel *evsel,int err,char *msg,size_t msgsize); -int perf_evsel__open_strerror (struct perf_evsel *evsel, -struct perf_target *target, +int perf_evsel__open_strerror (struct perf_evsel *evsel,struct target *target,int err,char *msg,size_t size);static inline int perf_evsel__group_idx (struct perf_evsel *evsel)
tools/perf/util/machine.c +3 -3
@@ -1396,12 +1396,12 @@ int machine__for_each_thread(struct machine *machine, }int __machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, -struct perf_target *target,struct thread_map *threads, +struct target *target,struct thread_map *threads,perf_event__handler_t process,bool data_mmap) { -if (perf_target__has_task (target)) +if (target__has_task (target))return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap); -else if (perf_target__has_cpu (target)) +else if (target__has_cpu (target))return perf_event__synthesize_threads (tool, process, machine, data_mmap);/* command specified */ return 0 ;
tools/perf/util/machine.h +2 -2
@@ -180,10 +180,10 @@ int machine__for_each_thread(struct machine *machine, void *priv);int __machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, -struct perf_target *target,struct thread_map *threads, +struct target *target,struct thread_map *threads,perf_event__handler_t process,bool data_mmap);static inline -int machine__synthesize_threads (struct machine *machine,struct perf_target *target, +int machine__synthesize_threads (struct machine *machine,struct target *target,struct thread_map *threads,bool data_mmap) { return __machine__synthesize_threads(machine, NULL, target, threads,
tools/perf/util/target.c +26 -28
134 lines not on this page · raw message
tools/perf/util/target.h +21 -23
78 lines not on this page · raw message
tools/perf/util/top.c +1 -1
@@ -27,7 +27,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)float ksamples_per_sec;float esamples_percent;struct perf_record_opts *opts = &top->record_opts; -struct perf_target *target = &opts->target; +struct target *target = &opts->target;size_t ret =0 ;if (top->samples) {
tip-bot for Arnaldo Carvalho de Melo
merge bot[tip:perf/core] perf tools: Rename 'perf_record_opts' to ' record_opts
In reply to Arnaldo Carvalho de Meloperf tools: Rename 'perf_record_opts' to 'record_opts
Commit-ID: b40067964f09a5b4d9e133dec225007ee0a13050 Gitweb: http://git.kernel.org/tip/b40067964f09a5b4d9e133dec225007ee0a13050 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Thu, 19 Dec 2013 14:43:45 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 19 Dec 2013 14:43:45 -0300
perf tools: Rename 'perf_record_opts' to 'record_opts
Reduce typing, functions use class__method convention, so unlikely to clash with other libraries.
This actually was discussed in the "Link:" referenced message below.
--- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-record.c | 18 +++++++++--------- tools/perf/builtin-top.c | 8 ++++---- tools/perf/builtin-trace.c | 2 +- tools/perf/perf.h | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/open-syscall-tp-fields.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/util/callchain.h | 2 +- tools/perf/util/evlist.h | 7 +++---- tools/perf/util/evsel.c | 3 +-- tools/perf/util/evsel.h | 4 ++-- tools/perf/util/record.c | 9 ++++----- tools/perf/util/top.c | 2 +- tools/perf/util/top.h | 2 +- 17 files changed, 34 insertions(+), 37 deletions(-)
tools/perf/builtin-kvm.c +1 -1
@@ -89,7 +89,7 @@ struct exit_reasons_table {struct perf_kvm_stat {struct perf_tool tool; -struct perf_record_opts opts; +struct record_opts opts;struct perf_evlist *evlist;struct perf_session *session;
tools/perf/builtin-record.c +9 -9
@@ -64,7 +64,7 @@ static void __handle_on_exit_funcs(void)struct record {struct perf_tool tool; -struct perf_record_opts opts; +struct record_opts opts;u64 bytes_written;struct perf_data_file file;struct perf_evlist *evlist;
@@ -178,7 +178,7 @@ static int record__open(struct record *rec)struct perf_evsel *pos;struct perf_evlist *evlist = rec->evlist;struct perf_session *session = rec->session; -struct perf_record_opts *opts = &rec->opts; +struct record_opts *opts = &rec->opts;int rc =0 ;perf_evlist__config (evlist, opts);
@@ -348,7 +348,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)const bool forks = argc >0 ;struct machine *machine;struct perf_tool *tool = &rec->tool; -struct perf_record_opts *opts = &rec->opts; +struct record_opts *opts = &rec->opts;struct perf_evlist *evsel_list = rec->evlist;struct perf_data_file *file = &rec->file;struct perf_session *session;
@@ -657,7 +657,7 @@ static int get_stack_size(char *str, unsigned long *_size) }#endif /* HAVE_LIBUNWIND_SUPPORT */ -int record_parse_callchain (const char *arg,struct perf_record_opts *opts) +int record_parse_callchain (const char *arg,struct record_opts *opts) {char *tok, *name, *saveptr =NULL ;char *buf;
@@ -713,7 +713,7 @@ int record_parse_callchain(const char *arg, struct perf_record_opts *opts)return ret; } -static void callchain_debug (struct perf_record_opts *opts) +static void callchain_debug (struct record_opts *opts) {pr_debug ("callchain: type %d\n" , opts->call_graph);
@@ -726,7 +726,7 @@ int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset) { -struct perf_record_opts *opts = opt->value; +struct record_opts *opts = opt->value;int ret;/* --no-call-graph */
@@ -747,7 +747,7 @@ int record_callchain_opt(const struct option *opt, const char *arg __maybe_unused, int unset __maybe_unused) { -struct perf_record_opts *opts = opt->value; +struct record_opts *opts = opt->value;if (opts->call_graph ==CALLCHAIN_NONE ) opts->call_graph =CALLCHAIN_FP ;
@@ -796,7 +796,7 @@ const char record_callchain_help[] = CALLCHAIN_HELP "fp";/* * XXX Will stay a global variable till we fix builtin-script.c to stop messing * with it and switch to use the library functions in perf_evlist that came -* from builtin-record.c, i.e. use perf_record_opts, +* from builtin-record.c, i.e. use record_opts, * perf_evlist__prepare_workload, etc instead of fork+exec'in 'perf record', * using pipes, etc. */
@@ -944,7 +944,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (perf_evlist__create_maps (evsel_list, &rec->opts.target) <0 )usage_with_options (record_usage, record_options); -if (perf_record_opts__config (&rec->opts)) { +if (record_opts__config (&rec->opts)) { err = -EINVAL ; goto out_free_fd; }
tools/perf/builtin-top.c +4 -4
@@ -854,7 +854,7 @@ static int perf_top__start_counters(struct perf_top *top)char msg[512 ];struct perf_evsel *counter;struct perf_evlist *evlist = top->evlist; -struct perf_record_opts *opts = &top->record_opts; +struct record_opts *opts = &top->record_opts;perf_evlist__config (evlist, opts);
@@ -906,7 +906,7 @@ static int perf_top__setup_sample_type(struct perf_top *top __maybe_unused)static int __cmd_top (struct perf_top *top) { -struct perf_record_opts *opts = &top->record_opts; +struct record_opts *opts = &top->record_opts;pthread_t thread;int ret;
@@ -1028,7 +1028,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) .max_stack = PERF_MAX_STACK_DEPTH, .sym_pcnt_filter = 5, }; -struct perf_record_opts *opts = &top.record_opts; +struct record_opts *opts = &top.record_opts;struct target *target = &opts->target;const struct option options[] = { OPT_CALLBACK('e', "event", &top.evlist, "event",
@@ -1179,7 +1179,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)if (top.delay_secs <1 ) top.delay_secs =1 ; -if (perf_record_opts__config (opts)) { +if (record_opts__config (opts)) { status = -EINVAL ; goto out_delete_maps; }
tools/perf/builtin-trace.c +1 -1
@@ -1159,7 +1159,7 @@ struct trace {int max;struct syscall *table; } syscalls; -struct perf_record_opts opts; +struct record_opts opts;struct machine *host;u64 base_time;bool full_time;
tools/perf/perf.h +1 -1
@@ -247,7 +247,7 @@ enum perf_call_graph_mode {CALLCHAIN_DWARF }; -struct perf_record_opts { +struct record_opts {struct target target;int call_graph;bool group;
tools/perf/tests/code-reading.c +1 -1
@@ -391,7 +391,7 @@ static int do_test_code_reading(bool try_kcore)struct machines machines;struct machine *machine;struct thread *thread; -struct perf_record_opts opts = { +struct record_opts opts = { .mmap_pages =UINT_MAX , .user_freq =UINT_MAX , .user_interval =ULLONG_MAX ,
tools/perf/tests/keep-tracking.c +1 -1
@@ -51,7 +51,7 @@ static int find_comm(struct perf_evlist *evlist, const char *comm)*/ int test__keep_tracking (void ) { -struct perf_record_opts opts = { +struct record_opts opts = { .mmap_pages =UINT_MAX , .user_freq =UINT_MAX , .user_interval =ULLONG_MAX ,
tools/perf/tests/open-syscall-tp-fields.c +1 -1
@@ -6,7 +6,7 @@int test__syscall_open_tp_fields (void ) { -struct perf_record_opts opts = { +struct record_opts opts = { .target = { .uid =UINT_MAX , .uses_mmap = true,
tools/perf/tests/perf-record.c +1 -1
@@ -34,7 +34,7 @@ realloc:int test__PERF_RECORD (void ) { -struct perf_record_opts opts = { +struct record_opts opts = { .target = { .uid =UINT_MAX , .uses_mmap = true,
tools/perf/tests/perf-time-to-tsc.c +1 -1
@@ -46,7 +46,7 @@ static u64 rdtsc(void)*/ int test__perf_time_to_tsc (void ) { -struct perf_record_opts opts = { +struct record_opts opts = { .mmap_pages =UINT_MAX , .user_freq =UINT_MAX , .user_interval =ULLONG_MAX ,
tools/perf/util/callchain.h +1 -1
@@ -146,7 +146,7 @@ static inline void callchain_cursor_advance(struct callchain_cursor *cursor)struct option ; -int record_parse_callchain (const char *arg,struct perf_record_opts *opts); +int record_parse_callchain (const char *arg,struct record_opts *opts);int record_parse_callchain_opt (const struct option *opt,const char *arg,int unset);int record_callchain_opt (const struct option *opt,const char *arg,int unset);
tools/perf/util/evlist.h +3 -4
@@ -12,7 +12,7 @@struct pollfd ;struct thread_map ;struct cpu_map ; -struct perf_record_opts ; +struct record_opts ;#define PERF_EVLIST__HLIST_BITS 8#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
@@ -97,9 +97,8 @@ void perf_evlist__close(struct perf_evlist *evlist);void perf_evlist__set_id_pos (struct perf_evlist *evlist);bool perf_can_sample_identifier (void ); -void perf_evlist__config (struct perf_evlist *evlist, -struct perf_record_opts *opts); -int perf_record_opts__config (struct perf_record_opts *opts); +void perf_evlist__config (struct perf_evlist *evlist,struct record_opts *opts); +int record_opts__config (struct record_opts *opts); int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *target,
tools/perf/util/evsel.c +1 -2
@@ -528,8 +528,7 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)* enable/disable events specifically, as there's no * initial traced exec call. */ -void perf_evsel__config (struct perf_evsel *evsel, -struct perf_record_opts *opts) +void perf_evsel__config (struct perf_evsel *evsel,struct record_opts *opts) {struct perf_evsel *leader = evsel->leader;struct perf_event_attr *attr = &evsel->attr;
tools/perf/util/evsel.h +2 -2
@@ -96,7 +96,7 @@ struct perf_evsel {struct cpu_map ;struct thread_map ;struct perf_evlist ; -struct perf_record_opts ; +struct record_opts ;struct perf_evsel *perf_evsel__new_idx (struct perf_event_attr *attr,int idx);
@@ -120,7 +120,7 @@ void perf_evsel__exit(struct perf_evsel *evsel);void perf_evsel__delete (struct perf_evsel *evsel);void perf_evsel__config (struct perf_evsel *evsel, -struct perf_record_opts *opts); +struct record_opts *opts);int __perf_evsel__sample_size (u64 sample_type);void perf_evsel__calc_id_pos (struct perf_evsel *evsel);
tools/perf/util/record.c +4 -5
@@ -74,8 +74,7 @@ bool perf_can_sample_identifier(void)return perf_probe_api (perf_probe_sample_identifier); } -void perf_evlist__config (struct perf_evlist *evlist, -struct perf_record_opts *opts) +void perf_evlist__config (struct perf_evlist *evlist,struct record_opts *opts) {struct perf_evsel *evsel;bool use_sample_identifier = false;
@@ -123,7 +122,7 @@ static int get_max_rate(unsigned int *rate)return filename__read_int (path, (int *) rate); } -static int perf_record_opts__config_freq (struct perf_record_opts *opts) +static int record_opts__config_freq (struct record_opts *opts) {bool user_freq = opts->user_freq !=UINT_MAX ;unsigned int max_rate;
@@ -173,9 +172,9 @@ static int perf_record_opts__config_freq(struct perf_record_opts *opts)return 0 ; } -int perf_record_opts__config (struct perf_record_opts *opts) +int record_opts__config (struct record_opts *opts) { -return perf_record_opts__config_freq (opts); +return record_opts__config_freq (opts); }bool perf_evlist__can_select_event (struct perf_evlist *evlist,const char *str)
tools/perf/util/top.c +1 -1
@@ -26,7 +26,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)float samples_per_sec;float ksamples_per_sec;float esamples_percent; -struct perf_record_opts *opts = &top->record_opts; +struct record_opts *opts = &top->record_opts;struct target *target = &opts->target;size_t ret =0 ;
tools/perf/util/top.h +1 -1
@@ -14,7 +14,7 @@ struct perf_session;struct perf_top {struct perf_tool tool;struct perf_evlist *evlist; -struct perf_record_opts record_opts; +struct record_opts record_opts;/* * Symbols will be added here in perf_event__process_sample and will * get out after decayed.
tip-bot for Arnaldo Carvalho de Melo
merge bot[tip:perf/core] perf report: Rename 'perf_report' to 'report'
In reply to Arnaldo Carvalho de Meloperf report: Rename 'perf_report' to 'report'
Commit-ID: 28b21393fa0472501b5a2a85a0b008b4e3dc154c Gitweb: http://git.kernel.org/tip/28b21393fa0472501b5a2a85a0b008b4e3dc154c Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Thu, 19 Dec 2013 14:53:53 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 19 Dec 2013 16:19:01 -0300
perf report: Rename 'perf_report' to 'report'
Reduce typing, functions use class__method convention, so unlikely to clash with other libraries.
This actually was discussed in the "Link:" referenced message below.
--- tools/perf/builtin-report.c | 73 +++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 42 deletions(-)
tools/perf/builtin-report.c +31 -42
@@ -39,7 +39,7 @@#include <dlfcn.h> #include <linux/bitmap.h> -struct perf_report { +struct report {struct perf_tool tool;struct perf_session *session;bool force, use_tui, use_gtk, use_stdio;
@@ -60,14 +60,14 @@ struct perf_report {DECLARE_BITMAP (cpu_bitmap,MAX_NR_CPUS ); }; -static int perf_report_config (const char *var,const char *value,void *cb) +static int report__config (const char *var,const char *value,void *cb) {if (!strcmp (var,"report.group" )) { symbol_conf.event_group =perf_config_bool (var, value);return 0 ; }if (!strcmp (var,"report.percent-limit" )) { -struct perf_report *rep = cb; +struct report *rep = cb; rep->min_percent =strtof (value,NULL );return 0 ; }
@@ -75,7 +75,7 @@ static int perf_report_config(const char *var, const char *value, void *cb)return perf_default_config (var, value, cb); } -static int report__resolve_callchain (struct perf_report *rep,struct symbol **parent, +static int report__resolve_callchain (struct report *rep,struct symbol **parent,struct perf_evsel *evsel,struct addr_location *al,struct perf_sample *sample,struct machine *machine) {
@@ -93,14 +93,11 @@ static int hist_entry__append_callchain(struct hist_entry *he, struct perf_samplreturn callchain_append (he->callchain, &callchain_cursor, sample->period); } -static int perf_report__add_mem_hist_entry (struct perf_tool *tool, -struct addr_location *al, -struct perf_sample *sample, -struct perf_evsel *evsel, -struct machine *machine, -union perf_event *event) +static int report__add_mem_hist_entry (struct perf_tool *tool,struct addr_location *al, +struct perf_sample *sample,struct perf_evsel *evsel, +struct machine *machine,union perf_event *event) { - struct perf_report *rep = container_of(tool, struct perf_report, tool); + struct report *rep = container_of(tool, struct report, tool);struct symbol *parent =NULL ;u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;struct hist_entry *he;
@@ -150,13 +147,11 @@ out:return err; } -static int perf_report__add_branch_hist_entry (struct perf_tool *tool, -struct addr_location *al, -struct perf_sample *sample, -struct perf_evsel *evsel, -struct machine *machine) +static int report__add_branch_hist_entry (struct perf_tool *tool,struct addr_location *al, +struct perf_sample *sample,struct perf_evsel *evsel, +struct machine *machine) { - struct perf_report *rep = container_of(tool, struct perf_report, tool); + struct report *rep = container_of(tool, struct report, tool);struct symbol *parent =NULL ;unsigned i;struct hist_entry *he;
@@ -208,13 +203,11 @@ out:return err; } -static int perf_evsel__add_hist_entry (struct perf_tool *tool, -struct perf_evsel *evsel, -struct addr_location *al, -struct perf_sample *sample, -struct machine *machine) +static int report__add_hist_entry (struct perf_tool *tool,struct perf_evsel *evsel, +struct addr_location *al,struct perf_sample *sample, +struct machine *machine) { - struct perf_report *rep = container_of(tool, struct perf_report, tool); + struct report *rep = container_of(tool, struct report, tool);struct symbol *parent =NULL ;struct hist_entry *he;int err =report__resolve_callchain (rep, &parent, evsel, al, sample, machine);
@@ -246,7 +239,7 @@ static int process_sample_event(struct perf_tool *tool,struct perf_evsel *evsel, struct machine *machine) { - struct perf_report *rep = container_of(tool, struct perf_report, tool); + struct report *rep = container_of(tool, struct report, tool);struct addr_location al;int ret;
@@ -263,21 +256,18 @@ static int process_sample_event(struct perf_tool *tool,return 0 ;if (sort__mode ==SORT_MODE__BRANCH ) { - ret =perf_report__add_branch_hist_entry (tool, &al, sample, - evsel, machine); + ret =report__add_branch_hist_entry (tool, &al, sample, evsel, machine);if (ret <0 )pr_debug ("problem adding lbr entry, skipping event\n" ); }else if (rep->mem_mode ==1 ) { - ret =perf_report__add_mem_hist_entry (tool, &al, sample, - evsel, machine, event); + ret =report__add_mem_hist_entry (tool, &al, sample, evsel, machine, event);if (ret <0 )pr_debug ("problem adding mem entry, skipping event\n" ); }else {if (al.map !=NULL ) al.map->dso->hit =1 ; - ret =perf_evsel__add_hist_entry (tool, evsel, &al, sample, - machine); + ret =report__add_hist_entry (tool, evsel, &al, sample, machine);if (ret <0 )pr_debug ("problem incrementing symbol period, skipping event\n" ); }
@@ -290,7 +280,7 @@ static int process_read_event(struct perf_tool *tool,struct perf_evsel *evsel, struct machine *machine __maybe_unused) { - struct perf_report *rep = container_of(tool, struct perf_report, tool); + struct report *rep = container_of(tool, struct report, tool);if (rep->show_threads) {const char *name = evsel ?perf_evsel__name (evsel) :"unknown" ;
@@ -309,7 +299,7 @@ static int process_read_event(struct perf_tool *tool, }/* For pipe mode, sample_type is not currently set */ -static int perf_report__setup_sample_type (struct perf_report *rep) +static int report__setup_sample_type (struct report *rep) {struct perf_session *session = rep->session;u64 sample_type =perf_evlist__combined_sample_type (session->evlist);
@@ -354,8 +344,7 @@ static void sig_handler(int sig __maybe_unused) session_done =1 ; } -static size_t hists__fprintf_nr_sample_events (struct perf_report *rep, -struct hists *hists, +static size_t hists__fprintf_nr_sample_events (struct hists *hists,struct report *rep,const char *evname,FILE *fp) {size_t ret;
@@ -392,7 +381,7 @@ static size_t hists__fprintf_nr_sample_events(struct perf_report *rep, }static int perf_evlist__tty_browse_hists (struct perf_evlist *evlist, -struct perf_report *rep, +struct report *rep,const char *help) {struct perf_evsel *pos;
@@ -405,7 +394,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, !perf_evsel__is_group_leader(pos))continue ; -hists__fprintf_nr_sample_events (rep, hists, evname, stdout); +hists__fprintf_nr_sample_events (hists, rep, evname, stdout);hists__fprintf (hists, true,0 ,0 , rep->min_percent, stdout);fprintf (stdout,"\n\n" ); }
@@ -425,7 +414,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,return 0 ; } -static int __cmd_report (struct perf_report *rep) +static int __cmd_report (struct report *rep) {int ret = -EINVAL ;u64 nr_samples;
@@ -449,7 +438,7 @@ static int __cmd_report(struct perf_report *rep)if (rep->show_threads)perf_read_values_init (&rep->show_threads_values); - ret =perf_report__setup_sample_type (rep); + ret =report__setup_sample_type (rep);if (ret)return ret;
@@ -568,7 +557,7 @@ static int __cmd_report(struct perf_report *rep)static int parse_callchain_opt (const struct option *opt,const char *arg,int unset) { -struct perf_report *rep = (struct perf_report *)opt->value; +struct report *rep = (struct report *)opt->value;char *tok, *tok2;char *endptr;
@@ -688,7 +677,7 @@ static int parse_percent_limit(const struct option *opt, const char *str, int unset __maybe_unused) { - struct perf_report *rep = opt->value; + struct report *rep = opt->value; rep->min_percent =strtof (str,NULL );return 0 ;
@@ -706,7 +695,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)"perf report [<options>]" ,NULL }; -struct perf_report report = { +struct report report = { .tool = { .sample = process_sample_event, .mmap = perf_event__process_mmap,
@@ -822,7 +811,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) .mode = PERF_DATA_MODE_READ, }; -perf_config (perf_report_config, &report); +perf_config (report__config, &report); argc =parse_options (argc, argv, options, report_usage,0 );
PATCH 5/10 perf machine: Simplify synthesize_threads method
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Several tools (top, kvm) don't need to be called back to process each of the syntheiszed records, instead relying on the machine__process_event function to change the per machine data structures that represent threads and mmaps, so provide a way to ask for this common idiom.
--- tools/perf/builtin-kvm.c | 5 ++--- tools/perf/builtin-record.c | 4 ++-- tools/perf/builtin-top.c | 5 ++--- tools/perf/builtin-trace.c | 4 ++-- tools/perf/util/machine.c | 6 +++--- tools/perf/util/machine.h | 14 +++++++++++--- 6 files changed, 22 insertions(+), 16 deletions(-)
tools/perf/builtin-kvm.c +2 -3
@@ -1544,9 +1544,8 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, } kvm->session->evlist = kvm->evlist;perf_session__set_id_hdr_size (kvm->session); -machine__synthesize_threads (&kvm->session->machines.host, &kvm->tool, - &kvm->opts.target, kvm->evlist->threads, - perf_event__process, false); +machine__synthesize_threads (&kvm->session->machines.host, &kvm->opts.target, + kvm->evlist->threads, false); err =kvm_live_open_events (kvm);if (err) goto out;
tools/perf/builtin-record.c +2 -2
@@ -480,8 +480,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) perf_event__synthesize_guest_os, tool); } - err =machine__synthesize_threads (machine, tool, &opts->target, evsel_list->threads, - process_synthesized_event, opts->sample_address); + err =__machine__synthesize_threads (machine, tool, &opts->target, evsel_list->threads, + process_synthesized_event, opts->sample_address);if (err !=0 ) goto out_delete_session;
tools/perf/builtin-top.c +2 -3
@@ -950,9 +950,8 @@ static int __cmd_top(struct perf_top *top)if (ret) goto out_delete; -machine__synthesize_threads (&top->session->machines.host, &top->tool, - &opts->target, top->evlist->threads, - perf_event__process, false); +machine__synthesize_threads (&top->session->machines.host, &opts->target, + top->evlist->threads, false); ret =perf_top__start_counters (top);if (ret) goto out_delete;
tools/perf/builtin-trace.c +2 -2
@@ -1340,8 +1340,8 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)if (trace->host ==NULL )return -ENOMEM ; - err =machine__synthesize_threads (trace->host, &trace->tool, &trace->opts.target, - evlist->threads, trace__tool_process, false); + err =__machine__synthesize_threads (trace->host, &trace->tool, &trace->opts.target, + evlist->threads, trace__tool_process, false);if (err)symbol__exit ();
tools/perf/util/machine.c +3 -3
@@ -1395,9 +1395,9 @@ int machine__for_each_thread(struct machine *machine,return rc; } -int machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, -struct perf_target *target,struct thread_map *threads, -perf_event__handler_t process,bool data_mmap) +int __machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, +struct perf_target *target,struct thread_map *threads, +perf_event__handler_t process,bool data_mmap) {if (perf_target__has_task (target))return perf_event__synthesize_thread_map (tool, threads, process, machine, data_mmap);
tools/perf/util/machine.h +11 -3
@@ -179,7 +179,15 @@ int machine__for_each_thread(struct machine *machine,int (*fn)(struct thread *thread,void *p), void *priv); -int machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, -struct perf_target *target,struct thread_map *threads, -perf_event__handler_t process,bool data_mmap); +int __machine__synthesize_threads (struct machine *machine,struct perf_tool *tool, +struct perf_target *target,struct thread_map *threads, +perf_event__handler_t process,bool data_mmap); +static inline +int machine__synthesize_threads (struct machine *machine,struct perf_target *target, +struct thread_map *threads,bool data_mmap) +{ +return __machine__synthesize_threads (machine,NULL , target, threads, + perf_event__process, data_mmap); +} +#endif /* __PERF_MACHINE_H */
Signature · 1 line
1.8.1.4
PATCH 6/10 perf tools: Prevent condition that all sort keys are elided
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
If given sort keys are all elided there'll be no output except for the overhead column - actually the TUI shows a noisy output. In this case it'd be better to show up the sort keys rather than elide.
Before:
$ perf report -s comm -c perf
(...)
# Overhead
# ........
#
100.00%After:
$ perf report -s comm -c perf
(...)
# Overhead Command
# ........ .......
#
100.00% perf--- tools/perf/util/sort.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
tools/perf/util/sort.c +13 -0
@@ -1137,6 +1137,8 @@ static void sort_entry__setup_elide(struct sort_entry *se,void sort__setup_elide (FILE *output) { +struct sort_entry *se; +sort_entry__setup_elide (&sort_dso, symbol_conf.dso_list,"dso" , output); sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list,
@@ -1172,4 +1174,15 @@ void sort__setup_elide(FILE *output) "snoop", output); } +/* +* It makes no sense to elide all of sort entries. +* Just revert them to show up again. +*/ +list_for_each_entry (se, &hist_entry__sort_list, list) { +if (!se->elide) +return ; + } + +list_for_each_entry (se, &hist_entry__sort_list, list) + se->elide = false; }
Signature · 1 line
1.8.1.4
PATCH 7/10 perf record: Use correct return type for write()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
write() returns a 'ssize_t' not an 'int'.
--- tools/perf/builtin-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
@@ -81,7 +81,7 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)struct perf_data_file *file = &rec->file;while (size) { -int ret =write (file->fd, buf, size); +ssize_t ret =write (file->fd, buf, size);if (ret <0 ) {pr_err ("failed to write perf data, error: %m\n" );
Signature · 1 line
1.8.1.4
PATCH 8/10 perf record: Move existing write_output into helper function
In reply to Arnaldo Carvalho de MeloFrom: David Ahern <[email protected]>
Code move only; no logic changes. In preparation for the mmap based output option in the next patch.
--- tools/perf/builtin-record.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +6 -1
@@ -76,7 +76,7 @@ struct perf_record {long samples; }; -static int write_output (struct perf_record *rec,void *buf,size_t size) +static int do_write_output (struct perf_record *rec,void *buf,size_t size) {struct perf_data_file *file = &rec->file;
@@ -97,6 +97,11 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)return 0 ; } +static int write_output (struct perf_record *rec,void *buf,size_t size) +{ +return do_write_output (rec, buf, size); +} + static int process_synthesized_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused,
Signature · 1 line
1.8.1.4
PATCH 9/10 perf tests: Check return of perf_evlist__open sw clock event period test
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We were not checking if we successfully opened the counters, i.e. if sys_perf_event_open worked, when it doesn't in this test, we were continuing anyway and then segfaulting when trying to access the file descriptor array, that at that point had been freed in perf_evlist__open error path:
[root@ssdandy ~]# perf test -v 19
19: Test software clock events have valid period values :
--- start ---
Segmentation fault (core dumped)
[root@ssdandy ~]#
Do the check and bail out instead.
--- tools/perf/tests/sw-clock.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/sw-clock.c +5 -1
@@ -57,7 +57,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) goto out_delete_maps; } -perf_evlist__open (evlist); +if (perf_evlist__open (evlist)) { + err = -errno; +pr_debug ("Couldn't open evlist: %s\n" ,strerror (errno)); + goto out_delete_maps; + } err =perf_evlist__mmap (evlist,128 , true);if (err <0 ) {
Signature · 1 line
1.8.1.4
PATCH 10/10 perf tests: Use lower sample_freq in sw clock event period test
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We were using it at 10 kHz, which doesn't work in machines where somehow the max freq was auto reduced by the kernel:
[root@ssdandy ~]# perf test 19
19: Test software clock events have valid period values : FAILED!
[root@ssdandy ~]# perf test -v 19
19: Test software clock events have valid period values :
--- start ---
Couldn't open evlist: Invalid argument
---- end ----
Test software clock events have valid period values: FAILED! [root@ssdandy ~]#
[root@ssdandy ~]# cat /proc/sys/kernel/perf_event_max_sample_rate 7000
Reducing it to 500 Hz should be good enough for this test and also shouldn't affect what it is testing.
But warn the user if it fails, informing the knob and the freq tried.
--- tools/perf/tests/sw-clock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/tests/sw-clock.c +5 -2
@@ -34,7 +34,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) .freq = 1, }; - attr.sample_freq =10000 ; + attr.sample_freq =500 ; evlist =perf_evlist__new ();if (evlist ==NULL ) {
@@ -58,8 +58,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) }if (perf_evlist__open (evlist)) { +const char *knob ="/proc/sys/kernel/perf_event_max_sample_rate" ; + err = -errno; -pr_debug ("Couldn't open evlist: %s\n" ,strerror (errno)); +pr_debug ("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64" in this test.\n" , +strerror (errno), knob, (u64 )attr.sample_freq); goto out_delete_maps; }
Signature · 1 line
1.8.1.4
Re: [PATCH 10/10] perf tests: Use lower sample_freq in sw clock event period test
tools/perf/tests/sw-clock.c static int __test__sw_clock_freq(enum perf_sw_ids clock_id) · line 67
Quoted 12 lines · Arnaldo Carvalho de Melo
tools/perf/tests/sw-clock.c +4
-1@@ -58,8 +58,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) }if (perf_evlist__open (evlist)) { +const char *knob ="/proc/sys/kernel/perf_event_max_sample_rate" ; + err = -errno; -pr_debug ("Couldn't open evlist: %s\n" ,strerror (errno)); +pr_debug ("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64" in this test.\n" , +strerror (errno), knob, (u64 )attr.sample_freq); goto out_delete_maps; }
Jiri had a patch to drop the sample rate to max. Perhaps re-use that here?
Adrian Hunter
reviewerRe: [PATCH 10/10] perf tests: Use lower sample_freq in sw clock event period test
In reply to Arnaldo Carvalho de MeloQuoted 15 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
We were using it at 10 kHz, which doesn't work in machines where somehow the max freq was auto reduced by the kernel:
[root@ssdandy ~]# perf test 19
19: Test software clock events have valid period values : FAILED!
[root@ssdandy ~]# perf test -v 19
19: Test software clock events have valid period values :
--- start ---
Couldn't open evlist: Invalid argument
---- end ----
Test software clock events have valid period values: FAILED! [root@ssdandy ~]#
Quoted 7 lines
[root@ssdandy ~]# cat
/proc/sys/kernel/perf_event_max_sample_rate7000Reducing it to 500 Hz should be good enough for this test and also shouldn't affect what it is testing.
But warn the user if it fails, informing the knob and the freq tried.
Doesn't work for me:
./perf test -v 19
19: Test software clock events have valid period values :
--- start ---
mmap size 528384B
mmap size 528384B
All (0) samples have period value of 1!
---- end ----
Test software clock events have valid period values: FAILED!
But this fixes it:
tools/perf/tests/sw-clock.c +1 -1
@@ -9,7 +9,7 @@#include "util/cpumap.h" #include "util/thread_map.h" -#define NR_LOOPS 1000000 +#define NR_LOOPS 10000000/* * This test will open software clock events (cpu-clock, task-clock)
Quoted 42 lines
Cc Adrian Hunter <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Jiri Olsa <[email protected]>Cc Mike Galbraith <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Stephane Eranian <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/tests/sw-clock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/perf/tests/sw-clock.c +5
-2@@ -34,7 +34,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) .freq = 1, }; - attr.sample_freq =10000 ; + attr.sample_freq =500 ; evlist =perf_evlist__new ();if (evlist ==NULL ) {@@ -58,8 +58,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) }if (perf_evlist__open (evlist)) { +const char *knob ="/proc/sys/kernel/perf_event_max_sample_rate" ; + err = -errno; -pr_debug ("Couldn't open evlist: %s\n" ,strerror (errno)); +pr_debug ("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64" in this test.\n" , +strerror (errno), knob, (u64 )attr.sample_freq); goto out_delete_maps; }
Namhyung Kim
maintainerRe: [PATCH 10/10] perf tests: Use lower sample_freq in sw clock event period test
Hi Adrian,
Quoted 42 lines · Adrian Hunter
Quoted 15 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
We were using it at 10 kHz, which doesn't work in machines where somehow the max freq was auto reduced by the kernel:
[root@ssdandy ~]# perf test 19
19: Test software clock events have valid period values : FAILED!
[root@ssdandy ~]# perf test -v 19
19: Test software clock events have valid period values :
--- start ---
Couldn't open evlist: Invalid argument
---- end ----
Test software clock events have valid period values: FAILED! [root@ssdandy ~]#Quoted 7 lines
[root@ssdandy ~]# cat
/proc/sys/kernel/perf_event_max_sample_rate7000Reducing it to 500 Hz should be good enough for this test and also shouldn't affect what it is testing.
But warn the user if it fails, informing the knob and the freq tried.
Doesn't work for me:
./perf test -v 19
19: Test software clock events have valid period values :
--- start ---
mmap size 528384B
mmap size 528384B
All (0) samples have period value of 1!
---- end ----
Test software clock events have valid period values: FAILED!But this fixes it:
tools/perf/tests/sw-clock.c +0
-0
tools/perf/tests/sw-clock.c line 12
Quoted 5 lines
tools/perf/tests/sw-clock.c +1
-1@@ -9,7 +9,7 @@#include "util/cpumap.h" #include "util/thread_map.h" -#define NR_LOOPS 1000000 +#define NR_LOOPS 10000000
Or else, why not using the max_sample_rate as the freq value?
Thanks,
Namhyung
Re: [PATCH 10/10] perf tests: Use lower sample_freq in sw clock event period test
Em Tue, Nov 12, 2013 at 05:40:39PM +0900, Namhyung Kim escreveu:
Quoted 48 lines
Hi Adrian,
Quoted 45 lines · Adrian Hunter
Quoted 15 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
We were using it at 10 kHz, which doesn't work in machines where somehow the max freq was auto reduced by the kernel:
[root@ssdandy ~]# perf test 19
19: Test software clock events have valid period values : FAILED!
[root@ssdandy ~]# perf test -v 19
19: Test software clock events have valid period values :
--- start ---
Couldn't open evlist: Invalid argument
---- end ----
Test software clock events have valid period values: FAILED! [root@ssdandy ~]#Quoted 7 lines
[root@ssdandy ~]# cat
/proc/sys/kernel/perf_event_max_sample_rate7000Reducing it to 500 Hz should be good enough for this test and also shouldn't affect what it is testing.
But warn the user if it fails, informing the knob and the freq tried.
Doesn't work for me:
./perf test -v 19
19: Test software clock events have valid period values :
--- start ---
mmap size 528384B
mmap size 528384B
All (0) samples have period value of 1!
---- end ----
Test software clock events have valid period values: FAILED!But this fixes it:
tools/perf/tests/sw-clock.c +0
-0@@ -9,7 +9,7 @@#include "util/cpumap.h" #include "util/thread_map.h"
Quoted 4 lines
tools/perf/tests/sw-clock.c line 12
Quoted 2 lines
tools/perf/tests/sw-clock.c +1
-1-#define NR_LOOPS 1000000 +#define NR_LOOPS 10000000Or else, why not using the
max_sample_rateas the freq value?
Sure, that probably is better, I was just trying the lazy way, as doing what you suggest entails reworking what Jiri did, since the routine that reads that max_sample_rate is not exported, needs some massaging, etc.
Using a low enough max_sample_rate and warning the user that anyway would be better knowing that the sample rate lowered so dramatically looked quicker/lazy enough ;-)
- Arnaldo
Re: [PATCH 10/10] perf tests: Use lower sample_freq in sw clock event period test
In reply to Adrian HunterEm Tue, Nov 12, 2013 at 09:07:36AM +0200, Adrian Hunter escreveu:
Quoted 40 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
We were using it at 10 kHz, which doesn't work in machines where somehow the max freq was auto reduced by the kernel:
[root@ssdandy ~]# perf test 19
19: Test software clock events have valid period values : FAILED!
[root@ssdandy ~]# perf test -v 19
19: Test software clock events have valid period values :
--- start ---
Couldn't open evlist: Invalid argument
---- end ----
Test software clock events have valid period values: FAILED! [root@ssdandy ~]#Quoted 7 lines
[root@ssdandy ~]# cat
/proc/sys/kernel/perf_event_max_sample_rate7000Reducing it to 500 Hz should be good enough for this test and also shouldn't affect what it is testing.
But warn the user if it fails, informing the knob and the freq tried.
Doesn't work for me:
./perf test -v 19
19: Test software clock events have valid period values :
--- start ---
mmap size 528384B
mmap size 528384B
All (0) samples have period value of 1!
---- end ----
Test software clock events have valid period values: FAILED!But this fixes it:
tools/perf/tests/sw-clock.c +0
-0
tools/perf/tests/sw-clock.c line 12
Quoted 5 lines
tools/perf/tests/sw-clock.c +1
-1@@ -9,7 +9,7 @@#include "util/cpumap.h" #include "util/thread_map.h" -#define NR_LOOPS 1000000 +#define NR_LOOPS 10000000
Lower frequency, need to generate more noise, ugh. Adding that, but I think this test needs to be reworked, Namhyung?
- Arnaldo
Namhyung Kim
maintainerRe: [PATCH 10/10] perf tests: Use lower sample_freq in sw clock event period test
Hi Arnaldo,
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Tue, Nov 12, 2013 at 09:07:36AM +0200, Adrian Hunter escreveu:
tools/perf/tests/sw-clock.c line 12
Quoted 2 lines
tools/perf/tests/sw-clock.c +1
-1-#define NR_LOOPS 1000000 +#define NR_LOOPS 10000000Lower frequency, need to generate more noise, ugh. Adding that, but I think this test needs to be reworked, Namhyung?
Hmm.. We might go back to use the default frequency of 4000 (or 1000) and make the loop based on time like using alarm or setitimer.
Or we can add an outer loop which doubles the inner loop counter if no samples are collected.
What do you think?
Thanks,
Namhyung
tip-bot for Adrian Hunter
merge bot[tip:perf/urgent] perf tests: Compensate lower sample freq with longer test loop
In reply to Adrian Hunterperf tests: Compensate lower sample freq with longer test loop
Commit-ID: 3fe2130523b2e098085eb4d38cd5b737a97cbee6 Gitweb: http://git.kernel.org/tip/3fe2130523b2e098085eb4d38cd5b737a97cbee6 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 12 Nov 2013 11:45:21 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 12 Nov 2013 13:00:37 -0300
perf tests: Compensate lower sample freq with longer test loop
Doesn't work for me:
./perf test -v 19
19: Test software clock events have valid period values :
--- start ---
mmap size 528384B
mmap size 528384B
All (0) samples have period value of 1!
---- end ----
Test software clock events have valid period values: FAILED!
Compensate the lower freq introduced in 67c1e4a53b17 with a longer loop,
--- tools/perf/tests/sw-clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/sw-clock.c +1 -1
@@ -9,7 +9,7 @@#include "util/cpumap.h" #include "util/thread_map.h" -#define NR_LOOPS 1000000 +#define NR_LOOPS 10000000/* * This test will open software clock events (cpu-clock, task-clock)