diff --git a/lib/result_root.rb b/lib/result_root.rb index 37fe3e396..493f766c8 100755 --- a/lib/result_root.rb +++ b/lib/result_root.rb @@ -2,6 +2,7 @@ require 'time' +require "#{LKP_SRC}/lib/string" require "#{LKP_SRC}/lib/common" require "#{LKP_SRC}/lib/property" require "#{LKP_SRC}/lib/yaml" @@ -128,7 +129,7 @@ def each class Completion def initialize(line) fields = line.split - @time = Time.parse(fields[0..2].join(' ')) + @time = fields[0..2].join(' ').to_time @_rt = MResultRoot.new fields[4] @status = fields.drop(4).join ' ' end diff --git a/lib/string.rb b/lib/string.rb index 16f0eae71..f2f564c6b 100755 --- a/lib/string.rb +++ b/lib/string.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +require 'active_support/core_ext/string/conversions' REGEX_ANSI_COLOR = /\e\[([0-9;]+m|[mK])/.freeze diff --git a/programs/igt/parse b/programs/igt/parse index b60fc038f..68aa91f77 100755 --- a/programs/igt/parse +++ b/programs/igt/parse @@ -13,7 +13,7 @@ subtest_name = nil has_dynamic_subtest = false def valid_datetime?(datetime_str) - Time.parse(datetime_str) + datetime_str.to_time rescue StandardError false end diff --git a/programs/iostat/parse b/programs/iostat/parse index 93d073437..7a61440ad 100755 --- a/programs/iostat/parse +++ b/programs/iostat/parse @@ -7,8 +7,10 @@ # Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util # sda 0.15 12.76 3.02 9.81 63.05 126.27 29.51 0.16 12.72 3.96 15.42 1.55 1.99 # sdd 0.09 34.01 8.43 20.57 189.15 750.68 64.80 0.79 27.07 1.31 37.63 0.45 1.31 +LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))) require 'time' +require "#{LKP_SRC}/lib/string" def normalize_key(key) key.sub('%', '') @@ -45,7 +47,7 @@ while (line = $stdin.gets) case line when /^[0-9T:+-]{24}$/ # "2013-04-02T13:58:40+0800", by 'S_TIME_FORMAT=ISO isotat -t' time = line.chomp('\n') - puts "time: #{Time.parse(time).to_i}" + puts "time: #{time.to_time.to_i}" when /^avg-cpu:/ extract_avg_cpu line when /^Device:/ diff --git a/programs/mpstat/parse b/programs/mpstat/parse index 35fa50533..4b49df2ba 100755 --- a/programs/mpstat/parse +++ b/programs/mpstat/parse @@ -5,6 +5,7 @@ require 'time' require 'json' require 'fileutils' require "#{LKP_SRC}/lib/log" +require "#{LKP_SRC}/lib/string" # The below is an example of mpstat output, read it then parse it into hash data. # {"sysstat": { @@ -170,7 +171,7 @@ mpstat_hash['sysstat']['hosts'][0]['statistics'].each do |item| elsif k == 'timestamp' # Append UTC to timestamp to fix the timezone as no timezone is provided by # mpstat, otherwise the parsed result is related to the timezone of local system. - time = Time.parse([data, v, 'UTC'].join(' ')).to_i + time = [data, v, 'UTC'].join(' ').to_time.to_i results['time'] = time end end diff --git a/programs/sar/parse b/programs/sar/parse index 200aaa170..675ef69b7 100755 --- a/programs/sar/parse +++ b/programs/sar/parse @@ -1,8 +1,9 @@ #!/usr/bin/env ruby +LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))) require 'time' require 'json' - +require "#{LKP_SRC}/lib/string" RESULT_ROOT = ENV['RESULT_ROOT'] # The below is part of the sar json file, read it then parse it into hash data. @@ -96,7 +97,7 @@ sar_hash['sysstat']['hosts'][0]['statistics'].each do |item| elsif v_.instance_of?(Hash) get_hash_result k_, v_, results elsif k == 'timestamp' - timestamp = Time.parse([v['data'], v['time']].join(' ')).to_i + timestamp = [v['data'], v['time']].join(' ').to_time.to_i results['timestamp'] = timestamp else results["#{k}.#{k_}"] = v_ diff --git a/programs/unixbench/parse b/programs/unixbench/parse index 3c5bb63f9..d9249e433 100755 --- a/programs/unixbench/parse +++ b/programs/unixbench/parse @@ -15,8 +15,8 @@ while (line = $stdin.gets) when /^Benchmark Run: .+ (\d+:\d+:\d+) - (\d+:\d+:\d+)$/ # Benchmark Run: Tue Jan 01 2019 15:48:24 - 15:56:36 # We only care about the difference value between end time and start time - start_time = Time.parse($1).to_f - end_time = Time.parse($2).to_f + start_time = $1.to_time.to_f + end_time = $2.to_time.to_f duration = if end_time > start_time end_time - start_time else diff --git a/programs/vmstat/parse b/programs/vmstat/parse index c16420de0..a3ec10373 100755 --- a/programs/vmstat/parse +++ b/programs/vmstat/parse @@ -1,7 +1,7 @@ #!/usr/bin/env ruby - +LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))) require 'time' - +require "#{LKP_SRC}/lib/string" # procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp----- # r b swpd free buff cache si so bi bo in cs us sy id wa st PST # 2 0 0 224636 33636 6760228 0 0 54 141 129 23 1 1 98 0 0 2015-01-11 20:18:35 @@ -29,7 +29,7 @@ while (line = $stdin.gets) data = line.split if data.size == keys.size + 1 # has "date time" in end of line - time = Time.parse(data.pop(2).join(' ')).to_i + time = data.pop(2).join(' ').to_time.to_i data.push time show_record keys, data elsif data.size == keys.size - 1 # no timestamp in old versions of vmstat