Changeset cb85603 for benchmark/benchcltr.hfa
- Timestamp:
- Jun 25, 2020, 2:57:39 PM (3 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ec21f13
- Parents:
- 566fde0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/benchcltr.hfa
r566fde0 rcb85603 4 4 #include <kernel.hfa> 5 5 #include <thread.hfa> 6 #include <stats.hfa> 6 7 8 #define BENCH_OPT_SHORT "d:p:t:SP" 9 #define BENCH_OPT_LONG \ 10 {"duration", required_argument, 0, 'd'}, \ 11 {"nthreads", required_argument, 0, 't'}, \ 12 {"nprocs", required_argument, 0, 'p'}, \ 13 {"nostats", no_argument , 0, 'S'}, \ 14 {"procstat", no_argument , 0, 'P'}, 15 16 #define BENCH_DECL \ 17 double duration = 5; \ 18 int nprocs = 1; \ 19 int nthreads = 1; 20 21 #define BENCH_OPT_CASE \ 22 case 'd': \ 23 duration = strtod(arg, &end); \ 24 if(*end != '\0') { \ 25 fprintf(stderr, "Duration must be a valid double, was %s\n", arg); \ 26 goto usage; \ 27 } \ 28 break; \ 29 case 't': \ 30 nthreads = strtoul(arg, &end, 10); \ 31 if(*end != '\0' || nthreads < 1) { \ 32 fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg); \ 33 goto usage; \ 34 } \ 35 break; \ 36 case 'p': \ 37 nprocs = strtoul(arg, &end, 10); \ 38 if(*end != '\0' || nprocs < 1) { \ 39 fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg); \ 40 goto usage; \ 41 } \ 42 break; \ 43 case 'S': \ 44 silent = true; \ 45 break; \ 46 case 'P': \ 47 procstats = true; \ 48 break; 49 50 bool silent = false; 51 bool procstats = false; 7 52 struct cluster * the_benchmark_cluster = 0p; 8 53 struct BenchCluster { 9 54 cluster self; 10 55 }; 11 56 12 void ?{}( BenchCluster & this, int flags ) {13 57 void ?{}( BenchCluster & this, int flags, int stats ) { 58 (this.self){ "Benchmark Cluster", flags }; 14 59 15 assert( the_benchmark_cluster == 0p ); 16 the_benchmark_cluster = &this.self; 60 assert( the_benchmark_cluster == 0p ); 61 the_benchmark_cluster = &this.self; 62 63 #if !defined(__CFA_NO_STATISTICS__) 64 if( !silent ) { 65 print_stats_at_exit( this.self, stats ); 66 } 67 #endif 17 68 } 18 69 … … 22 73 23 74 void ?{}( BenchProc & this ) { 24 75 assert( the_benchmark_cluster != 0p ); 25 76 (this.self){ "Benchmark Processor", *the_benchmark_cluster }; 77 78 #if !defined(__CFA_NO_STATISTICS__) 79 if( procstats ) { 80 print_stats_at_exit( this.self, the_benchmark_cluster->print_stats ); 81 } 82 #endif 26 83 } 27 84 28 85 void wait(double duration, Time & start, Time & end, bool is_tty) { 29 30 31 32 33 34 35 36 37 38 39 40 86 for() { 87 sleep(100`ms); 88 end = getTimeNsec(); 89 Duration delta = end - start; 90 if(is_tty) { 91 printf("\r%.1f", delta`ds); 92 fflush(stdout); 93 } 94 if( delta >= duration`s ) { 95 break; 96 } 97 } 41 98 } 99 100 void bench_usage( char * argv [] ) { 101 fprintf( stderr, "Usage: %s : [options]\n", argv[0] ); 102 fprintf( stderr, "\n" ); 103 fprintf( stderr, " -d, --duration=DURATION Duration of the experiment, in seconds\n" ); 104 fprintf( stderr, " -t, --nthreads=NTHREADS Number of user threads\n" ); 105 fprintf( stderr, " -p, --nprocs=NPROCS Number of kernel threads\n" ); 106 fprintf( stderr, " -S, --nostats Don't print cluster stats\n" ); 107 fprintf( stderr, " -P, --procstat Print processor stats" ); 108 }
Note: See TracChangeset
for help on using the changeset viewer.