diff --git a/lib/submission_helper.rb b/lib/submission_helper.rb --- a/lib/submission_helper.rb +++ b/lib/submission_helper.rb @@ -65,7 +65,8 @@ end result_fname = "#{test_result_dir}/result" - comment_fname = "#{test_result_dir}/comment" + comment_fname = "#{test_result_dir}/comment" + runstat_fname = "#{test_result_dir}/run_stat" if FileTest.exist?(result_fname) comment = "" begin @@ -85,9 +86,22 @@ comment += "" end - return {:points => result, - :comment => comment, - :cmp_msg => cmp_msg} + begin + runstat_file = File.open(runstat_fname) + max_runtime = runstat_file.readline.to_f + peak_memory = runstat_file.readline.to_i + rescue + max_runtime = -1 + peak_memory = -1 + end + + + return {points: result, + comment: comment, + cmp_msg: cmp_msg, + max_runtime: max_runtime, + peak_memory: peak_memory + } else if FileTest.exist?("#{test_result_dir}/a.out") return {:points => 0, @@ -108,6 +122,10 @@ submission.points = points comment = @config.report_comment(result[:comment]) + submission.peak_memory = result[:peak_memory] + submission.max_runtime = result[:max_runtime] + submission.effective_code_length =submission.source.length + # # TODO: FIX THIS MESSAGE # diff --git a/std-script/box64-new.c b/std-script/box64-new.c --- a/std-script/box64-new.c +++ b/std-script/box64-new.c @@ -1456,11 +1456,6 @@ err("TO: Time limit exceeded (wall clock)"); flush_line(); fprintf(stderr,"OK\n"); - print_running_stat( - (double)wall_ms/1000, - (double)total_ms/1000, - (double)sys_ms/1000, - (mem_peak_kb + 1023) / 1024); box_exit(0); } if (WIFSIGNALED(stat)) diff --git a/std-script/grade b/std-script/grade --- a/std-script/grade +++ b/std-script/grade @@ -31,6 +31,17 @@ end end +def extract_time(t) + puts "TIME: #{t}" + if (result=/^(.*)r(.*)u(.*)s(.*)m/.match(t)) + {:real => result[1], :user => result[2], :sys => result[3], :mem => result[4]} + else + #{:real => 0, :user => 0, :sys => 0} + #puts "ERROR READING RUNNING TIME: #{t}" + raise "Error reading running time: #{t}" + end +end + problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" load "#{problem_home}/test_cases/all_tests.cfg" @@ -43,6 +54,8 @@ all_score = 0 all_comment = '' +peak_memory = -1 +max_runtime = -1 (1..(problem.runs.length-1)).each do |k| log "grade run #{k}" run = problem.runs[k] @@ -58,10 +71,15 @@ else result_file = File.new(result_file_name, "r") result_file_lines = result_file.readlines - if result_file_lines.length>=2 + if result_file_lines.length>=3 current_run_score = result_file_lines[1].to_i run_comment += result_file_lines[0] run_comment_short += char_comment(result_file_lines[0].chomp) + + #update max runtime & memory + run_stat = extract_time result_file_lines[2] + peak_memory = [peak_memory,run_stat[:mem].to_i].max + max_runtime = [max_runtime,run_stat[:user].to_f + run_stat[:sys].to_f].max else current_run_score = 0 run_comment += "result file for test #{test_num} error\n" @@ -105,4 +123,11 @@ comment_file.write "#{all_comment}\n" comment_file.close -log "score = #{all_score} comment = #{all_comment}" + +File.open("run_stat","w") do |file| + file.puts max_runtime + file.puts peak_memory +end + +log "score = #{all_score}\ncomment = #{all_comment}" +log "max_runtime = #{max_runtime}\npeak_memory = #{peak_memory}"