lib/beaker-benchmark/helpers.rb in beaker-benchmark-0.0.2 vs lib/beaker-benchmark/helpers.rb in beaker-benchmark-0.0.3
- old
+ new
@@ -1,7 +1,8 @@
require 'csv'
require 'fileutils'
+require 'time'
module Beaker
module DSL
module BeakerBenchmark
module Helpers
@@ -26,12 +27,14 @@
PROC_MEM_INDEX = 11
PROC_DISK_READ_INDEX = 11
PROC_DISK_WRITE_INDEX = 13
- TMP_DIR = 'tmp/atop'
+ @@session_timestamp = Time.now.getutc.to_i
+ TMP_DIR = "tmp/atop/#{@@session_timestamp}"
+
# Example usage:
# test_name('measure_perf_on_puppetserver_start') {
# on(master, 'puppet resource service pe-puppetserver ensure=stopped')
# result = measure_perf_on(master, 'start_pe-puppetserver', true) {
# on(master, 'puppet resource service pe-puppetserver ensure=running')
@@ -61,16 +64,16 @@
end
end
def start_monitoring(infrastructure_host, action_name, include_processes=false, sample_interval=1)
raise('Monitoring already in progress, call stop_monitoring before calling start_monitoring a second time') unless @beaker_benchmark_start.nil?
- @atop_log = "atop_log_#{action_name.downcase.gsub(/[^a-z0-9]/i, '_')}.log"
- @action_name = action_name
+ @atop_log_filename = "atop_log_#{action_name.downcase.gsub(/[^a-z0-9]/i, '_')}.log"
+ @action_name = action_name
setup_atop(infrastructure_host)
additional_args = ''
additional_args = ',PRC,PRM,PRD' if include_processes
- atop_cmd = "sh -c 'nohup atop -P CPU,SWP,DSK#{additional_args} -i #{sample_interval} > #{@atop_log} 2>&1 &'"
+ atop_cmd = "sh -c 'nohup atop -P CPU,SWP,DSK#{additional_args} -i #{sample_interval} > #{@atop_log_filename} 2>&1 &'"
on(infrastructure_host, atop_cmd)
@beaker_benchmark_start = Time.now
end
@@ -91,23 +94,23 @@
@beaker_benchmark_start = nil
end
end
def parse_atop_log(infrastructure_host, duration)
- unless infrastructure_host.file_exist?(@atop_log)
- raise("atop log does not exist at #{@atop_log}")
+ unless infrastructure_host.file_exist?(@atop_log_filename)
+ raise("atop log does not exist at #{@atop_log_filename}")
end
log_dir = "#{TMP_DIR}/#{infrastructure_host.hostname}"
FileUtils::mkdir_p log_dir unless Dir.exist? log_dir
- scp_from(infrastructure_host, @atop_log, log_dir)
+ scp_from(infrastructure_host, @atop_log_filename, log_dir)
cpu_usage = []
mem_usage = []
disk_read = []
disk_write = []
skip = true
- CSV.parse(File.read(File.expand_path(File.basename(@atop_log), log_dir)), { :col_sep => ' ' }) do |row|
+ CSV.parse(File.read(File.expand_path(@atop_log_filename, log_dir)), { :col_sep => ' ' }) do |row|
#skip the first entry, until the first separator 'SEP'.
measure_type = row[MEASURE_TYPE_INDEX]
if skip
skip = (measure_type != 'SEP')
next