|
1 # |
|
2 # Copyright (c) 2010 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 # |
|
16 |
|
17 #Change Log: |
|
18 #version 0.2: Analyzes multiple files in current directory. |
|
19 #version 0.1: Initial functionality. |
|
20 # |
|
21 #Provides summary of performance logs which are in the format: |
|
22 #add nnn - Time for add operation |
|
23 #del nnn - Time for delete operation |
|
24 #upd nnn - Time for update opearation |
|
25 #Ignores all other lines. |
|
26 # |
|
27 #Reads the current directory looking for file names |
|
28 #with the pattern '*Perf.txt' (case sensitive). |
|
29 # |
|
30 #Prints the cumulative times for all ADD/DEL/UPD operations |
|
31 |
|
32 use warnings; |
|
33 use strict; |
|
34 |
|
35 #This prints the summary; called by analzyeFile |
|
36 sub printSummary($$$){ |
|
37 print "Total time for Add: ".(shift)."\n"; |
|
38 print "Total time for Delete: ".(shift)."\n"; |
|
39 print "Total time for Update: ".(shift)."\n"; |
|
40 print "-------------------------------------\n\n"; |
|
41 } |
|
42 |
|
43 #This function analyzes the contents of the performance logs file |
|
44 sub analyzeFile($){ |
|
45 my $fh = shift; |
|
46 my $add=0; |
|
47 my $del=0; |
|
48 my $upd=0; |
|
49 foreach my $line (<$fh>){ |
|
50 chomp($line);#remove the newline from $line. |
|
51 #Documentation recommends not to use $' for |
|
52 #performance reasons. In this case, its okay. |
|
53 if ($line =~ m/^add */) { |
|
54 $add += $'; |
|
55 } |
|
56 if($line =~ m/^del */) { |
|
57 $del += $'; |
|
58 } |
|
59 if($line =~ m/^upd */) { |
|
60 $upd += $'; |
|
61 } |
|
62 } |
|
63 #better if we can 'return; these values and have the |
|
64 #caller print the values returned. |
|
65 #very tight function coupling otherwise. |
|
66 printSummary($add, $del, $upd); |
|
67 } |
|
68 |
|
69 #Main entry point |
|
70 sub main(){ |
|
71 #We can change the function to be able to read |
|
72 #cmd line args and analyze the necessary directory |
|
73 #but thats for later. Not required for the moment. |
|
74 my $directory = "."; |
|
75 my $dirHandle; |
|
76 |
|
77 opendir($dirHandle, "$directory") or die("Could not list directory $directory."); |
|
78 my @thefiles = readdir($dirHandle); |
|
79 |
|
80 foreach my $f (@thefiles){ |
|
81 if ($f =~ m/Perf\.txt$/) {#should end with "Perf.txt" |
|
82 open my $inputFile, "<$f" or die("Could not open log file $f."); |
|
83 print "File: ".$f."\n"; |
|
84 print "-----------------------\n"; |
|
85 analyzeFile($inputFile); |
|
86 close($inputFile); |
|
87 } |
|
88 } |
|
89 closedir($dirHandle); |
|
90 } |
|
91 |
|
92 #Call main() to do the work. |
|
93 main(); |