Changeset ebb0835 in mainline for uspace/app/hbench/main.c


Ignore:
Timestamp:
2019-01-07T12:56:22Z (5 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c2db02a
Parents:
a787081
Message:

hbench: add tiny wrapper around stopwatch_t

This prepares the harness for future extensions when more than wallclock
time would be prepared. The data would be stored inside the new
structure and the actual benchmarks would not need to be modified at all
(they really should not care which metrics are collected).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/hbench/main.c

    ra787081 rebb0835  
    5353#define MAX_ERROR_STR_LENGTH 1024
    5454
    55 static void short_report(stopwatch_t *stopwatch, int run_index,
     55static void short_report(benchmeter_t *meter, int run_index,
    5656    benchmark_t *bench, uint64_t workload_size)
    5757{
    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));
    6161
    6262        printf("Completed %" PRIu64 " operations in %llu us",
    6363            workload_size, duration_usec);
    6464        if (duration_usec > 0) {
    65                 double nanos = stopwatch_get_nanos(stopwatch);
     65                double nanos = stopwatch_get_nanos(&meter->stopwatch);
    6666                double thruput = (double) workload_size / (nanos / 1000000000.0l);
    6767                printf(", %.0f ops/s.\n", thruput);
     
    106106 *
    107107 */
    108 static void compute_stats(stopwatch_t *stopwatch, size_t stopwatch_count,
     108static void compute_stats(benchmeter_t *meter, size_t stopwatch_count,
    109109    uint64_t workload_size, double precision, double *out_duration_avg,
    110110    double *out_duration_sigma, double *out_thruput_avg)
     
    115115
    116116        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);
    118118                double thruput = (double) workload_size / nanos;
    119119
     
    130130}
    131131
    132 static void summary_stats(stopwatch_t *stopwatch, size_t stopwatch_count,
     132static void summary_stats(benchmeter_t *meter, size_t meter_count,
    133133    benchmark_t *bench, uint64_t workload_size)
    134134{
    135135        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,
    137137            &duration_avg, &duration_sigma, &thruput_avg);
    138138
     
    140140            "%.0f ops/s; Samples: %zu\n",
    141141            workload_size, duration_avg / 1000.0, duration_sigma / 1000.0,
    142             thruput_avg * 1000000000.0, stopwatch_count);
     142            thruput_avg * 1000000000.0, meter_count);
    143143}
    144144
     
    175175                workload_size = ((uint64_t) 1) << bits;
    176176
    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,
    180181                    error_msg, MAX_ERROR_STR_LENGTH);
    181182                if (!ok) {
    182183                        goto leave_error;
    183184                }
    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);
    187188                if (duration > SEC2NSEC(MIN_DURATION_SECS)) {
    188189                        break;
     
    192193        printf("Workload size set to %" PRIu64 ", measuring %d samples.\n", workload_size, NUM_SAMPLES);
    193194
    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) {
    196197                snprintf(error_msg, MAX_ERROR_STR_LENGTH, "failed allocating memory");
    197198                goto leave_error;
    198199        }
    199200        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,
    203204                    error_msg, MAX_ERROR_STR_LENGTH);
    204205                if (!ok) {
    205                         free(stopwatch);
     206                        free(meter);
    206207                        goto leave_error;
    207208                }
    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);
    212213        printf("\nBenchmark completed\n");
    213214
    214         free(stopwatch);
     215        free(meter);
    215216
    216217        goto leave;
Note: See TracChangeset for help on using the changeset viewer.