Created
June 15, 2016 00:26
-
-
Save seancaffery/d69984a99d52bf6f468d5afb8839a83e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Capture
trace.csv
with: