Skip to content

Instantly share code, notes, and snippets.

@emrox
Created April 14, 2016 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrox/9e2c5b8ed12af102a19663ce97b8a3de to your computer and use it in GitHub Desktop.
Save emrox/9e2c5b8ed12af102a19663ce97b8a3de to your computer and use it in GitHub Desktop.
Rails production log partial timing
#!/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