Mercurial > hg > Members > nobuyasu > jungle_benchmark
changeset 23:446a5c242cc7
Added test_calc_sd_from_log.rb
author | Nobuyasu |
---|---|
date | Thu, 30 Jan 2014 23:31:30 +0900 |
parents | d6d3b7180e6d |
children | 4bc7b8835f56 |
files | distributed/weighttp/calc_sd_from_log.rb distributed/weighttp/test_calc_sd_from_log.rb |
diffstat | 2 files changed, 107 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/distributed/weighttp/calc_sd_from_log.rb Thu Jan 30 21:48:09 2014 +0900 +++ b/distributed/weighttp/calc_sd_from_log.rb Thu Jan 30 23:31:30 2014 +0900 @@ -1,48 +1,59 @@ -#!/usr/local/bin/ruby -include Math - -if ARGV.size() < 1 then - puts "Usage:ruby parse_log.rb filename" - exit -end +module CalcSD + include Math -def get_log_time(filename) - logArray = File.open(filename, "r") do |file| - file.readlines.select{|line| !(line =~ /mass/) } - end - totalFailed = 0 - totalTime = 0 - timeArray = [] - logArray.each {|line| + def get_time_array(logArray) + timeArray=[] + totalTime = 0 + totalFailed = 0 + logArray.each {|line| tokens = line.split(' ') - float = sprintf( "%.0f",tokens[2].to_i) - time = tokens[0]. + "." + float.to_s - timeArray.push(time.to_f) - totalTime = totalTime + time.to_f + sec = tokens[0].to_i * 1000 + millsec = sprintf( "%03d", tokens[2]).to_i + # millsecond + time = sec + millsec + timeArray.push(time) + totalTime = totalTime + time totalFailed = totalFailed + tokens[4].to_i - } - avarage = totalTime / timeArray.size() - avarage = sprintf("%.3f", avarage).to_f - totalN = 0 - puts "avarage: "+ avarage.to_s - timeArray.each {|time| - totalN = totalN + (time.to_f - avarage) - totalN = sprintf("%.3f", totalN).to_f - puts "time: "+ time.to_s - puts "time - avarage :" + sprintf("%.3f",(time - avarage).to_s) - puts "totalN: "+totalN.to_s - } - variance = totalN / timeArray.size() - variance = sprintf("%.3f", variance).to_f - puts "variance: " + variance.to_s - sigma = Math.sqrt(variance) - puts sigma - if totalFailed != 0 then puts "Failed " + totalFailed.to_s end + } + hashmap = {:totalTime => totalTime, :timeArray => timeArray, :totalFailed => totalFailed } + return hashmap + end + + def log_select(filename) + return logArray = File.open(filename, "r") do |file| + file.readlines.select{|line| !(line =~ /mass/) } + end + end + + def calclate_sigma(map) + timeArray = map[:timeArray] + totalTime = map[:totalTime] + avarage = totalTime / timeArray.size() + puts "avarage :" + avarage.to_s + + totalN = 0 + timeArray.each {|time| + timeMinusAv = time - avarage + element = timeMinusAv * timeMinusAv + totalN = totalN + element + } + variance = totalN / timeArray.size() + sigma = Math.sqrt(variance) + + end + + def get_sigma_from_log(filename) + return get_sigma(filename, method(:log_select)) + end + + def get_sigma(filename, parser) + logArray = parser.call(filename) + map = get_time_array(logArray) + sigma = calclate_sigma(map) + # unit is millisec + return sigma.to_i + end + end - -ARGV.each {|filename| - get_log_time(filename) -} - - - + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/distributed/weighttp/test_calc_sd_from_log.rb Thu Jan 30 23:31:30 2014 +0900 @@ -0,0 +1,52 @@ +#!/usr/local/bin/ruby + +require './calc_sd_from_log.rb' +include CalcSD +include Math + +$log=" +1 +2 +3 +4 +5 +" + +#puts get_sigma_from_log("./cassandra_log/log/read_cassandra.o7518") + +def log_parser(filename) + timeArray=[] + totalTime = 0 + totalFailed = 0 + timeStrArray = File.open(filename)do |file| + file.readlines.select{|line| line =~ /./ } + end + return timeStrArray.collect{|strTime| strTime.to_i } +end + +def create_map(timeArray) + totalTime = 0 + totalFailed = 0 + timeArray.each {|time| + totalTime = totalTime + time + } + hashmap = {:totalTime => totalTime, :timeArray => timeArray, :totalFailed => totalFailed} +end + +def main() + filename = (Time.now.to_i).to_s + puts "filename : "+filename + f = open(filename,"w") + f.puts $log + f.close() + + timeArray = log_parser(filename) + File.delete(filename) + map = create_map(timeArray) + sigma = calclate_sigma(map) + puts sigma.to_s + puts Math.sqrt(2).to_s +end + +main() +