diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /tools/perf/scripts/perl/rw-by-file.pl | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'tools/perf/scripts/perl/rw-by-file.pl')
-rw-r--r-- | tools/perf/scripts/perl/rw-by-file.pl | 106 |
1 files changed, 106 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..2a39097687b9 --- /dev/null +++ b/tools/perf/scripts/perl/rw-by-file.pl | |||
@@ -0,0 +1,106 @@ | |||
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 | my $usage = "perf trace -s rw-by-file.pl <comm>\n"; | ||
22 | |||
23 | my $for_comm = shift or die $usage; | ||
24 | |||
25 | my %reads; | ||
26 | my %writes; | ||
27 | |||
28 | sub syscalls::sys_enter_read | ||
29 | { | ||
30 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
31 | $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_; | ||
32 | |||
33 | if ($common_comm eq $for_comm) { | ||
34 | $reads{$fd}{bytes_requested} += $count; | ||
35 | $reads{$fd}{total_reads}++; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | sub syscalls::sys_enter_write | ||
40 | { | ||
41 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
42 | $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_; | ||
43 | |||
44 | if ($common_comm eq $for_comm) { | ||
45 | $writes{$fd}{bytes_written} += $count; | ||
46 | $writes{$fd}{total_writes}++; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | sub trace_end | ||
51 | { | ||
52 | printf("file read counts for $for_comm:\n\n"); | ||
53 | |||
54 | printf("%6s %10s %10s\n", "fd", "# reads", "bytes_requested"); | ||
55 | printf("%6s %10s %10s\n", "------", "----------", "-----------"); | ||
56 | |||
57 | foreach my $fd (sort {$reads{$b}{bytes_requested} <=> | ||
58 | $reads{$a}{bytes_requested}} keys %reads) { | ||
59 | my $total_reads = $reads{$fd}{total_reads}; | ||
60 | my $bytes_requested = $reads{$fd}{bytes_requested}; | ||
61 | printf("%6u %10u %10u\n", $fd, $total_reads, $bytes_requested); | ||
62 | } | ||
63 | |||
64 | printf("\nfile write counts for $for_comm:\n\n"); | ||
65 | |||
66 | printf("%6s %10s %10s\n", "fd", "# writes", "bytes_written"); | ||
67 | printf("%6s %10s %10s\n", "------", "----------", "-----------"); | ||
68 | |||
69 | foreach my $fd (sort {$writes{$b}{bytes_written} <=> | ||
70 | $writes{$a}{bytes_written}} keys %writes) { | ||
71 | my $total_writes = $writes{$fd}{total_writes}; | ||
72 | my $bytes_written = $writes{$fd}{bytes_written}; | ||
73 | printf("%6u %10u %10u\n", $fd, $total_writes, $bytes_written); | ||
74 | } | ||
75 | |||
76 | print_unhandled(); | ||
77 | } | ||
78 | |||
79 | my %unhandled; | ||
80 | |||
81 | sub print_unhandled | ||
82 | { | ||
83 | if ((scalar keys %unhandled) == 0) { | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | print "\nunhandled events:\n\n"; | ||
88 | |||
89 | printf("%-40s %10s\n", "event", "count"); | ||
90 | printf("%-40s %10s\n", "----------------------------------------", | ||
91 | "-----------"); | ||
92 | |||
93 | foreach my $event_name (keys %unhandled) { | ||
94 | printf("%-40s %10d\n", $event_name, $unhandled{$event_name}); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | sub trace_unhandled | ||
99 | { | ||
100 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
101 | $common_pid, $common_comm) = @_; | ||
102 | |||
103 | $unhandled{$event_name}++; | ||
104 | } | ||
105 | |||
106 | |||