3 # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 GetOptions
('tracepoint=s' => \
$opt_tracepoint)
26 or die("Invalid command-line option\n");
28 defined($opt_tracepoint)
29 or die("Missing tracepoint, use --tracepoint <name>");
31 # Parse an array string.
32 # The format is as follow: [ [index] = value, ... ]
38 # Strip leading and ending brackets, remove whitespace
43 my @entries = split(',', $arr_str);
45 foreach my $entry (@entries) {
46 if ($entry =~ /^\[(\d+)\]=(\d+)$/) {
49 splice @array, $index, 0, $value;
56 # Parse fields values.
57 # Format can either be a name = array or a name = value pair.
60 my ($fields_str) = @_;
63 my $field_name = '[\w\d_]+';
64 my $field_value = '[\w\d_\\\*"]+';
65 my $array = '\[(?:\s\[\d+\]\s=\s\d+,)*\s\[\d+\]\s=\s\d+\s\]';
67 # Split the various fields
68 my @fields = ($fields_str =~ /$field_name\s=\s(?:$array|$field_value)/g);
70 foreach my $field (@fields) {
71 if ($field =~ /($field_name)\s=\s($array)/) {
73 my $value = parse_array
($2);
74 $fields_hash{$name} = $value;
77 if ($field =~ /($field_name)\s=\s($field_value)/) {
80 $fields_hash{$name} = $value;
87 # Using an event array, merge all the fields
88 # of a particular tracepoint.
91 my ($events_ref) = @_;
94 foreach my $event (@
{$events_ref}) {
95 my $tp_event = $event->{'tp_event'};
96 my $tracepoint = "${tp_event}";
98 foreach my $key (keys %{$event->{'fields'}}) {
99 my $val = $event->{'fields'}->{$key};
101 # TODO: Merge of array is not implemented.
102 next if (ref($val) eq 'ARRAY');
103 $merged{$tracepoint}{$key}{$val} = undef;
110 # Print the minimum and maximum of each fields
111 # for a particular tracepoint.
112 sub print_fields_stats
114 my ($merged_ref, $tracepoint) = @_;
116 return unless ($tracepoint && exists $merged_ref->{$tracepoint});
118 foreach my $field (keys %{$merged_ref->{$tracepoint}}) {
120 my @val = keys %{$merged_ref->{$tracepoint}->{$field}};
122 if ($val[0] =~ /^\d+$/) {
124 @sorted = sort { $a <=> $b } @val;
125 } elsif ($val[0] =~ /^0x[\da-f]+$/i) {
126 # Convert the hex values and sort numerically
127 @sorted = sort { hex($a) <=> hex($b) } @val;
129 # Fallback, alphabetical sort
130 @sorted = sort { lc($a) cmp lc($b) } @val;
133 my $min = $sorted[0];
134 my $max = $sorted[-1];
136 print "$field $min $max\n";
144 my $timestamp = '\[(.*)\]';
145 my $elapsed = '\((.*)\)';
151 my $cpu_info = '{\scpu_id\s=\s(\d+)\s\}';
152 my $fields = '{(.*)}';
154 # Parse babeltrace text output format
155 if (/$timestamp\s$elapsed\s($pinfo)\s($tp_event):\s$cpu_info,\s$fields/) {
157 $event_hash{'timestamp'} = $1;
158 $event_hash{'elapsed'} = $2;
159 $event_hash{'pinfo'} = $3;
161 # my @split_pinfo = split(':', $3);
162 # $event_hash{'hostname'} = $split_pinfo[0];
163 # $event_hash{'pname'} = defined($split_pinfo[1]) ? $split_pinfo[1] : undef;
164 # $event_hash{'pid'} = defined($split_pinfo[2]) ? $split_pinfo[2] : undef;
166 $event_hash{'tp_event'} = $4;
167 $event_hash{'cpu_id'} = $5;
168 $event_hash{'fields'} = parse_fields
($6);
170 push @events, \
%event_hash;
174 my %merged_fields = %{merge_fields
(\@
{events
})};
175 print_fields_stats
(\
%merged_fields, $opt_tracepoint);
This page took 0.035603 seconds and 4 git commands to generate.