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


Ignore:
Timestamp:
2019-01-21T13:39:37Z (6 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
94d52d5
Parents:
e7f9a09
Message:

hbench: remove global state

Move benchmark parameters into a benchmark environment structure that is
passed to each benchmark.

File:
1 edited

Legend:

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

    re7f9a09 rd17cf8c  
    148148}
    149149
    150 static bool run_benchmark(benchmark_t *bench)
     150static bool run_benchmark(bench_env_t *env, benchmark_t *bench)
    151151{
    152152        printf("Warm up and determine workload size...\n");
     
    169169
    170170        if (bench->setup != NULL) {
    171                 ret = bench->setup(&helper_run);
     171                ret = bench->setup(env, &helper_run);
    172172                if (!ret) {
    173173                        goto leave_error;
     
    190190                bench_run_init(&run, error_msg, MAX_ERROR_STR_LENGTH);
    191191
    192                 bool ok = bench->entry(&run, workload_size);
     192                bool ok = bench->entry(env, &run, workload_size);
    193193                if (!ok) {
    194194                        goto leave_error;
     
    212212                bench_run_init(&runs[i], error_msg, MAX_ERROR_STR_LENGTH);
    213213
    214                 bool ok = bench->entry(&runs[i], workload_size);
     214                bool ok = bench->entry(env, &runs[i], workload_size);
    215215                if (!ok) {
    216216                        free(runs);
     
    233233leave:
    234234        if (bench->teardown != NULL) {
    235                 bool ok = bench->teardown(&helper_run);
     235                bool ok = bench->teardown(env, &helper_run);
    236236                if (!ok) {
    237237                        printf("Error: %s\n", error_msg);
     
    245245}
    246246
    247 static int run_benchmarks(void)
     247static int run_benchmarks(bench_env_t *env)
    248248{
    249249        unsigned int count_ok = 0;
     
    256256        for (size_t it = 0; it < benchmark_count; it++) {
    257257                printf("%s (%s)\n", benchmarks[it]->name, benchmarks[it]->desc);
    258                 if (run_benchmark(benchmarks[it])) {
     258                if (run_benchmark(env, benchmarks[it])) {
    259259                        count_ok++;
    260260                        continue;
     
    314314}
    315315
    316 static void handle_param_arg(char *arg)
     316static void handle_param_arg(bench_env_t *env, char *arg)
    317317{
    318318        char *value = NULL;
    319319        char *key = str_tok(arg, "=", &value);
    320         bench_param_set(key, value);
     320        bench_env_param_set(env, key, value);
    321321}
    322322
    323323int main(int argc, char *argv[])
    324324{
    325         errno_t rc = bench_param_init();
     325        bench_env_t bench_env;
     326        errno_t rc = bench_env_init(&bench_env);
    326327        if (rc != EOK) {
    327328                fprintf(stderr, "Failed to initialize internal params structure: %s\n",
     
    350351                        break;
    351352                case 'p':
    352                         handle_param_arg(optarg);
     353                        handle_param_arg(&bench_env, optarg);
    353354                        break;
    354355                case -1:
     
    378379
    379380        if (str_cmp(benchmark, "*") == 0) {
    380                 exit_code = run_benchmarks();
     381                exit_code = run_benchmarks(&bench_env);
    381382        } else {
    382383                bool benchmark_exists = false;
     
    384385                        if (str_cmp(benchmark, benchmarks[i]->name) == 0) {
    385386                                benchmark_exists = true;
    386                                 exit_code = run_benchmark(benchmarks[i]) ? 0 : -1;
     387                                exit_code = run_benchmark(&bench_env, benchmarks[i]) ? 0 : -1;
    387388                                break;
    388389                        }
     
    395396
    396397        csv_report_close();
    397         bench_param_cleanup();
     398        bench_env_cleanup(&bench_env);
    398399
    399400        return exit_code;
Note: See TracChangeset for help on using the changeset viewer.