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/Perf-Trace-Util | |
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/Perf-Trace-Util')
4 files changed, 292 insertions, 0 deletions
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL b/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL new file mode 100644 index 000000000000..b0de02e6950d --- /dev/null +++ b/tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL | |||
@@ -0,0 +1,12 @@ | |||
1 | use 5.010000; | ||
2 | use ExtUtils::MakeMaker; | ||
3 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence | ||
4 | # the contents of the Makefile that is written. | ||
5 | WriteMakefile( | ||
6 | NAME => 'Perf::Trace::Util', | ||
7 | VERSION_FROM => 'lib/Perf/Trace/Util.pm', # finds $VERSION | ||
8 | PREREQ_PM => {}, # e.g., Module::Name => 1.1 | ||
9 | ($] >= 5.005 ? ## Add these new keywords supported since 5.005 | ||
10 | (ABSTRACT_FROM => 'lib/Perf/Trace/Util.pm', # retrieve abstract from module | ||
11 | AUTHOR => 'Tom Zanussi <tzanussi@gmail.com>') : ()), | ||
12 | ); | ||
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/README b/tools/perf/scripts/perl/Perf-Trace-Util/README new file mode 100644 index 000000000000..0a58378f0836 --- /dev/null +++ b/tools/perf/scripts/perl/Perf-Trace-Util/README | |||
@@ -0,0 +1,35 @@ | |||
1 | Perf-Trace-Util version 0.01 | ||
2 | ============================ | ||
3 | |||
4 | This module contains utility functions for use with perf trace. | ||
5 | |||
6 | INSTALLATION | ||
7 | |||
8 | Building perf with perf trace Perl scripting should install this | ||
9 | module in the right place. | ||
10 | |||
11 | You should make sure libperl is installed first e.g. apt-get install | ||
12 | libperl-dev. | ||
13 | |||
14 | DEPENDENCIES | ||
15 | |||
16 | This module requires these other modules and libraries: | ||
17 | |||
18 | blah blah blah | ||
19 | |||
20 | COPYRIGHT AND LICENCE | ||
21 | |||
22 | Put the correct copyright and licence information here. | ||
23 | |||
24 | Copyright (C) 2009 by Tom Zanussi <tzanussi@gmail.com> | ||
25 | |||
26 | This library is free software; you can redistribute it and/or modify | ||
27 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||
28 | at your option, any later version of Perl 5 you may have available. | ||
29 | |||
30 | Alternatively, this software may be distributed under the terms of the | ||
31 | GNU General Public License ("GPL") version 2 as published by the Free | ||
32 | Software Foundation. | ||
33 | |||
34 | |||
35 | |||
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Core.pm b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Core.pm new file mode 100644 index 000000000000..fd250fb7be16 --- /dev/null +++ b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Core.pm | |||
@@ -0,0 +1,157 @@ | |||
1 | package Perf::Trace::Core; | ||
2 | |||
3 | use 5.010000; | ||
4 | use strict; | ||
5 | use warnings; | ||
6 | |||
7 | require Exporter; | ||
8 | |||
9 | our @ISA = qw(Exporter); | ||
10 | |||
11 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
12 | ) ] ); | ||
13 | |||
14 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
15 | |||
16 | our @EXPORT = qw( | ||
17 | define_flag_field define_flag_value flag_str dump_flag_fields | ||
18 | define_symbolic_field define_symbolic_value symbol_str dump_symbolic_fields | ||
19 | ); | ||
20 | |||
21 | our $VERSION = '0.01'; | ||
22 | |||
23 | my %flag_fields; | ||
24 | my %symbolic_fields; | ||
25 | |||
26 | sub flag_str | ||
27 | { | ||
28 | my ($event_name, $field_name, $value) = @_; | ||
29 | |||
30 | my $string; | ||
31 | |||
32 | if ($flag_fields{$event_name}{$field_name}) { | ||
33 | my $print_delim = 0; | ||
34 | foreach my $idx (sort {$a <=> $b} keys %{$flag_fields{$event_name}{$field_name}{"values"}}) { | ||
35 | if (!$value && !$idx) { | ||
36 | $string .= "$flag_fields{$event_name}{$field_name}{'values'}{$idx}"; | ||
37 | last; | ||
38 | } | ||
39 | if ($idx && ($value & $idx) == $idx) { | ||
40 | if ($print_delim && $flag_fields{$event_name}{$field_name}{'delim'}) { | ||
41 | $string .= " $flag_fields{$event_name}{$field_name}{'delim'} "; | ||
42 | } | ||
43 | $string .= "$flag_fields{$event_name}{$field_name}{'values'}{$idx}"; | ||
44 | $print_delim = 1; | ||
45 | $value &= ~$idx; | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | return $string; | ||
51 | } | ||
52 | |||
53 | sub define_flag_field | ||
54 | { | ||
55 | my ($event_name, $field_name, $delim) = @_; | ||
56 | |||
57 | $flag_fields{$event_name}{$field_name}{"delim"} = $delim; | ||
58 | } | ||
59 | |||
60 | sub define_flag_value | ||
61 | { | ||
62 | my ($event_name, $field_name, $value, $field_str) = @_; | ||
63 | |||
64 | $flag_fields{$event_name}{$field_name}{"values"}{$value} = $field_str; | ||
65 | } | ||
66 | |||
67 | sub dump_flag_fields | ||
68 | { | ||
69 | for my $event (keys %flag_fields) { | ||
70 | print "event $event:\n"; | ||
71 | for my $field (keys %{$flag_fields{$event}}) { | ||
72 | print " field: $field:\n"; | ||
73 | print " delim: $flag_fields{$event}{$field}{'delim'}\n"; | ||
74 | foreach my $idx (sort {$a <=> $b} keys %{$flag_fields{$event}{$field}{"values"}}) { | ||
75 | print " value $idx: $flag_fields{$event}{$field}{'values'}{$idx}\n"; | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | sub symbol_str | ||
82 | { | ||
83 | my ($event_name, $field_name, $value) = @_; | ||
84 | |||
85 | if ($symbolic_fields{$event_name}{$field_name}) { | ||
86 | foreach my $idx (sort {$a <=> $b} keys %{$symbolic_fields{$event_name}{$field_name}{"values"}}) { | ||
87 | if (!$value && !$idx) { | ||
88 | return "$symbolic_fields{$event_name}{$field_name}{'values'}{$idx}"; | ||
89 | last; | ||
90 | } | ||
91 | if ($value == $idx) { | ||
92 | return "$symbolic_fields{$event_name}{$field_name}{'values'}{$idx}"; | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | return undef; | ||
98 | } | ||
99 | |||
100 | sub define_symbolic_field | ||
101 | { | ||
102 | my ($event_name, $field_name) = @_; | ||
103 | |||
104 | # nothing to do, really | ||
105 | } | ||
106 | |||
107 | sub define_symbolic_value | ||
108 | { | ||
109 | my ($event_name, $field_name, $value, $field_str) = @_; | ||
110 | |||
111 | $symbolic_fields{$event_name}{$field_name}{"values"}{$value} = $field_str; | ||
112 | } | ||
113 | |||
114 | sub dump_symbolic_fields | ||
115 | { | ||
116 | for my $event (keys %symbolic_fields) { | ||
117 | print "event $event:\n"; | ||
118 | for my $field (keys %{$symbolic_fields{$event}}) { | ||
119 | print " field: $field:\n"; | ||
120 | foreach my $idx (sort {$a <=> $b} keys %{$symbolic_fields{$event}{$field}{"values"}}) { | ||
121 | print " value $idx: $symbolic_fields{$event}{$field}{'values'}{$idx}\n"; | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | |||
127 | 1; | ||
128 | __END__ | ||
129 | =head1 NAME | ||
130 | |||
131 | Perf::Trace::Core - Perl extension for perf trace | ||
132 | |||
133 | =head1 SYNOPSIS | ||
134 | |||
135 | use Perf::Trace::Core | ||
136 | |||
137 | =head1 SEE ALSO | ||
138 | |||
139 | Perf (trace) documentation | ||
140 | |||
141 | =head1 AUTHOR | ||
142 | |||
143 | Tom Zanussi, E<lt>tzanussi@gmail.com<gt> | ||
144 | |||
145 | =head1 COPYRIGHT AND LICENSE | ||
146 | |||
147 | Copyright (C) 2009 by Tom Zanussi | ||
148 | |||
149 | This library is free software; you can redistribute it and/or modify | ||
150 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||
151 | at your option, any later version of Perl 5 you may have available. | ||
152 | |||
153 | Alternatively, this software may be distributed under the terms of the | ||
154 | GNU General Public License ("GPL") version 2 as published by the Free | ||
155 | Software Foundation. | ||
156 | |||
157 | =cut | ||
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm new file mode 100644 index 000000000000..052f132ced24 --- /dev/null +++ b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm | |||
@@ -0,0 +1,88 @@ | |||
1 | package Perf::Trace::Util; | ||
2 | |||
3 | use 5.010000; | ||
4 | use strict; | ||
5 | use warnings; | ||
6 | |||
7 | require Exporter; | ||
8 | |||
9 | our @ISA = qw(Exporter); | ||
10 | |||
11 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
12 | ) ] ); | ||
13 | |||
14 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
15 | |||
16 | our @EXPORT = qw( | ||
17 | avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs | ||
18 | ); | ||
19 | |||
20 | our $VERSION = '0.01'; | ||
21 | |||
22 | sub avg | ||
23 | { | ||
24 | my ($total, $n) = @_; | ||
25 | |||
26 | return $total / $n; | ||
27 | } | ||
28 | |||
29 | my $NSECS_PER_SEC = 1000000000; | ||
30 | |||
31 | sub nsecs | ||
32 | { | ||
33 | my ($secs, $nsecs) = @_; | ||
34 | |||
35 | return $secs * $NSECS_PER_SEC + $nsecs; | ||
36 | } | ||
37 | |||
38 | sub nsecs_secs { | ||
39 | my ($nsecs) = @_; | ||
40 | |||
41 | return $nsecs / $NSECS_PER_SEC; | ||
42 | } | ||
43 | |||
44 | sub nsecs_nsecs { | ||
45 | my ($nsecs) = @_; | ||
46 | |||
47 | return $nsecs - nsecs_secs($nsecs); | ||
48 | } | ||
49 | |||
50 | sub nsecs_str { | ||
51 | my ($nsecs) = @_; | ||
52 | |||
53 | my $str = sprintf("%5u.%09u", nsecs_secs($nsecs), nsecs_nsecs($nsecs)); | ||
54 | |||
55 | return $str; | ||
56 | } | ||
57 | |||
58 | 1; | ||
59 | __END__ | ||
60 | =head1 NAME | ||
61 | |||
62 | Perf::Trace::Util - Perl extension for perf trace | ||
63 | |||
64 | =head1 SYNOPSIS | ||
65 | |||
66 | use Perf::Trace::Util; | ||
67 | |||
68 | =head1 SEE ALSO | ||
69 | |||
70 | Perf (trace) documentation | ||
71 | |||
72 | =head1 AUTHOR | ||
73 | |||
74 | Tom Zanussi, E<lt>tzanussi@gmail.com<gt> | ||
75 | |||
76 | =head1 COPYRIGHT AND LICENSE | ||
77 | |||
78 | Copyright (C) 2009 by Tom Zanussi | ||
79 | |||
80 | This library is free software; you can redistribute it and/or modify | ||
81 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||
82 | at your option, any later version of Perl 5 you may have available. | ||
83 | |||
84 | Alternatively, this software may be distributed under the terms of the | ||
85 | GNU General Public License ("GPL") version 2 as published by the Free | ||
86 | Software Foundation. | ||
87 | |||
88 | =cut | ||