Description:
add run_stat checking
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r160:f0502be39e3b - - 3 files changed: 48 inserted, 10 deleted
@@ -63,12 +63,13 | |||
|
63 | 63 | else |
|
64 | 64 | cmp_msg = "" |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | result_fname = "#{test_result_dir}/result" |
|
68 | 68 |
comment_fname = "#{test_result_dir}/comment" |
|
69 | + runstat_fname = "#{test_result_dir}/run_stat" | |
|
69 | 70 | if FileTest.exist?(result_fname) |
|
70 | 71 | comment = "" |
|
71 | 72 | begin |
|
72 | 73 | result_file = File.open(result_fname) |
|
73 | 74 | result = result_file.readline.to_i |
|
74 | 75 | result_file.close |
@@ -82,15 +83,28 | |||
|
82 | 83 | comment += comment_file.readline.chomp |
|
83 | 84 | comment_file.close |
|
84 | 85 | rescue |
|
85 | 86 | comment += "" |
|
86 | 87 | end |
|
87 | 88 | |
|
88 | - return {:points => result, | |
|
89 | - :comment => comment, | |
|
90 | - :cmp_msg => cmp_msg} | |
|
89 | + begin | |
|
90 | + runstat_file = File.open(runstat_fname) | |
|
91 | + max_runtime = runstat_file.readline.to_f | |
|
92 | + peak_memory = runstat_file.readline.to_i | |
|
93 | + rescue | |
|
94 | + max_runtime = -1 | |
|
95 | + peak_memory = -1 | |
|
96 | + end | |
|
97 | + | |
|
98 | + | |
|
99 | + return {points: result, | |
|
100 | + comment: comment, | |
|
101 | + cmp_msg: cmp_msg, | |
|
102 | + max_runtime: max_runtime, | |
|
103 | + peak_memory: peak_memory | |
|
104 | + } | |
|
91 | 105 | else |
|
92 | 106 | if FileTest.exist?("#{test_result_dir}/a.out") |
|
93 | 107 | return {:points => 0, |
|
94 | 108 | :comment => 'error during grading', |
|
95 | 109 | :cmp_msg => cmp_msg} |
|
96 | 110 | else |
@@ -105,12 +119,16 | |||
|
105 | 119 | problem = submission.problem |
|
106 | 120 | submission.graded_at = Time.now.gmtime |
|
107 | 121 | points = result[:points] |
|
108 | 122 | submission.points = points |
|
109 | 123 | comment = @config.report_comment(result[:comment]) |
|
110 | 124 | |
|
125 | + submission.peak_memory = result[:peak_memory] | |
|
126 | + submission.max_runtime = result[:max_runtime] | |
|
127 | + submission.effective_code_length =submission.source.length | |
|
128 | + | |
|
111 | 129 | # |
|
112 | 130 | # TODO: FIX THIS MESSAGE |
|
113 | 131 | # |
|
114 | 132 | if problem == nil |
|
115 | 133 | submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)' |
|
116 | 134 | elsif points == problem.full_score |
@@ -1453,17 +1453,12 | |||
|
1453 | 1453 | if (timeout && total_ms > timeout) |
|
1454 | 1454 | err("TO: Time limit exceeded"); |
|
1455 | 1455 | if (wall_timeout && wall_ms > wall_timeout) |
|
1456 | 1456 | err("TO: Time limit exceeded (wall clock)"); |
|
1457 | 1457 | flush_line(); |
|
1458 | 1458 | fprintf(stderr,"OK\n"); |
|
1459 | - print_running_stat( | |
|
1460 | - (double)wall_ms/1000, | |
|
1461 | - (double)total_ms/1000, | |
|
1462 | - (double)sys_ms/1000, | |
|
1463 | - (mem_peak_kb + 1023) / 1024); | |
|
1464 | 1459 | box_exit(0); |
|
1465 | 1460 | } |
|
1466 | 1461 | if (WIFSIGNALED(stat)) |
|
1467 | 1462 | { |
|
1468 | 1463 | box_pid = 0; |
|
1469 | 1464 | meta_printf("exitsig:%d\n", WTERMSIG(stat)); |
@@ -28,24 +28,37 | |||
|
28 | 28 | res[1] |
|
29 | 29 | else |
|
30 | 30 | RUN_ERROR_MARK # these are run time errors |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | + def extract_time(t) | |
|
35 | + puts "TIME: #{t}" | |
|
36 | + if (result=/^(.*)r(.*)u(.*)s(.*)m/.match(t)) | |
|
37 | + {:real => result[1], :user => result[2], :sys => result[3], :mem => result[4]} | |
|
38 | + else | |
|
39 | + #{:real => 0, :user => 0, :sys => 0} | |
|
40 | + #puts "ERROR READING RUNNING TIME: #{t}" | |
|
41 | + raise "Error reading running time: #{t}" | |
|
42 | + end | |
|
43 | + end | |
|
44 | + | |
|
34 | 45 | problem_home = ENV['PROBLEM_HOME'] |
|
35 | 46 | require "#{problem_home}/script/test_dsl.rb" |
|
36 | 47 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
37 | 48 | problem = Problem.get_instance |
|
38 | 49 | |
|
39 | 50 | if problem.well_formed? == false |
|
40 | 51 | log "The problem specification is not well formed." |
|
41 | 52 | exit(127) |
|
42 | 53 | end |
|
43 | 54 | |
|
44 | 55 | all_score = 0 |
|
45 | 56 | all_comment = '' |
|
57 | + peak_memory = -1 | |
|
58 | + max_runtime = -1 | |
|
46 | 59 | (1..(problem.runs.length-1)).each do |k| |
|
47 | 60 | log "grade run #{k}" |
|
48 | 61 | run = problem.runs[k] |
|
49 | 62 | run_score = nil |
|
50 | 63 | run_comment = '' |
|
51 | 64 | run_comment_short = '' |
@@ -55,16 +68,21 | |||
|
55 | 68 | run_comment += "result file for test #{test_num} not found\n" |
|
56 | 69 | run_comment_short += RUN_ERROR_MARK |
|
57 | 70 | log "Cannot find the file #{test_num}/result!" |
|
58 | 71 | else |
|
59 | 72 | result_file = File.new(result_file_name, "r") |
|
60 | 73 | result_file_lines = result_file.readlines |
|
61 |
- if result_file_lines.length>= |
|
|
74 | + if result_file_lines.length>=3 | |
|
62 | 75 | current_run_score = result_file_lines[1].to_i |
|
63 | 76 | run_comment += result_file_lines[0] |
|
64 | 77 | run_comment_short += char_comment(result_file_lines[0].chomp) |
|
78 | + | |
|
79 | + #update max runtime & memory | |
|
80 | + run_stat = extract_time result_file_lines[2] | |
|
81 | + peak_memory = [peak_memory,run_stat[:mem].to_i].max | |
|
82 | + max_runtime = [max_runtime,run_stat[:user].to_f + run_stat[:sys].to_f].max | |
|
65 | 83 | else |
|
66 | 84 | current_run_score = 0 |
|
67 | 85 | run_comment += "result file for test #{test_num} error\n" |
|
68 | 86 | run_comment_short += RUN_ERROR_MARK |
|
69 | 87 | log "Error in #{test_num}/result!" |
|
70 | 88 | end |
@@ -102,7 +120,14 | |||
|
102 | 120 | result_file.close |
|
103 | 121 | |
|
104 | 122 | comment_file = File.new("comment", "w") |
|
105 | 123 | comment_file.write "#{all_comment}\n" |
|
106 | 124 | comment_file.close |
|
107 | 125 | |
|
108 | - log "score = #{all_score} comment = #{all_comment}" | |
|
126 | + | |
|
127 | + File.open("run_stat","w") do |file| | |
|
128 | + file.puts max_runtime | |
|
129 | + file.puts peak_memory | |
|
130 | + end | |
|
131 | + | |
|
132 | + log "score = #{all_score}\ncomment = #{all_comment}" | |
|
133 | + log "max_runtime = #{max_runtime}\npeak_memory = #{peak_memory}" |
You need to be logged in to leave comments.
Login now