Created
April 14, 2016 09:01
-
-
Save emrox/9e2c5b8ed12af102a19663ce97b8a3de to your computer and use it in GitHub Desktop.
Rails production log partial timing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# use with: cat producion.log | perl production_log_stats.pl | |
use warnings; | |
use strict; | |
use List::Util qw(sum); | |
my $filestats_ref = (); | |
# collect | |
foreach my $line ( <STDIN> ) { | |
if ( $line =~ m/INFO \-\- \:\s+Rendered\s+([^\s]+)\s+\(([0-9\.]+)ms\)/ ) { | |
if (!$filestats_ref->{$1}) { | |
$filestats_ref->{$1} = []; | |
} | |
push($filestats_ref->{$1}, $2); | |
} | |
} | |
# ouput and calc | |
foreach my $file ( sort(keys %{$filestats_ref}) ) { | |
my @filestats = sort {$a <=> $b} (map { int($_) } @{$filestats_ref->{$file}}); | |
print "$file || count: " . scalar(@filestats) . ' | min: ' . $filestats[0] .'ms | max: ' . $filestats[-1] . 'ms | avg: '. mean(@filestats) . "ms\n"; | |
} | |
# helper functions | |
sub mean { | |
return int(sum(@_)/@_); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment