Skip to content

Instantly share code, notes, and snippets.

@pbyrne
Created February 3, 2014 14:52
Show Gist options
  • Save pbyrne/8785210 to your computer and use it in GitHub Desktop.
Save pbyrne/8785210 to your computer and use it in GitHub Desktop.
Stupid Analysis of `strace` Output
#!/usr/bin/env ruby
#
# Usage:
# strace_parser.rb < file.out
# head -n100 file.out | strace_parser.rb
# strace_parser.rb file.out
class StraceEntry
attr_accessor :line
attr_accessor :pid, :timestamp, :command, :args, :result, :runtime
# Assumes `strace -tt -T`
MATCHER = %r[(\d+)\s+(\d{2}:\d{2}:\d{2}.\d{6}) (\w+)\((.*)\) = (\d+) <(.*)>]
def initialize(line)
self.line = line
parse_line
end
private
def parse_line
line.match(MATCHER) do |match|
self.pid = match[1].to_i
self.timestamp = match[2]
self.command = match[3]
self.args = match[4]
self.result = match[5]
self.runtime = match[6].to_f
end
end
end
entries = []
ARGF.each_line do |line|
if line =~ StraceEntry::MATCHER
entries << StraceEntry.new(line)
end
end
puts "Matched #{entries.count} entries"
groups = entries.group_by(&:command)
puts "Grouped into #{groups.keys.count} commands"
groups.each do |command, es|
puts "#{command}: #{es.map(&:runtime).inject(:+)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment