Last active
May 2, 2020 01:52
-
-
Save vdinovi/5aac8d834957a09673551a5300e7c4ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'csv' | |
| require 'terminal-table' | |
| require 'optparse' | |
| require 'pry' | |
| ARGV[0] or raise "input csv required" | |
| ARGV[1] or raise "target branch name required" | |
| options = {} | |
| OptionParser.new do |opts| | |
| opts.banner = "Usage: parse_smaphore_timings csv_rimings target_branch_name [options]" | |
| opts.on("-t", "--threads", "Include thread timings") do |t| | |
| options[:threads] = t | |
| end | |
| end.parse! | |
| results = CSV.parse(File.read(ARGV[0].strip)) | |
| rows = results[1..].map { |r| Hash[results[0].zip(r)] } | |
| target, others = rows.partition { |r| r['branch'] == ARGV[1] } | |
| target.any? or raise "no rows for branch #{ARGV[1]}" | |
| table = Terminal::Table.new do |t| | |
| t << ['Branch', 'Sha', 'Total Seconds', 'Max Seconds', *(options[:threads] ? (1..14).map { |id| "Thread #{id}" } : [])] | |
| t << :separator | |
| target_total = 0 | |
| target_max = 0 | |
| target.each do |row| | |
| timing = (1..14).map { |id| Float(row["t#{id}"]).round(4) } | |
| t << [row['branch'][0...30], row['sha'][0...6], timing.sum.round(4), timing.max.round(4), *(options[:threads] ? timing : [])] | |
| target_total += timing.sum | |
| target_max += timing.max | |
| end | |
| target_total_avg = (target_total / target.count).round(4) | |
| target_max_avg = (target_max / target.count).round(4) | |
| t << ['** Average **', nil, target_total_avg, target_max_avg] | |
| t << :separator | |
| others_total = 0 | |
| others_max = 0 | |
| others.each do |row| | |
| timing = (1..14).map { |id| Float(row["t#{id}"]) } | |
| t << [row['branch'][0...30], row['sha'][0...6], timing.sum.round(4), timing.max.round(4), *(options[:threads] ? timing : [])] | |
| others_total += timing.sum | |
| others_max += timing.max | |
| end | |
| others_total_avg = (others_total / others.count).round(4) | |
| others_max_avg = (others_max / others.count).round(4) | |
| t << ['** Average **', nil, others_total_avg, others_max_avg] | |
| avg_efficiency = (((target_total_avg - others_total_avg) / others_total_avg) * 100).round(2) | |
| max_efficiency = (((target_max_avg - others_max_avg) / others_max_avg) * 100).round(2) | |
| puts "** Total efficiency: #{avg_efficiency} % **" | |
| puts "** Max efficiency: #{max_efficiency} % **" | |
| end | |
| puts table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment