3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
15 GetOptions
('tracepoint=s' => \
$opt_tracepoint)
16 or die("Invalid command-line option\n");
18 defined($opt_tracepoint)
19 or die("Missing tracepoint, use --tracepoint <name>");
21 # Parse an array string.
22 # The format is as follow: [ [index] = value, ... ]
28 # Strip leading and ending brackets, remove whitespace
33 my @entries = split(',', $arr_str);
35 foreach my $entry (@entries) {
36 if ($entry =~ /^\[(\d+)\]=(\d+)$/) {
39 splice @array, $index, 0, $value;
46 # Parse fields values.
47 # Format can either be a name = array or a name = value pair.
50 my ($fields_str) = @_;
53 my $field_name = '[\w\d_]+';
54 my $field_value = '[\w\d_\\\*"]+';
55 my $array = '\[(?:\s\[\d+\]\s=\s\d+,)*\s\[\d+\]\s=\s\d+\s\]';
57 # Split the various fields
58 my @fields = ($fields_str =~ /$field_name\s=\s(?:$array|$field_value)/g);
60 foreach my $field (@fields) {
61 if ($field =~ /($field_name)\s=\s($array)/) {
63 my $value = parse_array
($2);
64 $fields_hash{$name} = $value;
67 if ($field =~ /($field_name)\s=\s($field_value)/) {
70 $fields_hash{$name} = $value;
77 # Using an event array, merge all the fields
78 # of a particular tracepoint.
81 my ($events_ref) = @_;
84 foreach my $event (@
{$events_ref}) {
85 my $tp_event = $event->{'tp_event'};
86 my $tracepoint = "${tp_event}";
88 foreach my $key (keys %{$event->{'fields'}}) {
89 my $val = $event->{'fields'}->{$key};
91 # TODO: Merge of array is not implemented.
92 next if (ref($val) eq 'ARRAY');
93 $merged{$tracepoint}{$key}{$val} = undef;
100 # Print the minimum and maximum of each fields
101 # for a particular tracepoint.
102 sub print_fields_stats
104 my ($merged_ref, $tracepoint) = @_;
106 return unless ($tracepoint && exists $merged_ref->{$tracepoint});
108 foreach my $field (keys %{$merged_ref->{$tracepoint}}) {
110 my @val = keys %{$merged_ref->{$tracepoint}->{$field}};
112 if ($val[0] =~ /^\d+$/) {
114 @sorted = sort { $a <=> $b } @val;
115 } elsif ($val[0] =~ /^0x[\da-f]+$/i) {
116 # Convert the hex values and sort numerically
117 @sorted = sort { hex($a) <=> hex($b) } @val;
119 # Fallback, alphabetical sort
120 @sorted = sort { lc($a) cmp lc($b) } @val;
123 my $min = $sorted[0];
124 my $max = $sorted[-1];
126 print "$field $min $max\n";
134 my $timestamp = '\[(?:.*)\]';
135 my $elapsed = '\((?:.*)\)';
136 my $hostname = '(?:.*)';
137 my $tp_event = '(.*)';
138 my $pkt_context = '(?:\{[^}]*\},\s)*';
139 my $fields = '\{(.*)\}$';
141 # Parse babeltrace text output format
142 if (/$timestamp\s$elapsed\s$hostname\s$tp_event:\s$pkt_context$fields/) {
144 $event_hash{'tp_event'} = $1;
145 $event_hash{'fields'} = parse_fields
($2);
147 push @events, \
%event_hash;
151 my %merged_fields = %{merge_fields
(\@
{events
})};
152 print_fields_stats
(\
%merged_fields, $opt_tracepoint);
This page took 0.034619 seconds and 4 git commands to generate.