Description:
[grader] box.cc now reports running status when die
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@172 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r46:31f3935d33aa - - 2 files changed: 61 inserted, 47 deleted
@@ -54,29 +54,57 | |||||
|
54 | #define long_seek(f,o,w) llseek(f,o,w) |
|
54 | #define long_seek(f,o,w) llseek(f,o,w) |
|
55 | #endif |
|
55 | #endif |
|
56 |
|
56 | ||
|
|
57 | + int max_mem_used = 0; | ||
|
|
58 | + | ||
|
|
59 | + void print_running_stat(double wall_time, | ||
|
|
60 | + double user_time, | ||
|
|
61 | + double system_time, | ||
|
|
62 | + int mem_usage) | ||
|
|
63 | + { | ||
|
|
64 | + fprintf(stderr,"%.4lfr%.4lfu%.4lfs%dm\n", | ||
|
|
65 | + wall_time, user_time, system_time, mem_usage); | ||
|
|
66 | + } | ||
|
|
67 | + | ||
|
57 | static void NONRET |
|
68 | static void NONRET |
|
58 | box_exit(void) |
|
69 | box_exit(void) |
|
59 | { |
|
70 | { |
|
60 | - if (box_pid > 0) |
|
71 | + if (box_pid > 0) { |
|
61 | - { |
|
72 | + if (is_ptraced) |
|
62 | - if (is_ptraced) |
|
73 | + ptrace(PTRACE_KILL, box_pid); |
|
63 | - ptrace(PTRACE_KILL, box_pid); |
|
74 | + kill(-box_pid, SIGKILL); |
|
64 |
- |
|
75 | + kill(box_pid, SIGKILL); |
|
65 | - kill(box_pid, SIGKILL); |
|
76 | + } |
|
66 | - } |
|
||
|
67 | - exit(1); |
|
||
|
68 | - } |
|
||
|
69 |
|
77 | ||
|
70 | - static void |
|
78 | + struct timeval total; |
|
71 | - box_kill(void) |
|
79 | + int wall; |
|
72 | - { |
|
80 | + struct rusage rus; |
|
73 | - if (box_pid > 0) |
|
81 | + int stat; |
|
74 | - { |
|
82 | + pid_t p; |
|
75 | - if (is_ptraced) |
|
83 | + |
|
76 | - ptrace(PTRACE_KILL, box_pid); |
|
84 | + // wait so that we can get information |
|
77 | - kill(-box_pid, SIGKILL); |
|
85 | + p = wait4(box_pid, &stat, WUNTRACED, &rus); |
|
78 | - kill(box_pid, SIGKILL); |
|
86 | + if (p < 0) { |
|
79 | - } |
|
87 | + fprintf(stderr,"wait4: error\n"); |
|
|
88 | + print_running_stat(0,0,0,max_mem_used); | ||
|
|
89 | + } else if (p != box_pid) { | ||
|
|
90 | + fprintf(stderr,"wait4: unknown pid %d exited!\n", p); | ||
|
|
91 | + print_running_stat(0,0,0,max_mem_used); | ||
|
|
92 | + } else { | ||
|
|
93 | + if (!WIFEXITED(stat)) | ||
|
|
94 | + fprintf(stderr,"wait4: unknown status\n"); | ||
|
|
95 | + struct timeval total; | ||
|
|
96 | + int wall; | ||
|
|
97 | + wall = time(NULL) - start_time; | ||
|
|
98 | + timeradd(&rus.ru_utime, &rus.ru_stime, &total); | ||
|
|
99 | + | ||
|
|
100 | + print_running_stat((double)wall, | ||
|
|
101 | + (double) rus.ru_utime.tv_sec + | ||
|
|
102 | + ((double) rus.ru_utime.tv_usec/1000000.0), | ||
|
|
103 | + (double) rus.ru_stime.tv_sec + | ||
|
|
104 | + ((double) rus.ru_stime.tv_usec/1000000.0), | ||
|
|
105 | + max_mem_used); | ||
|
|
106 | + } | ||
|
|
107 | + exit(1); | ||
|
80 | } |
|
108 | } |
|
81 |
|
109 | ||
|
82 | static void NONRET __attribute__((format(printf,1,2))) |
|
110 | static void NONRET __attribute__((format(printf,1,2))) |
@@ -89,16 +117,6 | |||||
|
89 | box_exit(); |
|
117 | box_exit(); |
|
90 | } |
|
118 | } |
|
91 |
|
119 | ||
|
92 | - static void __attribute__((format(printf,1,2))) |
|
||
|
93 | - die_report(char *msg, ...) |
|
||
|
94 | - { |
|
||
|
95 | - va_list args; |
|
||
|
96 | - va_start(args, msg); |
|
||
|
97 | - vfprintf(stderr, msg, args); |
|
||
|
98 | - fputc('\n', stderr); |
|
||
|
99 | - box_kill(); |
|
||
|
100 | - } |
|
||
|
101 | - |
|
||
|
102 | static void __attribute__((format(printf,1,2))) |
|
120 | static void __attribute__((format(printf,1,2))) |
|
103 | log(char *msg, ...) |
|
121 | log(char *msg, ...) |
|
104 | { |
|
122 | { |
@@ -349,12 +367,10 | |||||
|
349 | if (verbose > 1) |
|
367 | if (verbose > 1) |
|
350 | fprintf(stderr, "[timecheck: %d seconds]\n", sec); |
|
368 | fprintf(stderr, "[timecheck: %d seconds]\n", sec); |
|
351 | if (sec > timeout) { |
|
369 | if (sec > timeout) { |
|
352 |
- die |
|
370 | + die("Time limit exceeded."); |
|
353 | } |
|
371 | } |
|
354 | } |
|
372 | } |
|
355 |
|
373 | ||
|
356 | - int max_mem_used = 0; |
|
||
|
357 | - |
|
||
|
358 | static void |
|
374 | static void |
|
359 | check_memory_usage() |
|
375 | check_memory_usage() |
|
360 | { |
|
376 | { |
@@ -452,13 +468,12 | |||||
|
452 | // report OK and statistics |
|
468 | // report OK and statistics |
|
453 | fprintf(stderr,"OK\n"); |
|
469 | fprintf(stderr,"OK\n"); |
|
454 |
|
470 | ||
|
455 | - fprintf(stderr,"%dr%.4lfu%.4lfs%dm\n", |
|
471 | + print_running_stat((double) wall, |
|
456 | - wall, |
|
472 | + (double) rus.ru_utime.tv_sec + |
|
457 |
- (double) rus.ru_utime.tv_ |
|
473 | + ((double) rus.ru_utime.tv_usec/1000000.0), |
|
458 |
- |
|
474 | + (double) rus.ru_stime.tv_sec + |
|
459 |
- (double) rus.ru_stime.tv_ |
|
475 | + ((double) rus.ru_stime.tv_usec/1000000.0), |
|
460 | - ((double) rus.ru_stime.tv_usec/1000000.0), |
|
476 | + max_mem_used); |
|
461 | - max_mem_used); |
|
||
|
462 | /* |
|
477 | /* |
|
463 | (%.4lf sec real (%d), %d sec wall, %d syscalls, %d kb)\n", |
|
478 | (%.4lf sec real (%d), %d sec wall, %d syscalls, %d kb)\n", |
|
464 | (double) total.tv_sec + ((double)total.tv_usec / 1000000.0), |
|
479 | (double) total.tv_sec + ((double)total.tv_usec / 1000000.0), |
@@ -478,13 +493,12 | |||||
|
478 | int wall; |
|
493 | int wall; |
|
479 | wall = time(NULL) - start_time; |
|
494 | wall = time(NULL) - start_time; |
|
480 | timeradd(&rus.ru_utime, &rus.ru_stime, &total); |
|
495 | timeradd(&rus.ru_utime, &rus.ru_stime, &total); |
|
481 | - fprintf(stderr,"%dr%.4lfu%.4lfs%dm\n", |
|
496 | + print_running_stat((double) wall, |
|
482 | - wall, |
|
497 | + (double) rus.ru_utime.tv_sec + |
|
483 |
- (double) rus.ru_utime.tv_ |
|
498 | + ((double) rus.ru_utime.tv_usec/1000000.0), |
|
484 |
- |
|
499 | + (double) rus.ru_stime.tv_sec + |
|
485 |
- (double) rus.ru_stime.tv_ |
|
500 | + ((double) rus.ru_stime.tv_usec/1000000.0), |
|
486 | - ((double) rus.ru_stime.tv_usec/1000000.0), |
|
501 | + max_mem_used); |
|
487 | - max_mem_used); |
|
||
|
488 | exit(0); |
|
502 | exit(0); |
|
489 | } |
|
503 | } |
|
490 | if (WIFSTOPPED(stat)) |
|
504 | if (WIFSTOPPED(stat)) |
@@ -241,7 +241,7 | |||||
|
241 | :graded_at= => nil, |
|
241 | :graded_at= => nil, |
|
242 | :compiler_message= => '', |
|
242 | :compiler_message= => '', |
|
243 | :grader_comment= => '', |
|
243 | :grader_comment= => '', |
|
244 | - :running_stat= => /[Ee]xit.*status.*10.*0\.0 sec/m, |
|
244 | + :running_stat= => /[Ee]xit.*status.*10.*0\.0\d* sec/m, |
|
245 | :output_file_name= => lambda { |fname| |
|
245 | :output_file_name= => lambda { |fname| |
|
246 | File.exists?(fname).should be_true |
|
246 | File.exists?(fname).should be_true |
|
247 | }, |
|
247 | }, |
You need to be logged in to leave comments.
Login now