Skip to content

Instantly share code, notes, and snippets.

@justinstoller
Created March 19, 2018 16:41
Show Gist options
  • Save justinstoller/09ba672acd0338c074d2569f8701b894 to your computer and use it in GitHub Desktop.
Save justinstoller/09ba672acd0338c074d2569f8701b894 to your computer and use it in GitHub Desktop.
summarize gatlins runs
#!/usr/bin/env ruby [23/9866]
require 'csv'
inputfile = ARGV[0]
intermediate = {
'node' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'filemeta plugins' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'filemeta pluginfacts' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'catalog' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'filemeta' => {'KOs' => 0, 'values' => [], 'ok' => 0},
'report' => {'KOs' => 0, 'values' => [], 'ok' => 0}
}
CSV.foreach(inputfile, col_sep: "\t") do |row|
if row[0] == 'REQUEST'
type = row[4]
if row[7] != 'OK'
intermediate[type]['KOs'] += 1
else
intermediate[type]['values'] << row[6].to_i - row[5].to_i
intermediate[type]['ok'] += 1
end
end
end
output = []
intermediate.each_pair do |type, info|
length = info['ok']
first_quarti = (length * 0.25).to_i
fourth_quarti = (length * 0.75).to_i
mediani = (length * 0.5).to_i
p90i = (length * 0.9).to_i
p95i = (length * 0.95).to_i
p99i = (length * 0.99).to_i
p999i = (length * 0.999).to_i
p9999i = (length * 0.9999).to_i
# puts "Sorting values for #{type}"
info['values'].sort!
# puts "Finding mean for #{type}"
mean = (info['values'].reduce(:+) / length)
# puts "Finding interquartile mean for #{type}"
rough_iqm = (info['values'][first_quarti..fourth_quarti].reduce(:+) / (length / 2))
# puts "Finding median of medians for #{type}"
median = info['values'][mediani]
distances_from_median = info['values'].map {|v| (v - median).abs }.sort
median_of_medians = distances_from_median[mediani]
output << [
type,
info['values'].first,
median,
info['values'][p90i],
info['values'][p95i],
info['values'][p99i],
info['values'][p999i],
info['values'][p9999i],
info['values'].last,
mean,
rough_iqm,
median_of_medians,
info['ok'] + info['KOs'],
info['KOs']
]
end
puts 'endpoint,min,median,p90,p95,p99,p999,p9999,max,mean,iqm,mm,count,kos'
output.each do |row|
puts row.join(',')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment