Description:
[grader] obsolete new_problem, fixed memory measurement bug in box.cc
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@186 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
r49:5746784ead66 - - 2 files changed: 11 inserted, 2 deleted
@@ -12,24 +12,29 | |||
|
12 | 12 | if ARGV[i]=='-t' |
|
13 | 13 | options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
14 | 14 | i += 1 |
|
15 | 15 | end |
|
16 | 16 | if ARGV[i]=='-m' |
|
17 | 17 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
18 | 18 | i += 1 |
|
19 | 19 | end |
|
20 | 20 | i += 1 |
|
21 | 21 | end |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | + | |
|
25 | + puts "This script is out of dated, shall be fixed soon" | |
|
26 | + puts "Right now, you can create raw_ev and import" | |
|
27 | + exit(0) | |
|
28 | + | |
|
24 | 29 | GRADER_DIR = File.dirname(__FILE__) |
|
25 | 30 | |
|
26 | 31 | # print usage |
|
27 | 32 | if ARGV.length < 2 |
|
28 | 33 | puts <<USAGE |
|
29 | 34 | using: new_problem problem number_of_testcase [options] |
|
30 | 35 | * creates a directory for a problem in the current directory, |
|
31 | 36 | * create standard testcase config file |
|
32 | 37 | * options: -t time-limit (in seconds) |
|
33 | 38 | -m mem-limit (in MB) |
|
34 | 39 | USAGE |
|
35 | 40 | exit(127) |
@@ -49,20 +54,20 | |||
|
49 | 54 | system("mkdir #{problem}/script") |
|
50 | 55 | system("mkdir #{problem}/test_cases") |
|
51 | 56 | |
|
52 | 57 | puts "creating testcases directories" |
|
53 | 58 | |
|
54 | 59 | 1.upto(num_testcases) do |i| |
|
55 | 60 | system("mkdir #{problem}/test_cases/#{i}") |
|
56 | 61 | end |
|
57 | 62 | |
|
58 | 63 | # generating all_tests.cfg |
|
59 | 64 | puts "generating testcase config file" |
|
60 | 65 | |
|
61 | - template = File.open(File.dirname(__FILE__) + "/all_tests.cfg.erb").read | |
|
66 | + template = File.open(File.dirname(__FILE__) + "/templates/all_tests.cfg.erb").read | |
|
62 | 67 | all_test_cfg = ERB.new(template) |
|
63 | 68 | |
|
64 | 69 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
65 | 70 | cfg_file.puts all_test_cfg.result |
|
66 | 71 | cfg_file.close |
|
67 | 72 | |
|
68 | 73 | puts "done" |
@@ -35,24 +35,25 | |||
|
35 | 35 | static int file_access; |
|
36 | 36 | static int verbose; |
|
37 | 37 | static int memory_limit; |
|
38 | 38 | static int allow_times; |
|
39 | 39 | static char *redir_stdin, *redir_stdout; |
|
40 | 40 | static char *set_cwd; |
|
41 | 41 | |
|
42 | 42 | static pid_t box_pid; |
|
43 | 43 | static int is_ptraced; |
|
44 | 44 | static volatile int timer_tick; |
|
45 | 45 | static time_t start_time; |
|
46 | 46 | static int ticks_per_sec; |
|
47 | + static int page_size; | |
|
47 | 48 | |
|
48 | 49 | #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0 |
|
49 | 50 | /* glibc 2.1 or newer -> has lseek64 */ |
|
50 | 51 | #define long_seek(f,o,w) lseek64(f,o,w) |
|
51 | 52 | #else |
|
52 | 53 | /* Touching clandestine places in glibc */ |
|
53 | 54 | extern loff_t llseek(int fd, loff_t pos, int whence); |
|
54 | 55 | #define long_seek(f,o,w) llseek(f,o,w) |
|
55 | 56 | #endif |
|
56 | 57 | |
|
57 | 58 | int max_mem_used = 0; |
|
58 | 59 | |
@@ -375,44 +376,47 | |||
|
375 | 376 | check_memory_usage() |
|
376 | 377 | { |
|
377 | 378 | char proc_fname[100]; |
|
378 | 379 | sprintf(proc_fname,"/proc/%d/statm",box_pid); |
|
379 | 380 | //printf("proc fname: %s\n",proc_fname); |
|
380 | 381 | FILE *fp = fopen(proc_fname,"r"); |
|
381 | 382 | if(fp!=NULL) { |
|
382 | 383 | char line[1000]; |
|
383 | 384 | fgets(line,999,fp); |
|
384 | 385 | //printf("%s\n",line); |
|
385 | 386 | int m; |
|
386 | 387 | |
|
387 | - if(sscanf(line,"%d",&m)==1) | |
|
388 | + if(sscanf(line,"%d",&m)==1) { | |
|
389 | + m = (m*page_size+1023)/1024; | |
|
388 | 390 | if(m>max_mem_used) |
|
389 | 391 | max_mem_used = m; |
|
392 | + } | |
|
390 | 393 | |
|
391 | 394 | fclose(fp); |
|
392 | 395 | } |
|
393 | 396 | } |
|
394 | 397 | |
|
395 | 398 | static void |
|
396 | 399 | boxkeeper(void) |
|
397 | 400 | { |
|
398 | 401 | int syscall_count = 0; |
|
399 | 402 | struct sigaction sa; |
|
400 | 403 | |
|
401 | 404 | is_ptraced = 1; |
|
402 | 405 | bzero(&sa, sizeof(sa)); |
|
403 | 406 | sa.sa_handler = signal_int; |
|
404 | 407 | sigaction(SIGINT, &sa, NULL); |
|
405 | 408 | start_time = time(NULL); |
|
406 | 409 | ticks_per_sec = sysconf(_SC_CLK_TCK); |
|
410 | + page_size = getpagesize(); | |
|
407 | 411 | if (ticks_per_sec <= 0) |
|
408 | 412 | die("Invalid ticks_per_sec!"); |
|
409 | 413 | |
|
410 | 414 | check_memory_usage(); |
|
411 | 415 | |
|
412 | 416 | sa.sa_handler = signal_alarm; |
|
413 | 417 | sigaction(SIGALRM, &sa, NULL); |
|
414 | 418 | //alarm(1); |
|
415 | 419 | |
|
416 | 420 | struct itimerval val; |
|
417 | 421 | val.it_interval.tv_sec = 0; |
|
418 | 422 | val.it_interval.tv_usec = 50000; |
You need to be logged in to leave comments.
Login now