Changeset ebb0835 in mainline
- Timestamp:
- 2019-01-07T12:56:22Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c2db02a
- Parents:
- a787081
- Location:
- uspace/app/hbench
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/hbench/csv.c
ra787081 rebb0835 67 67 * @param workload_size Workload size. 68 68 */ 69 void csv_report_add_entry( stopwatch_t *stopwatch, int run_index,69 void csv_report_add_entry(benchmeter_t *meter, int run_index, 70 70 benchmark_t *bench, uint64_t workload_size) 71 71 { … … 76 76 fprintf(csv_output, "%s,%d,%" PRIu64 ",%lld\n", 77 77 bench->name, run_index, workload_size, 78 (long long) stopwatch_get_nanos( stopwatch));78 (long long) stopwatch_get_nanos(&meter->stopwatch)); 79 79 } 80 80 -
uspace/app/hbench/doc/doxygroups.h
ra787081 rebb0835 19 19 * benchmark function to the benchmark_t. 20 20 * 21 * The benchmarking function has to accept for arguments: 22 * @li stopwatch_t: store the measured data there 21 * The benchmarking function has to accept four arguments: 22 * @li benchmeter_t: call benchmeter_start and benchmeter_stop around the 23 * actual benchmarking code 23 24 * @li uint64_t: size of the workload - typically number of inner loops in 24 25 * your benchmark (used to self-calibrate benchmark size) … … 28 29 * Typically, the structure of the function is following: 29 30 * @code{c} 30 * static bool runner( stopwatch_t *stopwatch, uint64_t size,31 * static bool runner(benchmeter_t *meter, uint64_t size, 31 32 * char *error, size_t error_size) 32 33 * { 33 * stopwatch_start(stopwatch);34 * benchmeter_start(meter); 34 35 * for (uint64_t i = 0; i < size; i++) { 35 36 * // measured action 36 37 * } 37 * stopwatch_stop(stopwatch);38 * benchmeter_stop(meter); 38 39 * 39 40 * return true; -
uspace/app/hbench/fs/dirread.c
ra787081 rebb0835 43 43 * that the corresponding blocks would be cached after first run. 44 44 */ 45 static bool runner( stopwatch_t *stopwatch, uint64_t size,45 static bool runner(benchmeter_t *meter, uint64_t size, 46 46 char *error, size_t error_size) 47 47 { 48 48 const char *path = bench_param_get("dirname", "/"); 49 49 50 stopwatch_start(stopwatch);50 benchmeter_start(meter); 51 51 for (uint64_t i = 0; i < size; i++) { 52 52 DIR *dir = opendir(path); … … 64 64 closedir(dir); 65 65 } 66 stopwatch_stop(stopwatch);66 benchmeter_stop(meter); 67 67 68 68 return true; -
uspace/app/hbench/fs/fileread.c
ra787081 rebb0835 44 44 * corresponding blocks would be cached after first run. 45 45 */ 46 static bool runner( stopwatch_t *stopwatch, uint64_t size,46 static bool runner(benchmeter_t *meter, uint64_t size, 47 47 char *error, size_t error_size) 48 48 { … … 65 65 } 66 66 67 stopwatch_start(stopwatch);67 benchmeter_start(meter); 68 68 for (uint64_t i = 0; i < size; i++) { 69 69 int rc = fseek(file, 0, SEEK_SET); … … 84 84 } 85 85 } 86 stopwatch_stop(stopwatch);86 benchmeter_stop(meter); 87 87 88 88 leave_close: -
uspace/app/hbench/hbench.h
ra787081 rebb0835 41 41 #include <perf.h> 42 42 43 typedef bool (*benchmark_entry_t)(stopwatch_t *, uint64_t, 43 /* 44 * So far, a simple wrapper around system stopwatch. 45 * Eventually, we could collection of hardware counters etc. without 46 * modifying signatures of any existing benchmark. 47 */ 48 typedef struct { 49 stopwatch_t stopwatch; 50 } benchmeter_t; 51 52 static inline void benchmeter_init(benchmeter_t *meter) 53 { 54 stopwatch_init(&meter->stopwatch); 55 } 56 57 static inline void benchmeter_start(benchmeter_t *meter) 58 { 59 stopwatch_start(&meter->stopwatch); 60 } 61 62 static inline void benchmeter_stop(benchmeter_t *meter) 63 { 64 stopwatch_stop(&meter->stopwatch); 65 } 66 67 typedef bool (*benchmark_entry_t)(benchmeter_t *, uint64_t, 44 68 char *, size_t); 45 69 typedef bool (*benchmark_helper_t)(char *, size_t); … … 57 81 58 82 extern errno_t csv_report_open(const char *); 59 extern void csv_report_add_entry( stopwatch_t *, int, benchmark_t *, uint64_t);83 extern void csv_report_add_entry(benchmeter_t *, int, benchmark_t *, uint64_t); 60 84 extern void csv_report_close(void); 61 85 -
uspace/app/hbench/ipc/ns_ping.c
ra787081 rebb0835 38 38 #include "../hbench.h" 39 39 40 static bool runner( stopwatch_t *stopwatch, uint64_t niter,40 static bool runner(benchmeter_t *meter, uint64_t niter, 41 41 char *error, size_t error_size) 42 42 { 43 stopwatch_start(stopwatch);43 benchmeter_start(meter); 44 44 45 45 for (uint64_t count = 0; count < niter; count++) { … … 54 54 } 55 55 56 stopwatch_stop(stopwatch);56 benchmeter_stop(meter); 57 57 58 58 return true; -
uspace/app/hbench/ipc/ping_pong.c
ra787081 rebb0835 59 59 } 60 60 61 static bool runner( stopwatch_t *stopwatch, uint64_t niter,61 static bool runner(benchmeter_t *meter, uint64_t niter, 62 62 char *error, size_t error_size) 63 63 { 64 stopwatch_start(stopwatch);64 benchmeter_start(meter); 65 65 66 66 for (uint64_t count = 0; count < niter; count++) { … … 75 75 } 76 76 77 stopwatch_stop(stopwatch);77 benchmeter_stop(meter); 78 78 79 79 return true; -
uspace/app/hbench/main.c
ra787081 rebb0835 53 53 #define MAX_ERROR_STR_LENGTH 1024 54 54 55 static void short_report( stopwatch_t *stopwatch, int run_index,55 static void short_report(benchmeter_t *meter, int run_index, 56 56 benchmark_t *bench, uint64_t workload_size) 57 57 { 58 csv_report_add_entry( stopwatch, run_index, bench, workload_size);59 60 usec_t duration_usec = NSEC2USEC(stopwatch_get_nanos( stopwatch));58 csv_report_add_entry(meter, run_index, bench, workload_size); 59 60 usec_t duration_usec = NSEC2USEC(stopwatch_get_nanos(&meter->stopwatch)); 61 61 62 62 printf("Completed %" PRIu64 " operations in %llu us", 63 63 workload_size, duration_usec); 64 64 if (duration_usec > 0) { 65 double nanos = stopwatch_get_nanos( stopwatch);65 double nanos = stopwatch_get_nanos(&meter->stopwatch); 66 66 double thruput = (double) workload_size / (nanos / 1000000000.0l); 67 67 printf(", %.0f ops/s.\n", thruput); … … 106 106 * 107 107 */ 108 static void compute_stats( stopwatch_t *stopwatch, size_t stopwatch_count,108 static void compute_stats(benchmeter_t *meter, size_t stopwatch_count, 109 109 uint64_t workload_size, double precision, double *out_duration_avg, 110 110 double *out_duration_sigma, double *out_thruput_avg) … … 115 115 116 116 for (size_t i = 0; i < stopwatch_count; i++) { 117 double nanos = stopwatch_get_nanos(& stopwatch[i]);117 double nanos = stopwatch_get_nanos(&meter[i].stopwatch); 118 118 double thruput = (double) workload_size / nanos; 119 119 … … 130 130 } 131 131 132 static void summary_stats( stopwatch_t *stopwatch, size_t stopwatch_count,132 static void summary_stats(benchmeter_t *meter, size_t meter_count, 133 133 benchmark_t *bench, uint64_t workload_size) 134 134 { 135 135 double duration_avg, duration_sigma, thruput_avg; 136 compute_stats( stopwatch, stopwatch_count, workload_size, 0.001,136 compute_stats(meter, meter_count, workload_size, 0.001, 137 137 &duration_avg, &duration_sigma, &thruput_avg); 138 138 … … 140 140 "%.0f ops/s; Samples: %zu\n", 141 141 workload_size, duration_avg / 1000.0, duration_sigma / 1000.0, 142 thruput_avg * 1000000000.0, stopwatch_count);142 thruput_avg * 1000000000.0, meter_count); 143 143 } 144 144 … … 175 175 workload_size = ((uint64_t) 1) << bits; 176 176 177 stopwatch_t stopwatch = STOPWATCH_INITIALIZE_STATIC; 178 179 bool ok = bench->entry(&stopwatch, workload_size, 177 benchmeter_t meter; 178 benchmeter_init(&meter); 179 180 bool ok = bench->entry(&meter, workload_size, 180 181 error_msg, MAX_ERROR_STR_LENGTH); 181 182 if (!ok) { 182 183 goto leave_error; 183 184 } 184 short_report(& stopwatch, -1, bench, workload_size);185 186 nsec_t duration = stopwatch_get_nanos(& stopwatch);185 short_report(&meter, -1, bench, workload_size); 186 187 nsec_t duration = stopwatch_get_nanos(&meter.stopwatch); 187 188 if (duration > SEC2NSEC(MIN_DURATION_SECS)) { 188 189 break; … … 192 193 printf("Workload size set to %" PRIu64 ", measuring %d samples.\n", workload_size, NUM_SAMPLES); 193 194 194 stopwatch_t *stopwatch = calloc(NUM_SAMPLES, sizeof(stopwatch_t));195 if ( stopwatch== NULL) {195 benchmeter_t *meter = calloc(NUM_SAMPLES, sizeof(benchmeter_t)); 196 if (meter == NULL) { 196 197 snprintf(error_msg, MAX_ERROR_STR_LENGTH, "failed allocating memory"); 197 198 goto leave_error; 198 199 } 199 200 for (int i = 0; i < NUM_SAMPLES; i++) { 200 stopwatch_init(&stopwatch[i]);201 202 bool ok = bench->entry(& stopwatch[i], workload_size,201 benchmeter_init(&meter[i]); 202 203 bool ok = bench->entry(&meter[i], workload_size, 203 204 error_msg, MAX_ERROR_STR_LENGTH); 204 205 if (!ok) { 205 free( stopwatch);206 free(meter); 206 207 goto leave_error; 207 208 } 208 short_report(& stopwatch[i], i, bench, workload_size);209 } 210 211 summary_stats( stopwatch, NUM_SAMPLES, bench, workload_size);209 short_report(&meter[i], i, bench, workload_size); 210 } 211 212 summary_stats(meter, NUM_SAMPLES, bench, workload_size); 212 213 printf("\nBenchmark completed\n"); 213 214 214 free( stopwatch);215 free(meter); 215 216 216 217 goto leave; -
uspace/app/hbench/malloc/malloc1.c
ra787081 rebb0835 36 36 #include "../hbench.h" 37 37 38 static bool runner( stopwatch_t *stopwatch, uint64_t size,38 static bool runner(benchmeter_t *meter, uint64_t size, 39 39 char *error, size_t error_size) 40 40 { 41 stopwatch_start(stopwatch);41 benchmeter_start(meter); 42 42 for (uint64_t i = 0; i < size; i++) { 43 43 void *p = malloc(1); … … 50 50 free(p); 51 51 } 52 stopwatch_stop(stopwatch);52 benchmeter_stop(meter); 53 53 54 54 return true; -
uspace/app/hbench/malloc/malloc2.c
ra787081 rebb0835 35 35 #include "../hbench.h" 36 36 37 static bool runner( stopwatch_t *stopwatch, uint64_t niter,37 static bool runner(benchmeter_t *meter, uint64_t niter, 38 38 char *error, size_t error_size) 39 39 { 40 stopwatch_start(stopwatch);40 benchmeter_start(meter); 41 41 42 42 void **p = malloc(niter * sizeof(void *)); … … 67 67 free(p); 68 68 69 stopwatch_stop(stopwatch);69 benchmeter_stop(meter); 70 70 71 71 return true;
Note:
See TracChangeset
for help on using the changeset viewer.