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:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r46:31f3935d33aa - - 2 files changed: 45 inserted, 31 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 - {
62 if (is_ptraced)
72 if (is_ptraced)
63 ptrace(PTRACE_KILL, box_pid);
73 ptrace(PTRACE_KILL, box_pid);
64 kill(-box_pid, SIGKILL);
74 kill(-box_pid, SIGKILL);
65 kill(box_pid, SIGKILL);
75 kill(box_pid, SIGKILL);
66 }
76 }
67 - exit(1);
77 +
68 - }
78 + struct timeval total;
79 + int wall;
80 + struct rusage rus;
81 + int stat;
82 + pid_t p;
69
83
70 - static void
84 + // wait so that we can get information
71 - box_kill(void)
85 + p = wait4(box_pid, &stat, WUNTRACED, &rus);
72 - {
86 + if (p < 0) {
73 - if (box_pid > 0)
87 + fprintf(stderr,"wait4: error\n");
74 - {
88 + print_running_stat(0,0,0,max_mem_used);
75 - if (is_ptraced)
89 + } else if (p != box_pid) {
76 - ptrace(PTRACE_KILL, box_pid);
90 + fprintf(stderr,"wait4: unknown pid %d exited!\n", p);
77 - kill(-box_pid, SIGKILL);
91 + print_running_stat(0,0,0,max_mem_used);
78 - kill(box_pid, SIGKILL);
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);
79 }
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)))
@@ -90,16 +118,6
90 }
118 }
91
119
92 static void __attribute__((format(printf,1,2)))
120 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)))
103 log(char *msg, ...)
121 log(char *msg, ...)
104 {
122 {
105 va_list args;
123 va_list args;
@@ -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_report("Time limit exceeded.");
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,8 +468,7
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,
457 (double) rus.ru_utime.tv_sec +
472 (double) rus.ru_utime.tv_sec +
458 ((double) rus.ru_utime.tv_usec/1000000.0),
473 ((double) rus.ru_utime.tv_usec/1000000.0),
459 (double) rus.ru_stime.tv_sec +
474 (double) rus.ru_stime.tv_sec +
@@ -478,8 +493,7
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,
483 (double) rus.ru_utime.tv_sec +
497 (double) rus.ru_utime.tv_sec +
484 ((double) rus.ru_utime.tv_usec/1000000.0),
498 ((double) rus.ru_utime.tv_usec/1000000.0),
485 (double) rus.ru_stime.tv_sec +
499 (double) rus.ru_stime.tv_sec +
@@ -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