[Why] Get rid of dependence on job.sh
[How] stats_program_list include: - stat-programs from job[key] which matched with lkp-tests/stats* - job[$suite] - time job[$suite].time - stderr - default stats: lkp-tests/etc/default_stats.yaml
Signed-off-by: Lu Weitao luweitaobe@163.com --- lib/matrix2.rb | 2 +- lib/stats.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++ sbin/result2stats | 16 +++++-------- 3 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 lib/stats.rb
diff --git a/lib/matrix2.rb b/lib/matrix2.rb index 2195ed4..ab92986 100644 --- a/lib/matrix2.rb +++ b/lib/matrix2.rb @@ -2,7 +2,7 @@
# frozen_string_literal: true
-LKP_SRC = ENV['LKP_SRC'] || '/c/lkp-tests' +LKP_SRC ||= ENV['LKP_SRC'] || '/c/lkp-tests'
require "#{LKP_SRC}/lib/stats" require "#{LKP_SRC}/lib/yaml" diff --git a/lib/stats.rb b/lib/stats.rb new file mode 100644 index 0000000..acd807a --- /dev/null +++ b/lib/stats.rb @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# frozen_string_literal: true + +require_relative './stats_wrapper' + +def load_yaml(path) + unless File.file?(path) + warn "#{path} does not exist" + exit + end + YAML.load_file(path) +end + +def available_stats + vailable_stats = [] + Dir.open(LKP_SRC + '/stats').each do |file| + vailable_stats << file unless file.start_with?('.') + end + + vailable_stats +end + +def assign_default_stats(stats_list) + default_stats = YAML.load_file(LKP_SRC + '/etc/default_stats.yaml').keys + default_stats.each { |stat| stats_list << stat } +end + +# extract each result from the script output +# format each result as $script.json +class Stats + def initialize(result_root) + @result_root = result_root + @job = load_yaml(File.join(result_root, 'job.yaml')) + @available_stats = available_stats + end + + def extract_stats + stats_list = assign_stats_list + stats_list.each do |stat| + StatsWrapper.wrapper(*stat) + end + end + + def assign_stats_list + stats_list = [] + stats_list << @job['suite'] + stats_list << ['time', @job['suite'] + '.time'] + stats_list << 'stderr' + @job.each_key do |k| + if @available_stats.include?(k) + stats_list << k + end + end + assign_default_stats(stats_list) + + stats_list + end +end diff --git a/sbin/result2stats b/sbin/result2stats index 6229b3c..6a09075 100755 --- a/sbin/result2stats +++ b/sbin/result2stats @@ -7,16 +7,10 @@ CCI_SRC = File.dirname(__dir__)
require 'optparse' require "#{CCI_SRC}/lib/matrix2" +require_relative '../lib/stats.rb'
File.umask 0o002
-def extract_stats(result_root) - ENV['RESULT_ROOT'] = result_root - job_script = result_root + '/job.sh' - - system job_script, 'extract_stats' -end - opt_parser = OptionParser.new do |opts| opts.banner = 'Usage: result2stats result_root' opts.separator 'eg: result2stats /srv/result/iperf/vm-1p1g/2020-09-30/crystal.91198' @@ -36,7 +30,9 @@ argv = if ARGV == [] end
opt_parser.parse!(argv) +RESULT_ROOT = argv[0] || ENV['RESULT_ROOT'] +ENV['RESULT_ROOT'] = RESULT_ROOT
-result_root = argv[0] || ENV['RESULT_ROOT'] -extract_stats result_root -create_stats result_root +stats = Stats.new(RESULT_ROOT) +stats.extract_stats +create_stats RESULT_ROOT