2 # Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 my ($regular_out_file, $range_out_file) = @ARGV;
23 print "Script requires two arguments,
24 which are file names to store the output\n
25 Regular points will be stored in first file,
26 ranges in second one.\n" and exit unless (defined $regular_out_file and defined $range_out_file);
29 print "Starting analysis\n";
33 foreach my $line (@lines)
36 my @splitted = split(/#/, $line);
37 my $prefix = $splitted[0];
38 my $name = $splitted[1];
39 my $time = $splitted[2];
40 my $description = $splitted[3];
42 $packet{time} = $time;
43 $packet{prefix} = $prefix;
44 $packet{name} = $name;
45 $packet{description} = $description;
46 push @packets, \%packet;
49 @packets = sort { $$a{time} <=> $$b{time} } @packets;
55 foreach my $packet (@packets)
57 my $name = $$packet{name};
58 my $prefix = $$packet{prefix};
60 if (not defined $starttime)
62 if (defined $name and $name eq "Profiling_Started")
64 $starttime = $$packet{time};
68 print "***** No Profiling Start Point Found *****\n";
72 $$packet{time} = $$packet{time} - $starttime;
74 if ($prefix eq "start")
76 if (exists($tmps{$name}))
78 print "***** Doubled start point found $name *****\n";
82 $tmps{$name} = \%$packet;
84 elsif ($prefix eq "stop")
86 if (not exists($tmps{$name}))
88 print "***** No start point found *****\n";
91 my %tmp = %{$tmps{$name}};
92 my %newpacket = %$packet;
93 $newpacket{time} = $newpacket{time} - $tmp{time};
94 delete ($tmps{$name});
96 foreach my $p (@ranges)
98 if ($$p{name} eq $newpacket{name})
100 $$p{time} += $newpacket{time};
104 if (not defined($found))
106 push(@ranges, \%newpacket);
111 open REGULAR_OUT_FILE, ">", $regular_out_file or die $!;
113 print REGULAR_OUT_FILE "name,prefix,timestamp[µs],timespan[µs]\n";
115 foreach my $point (@packets)
117 if (not defined $lastTime)
119 $lastTime = $$point{time};
121 my $toPrint = sprintf("%s-%s,%lu,%lu\n", $$point{name}, $$point{prefix}, $$point{time}, $$point{time} - $lastTime);
122 print REGULAR_OUT_FILE $toPrint;
123 $lastTime = $$point{time};
125 close REGULAR_OUT_FILE;
127 open RANGE_OUT_FILE, ">", $range_out_file or die $!;
128 print RANGE_OUT_FILE "range name,timespan[µs]\n";
129 foreach my $range (@ranges)
131 my $res = sprintf("%s,%lu\n", $$range{name}, $$range{time});
132 print RANGE_OUT_FILE $res;
134 close RANGE_OUT_FILE;