Changeset d5caf79 in mainline for uspace/app/perf/perf.c


Ignore:
Timestamp:
2018-12-28T13:56:05Z (5 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
980611d5
Parents:
c7de81b
git-author:
Vojtech Horky <vojtech.horky@…> (2018-12-28 13:54:23)
git-committer:
Vojtech Horky <vojtech.horky@…> (2018-12-28 13:56:05)
Message:

perf: hide more benchmark implementation

It is much easier to maintain the benchmark if all the definitions etc.
are in a single file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/perf/perf.c

    rc7de81b rd5caf79  
    4343#include <perf.h>
    4444#include "perf.h"
     45#include "benchlist.h"
    4546
    4647#define MIN_DURATION_SECS 10
    4748#define NUM_SAMPLES 10
    4849#define MAX_ERROR_STR_LENGTH 1024
    49 
    50 benchmark_t benchmarks[] = {
    51 #include "ipc/ns_ping.def"
    52 #include "ipc/ping_pong.def"
    53 #include "malloc/malloc1.def"
    54 #include "malloc/malloc2.def"
    55         { NULL, NULL, NULL, NULL, NULL }
    56 };
    5750
    5851static void short_report(stopwatch_t *stopwatch, int run_index,
     
    179172static int run_benchmarks(void)
    180173{
    181         benchmark_t *bench;
    182174        unsigned int i = 0;
    183175        unsigned int n = 0;
     
    187179        printf("\n*** Running all benchmarks ***\n\n");
    188180
    189         for (bench = benchmarks; bench->name != NULL; bench++) {
    190                 printf("%s (%s)\n", bench->name, bench->desc);
    191                 if (run_benchmark(bench)) {
     181        for (size_t it = 0; it < benchmark_count; it++) {
     182                printf("%s (%s)\n", benchmarks[it]->name, benchmarks[it]->desc);
     183                if (run_benchmark(benchmarks[it])) {
    192184                        i++;
    193185                        continue;
     
    195187
    196188                if (!failed_names) {
    197                         failed_names = str_dup(bench->name);
     189                        failed_names = str_dup(benchmarks[it]->name);
    198190                } else {
    199191                        char *f = NULL;
    200                         asprintf(&f, "%s, %s", failed_names, bench->name);
     192                        asprintf(&f, "%s, %s", failed_names, benchmarks[it]->name);
    201193                        if (!f) {
    202194                                printf("Out of memory.\n");
     
    219211{
    220212        size_t len = 0;
    221         benchmark_t *bench;
    222         for (bench = benchmarks; bench->name != NULL; bench++) {
    223                 if (str_length(bench->name) > len)
    224                         len = str_length(bench->name);
     213        for (size_t i = 0; i < benchmark_count; i++) {
     214                size_t len_now = str_length(benchmarks[i]->name);
     215                if (len_now > len)
     216                        len = len_now;
    225217        }
    226218
     
    231223        }
    232224
    233         for (bench = benchmarks; bench->name != NULL; bench++)
    234                 printf("%-*s %s\n", _len, bench->name, bench->desc);
     225        for (size_t i = 0; i < benchmark_count; i++)
     226                printf("%-*s %s\n", _len, benchmarks[i]->name, benchmarks[i]->desc);
    235227
    236228        printf("%-*s Run all benchmarks\n", _len, "*");
     
    250242        }
    251243
    252         benchmark_t *bench;
    253         for (bench = benchmarks; bench->name != NULL; bench++) {
    254                 if (str_cmp(argv[1], bench->name) == 0) {
    255                         return (run_benchmark(bench) ? 0 : -1);
     244        for (size_t i = 0; i < benchmark_count; i++) {
     245                if (str_cmp(argv[1], benchmarks[i]->name) == 0) {
     246                        return (run_benchmark(benchmarks[i]) ? 0 : -1);
    256247                }
    257248        }
Note: See TracChangeset for help on using the changeset viewer.