|
1 # |
|
2 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Script: performance_log_parser.pl |
|
16 # |
|
17 |
|
18 use strict; |
|
19 use FileHandle; |
|
20 |
|
21 my $Test_Case_Start_Tag = "START_TESTCASE"; |
|
22 my $Test_Case_End_Tag = "END_TESTCASE"; |
|
23 my $Event_print = "PERFORMANCE_LOG_INFORMATION"; |
|
24 my $Test_Case_Max_Duration = "TEST_CASE_MAXIMUM_ALLOWED_DURATION"; |
|
25 my $ScrEventCode = 1; |
|
26 |
|
27 my $defInputFile = "/epoc32/winscw/c/logs/testexecute/tscr_performance.htm"; |
|
28 my $defOutputFile = "/epoc32/winscw/c/logs/scr_performance.txt"; |
|
29 |
|
30 sub millisec |
|
31 { |
|
32 no warnings 'uninitialized'; |
|
33 my ($mytime) = @_ ; |
|
34 $mytime =~ /([0-9]*):([0-9]*):([0-9]*):([0-9]*)$/; |
|
35 my $milisec = $4; |
|
36 my $sec = $3; |
|
37 my $min = $2; |
|
38 my $hour = $1; |
|
39 |
|
40 my $msecs = ($milisec / 1000) + ($sec *1000) + ($min * 60000) + ($hour * 3600000); |
|
41 return $msecs; |
|
42 } |
|
43 |
|
44 sub process_log_file |
|
45 { |
|
46 my ($data_file, $output_FH) = @_; |
|
47 print $output_FH "#Test Case Name,Maximum Duration(ms),Actual Duration(ms),Result\n"; |
|
48 |
|
49 # enable reading whole file as one chunk |
|
50 my $SAVE_RS = $/; |
|
51 undef $/; |
|
52 |
|
53 # open and read the log file in a single line |
|
54 open(DAT, $data_file) || die("Could not open file $data_file!"); |
|
55 my $raw_data=<DAT>; |
|
56 close(DAT); |
|
57 $raw_data=~ s/\n/ /g; |
|
58 |
|
59 # restore previous record separator |
|
60 $/ = $SAVE_RS; |
|
61 |
|
62 my $num_passed = 0; |
|
63 my $num_failed = 0; |
|
64 |
|
65 while ($raw_data && $raw_data =~ /$Test_Case_Start_Tag\s+(\S+)/) |
|
66 { |
|
67 # step through the file in chunks delimited by the start/end test case tags. |
|
68 |
|
69 my $test_case_name = $1; |
|
70 my ($test_case_data) = ($raw_data =~ /$Test_Case_Start_Tag(.*?)$Test_Case_End_Tag/); |
|
71 |
|
72 if (not $test_case_data) |
|
73 { |
|
74 print STDERR "Error: Test case: $test_case_name: Suspected missing END_TESTCASE tag.\n"; |
|
75 } |
|
76 |
|
77 ($raw_data) = ($raw_data =~ /$Test_Case_End_Tag(.*)/); |
|
78 ($raw_data) = ($raw_data =~ /($Test_Case_Start_Tag.*)/) if $raw_data; |
|
79 |
|
80 my ($max_duration) = ($test_case_data =~ /$Test_Case_Max_Duration,([0-9]+)/); |
|
81 if (!defined $max_duration) |
|
82 { |
|
83 $max_duration = 0; |
|
84 } |
|
85 |
|
86 my $start_time = "0"; |
|
87 my $end_time = "0"; |
|
88 my $first = 1; |
|
89 |
|
90 while ($test_case_data and ($test_case_data =~ /$Event_print(.*)/) ) |
|
91 { |
|
92 # get the event time. if this is the first time value in the chunk, it is the start time of the event. |
|
93 #otherwise, continue until reaching the last time value. |
|
94 my $start_log_msg = $1; |
|
95 |
|
96 $start_log_msg =~ /,(.+?)\s(.*)/; |
|
97 |
|
98 if($first == 1) |
|
99 { |
|
100 $start_time = $1; |
|
101 $first = 0; |
|
102 } |
|
103 else |
|
104 { |
|
105 $end_time = $1; |
|
106 } |
|
107 |
|
108 $test_case_data = $2; |
|
109 } |
|
110 |
|
111 if(!($start_time eq "0") && !($end_time eq "0")) |
|
112 { |
|
113 my $actual_duration = millisec($end_time) - millisec($start_time); |
|
114 my $result; |
|
115 if( $actual_duration <= $max_duration) |
|
116 { |
|
117 $result = "Passed"; |
|
118 $num_passed += 1; |
|
119 } |
|
120 else |
|
121 { |
|
122 $result = "Failed"; |
|
123 $num_failed += 1; |
|
124 } |
|
125 |
|
126 print $output_FH "$test_case_name,$max_duration,$actual_duration,$result\n"; |
|
127 } |
|
128 } |
|
129 print $output_FH (sprintf "\n\n%d tests failed out of %d\n", $num_failed, $num_passed+$num_failed); |
|
130 } |
|
131 |
|
132 |
|
133 sub usage |
|
134 { |
|
135 print <<USAGE; |
|
136 usage: |
|
137 performance_log_parser.pl <input_file> <output_file> |
|
138 |
|
139 <input_file>: A log file to process |
|
140 (default- $defInputFile) |
|
141 |
|
142 <out_file>: Final output file name |
|
143 (default- $defOutputFile) |
|
144 USAGE |
|
145 } |
|
146 |
|
147 |
|
148 sub Main |
|
149 { |
|
150 my @argv = @_; |
|
151 # if input and output files are not provided, default ones will be used |
|
152 my $input_file = $defInputFile; |
|
153 my $output_file = $defOutputFile; |
|
154 |
|
155 if(@argv > 2) |
|
156 { |
|
157 usage; |
|
158 exit; |
|
159 } |
|
160 elsif(@argv == 2) |
|
161 {# input and output files are provided, don't use default ones |
|
162 $input_file = shift @argv; |
|
163 $output_file = shift @argv; |
|
164 } |
|
165 |
|
166 my $outputFH = \*STDOUT; # results to STDOUT by default |
|
167 |
|
168 if (defined $output_file) |
|
169 { |
|
170 $outputFH = FileHandle->new; |
|
171 $outputFH->open("> $output_file") or die "Error: File $output_file: $!"; |
|
172 } |
|
173 process_log_file($input_file,$outputFH); |
|
174 |
|
175 $outputFH->close; |
|
176 } |
|
177 |
|
178 Main(@ARGV); |