Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add count option

  - Count the number of times a key/value pair appears in the data
    section of each log entry.
  • Loading branch information...
commit f1a571b2740d726779c9a5f2adefa15a4f2c57c0 1 parent 52f7f27
Michael Pucyk mpucyk authored
Showing with 24 additions and 2 deletions.
  1. +24 −2 bin/log-defer-viz
26 bin/log-defer-viz
View
@@ -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
@@ -114,6 +115,7 @@ if ($opt->{'data-only'}) {
$opt->{data} = 1;
}
+my $count = {} if exists $opt->{count};
my $columns = $opt->{'timer-columns'};
@@ -157,6 +159,10 @@ while (my $file = shift) {
close($fh);
}
+if (scalar @{$opt->{count}}) {
+ print " Count:\n";
+ print output_data($count);
+}
sub handle_entry {
@@ -227,7 +233,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};
}
@@ -240,6 +246,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";
@@ -389,6 +404,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
Please sign in to comment.
Something went wrong with that request. Please try again.