perf tools: unify event type description
PATCH 1/3 perf tools: unify event type description
make event type description to a unified array and the array index consistent to perf_type_id.
--- tools/perf/util/parse-events.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-)
tools/perf/util/parse-events.c +10 -9
@@ -835,11 +835,12 @@ int parse_filter(const struct option *opt __used, const char *str, }static const char *const event_type_descriptors[] = { -"" ,"Hardware event" ,"Software event" ,"Tracepoint event" ,"Hardware cache event" , +"Raw hardware event descriptor" , +"Hardware breakpoint" , };/*
@@ -872,7 +873,7 @@ static void print_tracepoint_events(void)snprintf (evt_path,MAXPATHLEN ,"%s:%s" , sys_dirent.d_name, evt_dirent.d_name);printf (" %-42s [%s]\n" , evt_path, - event_type_descriptors[PERF_TYPE_TRACEPOINT +1 ]); + event_type_descriptors[PERF_TYPE_TRACEPOINT ]); }closedir (evt_dir); }
@@ -892,9 +893,7 @@ void print_events(void)printf ("List of pre-defined events (to be used in -e):\n" );for (i =0 ; i <ARRAY_SIZE (event_symbols); i++, syms++) { - type = syms->type +1 ; -if (type >=ARRAY_SIZE (event_type_descriptors)) - type =0 ; + type = syms->type;if (type != prev_type)printf ("\n" );
@@ -919,17 +918,19 @@ void print_events(void)for (i =0 ; i <PERF_COUNT_HW_CACHE_RESULT_MAX ; i++) {printf (" %-42s [%s]\n" ,event_cache_name (type, op, i), - event_type_descriptors[4 ]); + event_type_descriptors[PERF_TYPE_HW_CACHE ]); } } }printf ("\n" ); -printf (" %-42s [raw hardware event descriptor]\n" , -"rNNN" ); +printf (" %-42s [%s]\n" , +"rNNN" , event_type_descriptors[PERF_TYPE_RAW ]);printf ("\n" ); -printf (" %-42s [hardware breakpoint]\n" ,"mem:<addr>[:access]" ); +printf (" %-42s [%s]\n" , +"mem:<addr>[:access]" , + event_type_descriptors[PERF_TYPE_BREAKPOINT ]);printf ("\n" );print_tracepoint_events ();
Signature · 1 line
1.6.0.3
PATCH 2/3 perf tools: remove pid option from stat
pid option is useless for stat, so remove it.
--- tools/perf/builtin-stat.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
tools/perf/builtin-stat.c +0 -3
@@ -71,7 +71,6 @@ static int run_idx = 0;static int run_count =1 ;static int inherit =1 ;static int scale =1 ; -static pid_t target_pid =-1 ;static pid_t child_pid =-1 ;static int null_run =0 ;
@@ -471,8 +470,6 @@ static const struct option options[] = { parse_events),OPT_BOOLEAN ('i' ,"inherit" , &inherit,"child tasks inherit counters" ), -OPT_INTEGER ('p' ,"pid" , &target_pid, -"stat events on existing pid" ),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide,"system-wide collection from all CPUs" ), OPT_BOOLEAN('c', "scale", &scale,
Signature · 1 line
1.6.0.3
PATCH 3/3 perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
make the config name consistent
--- tools/perf/util/probe-event.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/probe-event.c +1 -1
@@ -368,7 +368,7 @@ static int open_kprobe_events(int flags, int mode)if (ret <0 ) {if (errno ==ENOENT )die ("kprobe_events file does not exist -" -" please rebuild with CONFIG_KPROBE_TRACER." ); +" please rebuild with CONFIG_KPROBE_EVENT." );else die ("Could not open kprobe_events file: %s" ,strerror (errno));
Signature · 1 line
1.6.0.3
Re: [PATCH 3/3] perf probe: change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
Quoted 3 lines · Liming Wang
make the config name consistent
Signed-off-by Liming Wang <[email protected]>
Ah, right. Thank you!
Quoted 17 lines
--- tools/perf/util/probe-event.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)tools/perf/util/probe-event.c +1
-1@@ -368,7 +368,7 @@ static int open_kprobe_events(int flags, int mode)if (ret <0 ) {if (errno ==ENOENT )die ("kprobe_events file does not exist -" -" please rebuild with CONFIG_KPROBE_TRACER." ); +" please rebuild with CONFIG_KPROBE_EVENT." );else die ("Could not open kprobe_events file: %s" ,strerror (errno));
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/core] perf probe: Change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
In reply to Liming WangCommit-ID: 63bbd5e2d539c9290b229c832f62d42aac23db94 Gitweb: http://git.kernel.org/tip/63bbd5e2d539c9290b229c832f62d42aac23db94 Author: Liming Wang <[email protected]> AuthorDate: Tue, 29 Dec 2009 16:37:09 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 30 Dec 2009 11:59:34 +0100
perf probe: Change CONFIG_KPROBE_TRACER to CONFIG_KPROBE_EVENT
make the config name consistent
LKML-Reference: <[email protected]>
--- tools/perf/util/probe-event.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/probe-event.c +1 -1
@@ -368,7 +368,7 @@ static int open_kprobe_events(int flags, int mode)if (ret <0 ) {if (errno ==ENOENT )die ("kprobe_events file does not exist -" -" please rebuild with CONFIG_KPROBE_TRACER." ); +" please rebuild with CONFIG_KPROBE_EVENT." );else die ("Could not open kprobe_events file: %s" ,strerror (errno));
Peter Zijlstra
maintainerRe: [PATCH 2/3] perf tools: remove pid option from stat
In reply to Liming WangQuoted 1 line · Liming Wang
pid option is useless for stat, so remove it.
Hmm, it shouldn't be.. and instead of removing it I would suggesting fixing this.
Quoted 26 lines
Signed-off-by Liming Wang <[email protected]>--- tools/perf/builtin-stat.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)tools/perf/builtin-stat.c +0
-3@@ -71,7 +71,6 @@ static int run_idx = 0;static int run_count =1 ;static int inherit =1 ;static int scale =1 ; -static pid_t target_pid =-1 ;static pid_t child_pid =-1 ;static int null_run =0 ;@@ -471,8 +470,6 @@ static const struct option options[] = { parse_events),OPT_BOOLEAN ('i' ,"inherit" , &inherit,"child tasks inherit counters" ), -OPT_INTEGER ('p' ,"pid" , &target_pid, -"stat events on existing pid" ),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide,"system-wide collection from all CPUs" ), OPT_BOOLEAN('c', "scale", &scale,
Re: [PATCH 2/3] perf tools: remove pid option from stat
Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Liming Wang
pid option is useless for stat, so remove it.
Hmm, it shouldn't be.. and instead of removing it I would suggesting fixing this.
Yes. For exampe something like:
perf stat --repeat 10 --pid $(pidof firefox) sleep 1
Should show firefox's resource usage sampled over 10 seconds.
If this doesnt work it should be fixed. Plus i suspect we should allow:
perf stat --pid $(pidof firefox)
to run until Ctrl-C - like perf record allows.
Ingo
Re: [PATCH 2/3] perf tools: remove pid option from stat
Quoted 10 lines · Ingo Molnar
Quoted 3 lines · Peter Zijlstra
Quoted 1 line · Liming Wang
pid option is useless for stat, so remove it.
Hmm, it shouldn't be.. and instead of removing it I would suggesting fixing this.
Yes. For exampe something like:
perf stat --repeat 10 --pid $(pidof firefox) sleep 1
Quoted 7 lines
Should show firefox's resource usage sampled over 10 seconds.
If this doesnt work it should be fixed. Plus i suspect we should allow:
perf stat --pid $(pidof firefox)to run until Ctrl-C - like perf record allows.
Yes, perf record works well with "--pid".
I think stat can borrow come code from record.
Please discard this patch.
Liming Wang
Quoted 3 lines
Ingo
PATCH 1/1 perf tools: fix pid option for stat
In reply to Ingo Molnarcurrent pid option doesn't work for perf stat. Change it to what perf record --pid acts as.
--- tools/perf/builtin-stat.c | 106 ++++++++++++++++++++++++++------------------- 1 files changed, 61 insertions(+), 45 deletions(-)
tools/perf/builtin-stat.c +61 -45
@@ -44,6 +44,7 @@#include "util/parse-events.h" #include "util/event.h" #include "util/debug.h" +#include "util/header.h" #include <sys/prctl.h> #include <math.h>
@@ -79,6 +80,8 @@ static int fd[MAX_NR_CPUS][MAX_COUNTERS];static int event_scaled[MAX_COUNTERS ]; +static volatile int done =0 ; +struct stats {double n, mean, M2;
@@ -247,61 +250,64 @@ static int run_perf_stat(int argc __used, const char **argv)unsigned long long t0, t1;int status =0 ;int counter; -int pid; +int pid = target_pid;int child_ready_pipe[2 ], go_pipe[2 ]; +const bool forks = (target_pid ==-1 && argc >0 );char buf;if (!system_wide) nr_cpus =1 ; -if (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 ) { +if (forks && (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 )) {perror ("failed to create pipes" );exit (1 ); } -if ((pid =fork ()) <0 ) -perror ("failed to fork" ); +if (forks) { +if ((pid =fork ()) <0 ) +perror ("failed to fork" ); + +if (!pid) { +close (child_ready_pipe[0 ]); +close (go_pipe[1 ]); +fcntl (go_pipe[0 ],F_SETFD ,FD_CLOEXEC ); + +/* +* Do a dummy execvp to get the PLT entry resolved, +* so we avoid the resolver overhead on the real +* execvp call. +*/ +execvp ("" , (char **)argv); + +/* +* Tell the parent we're ready to go +*/ +close (child_ready_pipe[1 ]); + +/* +* Wait until the parent tells us to go. +*/ +if (read (go_pipe[0 ], &buf,1 ) ==-1 ) +perror ("unable to read pipe" ); + +execvp (argv[0 ], (char **)argv); + +perror (argv[0 ]); +exit (-1 ); + } -if (!pid) { -close (child_ready_pipe[0 ]); -close (go_pipe[1 ]); -fcntl (go_pipe[0 ],F_SETFD ,FD_CLOEXEC ); + child_pid = pid;/* -* Do a dummy execvp to get the PLT entry resolved, -* so we avoid the resolver overhead on the real -* execvp call. -*/ -execvp ("" , (char **)argv); - -/* -* Tell the parent we're ready to go +* Wait for the child to be ready to exec. */ close (child_ready_pipe[1 ]); - -/* -* Wait until the parent tells us to go. -*/ -if (read (go_pipe[0 ], &buf,1 ) ==-1 ) +close (go_pipe[0 ]); +if (read (child_ready_pipe[0 ], &buf,1 ) ==-1 )perror ("unable to read pipe" ); - -execvp (argv[0 ], (char **)argv); - -perror (argv[0 ]); -exit (-1 ); +close (child_ready_pipe[0 ]); } - child_pid = pid; - -/* -* Wait for the child to be ready to exec. -*/ -close (child_ready_pipe[1 ]); -close (go_pipe[0 ]); -if (read (child_ready_pipe[0 ], &buf,1 ) ==-1 ) -perror ("unable to read pipe" ); -close (child_ready_pipe[0 ]); -for (counter =0 ; counter < nr_counters; counter++)create_perf_stat_counter (counter, pid);
@@ -310,8 +316,12 @@ static int run_perf_stat(int argc __used, const char **argv)*/ t0 =rdclock (); -close (go_pipe[1 ]); -wait (&status); +if (forks) { +close (go_pipe[1 ]); +wait (&status); + }else { +while (!done); + } t1 =rdclock ();
@@ -417,10 +427,13 @@ static void print_stat(int argc, const char **argv)fflush (stdout);fprintf (stderr,"\n" ); -fprintf (stderr," Performance counter stats for \'%s" , argv[0 ]); - -for (i =1 ; i < argc; i++) -fprintf (stderr," %s" , argv[i]); +fprintf (stderr," Performance counter stats for " ); +if (target_pid ==-1 ) { +fprintf (stderr,"\'%s" , argv[0 ]); +for (i =1 ; i < argc; i++) +fprintf (stderr," %s" , argv[i]); + }else +fprintf (stderr,"task pid \'%d" , target_pid);fprintf (stderr,"\'" );if (run_count >1 )
@@ -445,6 +458,9 @@ static volatile int signr = -1;static void skip_signal (int signo) { +if (target_pid !=-1 ) + done =1 ; + signr = signo; }
@@ -461,7 +477,7 @@ static void sig_atexit(void) }static const char *const stat_usage[] = { -"perf stat [<options>] <command>" , +"perf stat [<options>] [<command>]" ,NULL };
@@ -492,7 +508,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) argc =parse_options (argc, argv, options, stat_usage,PARSE_OPT_STOP_AT_NON_OPTION ); -if (!argc) +if (!argc && target_pid ==-1 )usage_with_options (stat_usage, options);if (run_count <=0 )usage_with_options (stat_usage, options);
Signature · 1 line
1.6.0.3
[tip:perf/core] perf tools: Fix --pid option for stat
Commit-ID: 60666c630bdb33983a894b050b588b663f38f368 Gitweb: http://git.kernel.org/tip/60666c630bdb33983a894b050b588b663f38f368 Author: Liming Wang <[email protected]> AuthorDate: Thu, 31 Dec 2009 16:05:50 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 13 Jan 2010 10:09:08 +0100
perf tools: Fix --pid option for stat
current pid option doesn't work for perf stat. Change it to what perf record --pid acts as.
LKML-Reference: <[email protected]>
--- tools/perf/builtin-stat.c | 106 ++++++++++++++++++++++++++------------------- 1 files changed, 61 insertions(+), 45 deletions(-)
tools/perf/builtin-stat.c +61 -45
@@ -44,6 +44,7 @@#include "util/parse-events.h" #include "util/event.h" #include "util/debug.h" +#include "util/header.h" #include <sys/prctl.h> #include <math.h>
@@ -79,6 +80,8 @@ static int fd[MAX_NR_CPUS][MAX_COUNTERS];static int event_scaled[MAX_COUNTERS ]; +static volatile int done =0 ; +struct stats {double n, mean, M2;
@@ -247,61 +250,64 @@ static int run_perf_stat(int argc __used, const char **argv)unsigned long long t0, t1;int status =0 ;int counter; -int pid; +int pid = target_pid;int child_ready_pipe[2 ], go_pipe[2 ]; +const bool forks = (target_pid ==-1 && argc >0 );char buf;if (!system_wide) nr_cpus =1 ; -if (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 ) { +if (forks && (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 )) {perror ("failed to create pipes" );exit (1 ); } -if ((pid =fork ()) <0 ) -perror ("failed to fork" ); +if (forks) { +if ((pid =fork ()) <0 ) +perror ("failed to fork" ); + +if (!pid) { +close (child_ready_pipe[0 ]); +close (go_pipe[1 ]); +fcntl (go_pipe[0 ],F_SETFD ,FD_CLOEXEC ); + +/* +* Do a dummy execvp to get the PLT entry resolved, +* so we avoid the resolver overhead on the real +* execvp call. +*/ +execvp ("" , (char **)argv); + +/* +* Tell the parent we're ready to go +*/ +close (child_ready_pipe[1 ]); + +/* +* Wait until the parent tells us to go. +*/ +if (read (go_pipe[0 ], &buf,1 ) ==-1 ) +perror ("unable to read pipe" ); + +execvp (argv[0 ], (char **)argv); + +perror (argv[0 ]); +exit (-1 ); + } -if (!pid) { -close (child_ready_pipe[0 ]); -close (go_pipe[1 ]); -fcntl (go_pipe[0 ],F_SETFD ,FD_CLOEXEC ); + child_pid = pid;/* -* Do a dummy execvp to get the PLT entry resolved, -* so we avoid the resolver overhead on the real -* execvp call. -*/ -execvp ("" , (char **)argv); - -/* -* Tell the parent we're ready to go +* Wait for the child to be ready to exec. */ close (child_ready_pipe[1 ]); - -/* -* Wait until the parent tells us to go. -*/ -if (read (go_pipe[0 ], &buf,1 ) ==-1 ) +close (go_pipe[0 ]); +if (read (child_ready_pipe[0 ], &buf,1 ) ==-1 )perror ("unable to read pipe" ); - -execvp (argv[0 ], (char **)argv); - -perror (argv[0 ]); -exit (-1 ); +close (child_ready_pipe[0 ]); } - child_pid = pid; - -/* -* Wait for the child to be ready to exec. -*/ -close (child_ready_pipe[1 ]); -close (go_pipe[0 ]); -if (read (child_ready_pipe[0 ], &buf,1 ) ==-1 ) -perror ("unable to read pipe" ); -close (child_ready_pipe[0 ]); -for (counter =0 ; counter < nr_counters; counter++)create_perf_stat_counter (counter, pid);
@@ -310,8 +316,12 @@ static int run_perf_stat(int argc __used, const char **argv)*/ t0 =rdclock (); -close (go_pipe[1 ]); -wait (&status); +if (forks) { +close (go_pipe[1 ]); +wait (&status); + }else { +while (!done); + } t1 =rdclock ();
@@ -417,10 +427,13 @@ static void print_stat(int argc, const char **argv)fflush (stdout);fprintf (stderr,"\n" ); -fprintf (stderr," Performance counter stats for \'%s" , argv[0 ]); - -for (i =1 ; i < argc; i++) -fprintf (stderr," %s" , argv[i]); +fprintf (stderr," Performance counter stats for " ); +if (target_pid ==-1 ) { +fprintf (stderr,"\'%s" , argv[0 ]); +for (i =1 ; i < argc; i++) +fprintf (stderr," %s" , argv[i]); + }else +fprintf (stderr,"task pid \'%d" , target_pid);fprintf (stderr,"\'" );if (run_count >1 )
@@ -445,6 +458,9 @@ static volatile int signr = -1;static void skip_signal (int signo) { +if (target_pid !=-1 ) + done =1 ; + signr = signo; }
@@ -461,7 +477,7 @@ static void sig_atexit(void) }static const char *const stat_usage[] = { -"perf stat [<options>] <command>" , +"perf stat [<options>] [<command>]" ,NULL };
@@ -492,7 +508,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) argc =parse_options (argc, argv, options, stat_usage,PARSE_OPT_STOP_AT_NON_OPTION ); -if (!argc) +if (!argc && target_pid ==-1 )usage_with_options (stat_usage, options);if (run_count <=0 )usage_with_options (stat_usage, options);
[tip:perf/core] perf tools: Unify event type description
In reply to Liming WangCommit-ID: 41bdcb23dab22bf27361c5f2d89fe895d8904915 Gitweb: http://git.kernel.org/tip/41bdcb23dab22bf27361c5f2d89fe895d8904915 Author: Liming Wang <[email protected]> AuthorDate: Tue, 29 Dec 2009 16:37:07 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 30 Dec 2009 11:58:53 +0100
perf tools: Unify event type description
make event type description to a unified array and the array index consistent to perf_type_id.
LKML-Reference: <[email protected]>
--- tools/perf/util/parse-events.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-)
tools/perf/util/parse-events.c +10 -9
@@ -835,11 +835,12 @@ int parse_filter(const struct option *opt __used, const char *str, }static const char *const event_type_descriptors[] = { -"" ,"Hardware event" ,"Software event" ,"Tracepoint event" ,"Hardware cache event" , +"Raw hardware event descriptor" , +"Hardware breakpoint" , };/*
@@ -872,7 +873,7 @@ static void print_tracepoint_events(void)snprintf (evt_path,MAXPATHLEN ,"%s:%s" , sys_dirent.d_name, evt_dirent.d_name);printf (" %-42s [%s]\n" , evt_path, - event_type_descriptors[PERF_TYPE_TRACEPOINT +1 ]); + event_type_descriptors[PERF_TYPE_TRACEPOINT ]); }closedir (evt_dir); }
@@ -892,9 +893,7 @@ void print_events(void)printf ("List of pre-defined events (to be used in -e):\n" );for (i =0 ; i <ARRAY_SIZE (event_symbols); i++, syms++) { - type = syms->type +1 ; -if (type >=ARRAY_SIZE (event_type_descriptors)) - type =0 ; + type = syms->type;if (type != prev_type)printf ("\n" );
@@ -919,17 +918,19 @@ void print_events(void)for (i =0 ; i <PERF_COUNT_HW_CACHE_RESULT_MAX ; i++) {printf (" %-42s [%s]\n" ,event_cache_name (type, op, i), - event_type_descriptors[4 ]); + event_type_descriptors[PERF_TYPE_HW_CACHE ]); } } }printf ("\n" ); -printf (" %-42s [raw hardware event descriptor]\n" , -"rNNN" ); +printf (" %-42s [%s]\n" , +"rNNN" , event_type_descriptors[PERF_TYPE_RAW ]);printf ("\n" ); -printf (" %-42s [hardware breakpoint]\n" ,"mem:<addr>[:access]" ); +printf (" %-42s [%s]\n" , +"mem:<addr>[:access]" , + event_type_descriptors[PERF_TYPE_BREAKPOINT ]);printf ("\n" );print_tracepoint_events ();