perf-trace/scripting: script fixes
cover perf-trace/scripting: script fixes
While testing the new 'trace events reordering' patches, I noticed some problems with the current set of scripts, mostly annoying warning messages, but a couple of real problems too.
Another annoyance, which I moved to verbose mode, was the display of the script name on each invocation.
Anyway, after testing all the scripts in both normal and live mode, I haven't seen any problems with the new event reordering patches...
Tom Zanussi (9):
perf/trace/scripting: failed-syscalls script cleanup perf/trace/scripting: rw-by-pid script cleanup perf/trace/scripting: rwtop script cleanup perf/trace/scripting: wakeup-latency script cleanup perf/trace/scripting: workqueue-stats script cleanup perf/trace/scripting: don't show script start/stop messages by
default
perf/trace/scripting: failed-syscalls-by-pid script cleanup perf/trace/scripting: syscall-counts-by-pid script cleanup perf/trace/scripting: syscall-counts script cleanup
tools/perf/builtin-trace.c | 3 + tools/perf/scripts/perl/bin/failed-syscalls-report | 2 +- tools/perf/scripts/perl/failed-syscalls.pl | 6 ++- tools/perf/scripts/perl/rw-by-pid.pl | 60 ++++++++++++-------- tools/perf/scripts/perl/rwtop.pl | 48 +++++++++++---- tools/perf/scripts/perl/wakeup-latency.pl | 12 +++- tools/perf/scripts/perl/workqueue-stats.pl | 12 ++-- .../python/bin/failed-syscalls-by-pid-report | 2 +- .../python/bin/syscall-counts-by-pid-report | 2 +- .../perf/scripts/python/bin/syscall-counts-report | 2 +- .../perf/util/scripting-engines/trace-event-perl.c | 3 - .../util/scripting-engines/trace-event-python.c | 4 - 12 files changed, 98 insertions(+), 58 deletions(-)
PATCH 1/9 perf/trace/scripting: failed-syscalls script cleanup
A couple small fixes for the failed syscalls script:
- The script description says it can be restricted to a specific comm, make it so.
- silence the match output in the shell script
--- tools/perf/scripts/perl/bin/failed-syscalls-report | 2 +- tools/perf/scripts/perl/failed-syscalls.pl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-)
tools/perf/scripts/perl/bin/failed-syscalls-report +1 -1
@@ -2,7 +2,7 @@ # description: system-wide failed syscalls # args: [comm] if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" ; then + if ! expr match "$1" "-" > /dev/null ; then comm=$1 shift fi
tools/perf/scripts/perl/failed-syscalls.pl +5 -1
@@ -11,6 +11,8 @@ use Perf::Trace::Core; use Perf::Trace::Context; use Perf::Trace::Util; +my $for_comm = shift; + my %failed_syscalls; sub raw_syscalls::sys_exit
@@ -33,6 +35,8 @@ sub trace_end foreach my $comm (sort {$failed_syscalls{$b} <=> $failed_syscalls{$a}} keys %failed_syscalls) { - printf("%-20s %10s\n", $comm, $failed_syscalls{$comm}); + next if ($for_comm && $comm ne $for_comm); + + printf("%-20s %10s\n", $comm, $failed_syscalls{$comm}); } }
Signature · 1 line
1.6.4.GIT
PATCH 2/9 perf/trace/scripting: rw-by-pid script cleanup
In reply to Tom ZanussiSome minor fixes for the rw-by-pid script:
- Fix nuisance 'use of uninitialized value' warnings
- Change the failed read/write sections to sort by error counts
--- tools/perf/scripts/perl/rw-by-pid.pl | 60 +++++++++++++++++++++------------- 1 files changed, 37 insertions(+), 23 deletions(-)
tools/perf/scripts/perl/rw-by-pid.pl +37 -23
@@ -79,12 +79,12 @@ sub trace_end printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", "-----------", "----------", "----------"); - foreach my $pid (sort {$reads{$b}{bytes_read} <=> - $reads{$a}{bytes_read}} keys %reads) { - my $comm = $reads{$pid}{comm}; - my $total_reads = $reads{$pid}{total_reads}; - my $bytes_requested = $reads{$pid}{bytes_requested}; - my $bytes_read = $reads{$pid}{bytes_read}; + foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=> + ($reads{$a}{bytes_read} || 0) } keys %reads) { + my $comm = $reads{$pid}{comm} || ""; + my $total_reads = $reads{$pid}{total_reads} || 0; + my $bytes_requested = $reads{$pid}{bytes_requested} || 0; + my $bytes_read = $reads{$pid}{bytes_read} || 0; printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, $total_reads, $bytes_requested, $bytes_read);
@@ -96,16 +96,23 @@ sub trace_end printf("%6s %20s %6s %10s\n", "------", "--------------------", "------", "----------"); - foreach my $pid (keys %reads) { - my $comm = $reads{$pid}{comm}; - foreach my $err (sort {$reads{$b}{comm} cmp $reads{$a}{comm}} - keys %{$reads{$pid}{errors}}) { - my $errors = $reads{$pid}{errors}{$err}; + my @errcounts = (); - printf("%6d %-20s %6d %10s\n", $pid, $comm, $err, $errors); + foreach my $pid (keys %reads) { + foreach my $error (keys %{$reads{$pid}{errors}}) { + my $comm = $reads{$pid}{comm} || ""; + my $errcount = $reads{$pid}{errors}{$error} || 0; + push @errcounts, [$pid, $comm, $error, $errcount]; } } + @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts; + + for my $i (0 .. $#errcounts) { + printf("%6d %-20s %6d %10s\n", $errcounts[$i][0], + $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]); + } + printf("\nwrite counts by pid:\n\n"); printf("%6s %20s %10s %10s\n", "pid", "comm",
@@ -113,11 +120,11 @@ sub trace_end printf("%6s %-20s %10s %10s\n", "------", "--------------------", "-----------", "----------"); - foreach my $pid (sort {$writes{$b}{bytes_written} <=> - $writes{$a}{bytes_written}} keys %writes) { - my $comm = $writes{$pid}{comm}; - my $total_writes = $writes{$pid}{total_writes}; - my $bytes_written = $writes{$pid}{bytes_written}; + foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=> + ($writes{$a}{bytes_written} || 0)} keys %writes) { + my $comm = $writes{$pid}{comm} || ""; + my $total_writes = $writes{$pid}{total_writes} || 0; + my $bytes_written = $writes{$pid}{bytes_written} || 0; printf("%6s %-20s %10s %10s\n", $pid, $comm, $total_writes, $bytes_written);
@@ -129,16 +136,23 @@ sub trace_end printf("%6s %20s %6s %10s\n", "------", "--------------------", "------", "----------"); - foreach my $pid (keys %writes) { - my $comm = $writes{$pid}{comm}; - foreach my $err (sort {$writes{$b}{comm} cmp $writes{$a}{comm}} - keys %{$writes{$pid}{errors}}) { - my $errors = $writes{$pid}{errors}{$err}; + @errcounts = (); - printf("%6d %-20s %6d %10s\n", $pid, $comm, $err, $errors); + foreach my $pid (keys %writes) { + foreach my $error (keys %{$writes{$pid}{errors}}) { + my $comm = $writes{$pid}{comm} || ""; + my $errcount = $writes{$pid}{errors}{$error} || 0; + push @errcounts, [$pid, $comm, $error, $errcount]; } } + @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts; + + for my $i (0 .. $#errcounts) { + printf("%6d %-20s %6d %10s\n", $errcounts[$i][0], + $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]); + } + print_unhandled(); }
Signature · 1 line
1.6.4.GIT
PATCH 3/9 perf/trace/scripting: rwtop script cleanup
In reply to Tom ZanussiA couple of fixes for the rwtop script:
- printing the totals and clearing the hashes in the signal handler eventually leads to various random and serious problems when running the rwtop script continuously. Moving the print_totals() calls to the event handlers solves that problem, and the event handlers are invoked frequently enough that it doesn't affect the timeliness of the output.
- Fix nuisance 'use of uninitialized value' warnings
--- tools/perf/scripts/perl/rwtop.pl | 48 +++++++++++++++++++++++++++---------- 1 files changed, 35 insertions(+), 13 deletions(-)
tools/perf/scripts/perl/rwtop.pl +35 -13
@@ -21,6 +21,7 @@ use Perf::Trace::Util; my $default_interval = 3; my $nlines = 20; my $print_thread; +my $print_pending = 0; my %reads; my %writes;
@@ -36,6 +37,8 @@ sub syscalls::sys_exit_read $common_pid, $common_comm, $nr, $ret) = @_; + print_check(); + if ($ret > 0) { $reads{$common_pid}{bytes_read} += $ret; } else {
@@ -52,6 +55,8 @@ sub syscalls::sys_enter_read $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_; + print_check(); + $reads{$common_pid}{bytes_requested} += $count; $reads{$common_pid}{total_reads}++; $reads{$common_pid}{comm} = $common_comm;
@@ -63,6 +68,8 @@ sub syscalls::sys_exit_write $common_pid, $common_comm, $nr, $ret) = @_; + print_check(); + if ($ret <= 0) { $writes{$common_pid}{errors}{$ret}++; }
@@ -74,6 +81,8 @@ sub syscalls::sys_enter_write $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_; + print_check(); + $writes{$common_pid}{bytes_written} += $count; $writes{$common_pid}{total_writes}++; $writes{$common_pid}{comm} = $common_comm;
@@ -81,7 +90,7 @@ sub syscalls::sys_enter_write sub trace_begin { - $SIG{ALRM} = \&print_totals; + $SIG{ALRM} = \&set_print_pending; alarm 1; }
@@ -91,6 +100,20 @@ sub trace_end print_totals(); } +sub print_check() +{ + if ($print_pending == 1) { + $print_pending = 0; + print_totals(); + } +} + +sub set_print_pending() +{ + $print_pending = 1; + alarm $interval; +} + sub print_totals { my $count;
@@ -106,12 +129,12 @@ sub print_totals printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", "----------", "----------", "----------"); - foreach my $pid (sort {$reads{$b}{bytes_read} <=> - $reads{$a}{bytes_read}} keys %reads) { - my $comm = $reads{$pid}{comm}; - my $total_reads = $reads{$pid}{total_reads}; - my $bytes_requested = $reads{$pid}{bytes_requested}; - my $bytes_read = $reads{$pid}{bytes_read}; + foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=> + ($reads{$a}{bytes_read} || 0) } keys %reads) { + my $comm = $reads{$pid}{comm} || ""; + my $total_reads = $reads{$pid}{total_reads} || 0; + my $bytes_requested = $reads{$pid}{bytes_requested} || 0; + my $bytes_read = $reads{$pid}{bytes_read} || 0; printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, $total_reads, $bytes_requested, $bytes_read);
@@ -130,11 +153,11 @@ sub print_totals printf("%6s %-20s %10s %13s\n", "------", "--------------------", "----------", "-------------"); - foreach my $pid (sort {$writes{$b}{bytes_written} <=> - $writes{$a}{bytes_written}} keys %writes) { - my $comm = $writes{$pid}{comm}; - my $total_writes = $writes{$pid}{total_writes}; - my $bytes_written = $writes{$pid}{bytes_written}; + foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=> + ($writes{$a}{bytes_written} || 0)} keys %writes) { + my $comm = $writes{$pid}{comm} || ""; + my $total_writes = $writes{$pid}{total_writes} || 0; + my $bytes_written = $writes{$pid}{bytes_written} || 0; printf("%6s %-20s %10s %13s\n", $pid, $comm, $total_writes, $bytes_written);
@@ -146,7 +169,6 @@ sub print_totals %reads = (); %writes = (); - alarm $interval; } my %unhandled;
Signature · 1 line
1.6.4.GIT
PATCH 4/9 perf/trace/scripting: wakeup-latency script cleanup
In reply to Tom ZanussiSome minor fixes for the wakeup-latency script:
- Fix nuisance 'use of uninitialized value' warnings
- Avoid divide-by-zero error
--- tools/perf/scripts/perl/wakeup-latency.pl | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
tools/perf/scripts/perl/wakeup-latency.pl +8 -4
@@ -22,8 +22,8 @@ my %last_wakeup; my $max_wakeup_latency; my $min_wakeup_latency; -my $total_wakeup_latency; -my $total_wakeups; +my $total_wakeup_latency = 0; +my $total_wakeups = 0; sub sched::sched_switch {
@@ -67,8 +67,12 @@ sub trace_end { printf("wakeup_latency stats:\n\n"); print "total_wakeups: $total_wakeups\n"; - printf("avg_wakeup_latency (ns): %u\n", - avg($total_wakeup_latency, $total_wakeups)); + if ($total_wakeups) { + printf("avg_wakeup_latency (ns): %u\n", + avg($total_wakeup_latency, $total_wakeups)); + } else { + printf("avg_wakeup_latency (ns): N/A\n"); + } printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency); printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency);
Signature · 1 line
1.6.4.GIT
PATCH 5/9 perf/trace/scripting: workqueue-stats script cleanup
In reply to Tom ZanussiSome minor fixes for the workqueue-stats script:
- Fix nuisance 'use of uninitialized value' warnings
--- tools/perf/scripts/perl/workqueue-stats.pl | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
tools/perf/scripts/perl/workqueue-stats.pl +6 -6
@@ -71,9 +71,9 @@ sub trace_end printf("%3s %6s %6s\t%-20s\n", "---", "---", "----", "----"); foreach my $pidhash (@cpus) { while ((my $pid, my $wqhash) = each %$pidhash) { - my $ins = $$wqhash{'inserted'}; - my $exe = $$wqhash{'executed'}; - my $comm = $$wqhash{'comm'}; + my $ins = $$wqhash{'inserted'} || 0; + my $exe = $$wqhash{'executed'} || 0; + my $comm = $$wqhash{'comm'} || ""; if ($ins || $exe) { printf("%3u %6u %6u\t%-20s\n", $cpu, $ins, $exe, $comm); }
@@ -87,9 +87,9 @@ sub trace_end printf("%3s %6s %6s\t%-20s\n", "---", "-------", "---------", "----"); foreach my $pidhash (@cpus) { while ((my $pid, my $wqhash) = each %$pidhash) { - my $created = $$wqhash{'created'}; - my $destroyed = $$wqhash{'destroyed'}; - my $comm = $$wqhash{'comm'}; + my $created = $$wqhash{'created'} || 0; + my $destroyed = $$wqhash{'destroyed'} || 0; + my $comm = $$wqhash{'comm'} || ""; if ($created || $destroyed) { printf("%3u %6u %6u\t%-20s\n", $cpu, $created, $destroyed, $comm);
Signature · 1 line
1.6.4.GIT
PATCH 6/9 perf/trace/scripting: don't show script start/stop messages by default
In reply to Tom ZanussiOnly print the script start/stop messages in verbose mode - users normally don't care and it just clutters up the output.
--- tools/perf/builtin-trace.c | 3 +++ .../perf/util/scripting-engines/trace-event-perl.c | 3 --- .../util/scripting-engines/trace-event-python.c | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-)
tools/perf/builtin-trace.c +3 -0
@@ -53,6 +53,8 @@ static void setup_scripting(void)static int cleanup_scripting (void ) { +pr_debug ("\nperf trace script stopped\n" ); +return scripting_ops->stop_script (); }
@@ -703,6 +705,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) err = scripting_ops->start_script (script_name, argc, argv);if (err) goto out; +pr_debug ("perf trace started with script %s\n\n" , script_name); } err =__cmd_trace (session);
tools/perf/util/scripting-engines/trace-event-perl.c +0 -3
@@ -371,7 +371,6 @@ static int perl_start_script(const char *script, int argc, const char **argv)run_start_sub ();free (command_line); -fprintf (stderr,"perf trace started with Perl script %s\n\n" , script);return 0 ; error:perl_free (my_perl);
@@ -394,8 +393,6 @@ static int perl_stop_script(void)perl_destruct (my_perl);perl_free (my_perl); -fprintf (stderr,"\nperf trace Perl script stopped\n" ); -return 0 ; }
tools/perf/util/scripting-engines/trace-event-python.c +0 -4
@@ -374,8 +374,6 @@ static int python_start_script(const char *script, int argc, const char **argv) }free (command_line); -fprintf (stderr,"perf trace started with Python script %s\n\n" , - script);return err; error:
@@ -407,8 +405,6 @@ out:Py_XDECREF (main_module);Py_Finalize (); -fprintf (stderr,"\nperf trace Python script stopped\n" ); -return err; }
Signature · 1 line
1.6.4.GIT
PATCH 7/9 perf/trace/scripting: failed-syscalls-by-pid script cleanup
In reply to Tom ZanussiA small fixe for the failed syscalls by pid script:
- silence the match output in the shell script
--- .../python/bin/failed-syscalls-by-pid-report | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/scripts/python/bin/failed-syscalls-by-pid-report +1 -1
@@ -2,7 +2,7 @@ # description: system-wide failed syscalls, by pid # args: [comm] if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" ; then + if ! expr match "$1" "-" > /dev/null ; then comm=$1 shift fi
Signature · 1 line
1.6.4.GIT
PATCH 8/9 perf/trace/scripting: syscall-counts-by-pid script cleanup
In reply to Tom ZanussiA small fix for the syscall counts by pid script:
- silence the match output in the shell script
--- .../python/bin/syscall-counts-by-pid-report | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/scripts/python/bin/syscall-counts-by-pid-report +1 -1
@@ -2,7 +2,7 @@ # description: system-wide syscall counts, by pid # args: [comm] if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" ; then + if ! expr match "$1" "-" > /dev/null ; then comm=$1 shift fi
Signature · 1 line
1.6.4.GIT
PATCH 9/9 perf/trace/scripting: syscall-counts script cleanup
In reply to Tom ZanussiA small fix for the syscall counts script:
- silence the match output in the shell script
--- .../perf/scripts/python/bin/syscall-counts-report | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/scripts/python/bin/syscall-counts-report +1 -1
@@ -2,7 +2,7 @@ # description: system-wide syscall counts # args: [comm] if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" ; then + if ! expr match "$1" "-" > /dev/null ; then comm=$1 shift fi
Signature · 1 line
1.6.4.GIT