diff --git a/bin/log-defer-viz b/bin/log-defer-viz index bbae3fb..3595c06 100755 --- a/bin/log-defer-viz +++ b/bin/log-defer-viz @@ -22,7 +22,7 @@ my $colour_spec = { my @opt_spec = ( ## INPUT FORMAT - + 'input-format=s', ## DATE @@ -55,6 +55,7 @@ my @opt_spec = ( 'data!', 'data-format=s', 'data-only', + 'count=s@', ## MISC @@ -115,6 +116,7 @@ if ($opt->{'data-only'}) { $opt->{data} = 1; } +my $count = {} if exists $opt->{count}; my $columns = $opt->{'timer-columns'}; @@ -169,6 +171,10 @@ while (my $file = shift) { close($fh); } +if (scalar @{$opt->{count}}) { + print " Count:\n"; + print output_data($count); +} sub handle_entry { @@ -270,7 +276,7 @@ sub handle_entry { print " |_" . format_time_offset($entry->{end}) . " [END]\n\n"; } - + if ($opt->{timers}) { print Log::Defer::Viz::render_timers(width => $columns-10, timers => $entry->{timers}) if $entry->{timers}; } @@ -283,6 +289,15 @@ sub handle_entry { print " ** This log has associated data. See it with --data\n" 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"; @@ -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-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 $ log-defer-viz --help ## the text you're reading now