#!/bin/bash # GNU All-Permissive License # Copying and distribution of this file, with or without modification, # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. This file is offered as-is, # without any warranty. # Copyright 2009 Daniel Einspanjer - Mozilla Corporation BEGIN { scale = 100000000 # Each '*' corresponds to this count timefield = 4 # Which field contains the 'time' column = 13 # Start of 'time' within the field width = 8 # Width of the 'time' defining field fuzz = 0 # Flag: Turn on to see 'error bars' on readings sumfield = 2 # Field to sum (default 2 for gzip -l) usekmg = 1 startline = 2 skiplastline = 1 totalCounts = 0 } function kmg(value) { if (usekmg != 1) return sprintf("%8d", value); kilo = value / 1024; mega = kilo / 1024; giga = mega / 1024 if ( kilo < 1 ) { suffix = "B"; retval = value; } else if ( mega < 1 ) { suffix = "KB"; retval = kilo; } else if ( giga < 1 ) { suffix = "MB"; retval = mega; } else { suffix = "GB"; retval = giga; } return sprintf("%3.2f%2-s", retval, suffix); } # DUMP HISTOGRAM BAR - Draw one bar of the histogram function DumpHistogramBar() { histoBar = "" # If we want 'error bars', if ( fuzz ) { # Generate lower/upper bound for reading lbound = nCounts - sqrt(nCounts); ubound = nCounts + sqrt(nCounts); # Generate a two-colour bar to show the reading for ( i = 0; i < ((ubound+scale-1)/scale); i++ ) { if ( (i+1)*scale <= lbound ) { histoBar = histoBar " " } else if ( i*scale < nCounts ) { histoBar = histoBar "*" } else { histoBar = histoBar "+" } } # Otherwise, just a straight histogram } else { for ( i = 1; i < ((nCounts+scale-1)/scale); i++) { histoBar = histoBar "*" } } printf( "%" width "s - %8s: %s\n", oldTime, kmg(nCounts), histoBar ); totalCounts += nCounts; } FNR < startline { next; } { timeStr = substr( $timefield, column, width ); if ( timeStr == oldTime ) { nCounts += $sumfield; } else { if ( oldTime != "") DumpHistogramBar(); oldTime = timeStr; nCounts = $sumfield; } } END { if ( nCounts > 0 && skiplastline == 0 ) DumpHistogramBar(); print "Total counts = " kmg(totalCounts); }