Last active
August 29, 2015 14:06
-
-
Save Jared-Prime/f8d6a98fb2318c2532fc 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/ruby | |
require 'csv' | |
class Parser | |
attr_reader :original_file, :run_id, :timestamp, :partition_table, :node_ip_address | |
attr_reader :peak_concurrency, :average_duration, :average_rate, :target_rate | |
attr_reader :total_calls, :success_rate, :error_rate | |
class << self | |
def open_file(path) | |
orig = File.read path | |
run_id = path.gsub /[A-Za-z_\.]/, '' | |
return new orig, run_id | |
end | |
end | |
def initialize(orig, run_id='NA') | |
@original_file, @run_id = orig, run_id | |
get_timestamp | |
get_peak_concurrency | |
get_target_rate | |
get_average_rate | |
get_average_duration | |
get_node_ip_address | |
get_partition_table | |
get_total_calls | |
get_success_rate | |
get_error_rate | |
return self | |
end | |
private | |
def lines | |
original_file.split "\r\n" | |
end | |
def get_partition_table | |
@partition_table = lines.map do |line| | |
if line.match "ms <= n <" | |
line = line.split | |
frame, count = line[5], line[8] | |
[frame, count] | |
end | |
end.reject(&:nil?) | |
end | |
def get_timestamp | |
ts = original_file | |
.match(/Timestamp.*/).to_s | |
.split(/(:|\s)/) | |
.reject { |s| s.strip.empty? || s == ":"} | |
@timestamp = Time.new ts[7], ts[2], ts[3], ts[4], ts[5], ts[6] | |
end | |
def get_peak_concurrency | |
@peak_concurrency = original_file | |
.match(/Peak was.* calls/) | |
.to_s.split[2] | |
end | |
def get_total_calls | |
@total_calls = @partition_table.inject(0) do |sum,entry| | |
sum + entry.last.to_i | |
end | |
end | |
def get_target_rate | |
@target_rate = original_file | |
.match(/.*8838.*UDP\)/).to_s | |
.split("(").first.to_i | |
end | |
def get_average_rate | |
@average_rate = original_file | |
.match(/Call Rate.*/).to_s | |
.split[-2].to_f | |
end | |
def get_error_rate | |
failures = @partition_table.inject(0) do |sum,entry| | |
frame = entry.first | |
if frame <= '9000' && frame >= '10000' | |
sum.to_i + frame.to_i | |
end | |
end | |
@error_rate = failures.to_f / @total_calls.to_f | |
end | |
def get_success_rate | |
successes = @partition_table.inject(0) do |sum,entry| | |
frame = entry.first | |
if frame > '9000' && frame < '10000' | |
sum + frame.last.to_i | |
end | |
end | |
@success_rate = successes.to_f / @total_calls.to_f | |
end | |
def get_average_duration | |
seconds, milliseconds = original_file | |
.match(/Call Length.*/).to_s | |
.split(":")[-2..-1] | |
@average_duration = (seconds + '.' + milliseconds).strip.to_f | |
end | |
def get_node_ip_address | |
@node_ip_address = original_file | |
.match(/\d{3}\.\d{3}\.\d{2}\.\d{1}/).to_s | |
end | |
end | |
parsed_files = ARGV.map do |filename| | |
Parser.open_file filename | |
end | |
CSV.open('./partition_tables.csv', 'w') do |csv| | |
heading1 = [] | |
heading1_data = [] | |
heading2 = [] | |
heading2_data = [] | |
spacer_col = ['',''] | |
parsed_files.each.with_index do |data,i| | |
heading1 = heading1 + ['Node', 'Test Run ID'] + spacer_col | |
heading2 = heading2 + ['Frame', 'Count'] + spacer_col | |
heading1_data = heading1_data + [data.node_ip_address, data.run_id] + spacer_col | |
data.partition_table.each.with_index do |entry,j| | |
if i == 0 | |
heading2_data << entry + spacer_col | |
else | |
heading2_data[j] = heading2_data[j] + entry + spacer_col | |
end | |
end | |
end | |
csv << heading1 | |
csv << heading1_data | |
csv << heading2 | |
heading2_data.each do |row| | |
csv << row | |
end | |
end | |
CSV.open('./results-summary.csv', 'w') do |csv| | |
csv << ['Node','Test Run ID','Timestamp', 'Peak Concurrency', 'Target Rate', 'Average Rate', 'Average Duration', 'Total Count', 'Percent Successful', 'Percent Failed'] | |
parsed_files.each do |data| | |
csv << [data.node_ip_address, data.run_id, data.timestamp, data.peak_concurrency, data.target_rate, data.average_rate, data.average_duration, data.total_calls, data.success_rate, data.error_rate] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment