Skip to content

Instantly share code, notes, and snippets.

@unfo

unfo/log_line_durations.rb

Last active Aug 29, 2015
Embed
What would you like to do?
#!/bin/ruby
require 'date'
THRESHOLD = ARGV[0].to_i || 10 # seconds
prev_line = ''
prev_dtm = nil
prev_line_printed = false
def seconds_between(dtm1, dtm2)
seconds_in_a_day = 24 * 60 * 60
((dtm2 - dtm1) * seconds_in_a_day).round # dtm - dtm is a Rational of how many days
end
def humanize(seconds)
hours = seconds / (60*60)
seconds -= (hours * 60*60)
minutes = seconds / 60
seconds -= (minutes * 60)
'%02d:%02d:%02d' % [hours,minutes,seconds]
end
STDIN.each_line do |line|
timestamp_str = line.scan(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)
next if timestamp_str.nil?
dtm = DateTime.parse(timestamp_str.first) || timestamp_str.empty?
unless prev_dtm.nil?
secs = seconds_between(prev_dtm, dtm)
if secs > THRESHOLD
unless prev_line_printed
puts
puts " "*9 + prev_line
end
puts humanize(secs) + " " + line
prev_line_printed = true
else
prev_line_printed = false
end
end
prev_dtm = dtm
prev_line = line
end
@unfo

This comment has been minimized.

Copy link
Owner Author

@unfo unfo commented Apr 3, 2014

         2014-03-31 07:34:38,845 INFO  [TransactionReaderCommand] Read 169359 transactions, 169359 transactions skipped.
01:15:14 2014-03-31 08:49:52,889 INFO  [TransactionReaderCommand] reading transactions from file input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment