Skip to content

Instantly share code, notes, and snippets.

@seancaffery
Created June 15, 2016 00:26
Show Gist options
  • Save seancaffery/d69984a99d52bf6f468d5afb8839a83e to your computer and use it in GitHub Desktop.
Save seancaffery/d69984a99d52bf6f468d5afb8839a83e to your computer and use it in GitHub Desktop.
require "csv"
require "time"
require "file"
res = Hash(String, Array(Int64 | Int32)).new {|hsh, key| hsh[key] = [] of Int32 | Int64 }
stack = [] of Hash(String, Array(String | Int64 | Int32))
CSV.each_row(File.open("trace.csv")) do |line|
begin
type, file, no, time = line
if type == "call"
stack.push( { "#{file}#{no}" => [file,no,time] } )
else
if kaller = stack.pop?
info = kaller[kaller.keys.first]
res[kaller.keys.first] << time.to_i64 - info.last.to_i64
end
end
rescue e
# puts e
# puts line
# puts stack
end
end
end_result = res.map do |key, value|
[key, value.size, value.reduce(0) {|mem, v| mem + v}]
end
end_result_sorted = end_result.sort_by { |a| a.last.as(Int32) }
end_result_sorted[200..-1].each do |a|
puts a.inspect
end
require 'csv'
require 'time'
res = Hash.new {|hsh,key| hsh[key] = Array.new }
stack = []
CSV.foreach('trace.csv') do |line|
begin
type, file, no, time = line
if type == 'call'
stack.push( { "#{file}#{no}" => [file,no,time] } )
else
if kaller = stack.pop
info = kaller[kaller.keys.first]
res[kaller.keys.first] << time.to_i - info.last.to_i
end
end
rescue => e
puts line.inspect
puts e.inspect
end
end
end_result = res.map do |a|
[a.first, a.last.count, a.last.inject(:+)]
end
end_result_sorted = end_result.sort_by { |a| a.last }
end_result_sorted[200..-1].each do |a|
puts a.inspect
end
@seancaffery
Copy link
Author

Capture trace.csv with:

set_trace_func proc { |event, file, line, id, binding, classname|
  if ['call', 'return'].include?(event) && file !~ /(\/bundle|log_rotator)/
    debug_file.puts "#{event},#{file},#{line},#{(Time.now.to_f.round(3) * 1000).to_i}"
  end
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment