16766baabd2810412bb27253f5fd5ab9aaaaddb9
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 = '\((?:.*)\)';
146 my $hostname = '(?:.*)';
147 my $tp_event = '(.*)';
148 my $pkt_context = '(?:\{[^}]*\},\s)*';
149 my $fields = '\{(.*)\}$';
151 # Parse babeltrace text output format
152 if (/$timestamp\s$elapsed\s$hostname\s$tp_event:\s$pkt_context$fields/) {
154 $event_hash{'tp_event'} = $1;
155 $event_hash{'fields'} = parse_fields
($2);
157 push @events, \
%event_hash;
161 my %merged_fields = %{merge_fields
(\@
{events
})};
162 print_fields_stats
(\
%merged_fields, $opt_tracepoint);
This page took 0.033867 seconds and 3 git commands to generate.