root/branches/newmole/scripts/ir_extime.pl

Revision 13, 8.2 kB (checked in by gary, 3 years ago)

adjust file properties for ascii and perl files - no source change

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2
3#**********************************************************************#
4#*  Perl script to check the current itr/zn and execution time of a   *#
5#*  model with its previous itr/zn and execution time                 *#
6#*  If the increase is above a set threshold percentage it sends a    *#
7#*  mail stating so. It also creates a itrlogs/ directory and keeps   *#
8#*  the log of the itr/zn and execution time of the models, every     *#
9#*  time the models are executed. The percentage increse in time is   *#
10#*  recorded in the file auto/itrzn.log                               *#
11#*                                                                    *#
12#*  Program written by Geetashree Chakravorty, Graduate Student       *#
13#*  Computer Science Department, University of Kentucky               *#
14#*  in the year 2002 for Dr. Gary Ferland. Modified: August,2003      *#
15#**********************************************************************#
16
17
18# Common directory
19$curr_dir = "c://projects//cloudy//trunk//tsuite";
20#$curr_dir = "/home62/guests/geetac/PROJECT2003/proj1";
21
22# Directory to store all the log files
23$lgdir = 'itrlogs/';
24
25if ( !chdir ($curr_dir))
26{
27   printf (" invalid directory\n");
28   exit;
29}
30
31# If itrlogs/ directory not present then create one
32if ( !-e $lgdir)
33{
34  system "mkdir $lgdir";
35}
36
37# move to dir with all the current models
38if ( !chdir ( "$curr_dir/auto" ) )
39{
40   printf (" invalid directory\n");
41   exit;
42}
43
44$tlog = 'itrzn.log'; # File to keep record of recent execution time and itr/zn
45$efile = 'mailitr.log'; # File where the mail format is stored
46$exitr= 'extime_itrzn.log';
47$tholditr = 5;
48$tholdetime = 10;
49$flag=0;
50$no_itr=0;
51$no_extime=0;
52
53# Open the output files
54open (LGFILE, ">$tlog");
55open (ELOG, ">$efile");
56open (EXITR, ">$exitr");
57print ELOG "List of models with increase in itr/zn and/or execution time\n\n";
58print EXITR "Model\tExectime\titr/zn\n";
59
60print LGFILE "Records of itr/zn and Exectime of models if .bak file exists";
61print LGFILE "\n************************************************************";
62
63# Scans the .out files
64while (defined ($ofile = glob ("*.out")))
65{
66   $bfile = $ofile;
67   $bfile =~s/\.out/\.bak/;    # Substitutes '.out' by '.bak' in $bfile
68
69# Creates a '.log' file having same name as .out. Saves .log file in
70# directory /logs
71   open (OUTFILE,"$ofile");
72   $lfile = $ofile;
73   $lfile =~s/\.out/\.log/;
74   $lfile =~s/$lfile/$curr_dir\/$lgdir\/$lfile/;
75   $present=0;
76   if(-e $lfile)
77   {
78     $present=1;  # Variable to check if the model file is present
79
80# Opening the .log files in read mode to get the average of last 10 execution times
81     open (LFILE, "$lfile");
82     $count=0;
83
84     while($log = <LFILE>)
85     {
86       $log=~s/(.*Exectime\t\s)(\d*\.\d*|\d*)(.*)/$2/;
87       $exectime[$count] = $log;
88       $count = $count + 1;
89     }
90     close(LFILE);
91   }
92   else
93   {
94    print "No files present";
95   }
96
97   if($present==1)
98   {
99     $total = 0;
100     if($count>10)
101     {
102       for($i = $count-1; $i> ($count-11); $i = $i-1)
103       {
104         $total = $total + $exectime[$i];
105       }
106       $ave = $total / 10; # Average execution time of the last 10 extries of the model log file
107     }
108     else
109     {
110       for($i = $count-1; $i>-1; $i = $i-1)
111       {
112         $total = $total + $exectime[$i];
113       }
114       if($count>1)
115       {
116         $ave = $total / ($count-1); # Average execution time of the last few extries of the model log file
117       }
118       else
119       {
120         $ave=$total;
121       }
122     }# End if-else
123   }# End if $present
124
125   # Opening the .log files in append mode
126   open (LOGFILE, ">>$lfile");
127
128# get current time and date
129  ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
130   $mon = $mon+1; #Since month returned is 1 less than actual
131   $year =~s/^\d//;
132   print LOGFILE "Date\t$mon/$mday/$year\tTime\t$hour:$min:$sec";
133
134
135# Checks and computes if .bak file exists
136   if (-e $bfile)
137   {
138      open (BKFILE,"$bfile");
139      $mo = $ofile;
140      $mo =~s/\.out//;        # removes '.out'
141      print LGFILE "\nModel             :  $mo\n";
142
143# Gets itr/zn and execution time from .bak file. Extracts the
144# digits  only and ignores everything else
145      while ($bk = <BKFILE>)
146      {
147         if ($bk=~/itr\/zn\:/)
148         {
149            $prev_itr = $bk;
150            $prev_itr =~s/(.*itr\/zn\:)(\s\d*\.\d*|\d*\.\d*)(\s*.*)/$2/gi;  # gives the itr/zn
151            $prev_itr =~s/\n//;
152            print LGFILE "Previous itr/zn   :  $prev_itr\t";
153         }
154         elsif ($bk=~/ExecTime/)
155         {
156            $prev_etime = $bk;
157            $prev_etime =~s/.*ExecTime\(s\)//gi;  # gives the execution time
158            print LGFILE "Previous Exectime : $prev_etime";
159         }
160      }
161
162# Gets itr/an and execution time from .out file
163      while ($new = <OUTFILE>)
164      {
165         if ($new=~/itr\/zn\:/)
166         {
167            $curr_itr = $new;
168            $curr_itr =~s/(.*itr\/zn\:)(\s\d*\.\d*|\d*\.\d*)(\s*.*)/$2/gi;  # gives the itr/zn
169            $curr_itr =~s/\n//;
170            print LGFILE "New itr/zn        :  $curr_itr\t";
171         }
172         elsif ($new=~/ExecTime/)
173         {
174            $curr_etime = $new;
175            $curr_etime =~s/.*ExecTime\(s\)//gi;  # gives the execution time
176            print LGFILE "New Exectime      : $curr_etime";
177         }
178      }
179
180# Calculates difference between itr/zn
181      $diff_itr =   $curr_itr - $prev_itr;
182      printf(LGFILE "Difference in itr/zn: %.2f\n", $diff_itr);
183
184
185
186# Checking if present itr/zn is greater than previous itr/zn
187      if ($diff_itr !~/^-/)
188      {
189        if ($prev_itr > 0)
190        {
191          $ptage = ($diff_itr / $prev_itr) * 100;
192          $ptage = sprintf "%.2f", $ptage;
193          if ($ptage > $tholditr)
194          {
195            print LGFILE "% increase of itr/zn which is beyond the set threshold of 5:  $ptage \n";
196
197            $itr[$no_itr]="$mo\t$ptage%";       # Array to store model itr/zn info
198            $no_itr = $no_itr + 1;
199            $flag = 1;
200          }#end of if
201        }#end of if
202      }#end of if
203
204      if($present == 1)
205      {
206# Calculates the increase in execution time
207        $diff_etime = $curr_etime - $ave;
208        printf(LGFILE "Increase/Decrease in execution time from the average: %.2f\n", $diff_etime);
209
210# Checking if present execution time is greater than 10% increase of the average of last 10 execution times
211        if ($diff_etime >0)
212        {
213          if ($ave > 0)
214          {
215            $ptage = ($diff_etime / $ave) * 100;
216            $ptage = sprintf "%.2f", $ptage;
217
218            if ($ptage > $tholdetime)
219            {
220              print LGFILE "% increase in execution time which is more the set threshold of 10 percent:  $ptage \n";
221              $extime[$no_extime]="$mo\t$ptage%";       # Array to store model execution time info
222              $no_extime = $no_extime + 1;
223              $flag = 1;
224            }#end of if
225          }#end of if
226        }#end of if
227      }# End if $present
228    }
229
230# Prints the itr/zn and execution time to the .log file
231    $curr_etime =~s/\n//;
232    print LOGFILE "\t Exectime\t$curr_etime\titr/zn\t$curr_itr\n";
233    print EXITR "$mo\t$curr_etime\t$curr_itr\n";
234    close (LOGFILE);
235}# End of while
236
237print ELOG "Models with 10% increase in ExecTime than the average of previous 10 models:\n";
238print ELOG "---------------------------------------------------------------------------\n";
239for( $noe=0; $noe<$no_extime; ++$noe){
240   print ELOG "$extime[$noe]\n";
241}
242print ELOG "\n\n\nModels with 5% increase than previous itr/zn):\n";
243print ELOG "-------------------------------------------------\n";
244for( $noi=0; $noi<$no_itr; ++$noi){
245   print ELOG "$itr[$noi]\n";
246}
247 close (EXITR);
248 close (BKFILE);
249 close (OUTFILE);
250 close (LGFILE);
251 close (ELOG);
252 
253# Checks if there is any model which took more time than the threshold.
254# If yes than send a mail.
255if (-e $efile){
256  if($flag == 1){
257# Path set to use Perl mail utility SENDMAIL
258 #   $sendmailpath="/usr/sbin/sendmail";
259 #   open(SENDMAIL, "|$sendmailpath -t");
260
261 #  $from = "gary\@pa.uky.edu";
262 #  $to = "gary\@pa.uky.edu";
263 #   $subject = "Incease in execution time";
264
265# For Windows machines
266   system("c:\\u\\blat\\blat.exe $efile -t gary\@pa.uky.edu -s \"Increase in exe time and itr/zn found in automatic testing\" " );
267
268# For Unix machines
269 #   open (ELOG,"$efile");
270 #   print SENDMAIL "Subject: $subject\n";
271 #   print SENDMAIL "From: $from\n";
272 #   print SENDMAIL "To: $to\n\n";
273 #   while (<ELOG>){
274 #     print SENDMAIL "$_";
275 #   }
276 #   close(ELOG);
277  } # End of if flag
278} # End of if efile
279unlink($efile);
280# End of program
Note: See TracBrowser for help on using the browser.