diff options
author | Tom Zanussi <tzanussi@gmail.com> | 2009-11-25 02:15:49 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-28 04:04:26 -0500 |
commit | bcefe12eff5dca6fdfa94ed85e5bee66380d5cd9 (patch) | |
tree | 9a0f39f63d4e542322f4bc58626e1bd1d3d0f3c1 /tools/perf/scripts/perl/rw-by-file.pl | |
parent | 16c632de64a74644a46e7636db26b2cfb530ca13 (diff) |
perf trace: Add perf trace scripting support modules for Perl
Add Perf-Trace-Util Perl module and some scripts that use it.
Core.pm contains Perl code to define and access flag and
symbolic fields. Util.pm contains general-purpose utility
functions.
Also adds some makefile bits to install them in
libexec/perf-core/scripts/perl (or wherever perfexec_instdir
points).
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Cc: fweisbec@gmail.com
Cc: rostedt@goodmis.org
Cc: anton@samba.org
Cc: hch@infradead.org
LKML-Reference: <1259133352-23685-5-git-send-email-tzanussi@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/scripts/perl/rw-by-file.pl')
-rw-r--r-- | tools/perf/scripts/perl/rw-by-file.pl | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tools/perf/scripts/perl/rw-by-file.pl b/tools/perf/scripts/perl/rw-by-file.pl new file mode 100644 index 000000000000..61f91561d848 --- /dev/null +++ b/tools/perf/scripts/perl/rw-by-file.pl | |||
@@ -0,0 +1,105 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # (c) 2009, Tom Zanussi <tzanussi@gmail.com> | ||
3 | # Licensed under the terms of the GNU GPL License version 2 | ||
4 | |||
5 | # Display r/w activity for files read/written to for a given program | ||
6 | |||
7 | # The common_* event handler fields are the most useful fields common to | ||
8 | # all events. They don't necessarily correspond to the 'common_*' fields | ||
9 | # in the status files. Those fields not available as handler params can | ||
10 | # be retrieved via script functions of the form get_common_*(). | ||
11 | |||
12 | use 5.010000; | ||
13 | use strict; | ||
14 | use warnings; | ||
15 | |||
16 | use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib"; | ||
17 | use lib "./Perf-Trace-Util/lib"; | ||
18 | use Perf::Trace::Core; | ||
19 | use Perf::Trace::Util; | ||
20 | |||
21 | # change this to the comm of the program you're interested in | ||
22 | my $for_comm = "perf"; | ||
23 | |||
24 | my %reads; | ||
25 | my %writes; | ||
26 | |||
27 | sub syscalls::sys_enter_read | ||
28 | { | ||
29 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
30 | $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_; | ||
31 | |||
32 | if ($common_comm eq $for_comm) { | ||
33 | $reads{$fd}{bytes_requested} += $count; | ||
34 | $reads{$fd}{total_reads}++; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | sub syscalls::sys_enter_write | ||
39 | { | ||
40 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
41 | $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_; | ||
42 | |||
43 | if ($common_comm eq $for_comm) { | ||
44 | $writes{$fd}{bytes_written} += $count; | ||
45 | $writes{$fd}{total_writes}++; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | sub trace_end | ||
50 | { | ||
51 | printf("file read counts for $for_comm:\n\n"); | ||
52 | |||
53 | printf("%6s %10s %10s\n", "fd", "# reads", "bytes_requested"); | ||
54 | printf("%6s %10s %10s\n", "------", "----------", "-----------"); | ||
55 | |||
56 | foreach my $fd (sort {$reads{$b}{bytes_requested} <=> | ||
57 | $reads{$a}{bytes_requested}} keys %reads) { | ||
58 | my $total_reads = $reads{$fd}{total_reads}; | ||
59 | my $bytes_requested = $reads{$fd}{bytes_requested}; | ||
60 | printf("%6u %10u %10u\n", $fd, $total_reads, $bytes_requested); | ||
61 | } | ||
62 | |||
63 | printf("\nfile write counts for $for_comm:\n\n"); | ||
64 | |||
65 | printf("%6s %10s %10s\n", "fd", "# writes", "bytes_written"); | ||
66 | printf("%6s %10s %10s\n", "------", "----------", "-----------"); | ||
67 | |||
68 | foreach my $fd (sort {$writes{$b}{bytes_written} <=> | ||
69 | $writes{$a}{bytes_written}} keys %writes) { | ||
70 | my $total_writes = $writes{$fd}{total_writes}; | ||
71 | my $bytes_written = $writes{$fd}{bytes_written}; | ||
72 | printf("%6u %10u %10u\n", $fd, $total_writes, $bytes_written); | ||
73 | } | ||
74 | |||
75 | print_unhandled(); | ||
76 | } | ||
77 | |||
78 | my %unhandled; | ||
79 | |||
80 | sub print_unhandled | ||
81 | { | ||
82 | if ((scalar keys %unhandled) == 0) { | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | print "\nunhandled events:\n\n"; | ||
87 | |||
88 | printf("%-40s %10s\n", "event", "count"); | ||
89 | printf("%-40s %10s\n", "----------------------------------------", | ||
90 | "-----------"); | ||
91 | |||
92 | foreach my $event_name (keys %unhandled) { | ||
93 | printf("%-40s %10d\n", $event_name, $unhandled{$event_name}); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | sub trace_unhandled | ||
98 | { | ||
99 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
100 | $common_pid, $common_comm) = @_; | ||
101 | |||
102 | $unhandled{$event_name}++; | ||
103 | } | ||
104 | |||
105 | |||