Debian Codegraph @

rmark/rmark-time.pl

raw
1 #! /usr/bin/perl
2 #
3 # Given a list of .time files each with 1 line
4 # formatted like:
5 #
6 # tRNA 2524 seconds OR
7 # CPU time: 372.42u 1.51s 00:06:13.92 Elapsed: 00:00:47.20
8 #
9 # Output the summed time for all such lines in each file, and
10 # in all files.
11 #
12 # Example usage: ls *.search | perl rmark-time.pl
13 #
14 $total_seconds = 0;
15 %fam_seconds_H = ();
16 while($file = <>) {
17 chomp $file;
18 open(FILE, $file) || die "ERROR couldn't open file $file";
19 $fam_seconds = 0;
20 $fam = $file;
21 $fam =~ s/^.+\///; # remove path
22 $fam =~ s/\..+//; # remove suffix
23 while($line = <FILE>) {
24 chomp $line;
25 if($line =~ /CPU time\:\s+\S+\s+\S+\s+(\d+)\:(\d+)\:(\S+)\s+/) {
26 ($hours, $minutes, $seconds) = ($1, $2, $3);
27 $fam_seconds += ($hours * 3600) + ($minutes * 60) + $seconds;
28 $total_seconds += ($hours * 3600) + ($minutes * 60) + $seconds;
29 }
30 elsif($line =~ /^$fam\s+(\d+)\s+seconds/) {
31 $fam_seconds += $1;
32 $total_seconds += $1;
33 }
34 }
35 close(FILE);
36 printf("%-20s %10.2f hours == %10.2f minutes == %10.2f seconds\n",
37 $fam,
38 $fam_seconds / 3600.,
39 $fam_seconds / 60.,
40 $fam_seconds);
41 }
42 printf("%-20s %10.2f hours == %10.2f minutes == %10.2f seconds\n",
43 "total",
44 $total_seconds / 3600.,
45 $total_seconds / 60.,
46 $total_seconds);