On Wed, Mar 10, 2021 at 10:04:06AM +0800, Luan Shengde wrote:
vailable_stats = []
- available_stats_func = [] Dir.open(LKP_SRC + '/stats').each do |file|
- vailable_stats << file unless file.start_with?('.')
next if file.start_with('.')
- if file.end_with?('.rb')
available_stats_func << file.chomp('.rb')
- else
vailable_stats << file unless file.start_with?('.')
vailable_stats << file
good iead
Thanks, Weitao
Thanks, Luan Shengde
- end end
- vailable_stats
- [vailable_stats, available_stats_func]
end
def assign_default_stats(stats_list) @@ -32,13 +37,17 @@ class Stats def initialize(result_root) @result_root = result_root @job = load_yaml(File.join(result_root, 'job.yaml'))
- @available_stats = available_stats
@available_stats, @available_stats_func = available_stats end
def extract_stats stats_list = assign_stats_list stats_list.each do |stat|
StatsWrapper.wrapper(*stat)
if @available_stats_func.include?(stat)
StatsWrapper.wrapper_func(*stat)
else
StatsWrapper.wrapper(*stat)
end endend
@@ -48,7 +57,7 @@ class Stats stats_list << ['time', @job['suite'] + '.time'] stats_list << 'stderr' @job.each_key do |k|
if @available_stats.include?(k)
endif @available_stats.include?(k) || @available_stats_func.include?(k) stats_list << k end
diff --git a/lib/stats_wrapper.rb b/lib/stats_wrapper.rb index 8a6d6a9..faa81df 100644 --- a/lib/stats_wrapper.rb +++ b/lib/stats_wrapper.rb @@ -6,6 +6,11 @@ LKP_SRC ||= ENV['LKP_SRC'] || '/c/lkp-tests' require "#{LKP_SRC}/lib/log.rb" require 'tempfile' require 'English' +require_relative './dump_stat'
+Dir[File.expand_path("#{LKP_SRC}/stats/*.rb")].uniq.each do |file|
- require file
+end
PROGRAM_DIR = "#{LKP_SRC}/stats"
@@ -35,6 +40,27 @@ module StatsWrapper delete_log_package end
- def self.wrapper_func(program, program_time = nil)
- @program = program
- @stats_group = program_time || program
- @log = "#{RESULT_ROOT}/#{@stats_group}"
- return unless File.exist?("#{@log}.yaml") || pretreatment
- if File.exist?("#{@log}.yaml")
log_lines = read_log("#{@log}.yaml")
stat_result = parse_simple_log_yaml(log_lines)
- else
log_lines = read_log(@log)
call_func_cmd = "#{@program.gsub('-', '_')}(log_lines)" # eg: proc_vmstats(log_lines)
stat_result = eval(call_func_cmd)
- end
- return unless DumpStat.dump_stat(@stats_group, stat_result)
- check_empty_json
- delete_log_package
- end
- def self.pretreatment return unless available_program? return unless unzip_log
@@ -261,3 +287,21 @@ module StatsWrapper File.delete(@tmpfile) if File.exist?(@tmpfile) end end
+# read line of log +# return Array(String) +def read_log(log_path)
- return nil unless File.exist?(log_path)
- File.readlines(log_path)
+end
+def parse_simple_log_yaml(log_lines)
- result = Hash.new { |hash, key| hash[key] = [] }
- log_lines.each do |line|
- key, value = line.split(/:?\s+/)
- result[key] << value
- end
- result
+end
2.23.0