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: 61 inserted, 47 deleted

@@ -51,57 +51,75
51 #else
51 #else
52 /* Touching clandestine places in glibc */
52 /* Touching clandestine places in glibc */
53 extern loff_t llseek(int fd, loff_t pos, int whence);
53 extern loff_t llseek(int fd, loff_t pos, int whence);
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 - kill(-box_pid, SIGKILL);
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)))
83 die(char *msg, ...)
111 die(char *msg, ...)
84 {
112 {
85 va_list args;
113 va_list args;
86 va_start(args, msg);
114 va_start(args, msg);
87 vfprintf(stderr, msg, args);
115 vfprintf(stderr, msg, args);
88 fputc('\n', stderr);
116 fputc('\n', stderr);
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 {
105 va_list args;
123 va_list args;
106 va_start(args, msg);
124 va_start(args, msg);
107 if (verbose)
125 if (verbose)
@@ -346,18 +364,16
346 //printf("%s - %d\n",x,ticks_per_sec);
364 //printf("%s - %d\n",x,ticks_per_sec);
347 sec = (utime + stime + ticks_per_sec-1)/ticks_per_sec;
365 sec = (utime + stime + ticks_per_sec-1)/ticks_per_sec;
348 }
366 }
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 {
361 char proc_fname[100];
377 char proc_fname[100];
362 sprintf(proc_fname,"/proc/%d/statm",box_pid);
378 sprintf(proc_fname,"/proc/%d/statm",box_pid);
363 //printf("proc fname: %s\n",proc_fname);
379 //printf("proc fname: %s\n",proc_fname);
@@ -449,19 +465,18
449 else if ((use_wall_clock ? wall : total.tv_sec) > timeout)
465 else if ((use_wall_clock ? wall : total.tv_sec) > timeout)
450 fprintf(stderr,"Time limit exceeded.\n");
466 fprintf(stderr,"Time limit exceeded.\n");
451 else
467 else
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_sec +
473 + ((double) rus.ru_utime.tv_usec/1000000.0),
458 - ((double) rus.ru_utime.tv_usec/1000000.0),
474 + (double) rus.ru_stime.tv_sec +
459 - (double) rus.ru_stime.tv_sec +
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),
465 (int) total.tv_usec,
480 (int) total.tv_usec,
466 wall,
481 wall,
467 syscall_count,
482 syscall_count,
@@ -475,19 +490,18
475 fprintf(stderr,"Caught fatal signal %d.\n", WTERMSIG(stat));
490 fprintf(stderr,"Caught fatal signal %d.\n", WTERMSIG(stat));
476
491
477 struct timeval total;
492 struct timeval total;
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_sec +
498 + ((double) rus.ru_utime.tv_usec/1000000.0),
484 - ((double) rus.ru_utime.tv_usec/1000000.0),
499 + (double) rus.ru_stime.tv_sec +
485 - (double) rus.ru_stime.tv_sec +
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))
491 {
505 {
492 int sig = WSTOPSIG(stat);
506 int sig = WSTOPSIG(stat);
493 if (sig == SIGTRAP)
507 if (sig == SIGTRAP)
@@ -238,13 +238,13
238 :on => problem,
238 :on => problem,
239 :with => 'in1.txt',
239 :with => 'in1.txt',
240 :and_report => {
240 :and_report => {
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 },
248 :running_time= => nil,
248 :running_time= => nil,
249 :exit_status= => /10/,
249 :exit_status= => /10/,
250 :memory_usage= => nil,
250 :memory_usage= => nil,
You need to be logged in to leave comments. Login now