Skip to content

Commit

Permalink
Merge pull request #2 from mikep/master
Browse files Browse the repository at this point in the history
Add count option
  • Loading branch information
hoytech committed Aug 26, 2013
2 parents e260988 + f1a571b commit e7f60d5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions bin/log-defer-viz
Expand Up @@ -22,7 +22,7 @@ my $colour_spec = {


my @opt_spec = ( my @opt_spec = (
## INPUT FORMAT ## INPUT FORMAT

'input-format=s', 'input-format=s',


## DATE ## DATE
Expand Down Expand Up @@ -55,6 +55,7 @@ my @opt_spec = (
'data!', 'data!',
'data-format=s', 'data-format=s',
'data-only', 'data-only',
'count=s@',


## MISC ## MISC


Expand Down Expand Up @@ -115,6 +116,7 @@ if ($opt->{'data-only'}) {
$opt->{data} = 1; $opt->{data} = 1;
} }


my $count = {} if exists $opt->{count};


my $columns = $opt->{'timer-columns'}; my $columns = $opt->{'timer-columns'};


Expand Down Expand Up @@ -169,6 +171,10 @@ while (my $file = shift) {
close($fh); close($fh);
} }


if (scalar @{$opt->{count}}) {
print " Count:\n";
print output_data($count);
}




sub handle_entry { sub handle_entry {
Expand Down Expand Up @@ -270,7 +276,7 @@ sub handle_entry {


print " |_" . format_time_offset($entry->{end}) . " [END]\n\n"; print " |_" . format_time_offset($entry->{end}) . " [END]\n\n";
} }

if ($opt->{timers}) { if ($opt->{timers}) {
print Log::Defer::Viz::render_timers(width => $columns-10, timers => $entry->{timers}) if $entry->{timers}; print Log::Defer::Viz::render_timers(width => $columns-10, timers => $entry->{timers}) if $entry->{timers};
} }
Expand All @@ -283,6 +289,15 @@ sub handle_entry {
print " ** This log has associated data. See it with --data\n" print " ** This log has associated data. See it with --data\n"
unless $opt->{quiet} || (defined $opt->{data} && !$opt->{data}); unless $opt->{quiet} || (defined $opt->{data} && !$opt->{data});
} }

foreach my $key (@{ $opt->{count} }) {
if (!exists $count->{$key}) {
$count->{$key} = {};
}
if (exists $entry->{data}->{$key}) {
$count->{$key}->{$entry->{data}->{$key}} += 1;
}
}
} }


print "\n"; print "\n";
Expand Down Expand Up @@ -432,6 +447,13 @@ Data is extra embedded information in the log file. The available outputs are C<
$ log-defer-viz --data-format=dumper ## Data::Dumper $ log-defer-viz --data-format=dumper ## Data::Dumper
$ log-defer-viz --data-only ## only show data $ log-defer-viz --data-only ## only show data
=head1 COUNT
The count parameter provides a method to count the number of times a specific key/value appears in the data section of the log file.
$ log-defer-viz --data --count ip_address ## Display how many log lines for each ip address
$ log-defer-viz --data --count ip_address --count user_id ## Display how many log lines for each ip address and each user_id
=head1 MISC =head1 MISC
$ log-defer-viz --help ## the text you're reading now $ log-defer-viz --help ## the text you're reading now
Expand Down

0 comments on commit e7f60d5

Please sign in to comment.