#!/usr/bin/perl -w # # use strict; use Getopt::Long; my ($LineNum, $time, $cmd, $cmdtmp); my ($cmd_unit, $hour, $min, $sec, $usec); my (@CmdStore, @ElapsedTime); # Arrays for storing Time (1 -> Number of lines) my (@HourStore, @MinStore, @SecStore, @USecStore); my ($lineOutput); my (%CmdCounter); my $lineCount; # Time Variables my ($BeginTime, $EndTime); # Write variables and arrays: my (@Write); my ($WriteBytesTotal); my (%WriteMax); # Read variables and arrays: my (@Read); my ($ReadBytesTotal); my (%ReadMax); # Close variables and arrays my (@Close); my (%CloseMax); # Open variables and arrays my (@Open); my (%OpenMax); # Hash and array for file sizes my (@FileSizes, %FileSizeCounter); # Temporary variables and arrays: my (@parts); my ($hour_prev, $min_prev, $sec_prev, $usec_prev); my ($iwrite, $iread, $iclose, $iopen); my ($junk, $junk1, $junk2, $junk3, $sum); my ($ielement); my ($zero); my ($before, $filename, $after); my ($iloop, $icount); # Command line arguments my ($filesizeinput, $debug, $helpflag); $debug = 0; $filesizeinput = 0; $helpflag = 0; GetOptions('f|file=s' => \$filesizeinput, "debug" => \$debug, "h|help" => \$helpflag ); #printf("filesizeinput: %s \n",$filesizeinput); #printf("debug: %s \n",$debug); #printf("help: %s \n", $helpflag); if ($helpflag > 0) { helpoutput(); exit; } # Define IO functions we are interested in my $OPEN = "open"; my $READ = "read"; my $WRITE = "write"; my $LSEEK = "lseek"; my $LLSEEK = "llseek"; my $CLOSE = "close"; my $STAT = "stat"; my $STAT64 = "stat64"; # Initialization $LineNum = 0; $iwrite = -1; $iread = -1; $iclose = -1; $iopen = -1; $zero = 0.0; $CloseMax{"line"} = 0; $CloseMax{"MaxTime"} = -1.0; $ReadMax{"line"} = 0; $ReadMax{"MaxTime"} = -1.0; $WriteMax{"line"} = 0; $WriteMax{"MaxTime"} = -1.0; $OpenMax{"line"} = 0; $OpenMax{"MaxTime"} = -1.0; $BeginTime = -1.0; $EndTime = -1.0; # # Loop over lines in file # while(<>){ chomp; # Split current line using spaces ($sec, $cmdtmp, @parts) = split; #printf("sec: %s \n",$sec); #printf("usec: %s \n",$usec); #printf("cmdtmp: %s \n",$cmdtmp); #my $iloop = 0; #foreach my $specific_part (@parts) #{ # if (defined $specific_part) { # $iloop++; # printf("parts(%2d): %s \n",$iloop, $specific_part); # } #} # Increment Line Number $LineNum++; # Echo input line to output if ($debug > 0) { $lineOutput = $sec . " " . $cmdtmp . " "; foreach my $specific_part (@parts) { if (defined $specific_part) { $lineOutput = $lineOutput . $specific_part . " "; } } printf("(%d)\t%s \n",$LineNum, $lineOutput); } # Split the temporary command ($cmdtmp) to get the correct "command" ($cmd, $cmd_unit) = split(/\(/,$cmdtmp); $cmd =~ s/^_{1,}(\S+)/$1/; #printf("cmd: %s \n",$cmd); #printf("cmd_unit: %s \n",$cmd_unit); #printf("LineNum: %s \n",$LineNum); # Split the time into hours, minutes, seconds, microseconds ($junk, $usec) = split(/\./,$sec); ($hour, $min, $sec) = split(/\:/,$junk); #printf("hour = %s \n",$hour); #printf("min = %s \n",$min); #printf("sec = %s \n",$sec); #printf("usec = %s \n",$usec); # Storage beginning time if ($LineNum == 1) { $BeginTime = TimeConv( $hour, $min, $sec, $usec); } # Store time in arrays (currently not used) $HourStore[$LineNum] = $hour; $MinStore[$LineNum] = $min; $SecStore[$LineNum] = $sec; $USecStore[$LineNum] = $usec; # Store command in arrays $CmdStore[$LineNum] = $cmd; #if ($cmd eq $OPEN) { # printf("sec: %s \n",$sec); # printf("usec: %s \n",$usec); # printf("cmdtmp: %s \n",$cmdtmp); # my $iloop = 0; # foreach my $specific_part (@parts) # { # if (defined $specific_part) { # $iloop++; # printf("parts(%2d): %s \n",$iloop, $specific_part); # } # } #} # If previous command was a write or read, then compute the throughput # (need time from this function to compute elapsed time for read or write) if ($iwrite > 0) { #printf(" Compute time for write \n"); # Extract previous time from @Write array of hash $hour_prev = $Write[$#Write]->{hour}; $min_prev = $Write[$#Write]->{min}; $sec_prev = $Write[$#Write]->{sec}; $usec_prev = $Write[$#Write]->{usec}; $junk = ElapsedTimeComp( $hour, $min, $sec, $usec, $hour_prev, $min_prev, $sec_prev, $usec_prev); $Write[$#Write]->{elapsed_time} = $junk; if ($junk > $WriteMax{"MaxTime"} ) { $WriteMax{"MaxTime"} = $junk; $WriteMax{"line"} = $LineNum - 1; } $iwrite = 0; } elsif ($iread > 0) { #printf(" Compute time for read \n"); # Extract previous time from @Read array of hash $hour_prev = $Read[$#Read]->{hour}; $min_prev = $Read[$#Read]->{min}; $sec_prev = $Read[$#Read]->{sec}; $usec_prev = $Read[$#Read]->{usec}; $junk = ElapsedTimeComp( $hour, $min, $sec, $usec, $hour_prev, $min_prev, $sec_prev, $usec_prev); $Read[$#Read]->{elapsed_time} = $junk; if ($junk > $ReadMax{"MaxTime"} ) { $ReadMax{"MaxTime"} = $junk; $ReadMax{"line"} = $LineNum - 1; } $iread = 0; } elsif ($iclose > 0) { #printf(" Compute time for close \n"); # Extract previous time from @Close array of hash $hour_prev = $Close[$#Close]->{hour}; $min_prev = $Close[$#Close]->{min}; $sec_prev = $Close[$#Close]->{sec}; $usec_prev = $Close[$#Close]->{usec}; $junk = ElapsedTimeComp( $hour, $min, $sec, $usec, $hour_prev, $min_prev, $sec_prev, $usec_prev); $Close[$#Close]->{elapsed_time} = $junk; if ($junk > $CloseMax{"MaxTime"} ) { $CloseMax{"MaxTime"} = $junk; $CloseMax{"line"} = $LineNum - 1; } $iclose = 0; } elsif ($iopen > 0) { #printf(" Compute time for open \n"); # Extract previous time from @Open array of hash $hour_prev = $Open[$#Open]->{hour}; $min_prev = $Open[$#Open]->{min}; $sec_prev = $Open[$#Open]->{sec}; $usec_prev = $Open[$#Open]->{usec}; $junk = ElapsedTimeComp( $hour, $min, $sec, $usec, $hour_prev, $min_prev, $sec_prev, $usec_prev); $Open[$#Open]->{elapsed_time} = $junk; if ($junk > $OpenMax{"MaxTime"} ) { $OpenMax{"MaxTime"} = $junk; $OpenMax{"line"} = $LineNum - 1; } $iopen = 0; } # ======================= # If ladder to store data # ======================= if ($cmd eq $OPEN){ #printf("FOUND AN OPEN!!!\n"); $iopen = 1; $ielement = $#Open; # 15:12:54.920816 open("testfile1", O_RDWR|O_CREAT|O_LARGEFILE, 0666) = 7 # # 15:12:54.836275 open("tls/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory) # file name is contained in cmdtemp # opening options are contained in @parts (usually parts(1) with a comma or ")" at the end ) # Unit is contained after the "=" in the @parts # Increment the write counter (number of writes) $CmdCounter{"open"}++; # Split $cmdtmp to get the file name ($before, $filename, $after) = split('"', $cmdtmp); # Find unit assocaited with open $iloop = 0; foreach my $specific_part (@parts) { if ($iloop == 1) { $junk = $specific_part; $iloop = 0; } if ($specific_part eq "=") { $iloop = 1; } } # Add to hash $Open[$ielement+1]->{line_number} = $LineNum; $Open[$ielement+1]->{hour} = $hour; $Open[$ielement+1]->{min} = $min; $Open[$ielement+1]->{sec} = $sec; $Open[$ielement+1]->{usec} = $usec; $Open[$ielement+1]->{file} = $filename; $Open[$ielement+1]->{unit} = $junk; $Open[$ielement+1]->{elapsed_time} = $zero; } elsif ($cmd eq $STAT) { printf("FOUND A STAT!!!\n"); $CmdCounter{"stat"}++; } elsif ($cmd eq $STAT64) { $CmdCounter{"stat64"}++; } elsif ($cmd eq $LSEEK){ #printf("FOUND A LSEEK!!!\n"); $CmdCounter{"lseek"}++; } elsif ($cmd eq $LLSEEK){ $CmdCounter{"llseek"}++; #$OPS_sec{$sec}++; } elsif ($cmd eq $READ) { #printf("FOUND A READ!!!\n"); $iread = 1; $ielement = $#Read; # Increment the read counter (number of reads) $CmdCounter{"read"}++; # Increment counter for total bytes read # For a read the number of bytes read is stored in the last defined array # element in @parts foreach my $specific_part (@parts) { if (defined $specific_part) { $junk = $specific_part; } } $junk =~ s/[^0-9]//g; # Keep track of total number bytes read $ReadBytesTotal += $junk; # Clean up write unit ($junk1, $junk2)=split(/\,/,$cmd_unit); # Add to hash $Read[$ielement+1]->{line_number} = $LineNum; $Read[$ielement+1]->{hour} = $hour; $Read[$ielement+1]->{min} = $min; $Read[$ielement+1]->{sec} = $sec; $Read[$ielement+1]->{usec} = $usec; $Read[$ielement+1]->{bytes} = $junk; $Read[$ielement+1]->{byte_sec} = $zero; $Read[$ielement+1]->{elapsed_time} = $zero; $Read[$ielement+1]->{unit} = $junk1; } elsif ($cmd eq $WRITE) { #printf("FOUND A WRITE!!!\n"); $iwrite = 1; $ielement = $#Write; # Increment the write counter (number of writes) $CmdCounter{"write"}++; # Increment counter for total bytes written # For a write the number of bytes written is stored in the last defined array # element in @parts foreach my $specific_part (@parts) { if (defined $specific_part) { $junk = $specific_part; } } $junk =~ s/[^0-9]//g; # Keep track of total number bytes written $WriteBytesTotal += $junk; # Clean up write unit ($junk1, $junk2)=split(/\,/,$cmd_unit); # Add to hash $Write[$ielement+1]->{line_number} = $LineNum; $Write[$ielement+1]->{hour} = $hour; $Write[$ielement+1]->{min} = $min; $Write[$ielement+1]->{sec} = $sec; $Write[$ielement+1]->{usec} = $usec; $Write[$ielement+1]->{bytes} = $junk; $Write[$ielement+1]->{byte_sec} = $zero; $Write[$ielement+1]->{elapsed_time} = $zero; $Write[$ielement+1]->{unit} = $junk1; } elsif ($cmd eq $CLOSE) { #printf("FOUND A CLOSE!!!\n"); $iclose = 1; $ielement = $#Close; # Increment the write counter (number of writes) $CmdCounter{"close"}++; # Need to extract number from cmdtmp $junk = $cmdtmp; $junk =~ s/[^0-9]//g; # Add to hash $Close[$ielement+1]->{line_number} = $LineNum; $Close[$ielement+1]->{hour} = $hour; $Close[$ielement+1]->{min} = $min; $Close[$ielement+1]->{sec} = $sec; $Close[$ielement+1]->{usec} = $usec; $Close[$ielement+1]->{bytes} = $junk; $Close[$ielement+1]->{byte_sec} = $zero; $Close[$ielement+1]->{elapsed_time} = $zero; $Close[$ielement+1]->{unit} = $junk; } else { #$CmdStore[$LineNum] = $cmd; } # End of loop } # End Time $EndTime = TimeConv( $hour, $min, $sec, $usec); # ============== # ============== # Output Summary # ============== # ============== my $Numlines = @CmdStore; printf("\n\nNumber of Lines in strace file: %d \n",$Numlines); printf("\n"); $FileSizeCounter{1024} = 0; $FileSizeCounter{8192} = 0; $FileSizeCounter{32768} = 0; $FileSizeCounter{1048576} = 0; $FileSizes[0] = 1024; $FileSizes[1] = 8192; $FileSizes[2] = 32768; $FileSizes[3] = 1048576; ############################################################### # Elapsed Time for run length printf("----------------\n"); printf("-- Time Stats --\n"); printf("----------------\n\n"); printf("Elapsed Time for run: %f (secs) \n", ($EndTime - $BeginTime) ); ############################################################### # ===================== # IO Command statistics # ===================== printf(" \n\n"); printf("---------------------- \n"); printf("-- IO Command Count -- \n"); printf("---------------------- \n\n"); printf("%-7s\t\t%6s \n", "Command", "Count"); printf("======================\n"); foreach my $key (keys %CmdCounter) { printf("%-s \t\t%6d \n", $key, $CmdCounter{$key} ); } printf(" \n\n"); ############################################################### # ================ # Write statistics # ================ if ($CmdCounter{"write"} > 0) { printf("---------------------- \n"); printf("-- Write Statistics -- \n"); printf("---------------------- \n\n"); printf("%-4s \t\t\t%7s\t\t%4s \t\t%5s \t%20s \t%16s \n", "Time", "Command", "Unit", "Bytes", "Bandwidth (Bytes/s)", "Bandwidth (MB/s)"); printf("=========================================================================================================\n"); $sum = 0.0; foreach my $specific_hash (@Write) { $sum = $sum + $specific_hash->{elapsed_time}; $junk1 = sprintf("%.3f",($specific_hash->{bytes}/$specific_hash->{elapsed_time}) ); $junk2 = sprintf("%.3f",(($specific_hash->{bytes}/$specific_hash->{elapsed_time})/1000000.0) ); printf("%2d:%2d:%d.%d\t\t%7s\t\t%4d\t%13s\t%20s\t\t%8s \n", $specific_hash->{hour}, $specific_hash->{min}, $specific_hash->{sec}, $specific_hash->{usec}, "write", $specific_hash->{unit}, commify2( $specific_hash->{bytes} ), commify2( $junk1 ),commify2( $junk2 ) ); } # # File Size Interval Summary # $junk3= $#FileSizes; # Number of File sizes foreach my $specific_hash (@Write) { $junk = $specific_hash->{bytes}; if ($junk < $FileSizes[0]) { $FileSizeCounter{$FileSizes[0]}++; #printf("First one \n"); } elsif ($junk > $FileSizes[$junk3] ) { $FileSizeCounter{$FileSizes[$junk3]}++; #printf("Last one \n"); } else { $iloop = 0; for ($icount=1; $icount < ($junk3+1); $icount++) { #printf("junk = %d \n", $junk); #printf("FileSizes[ %d ] = %d \n", $icount, $FileSizes[$icount]); #printf("FileSizes[ %d ] = %d \n", $icount-1, $FileSizes[$icount-1]); if ($junk < $FileSizes[$icount] && $junk > $FileSizes[$icount-1] ) { $iloop = $icount; } } #printf("iloop = %d \n", $iloop); $FileSizeCounter{$FileSizes[$iloop]}++; } } # print out intervals and count printf(" \n\n"); printf("-- File sizes for write() function --\n\n"); printf("%-21s \t\t%15s \n", "IO Size Range (Bytes)", "Number of Files"); printf("=============================================== \n"); # Do First File Size interval $iloop = 1; # FileSizes[0]: my $junk1_str = FileSizeStr( $FileSizes[0] ); printf("(%3d) < %4s\t\tBytes \t\t%d \n", $iloop, $junk1_str, $FileSizeCounter{$FileSizes[0]} ); # Rest of the File Size Intervals for ($icount=1; $icount < ($junk3+1); $icount++) { $iloop++; $junk1 = $FileSizes[$icount]; $junk2 = $FileSizes[$icount-1]; #printf("iloop = %3d \n", $iloop); #printf(" junk1 = %s \n", $junk1); #printf(" junk2 = %s \n", $junk2); #printf(" FileSizeCounter = %d \n", $FileSizeCounter{$FileSizes[$iloop-1]}); my $junk1_str = FileSizeStr( $junk1 ); my $junk2_str = FileSizeStr( $junk2 ); printf("(%3d) %4s < < %4s Bytes\t\t %d \n", $iloop, $junk2_str, $junk1_str, $FileSizeCounter{$FileSizes[$iloop-1]} ); } # # Write summary # printf(" \n\n"); printf("-- WRITE SUMMARY -- \n"); printf("Total number of Bytes written = %24s \n",commify2($WriteBytesTotal) ); printf(" (Megabytes = %12s MB)\n", commify2($WriteBytesTotal / 1000000.0) ); printf("Number of Write function calls = %8d \n",commify2($CmdCounter{"write"}) ); printf("Average Bytes per call = %13s (bytes) \n", commify($WriteBytesTotal / $CmdCounter{"write"}) ); printf(" (Megabytes per call = %9s MB)\n", commify(($WriteBytesTotal / $CmdCounter{"write"})/1000000.0 ) ); printf("Time for slowest write function (secs) = %f \n",$WriteMax{"MaxTime"} ); printf(" Line location in file: %d \n", $WriteMax{"line"} ); printf(" \n"); } # #a) <1K Bytes #b) 1K< <8K Bytes #c) 8K< <32K Bytes #d) 32K< <1M Bytes #e) 1M+ Bytes # #-- Write Stats ----------------------- #a) <1K Bytes 211,580 #b) <8K Bytes 1,199 #c) <1M Bytes 54,934 #d) >1M Bytes 6 #totalBytesWrite 3,361,660,572 #Peak 164,080,216 Bytes/sec ############################################################### # =============== # Read statistics # =============== if ($CmdCounter{"read"} > 0) { printf(" \n\n"); printf("--------------------- \n"); printf("-- Read Statistics -- \n"); printf("--------------------- \n\n"); printf("%-4s \t\t\t%7s\t\t%4s \t\t%5s \t%20s \t%16s \n", "Time", "Command", "Unit", "Bytes", "Bandwidth (Bytes/s)", "Bandwidth (MB/s)"); printf("=========================================================================================================\n"); $sum = 0.0; foreach my $specific_hash (@Read) { $sum = $sum + $specific_hash->{elapsed_time}; $junk1 = sprintf("%.3f",($specific_hash->{bytes}/$specific_hash->{elapsed_time}) ); $junk2 = sprintf("%.3f",(($specific_hash->{bytes}/$specific_hash->{elapsed_time})/1000000.0) ); printf("%2d:%2d:%d.%d\t\t%7s\t\t%4d\t%13s\t%20s\t\t%8s \n", $specific_hash->{hour}, $specific_hash->{min}, $specific_hash->{sec}, $specific_hash->{usec}, "read", $specific_hash->{unit}, commify2( $specific_hash->{bytes} ), commify2( $junk1 ),commify2( $junk2 ) ); } # # File Size Interval Summary # $FileSizeCounter{1024} = 0; $FileSizeCounter{8192} = 0; $FileSizeCounter{32768} = 0; $FileSizeCounter{1048576} = 0; $junk3= $#FileSizes; # Number of File sizes foreach my $specific_hash (@Read) { $junk = $specific_hash->{bytes}; if ($junk < $FileSizes[0]) { $FileSizeCounter{$FileSizes[0]}++; #printf("First one \n"); } elsif ($junk > $FileSizes[$junk3] ) { $FileSizeCounter{$FileSizes[$junk3]}++; #printf("Last one \n"); } else { $iloop = 0; for ($icount=1; $icount < ($junk3+1); $icount++) { #printf("junk = %d \n", $junk); #printf("FileSizes[ %d ] = %d \n", $icount, $FileSizes[$icount]); #printf("FileSizes[ %d ] = %d \n", $icount-1, $FileSizes[$icount-1]); if ($junk < $FileSizes[$icount] && $junk > $FileSizes[$icount-1] ) { $iloop = $icount; } } #printf("iloop = %d \n", $iloop); $FileSizeCounter{$FileSizes[$iloop]}++; } } # print out intervals and count printf(" \n\n"); printf("-- File sizes for read function() -- \n\n"); printf("%-21s \t\t%15s \n", "IO Size Range (Bytes)", "Number of Files"); printf("=============================================== \n"); # Do First File Size interval $iloop = 1; # FileSizes[0]: my $junk1_str = FileSizeStr( $FileSizes[0] ); printf("(%3d) < %4s\t\tBytes \t\t%d \n", $iloop, $junk1_str, $FileSizeCounter{$FileSizes[0]} ); # Rest of the File Size Intervals for ($icount=1; $icount < ($junk3+1); $icount++) { $iloop++; $junk1 = $FileSizes[$icount]; $junk2 = $FileSizes[$icount-1]; #printf("iloop = %3d \n", $iloop); #printf(" junk1 = %s \n", $junk1); #printf(" junk2 = %s \n", $junk2); #printf(" FileSizeCounter = %d \n", $FileSizeCounter{$FileSizes[$iloop-1]}); my $junk1_str = FileSizeStr( $junk1 ); my $junk2_str = FileSizeStr( $junk2 ); printf("(%3d) %4s < < %4s Bytes\t\t %d \n", $iloop, $junk2_str, $junk1_str, $FileSizeCounter{$FileSizes[$iloop-1]} ); } # # Read summary # printf(" \n\n"); printf("-- READ SUMMARY -- \n"); printf("Total number of Bytes read = %24s \n",commify2($ReadBytesTotal) ); printf(" (Megabytes = %12s MB)\n", commify2($ReadBytesTotal / 1000000.0) ); printf("Number of Read function calls = %8d \n",commify2($CmdCounter{"read"}) ); printf("Average Bytes per call = %13s (bytes) \n", commify($ReadBytesTotal / $CmdCounter{"read"}) ); printf(" (Megabytes per call = %9s MB)\n", commify(($ReadBytesTotal / $CmdCounter{"read"})/1000000.0 ) ); printf("Time for slowest read function (secs) = %f \n",$ReadMax{"MaxTime"} ); printf(" Line location in file: %d \n", $ReadMax{"line"} ); printf(" \n\n"); #-- Read Stats ----------------------- #a) <1K Bytes 888 #b) <8K Bytes 10 #c) <1M Bytes 142,708 #d) >1M Bytes 12 #totalBytesRead 9,518,258,252 #Peak 330,563,584 Bytes/sec } ############################################################### # ================ # Close statistics # ================ if ($CmdCounter{"close"} > 0) { printf(" \n\n"); printf("---------------------- \n"); printf("-- Close Statistics -- \n"); printf("---------------------- \n\n"); printf("%-4s \t\t\t%7s\t\t%4s \t%19s \n", "Time", "Command", "Unit", "Elapsed Time (sec)"); printf("=========================================================================================================\n"); $sum = 0.0; foreach my $specific_hash (@Close) { $sum = $sum + $specific_hash->{elapsed_time}; printf("%2d:%2d:%d.%d\t\t%7s\t\t%4d\t%18s \n", $specific_hash->{hour}, $specific_hash->{min}, $specific_hash->{sec}, $specific_hash->{usec}, "close", $specific_hash->{unit}, commify2( $specific_hash->{elapsed_time} ) ); } # # Close summary # printf(" \n\n"); printf("-- CLOSE SUMMARY -- \n"); printf("Total number of close function calls = %d \n", $CmdCounter{"close"} ); printf("Average time for close function calls (secs) = %f \n", commify2( $sum/$CmdCounter{"close"} ) ); printf("Maximum Time for close function (secs) = %f \n",$CloseMax{"MaxTime"} ); printf(" Line location in file: %d \n", $CloseMax{"line"} ); printf(" \n\n"); } ############################################################### # =============== # Open statistics # =============== if ($CmdCounter{"open"} > 0) { printf(" \n\n"); printf("--------------------- \n"); printf("-- Open Statistics -- \n"); printf("--------------------- \n\n"); printf("%-4s \t\t\t%7s\t\t%4s \t%-s \t\t\t\t\t\t\t\t\t\t%19s \n", "Time", "Command", "Unit", "File", "Elapsed Time (sec)"); printf("====================================================================================================================================================\n"); $sum = 0.0; foreach my $specific_hash (@Open) { $sum = $sum + $specific_hash->{elapsed_time}; printf("%2d:%2d:%d.%d\t\t%7s\t\t%4d\t%-65s\t%27s \n", $specific_hash->{hour}, $specific_hash->{min}, $specific_hash->{sec}, $specific_hash->{usec}, "open", $specific_hash->{unit}, $specific_hash->{file}, commify2( $specific_hash->{elapsed_time} ) ); } # # Open summary # printf(" \n\n"); printf("-- OPEN SUMMARY -- \n"); printf("Total number of open function calls = %d \n", $CmdCounter{"open"} ); printf("Average time for open function calls (secs) = %f \n", commify2( $sum/$CmdCounter{"open"} ) ); printf("Maximum Time for open function (secs) = %f \n",$OpenMax{"MaxTime"} ); printf(" Line location in file: %d \n", $OpenMax{"line"} ); printf(" \n\n"); } ##################################################################################################################### ##################################################################################################################### ##################################################################################################################### sub commify { local $_ = shift; 1 while s/^([-+]?\d+)(\d{3})/$1,$2/; return $_; } sub commify2 { # commify a number. Perl Cookbook, 2.17, p. 64 my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } sub ElapsedTimeComp { my ($hour, $min, $sec, $usec, $hour_prev, $min_prev, $sec_prev, $usec_prev) = @_; $junk = 0.0; if ($hour != $hour_prev) { $junk = ($hour - $hour_prev)*3600.0 + ($min - $min_prev)*60.0 + ($sec - $sec_prev) + ($usec- $usec_prev)*0.000001; } elsif ($min != $min_prev) { $junk = ($min - $min_prev)*60.0 + ($sec - $sec_prev) + ($usec- $usec_prev)*0.000001; } elsif ($sec != $sec_prev) { $junk = ($sec - $sec_prev) + ($usec- $usec_prev)*0.000001; } else { $junk = ($usec- $usec_prev)*0.000001; } return $junk } sub FileSizeStr { my ($junk) = @_; my $junk_str; #printf("FileSizeStr function: junk = %s \n", $junk); if ($junk < 1048576) { $junk_str = sprintf("%3d",($junk/1024) ); $junk_str = $junk_str . "K"; } elsif ($junk >= 1048576 && $junk < (1048576*1024) ) { $junk_str = sprintf("%3d", ($junk/1048576) ); $junk_str = $junk_str . "M"; } elsif ($junk >= (1048576*1024) ) { $junk_str = sprintf("%3d", ($junk/(1048576*1024)) ); $junk_str = $junk_str . "G"; } else { $junk_str = sprintf("Are you sure that is correct? That is a huge file size"); } return $junk_str; } sub TimeConv { my ($hour, $min, $sec, $usec) = @_; $junk = 0.0; $junk = $hour*3600.0 + $min*60.0 + $sec + $usec*0.000001; return $junk } sub helpoutput { printf("Usage: strace-analyze [OPTION]... [FILE] \n"); printf("Analyzes strace output for IO functions. It creates statistics \n"); printf("on IO functions and performance of the read and write functions.\n"); printf("The strace file should have been run with 'strace -tt [PROGRAM] \n"); printf(" \n"); printf(" -d Debug - echo the input lines to stdout and provide debugging information\n"); printf(" -debug same as -d \n"); printf(" --d same as -d \n"); printf(" --debug same as -d \n"); printf(" -h Produces help output (this message) \n"); printf(" -help same as -h \n"); printf(" --h same as -h \n"); printf(" --help same as -h \n"); printf(" -f [FILE] input a list of file sizes for examining IO functions \n"); printf(" The format of the file is: \n"); printf(" 1024 \n"); printf(" 8192 \n"); printf(" ... \n"); printf(" 32768 \n"); printf(" 1048576 \n"); printf(" -file same as -f \n"); printf(" --f same as -f \n"); printf(" --file same as -f \n"); }