Changeset 871cff9a in mainline for uspace/app/hbench/main.c


Ignore:
Timestamp:
2019-01-21T18:01:59Z (5 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fea752
Parents:
2d81880
Message:

hbench: add options to set duration and run count

File:
1 edited

Legend:

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

    r2d81880 r871cff9a  
    4949#include "hbench.h"
    5050
    51 #define MIN_DURATION_SECS 10
    52 #define NUM_SAMPLES 10
    5351#define MAX_ERROR_STR_LENGTH 1024
    5452
     
    131129            ((double) run_count - 1);
    132130        // FIXME: implement sqrt properly
    133         *out_duration_sigma = estimate_square_root(sigma2, precision);
     131        if (run_count > 1) {
     132                *out_duration_sigma = estimate_square_root(sigma2, precision);
     133        } else {
     134                *out_duration_sigma = NAN;
     135        }
    134136        *out_thruput_avg = 1.0 / (inv_thruput_sum / run_count);
    135137}
     
    197199
    198200                nsec_t duration = stopwatch_get_nanos(&run.stopwatch);
    199                 if (duration > SEC2NSEC(MIN_DURATION_SECS)) {
    200                         break;
    201                 }
    202         }
    203 
    204         printf("Workload size set to %" PRIu64 ", measuring %d samples.\n", workload_size, NUM_SAMPLES);
    205 
    206         bench_run_t *runs = calloc(NUM_SAMPLES, sizeof(bench_run_t));
     201                if (duration > env->minimal_run_duration_nanos) {
     202                        break;
     203                }
     204        }
     205
     206        printf("Workload size set to %" PRIu64 ", measuring %zu samples.\n",
     207            workload_size, env->run_count);
     208
     209        bench_run_t *runs = calloc(env->run_count, sizeof(bench_run_t));
    207210        if (runs == NULL) {
    208211                snprintf(error_msg, MAX_ERROR_STR_LENGTH, "failed allocating memory");
    209212                goto leave_error;
    210213        }
    211         for (int i = 0; i < NUM_SAMPLES; i++) {
     214        for (size_t i = 0; i < env->run_count; i++) {
    212215                bench_run_init(&runs[i], error_msg, MAX_ERROR_STR_LENGTH);
    213216
     
    220223        }
    221224
    222         summary_stats(runs, NUM_SAMPLES, bench, workload_size);
     225        summary_stats(runs, env->run_count, bench, workload_size);
    223226        printf("\nBenchmark completed\n");
    224227
     
    306309        printf("-h, --help                 "
    307310            "Print this help and exit\n");
     311        printf("-d, --duration MILLIS      "
     312            "Set minimal run duration (milliseconds)\n");
     313        printf("-n, --count N              "
     314            "Set number of measured runs\n");
    308315        printf("-o, --output filename.csv  "
    309316            "Store machine-readable data in filename.csv\n");
     
    331338        }
    332339
    333         const char *short_options = "ho:p:";
     340        const char *short_options = "ho:p:n:d:";
    334341        struct option long_options[] = {
     342                { "duration", required_argument, NULL, 'd' },
    335343                { "help", optional_argument, NULL, 'h' },
     344                { "count", required_argument, NULL, 'n' },
     345                { "output", required_argument, NULL, 'o' },
    336346                { "param", required_argument, NULL, 'p' },
    337                 { "output", required_argument, NULL, 'o' },
    338347                { 0, 0, NULL, 0 }
    339348        };
     
    344353        while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) > 0) {
    345354                switch (opt) {
     355                case 'd':
     356                        errno = EOK;
     357                        bench_env.minimal_run_duration_nanos = MSEC2NSEC(atoll(optarg));
     358                        if ((errno != EOK) || (bench_env.minimal_run_duration_nanos <= 0)) {
     359                                fprintf(stderr, "Invalid -d argument.\n");
     360                                return -3;
     361                        }
     362                        break;
    346363                case 'h':
    347364                        print_usage(*argv);
    348365                        return 0;
     366                case 'n':
     367                        errno = EOK;
     368                        bench_env.run_count = (nsec_t) atoll(optarg);
     369                        if ((errno != EOK) || (bench_env.run_count <= 0)) {
     370                                fprintf(stderr, "Invalid -n argument.\n");
     371                                return -3;
     372                        }
     373                        break;
    349374                case 'o':
    350375                        csv_output_filename = optarg;
Note: See TracChangeset for help on using the changeset viewer.