Skip to content

Instantly share code, notes, and snippets.

@rdeva31
Created October 14, 2017 03:50
Show Gist options
  • Save rdeva31/fc2dbf25e24296a82ccf447fc5148ad7 to your computer and use it in GitHub Desktop.
Save rdeva31/fc2dbf25e24296a82ccf447fc5148ad7 to your computer and use it in GitHub Desktop.
puts <<EOS
[ 0.000000] event foo.bar START
[ 0.500000] some other generic log that should be ignored
[ 1.000000] event foo.bar STOP
[ 2.000000] event foo.bar START
[ 5.000000] event foo.bar STOP
[ 6.000000] event foo.qux START
[ 7.000000] event foo.qux STOP
EOS
.split("\n")
.lazy
.select {|line| line =~ /\[(.*)\] event (.*) (START|STOP)/}
.map { {:event => $2, :ts => $1.to_f, :start => $3 == "START"} }
.chunk {|event| event[:event]}
.map { |chunk|
name, events = chunk
deltas = events.lazy
.each_slice(2)
.map {|slice| slice.last[:ts] - slice.first[:ts]}
"Event #{name}: max #{deltas.max}, average #{deltas.reduce(&:+) / deltas.size}"
}
.force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment