use open qw( :std :utf8 );
use re '/msx';
-our $VERSION = '1.08';
+our $VERSION = '1.09';
my %opt;
if (@ARGV) {
" (range expected)\n"
);
},
+ 'log|e!',
'header!',
'markers|m=s',
'graph-format=s' => sub {
) // 0;
my $minval = $opt{minval} // min $order[-1] // (), 0;
my $range = $maxval - $minval;
+$range &&= log $maxval if $opt{log};
my $lenval = $opt{'value-length'} // max map { length } @order;
my $len = defined $opt{trim} && $opt{trim} <= 0 ? -$opt{trim} + 1 :
max map { length $values[$_] && length $lines[$_] }
return sum(@order) / @order;
}
elsif ($func =~ /\A([0-9.]+)v\z/) {
- die "Invalid marker $char: percentile $1 out of bounds\n" if $1 > 100;
+ $1 <= 100 or die(
+ "Invalid marker $char: percentile $1 out of bounds\n"
+ );
my $index = $#order * $1 / 100;
return ($order[$index] + $order[$index + .5]) / 2;
}
next;
};
$pos -= $minval;
+ $pos &&= log $pos if $opt{log};
$pos >= 0 or next;
color(36) for $barmark[$pos * $size] = $char;
}
next;
}
printf '%-*s', $len + length($val), $line;
+ my $barlen = $values[$nr] || 0;
+ $barlen &&= log $barlen if $opt{log};
print $barmark[$_] // $opt{'graph-format'}
- for 1 .. $size && (($values[$nr] || 0) - $minval) * $size + .5;
+ for 1 .. $size && ($barlen - $minval) * $size + .5;
say '';
}
continue {
-l, --length=[-]SIZE[%] Trim line contents (between number and bars)
-L, --limit[=(N|-LAST|START-[END])]
Stop output after a number of lines
+ -e, --log Logarithmic (exponential) scale instead of linear
--graph-format=CHAR Glyph to repeat for the graph line
-m, --markers=FORMAT Statistical positions to indicate on bars
--min=N, --max=N Bars extend from 0 or the minimum value if lower
All input is still counted and analyzed for statistics,
but disregarded for padding and bar size.
+=item -e, --log
+
+Logarithmic (I<e>xponential) scale instead of linear
+to compare orders of magnitude.
+
=item --graph-format=<character>
Glyph to repeat for the graph line.
cat httpd/access.log | cut -d\ -f4 | cut -d: -f1 | uniq -c | barcat
-Any kind of database query with counts, preserving returned alignment:
+Any kind of database query results, preserving returned alignment:
- echo 'SELECT count(*),schemaname FROM pg_tables GROUP BY 2' |
+ echo 'SELECT sin(value * .1) FROM generate_series(0, 30) value' |
psql -t | barcat -u
-In PostgreSQL from within the client:
+In PostgreSQL from within the client; a fancy C<\dt+> perhaps:
+
+ > SELECT schemaname, relname, pg_total_relation_size(relid)
+ FROM pg_statio_user_tables ORDER BY idx_blks_hit
+ \g |barcat -uHf+
+
+Same thing in SQLite (requires the sqlite3 client):
- > SELECT sin(generate_series(0, 3, .1)) \g |barcat
+ > .once |barcat -Hf+
+ > SELECT name, sum(pgsize) FROM dbstat GROUP BY 1;
Earthquakes worldwide magnitude 1+ in the last 24 hours:
Population and other information for all countries:
curl http://download.geonames.org/export/dump/countryInfo.txt |
- grep -v '^#\s' | column -ts$'\t' -n | barcat -f+2 -u -l150 -s
+ grep -v '^#\s' | column -ts$'\t' -n | barcat -f+2 -e -u -l150 -s
And of course various Git statistics, such commit count by year: