|
1 #!perl |
|
2 # Copyright (c) 2002-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 "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 # Perl script to output the current build rom_metric to a csv file. |
|
16 # The file is of the format <build_no>,<rom_size> |
|
17 # use warnings; |
|
18 # |
|
19 # |
|
20 |
|
21 use strict; |
|
22 use Getopt::Long; |
|
23 use File::Copy; |
|
24 |
|
25 # |
|
26 # Main |
|
27 # |
|
28 |
|
29 # Check arguments |
|
30 my $build = ''; |
|
31 my $do_all = 0; |
|
32 my $device = ''; |
|
33 my $rom_loc = ''; |
|
34 my $publish_loc = ''; |
|
35 my $preview = 0; |
|
36 my $help = 0; |
|
37 my $dir_name; |
|
38 my $roms_loc; |
|
39 |
|
40 GetOptions ( 'n' => \$preview, 'b=s' => \$build, 'a' => \$do_all, 'd=s' => \$device, 'p=s' => \$publish_loc, 'h|?' => \$help ); |
|
41 &Usage() if $help; |
|
42 &Usage() if ( !$do_all && $build eq '' ); |
|
43 &Usage() if ( ( $publish_loc eq '' ) || ( $device eq '' ) ); |
|
44 |
|
45 # |
|
46 # Check if all builds are to be processed |
|
47 |
|
48 my $pathspec = $publish_loc.'\\logs\\<build>\\rom_logs'; |
|
49 my $rom_logfilespec = "$pathspec\\${device}.log"; |
|
50 my $csv_logfilespec = $publish_loc."\\Rom_metrics"."\\${device}.csv"; |
|
51 my $csv_logfilespec_old = $publish_loc."\\Rom_metrics"."\\${device}.old"; |
|
52 $roms_loc = $publish_loc.'\\logs'; |
|
53 my $do_read = 1; |
|
54 |
|
55 if ( $do_all ) |
|
56 { |
|
57 # Get all the log directories and process a new csv file. |
|
58 |
|
59 |
|
60 # Check if old log file exist then remove it then move the current file to old name. |
|
61 if ( -e $csv_logfilespec ) |
|
62 { |
|
63 print ( "Moving old file\n" ); |
|
64 if ( -e $csv_logfilespec_old ) |
|
65 { |
|
66 if ( $preview ) |
|
67 { |
|
68 print( "\ndel $csv_logfilespec_old\n" ); |
|
69 } |
|
70 else |
|
71 { |
|
72 unlink( "$csv_logfilespec_old" ); |
|
73 } |
|
74 } |
|
75 if ( $preview ) |
|
76 { |
|
77 print( "\nmove $csv_logfilespec $csv_logfilespec_old\n" ); |
|
78 } |
|
79 else |
|
80 { |
|
81 move( "$csv_logfilespec", "$csv_logfilespec_old" ); |
|
82 } |
|
83 } |
|
84 |
|
85 # Get list of directories |
|
86 opendir ( DIRS, $roms_loc ); |
|
87 while ( defined ( $dir_name = readdir( DIRS ) ) ) |
|
88 { |
|
89 # $dir_name = $_; |
|
90 chomp ( $dir_name ); |
|
91 |
|
92 # Look for name starting with 5 numbers, should be a build directory |
|
93 print "Checking dir $dir_name \n"; |
|
94 if ( -d $roms_loc."\\".$dir_name ) |
|
95 { |
|
96 if ( $dir_name =~ /^(\d{5})/ ) |
|
97 { |
|
98 $rom_logfilespec = "$roms_loc\\$dir_name\\rom_logs\\${device}.log"; |
|
99 print "Looking in $roms_loc\\$dir_name for $rom_logfilespec\n"; |
|
100 $do_read = 1; |
|
101 |
|
102 # Open the file for reading |
|
103 if ( -e $rom_logfilespec ) |
|
104 { |
|
105 open( INPUT, $rom_logfilespec ) or next "Can't open $rom_logfilespec\n"; |
|
106 } |
|
107 else |
|
108 { |
|
109 print "Can't find log file $rom_logfilespec\n"; |
|
110 open(CSVFILE, ">> $csv_logfilespec" ) or die "Can't open log file for appending.\n"; |
|
111 if ( $preview ) |
|
112 { |
|
113 print ( "$dir_name,-1,\n" ); |
|
114 } |
|
115 else |
|
116 { |
|
117 print CSVFILE ( "$dir_name,-1,\n" ); |
|
118 } |
|
119 close(CSVFILE); |
|
120 $do_read = 0; |
|
121 |
|
122 } |
|
123 |
|
124 # Extract details from the log file |
|
125 print "Checking do_read $do_read \n"; |
|
126 if ( $do_read ) |
|
127 { |
|
128 my $line; |
|
129 while($line = <INPUT>) |
|
130 { |
|
131 # Find size information |
|
132 if($line =~ /^Total used (\d+)$/) |
|
133 { |
|
134 # Open the csv file for appending |
|
135 open(CSVFILE, ">> $csv_logfilespec" ) or die "Can't open log file for appending.\n"; |
|
136 if ( $preview ) |
|
137 { |
|
138 print ( "$dir_name,$1,\n" ); |
|
139 } |
|
140 else |
|
141 { |
|
142 print CSVFILE ( "$dir_name,$1,\n" ); |
|
143 } |
|
144 close(CSVFILE); |
|
145 } |
|
146 } |
|
147 |
|
148 close(INPUT); |
|
149 } |
|
150 } |
|
151 } |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 # Do not process all directories. Just get the log file from the given one and append to the csv file. |
|
157 |
|
158 # Check if old log file exist then remove it then move the current file to old name. |
|
159 if ( -e $csv_logfilespec ) |
|
160 { |
|
161 print ( "Copy to old file\n" ); |
|
162 if ( -e $csv_logfilespec_old ) |
|
163 { |
|
164 if ( $preview ) |
|
165 { |
|
166 print( "del $csv_logfilespec_old\n" ); |
|
167 } |
|
168 else |
|
169 { |
|
170 unlink( "$csv_logfilespec_old" ); |
|
171 } |
|
172 } |
|
173 if ( $preview ) |
|
174 { |
|
175 print( "copy $csv_logfilespec $csv_logfilespec_old\n" ); |
|
176 } |
|
177 else |
|
178 { |
|
179 copy( "$csv_logfilespec", "$csv_logfilespec_old" ); |
|
180 } |
|
181 } |
|
182 |
|
183 $rom_logfilespec = "$roms_loc\\${build}\\rom_logs\\${device}.log"; |
|
184 print "Looking in $roms_loc\\$build for $rom_logfilespec\n"; |
|
185 |
|
186 # Open the file for reading |
|
187 if ( -e $rom_logfilespec ) |
|
188 { |
|
189 open( INPUT, $rom_logfilespec ) or die "Can't open $rom_logfilespec\n"; |
|
190 } |
|
191 else |
|
192 { |
|
193 open(CSVFILE, ">> $csv_logfilespec" ) or die "Can't open log file for appending.\n"; |
|
194 if ( $preview ) |
|
195 { |
|
196 print ( "$build,-1,\n" ); |
|
197 } |
|
198 else |
|
199 { |
|
200 print CSVFILE ( "$build,-1,\n" ); |
|
201 } |
|
202 close(CSVFILE); |
|
203 die "Can't find log file $rom_logfilespec\n"; |
|
204 } |
|
205 |
|
206 # Extract details from the log file |
|
207 my $line; |
|
208 while($line = <INPUT>) |
|
209 { |
|
210 # Find size information |
|
211 if($line =~ /^Total used (\d+)$/) |
|
212 { |
|
213 # Open the csv file for appending |
|
214 open(CSVFILE, ">> $csv_logfilespec" ) or die "Can't open log file for appending.\n"; |
|
215 if ( $preview ) |
|
216 { |
|
217 print ( "$build,$1,\n" ); |
|
218 } |
|
219 else |
|
220 { |
|
221 print CSVFILE ( "$build,$1,\n" ); |
|
222 } |
|
223 } |
|
224 } |
|
225 |
|
226 close(INPUT); |
|
227 |
|
228 } |
|
229 |
|
230 sub Usage |
|
231 { |
|
232 print "\nperl rom_metrics_list.pl [-a | -b %1] -d %2 -p %3 [-n]\n\n"; |
|
233 print "-a Process all builds.\n"; |
|
234 print "-b Build number.\n"; |
|
235 print "-d Device type.e.g. ab_001.techview\n"; |
|
236 print "-p Publish location.\n"; |
|
237 print "-n Preview only.\n"; |
|
238 print "-h Help.\n\n"; |
|
239 exit (0); |
|
240 } |