Changeset d5caf79 in mainline


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.

Location:
uspace/app/perf
Files:
2 added
4 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/perf/Makefile

    rc7de81b rd5caf79  
    3434
    3535SOURCES = \
     36        benchlist.c \
    3637        perf.c \
    3738        ipc/ns_ping.c \
  • uspace/app/perf/ipc/ns_ping.c

    rc7de81b rd5caf79  
    3232#include <errno.h>
    3333#include <str_error.h>
     34#include "../benchlist.h"
    3435#include "../perf.h"
    3536
    36 bool bench_ns_ping(stopwatch_t *stopwatch, uint64_t niter,
     37static bool runner(stopwatch_t *stopwatch, uint64_t niter,
    3738    char *error, size_t error_size)
    3839{
     
    5455        return true;
    5556}
     57
     58benchmark_t bench_ns_ping = {
     59        .name = "ns_ping",
     60        .desc = "Name service IPC ping-pong benchmark",
     61        .entry = &runner,
     62        .setup = NULL,
     63        .teardown = NULL
     64};
  • uspace/app/perf/ipc/ping_pong.c

    rc7de81b rd5caf79  
    3232#include <errno.h>
    3333#include <str_error.h>
     34#include "../benchlist.h"
    3435#include "../perf.h"
    3536
    3637static ipc_test_t *test = NULL;
    3738
    38 bool bench_ping_pong_setup(char *error, size_t error_size)
     39static bool setup(char *error, size_t error_size)
    3940{
    4041        errno_t rc = ipc_test_create(&test);
     
    4950}
    5051
    51 bool bench_ping_pong_teardown(char *error, size_t error_size)
     52static bool teardown(char *error, size_t error_size)
    5253{
    5354        ipc_test_destroy(test);
     
    5556}
    5657
    57 bool bench_ping_pong(stopwatch_t *stopwatch, uint64_t niter,
     58static bool runner(stopwatch_t *stopwatch, uint64_t niter,
    5859    char *error, size_t error_size)
    5960{
     
    7576        return true;
    7677}
     78
     79benchmark_t bench_ping_pong = {
     80        .name = "ping_pong",
     81        .desc = "IPC ping-pong benchmark",
     82        .entry = &runner,
     83        .setup = &setup,
     84        .teardown = &teardown
     85};
  • uspace/app/perf/malloc/malloc1.c

    rc7de81b rd5caf79  
    3030#include <stdio.h>
    3131#include <stdlib.h>
     32#include "../benchlist.h"
    3233#include "../perf.h"
    3334
    34 bool bench_malloc1(stopwatch_t *stopwatch, uint64_t size,
     35static bool runner(stopwatch_t *stopwatch, uint64_t size,
    3536    char *error, size_t error_size)
    3637{
     
    5051        return true;
    5152}
     53
     54benchmark_t bench_malloc1 = {
     55        .name = "malloc1",
     56        .desc = "User-space memory allocator benchmark, repeatedly allocate one block",
     57        .entry = &runner,
     58        .setup = NULL,
     59        .teardown = NULL
     60};
  • uspace/app/perf/malloc/malloc2.c

    rc7de81b rd5caf79  
    2929#include <stdlib.h>
    3030#include <stdio.h>
     31#include "../benchlist.h"
    3132#include "../perf.h"
    3233
    33 bool bench_malloc2(stopwatch_t *stopwatch, uint64_t niter,
     34static bool runner(stopwatch_t *stopwatch, uint64_t niter,
    3435    char *error, size_t error_size)
    3536{
     
    6768        return true;
    6869}
     70
     71benchmark_t bench_malloc2 = {
     72        .name = "malloc2",
     73        .desc = "User-space memory allocator benchmark, allocate many small blocks",
     74        .entry = &runner,
     75        .setup = NULL,
     76        .teardown = NULL
     77};
  • 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        }
  • uspace/app/perf/perf.h

    rc7de81b rd5caf79  
    5151} benchmark_t;
    5252
    53 extern bool bench_malloc1(stopwatch_t *, uint64_t, char *, size_t);
    54 extern bool bench_malloc2(stopwatch_t *, uint64_t, char *, size_t);
    55 extern bool bench_ns_ping(stopwatch_t *, uint64_t, char *, size_t);
    56 extern bool bench_ping_pong(stopwatch_t *, uint64_t, char *, size_t);
    57 extern bool bench_ping_pong_setup(char *, size_t);
    58 extern bool bench_ping_pong_teardown(char *, size_t);
    59 
    60 extern benchmark_t benchmarks[];
    61 
    6253#endif
    6354
Note: See TracChangeset for help on using the changeset viewer.