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_provider = $event->{'tp_provider'};
96 my $tp_name = $event->{'tp_name'};
97 my $tracepoint = "$tp_provider:$tp_name";
99 foreach my $key (keys %{$event->{'fields'}}) {
100 my $val = $event->{'fields'}->{$key};
102 # TODO: Merge of array is not implemented.
103 next if (ref($val) eq 'ARRAY');
104 $merged{$tracepoint}{$key}{$val} = undef;
111 # Print the minimum and maximum of each fields
112 # for a particular tracepoint.
113 sub print_fields_stats
115 my ($merged_ref, $tracepoint) = @_;
117 return unless ($tracepoint && exists $merged_ref->{$tracepoint});
119 foreach my $field (keys %{$merged_ref->{$tracepoint}}) {
121 my @val = keys %{$merged_ref->{$tracepoint}->{$field}};
123 if ($val[0] =~ /^\d+$/) {
125 @sorted = sort { $a <=> $b } @val;
126 } elsif ($val[0] =~ /^0x[\da-f]+$/i) {
127 # Convert the hex values and sort numerically
128 @sorted = sort { hex($a) <=> hex($b) } @val;
130 # Fallback, alphabetical sort
131 @sorted = sort { lc($a) cmp lc($b) } @val;
134 my $min = $sorted[0];
135 my $max = $sorted[-1];
137 print "$field $min $max\n";
145 my $timestamp = '\[(.*)\]';
146 my $elapsed = '\((.*)\)';
151 my $tp_provider = '.*';
153 my $cpu_info = '{\scpu_id\s=\s(\d+)\s\}';
154 my $fields = '{(.*)}';
156 # Parse babeltrace text output format
157 if (/$timestamp\s$elapsed\s($pinfo)\s($tp_provider):($tp_name):\s$cpu_info,\s$fields/) {
159 $event_hash{'timestamp'} = $1;
160 $event_hash{'elapsed'} = $2;
161 $event_hash{'pinfo'} = $3;
163 # my @split_pinfo = split(':', $3);
164 # $event_hash{'hostname'} = $split_pinfo[0];
165 # $event_hash{'pname'} = defined($split_pinfo[1]) ? $split_pinfo[1] : undef;
166 # $event_hash{'pid'} = defined($split_pinfo[2]) ? $split_pinfo[2] : undef;
168 $event_hash{'tp_provider'} = $4;
169 $event_hash{'tp_name'} = $5;
170 $event_hash{'cpu_id'} = $6;
171 $event_hash{'fields'} = parse_fields
($7);
173 push @events, \
%event_hash;
177 my %merged_fields = %{merge_fields
(\@
{events
})};
178 print_fields_stats
(\
%merged_fields, $opt_tracepoint);
This page took 0.036377 seconds and 5 git commands to generate.