Skip to content

4. How to add the driver to Runner

BlaCkinkGJ edited this page Aug 25, 2020 · 2 revisions

If you want to add the driver to runner, then you must follow the below. In this example, we assume that we make a bench-driver. (Please keep the naming rule to <BENCHMARK>-driver)

Prepare to create a driver

This section describes making directories and files for driver.

  1. First of all, you make the runner/driver directory and the include/driver directory which has the bench-driver sub-directory
  2. Add the bench-driver.h file to include/driver/bench-driver directory.
  3. Add the bench-driver.c file to runner/driver/bench-driver directory.
  4. bench-driver.h and bench-driver.c must follow the below template source files.

bench-driver.h

#include <generic.h>

int bench_init(void *object);
int bench_runner(void);
int bench_get_interval(const char *key, char *buffer);
int bench_get_total(const char *key, char *buffer);
void bench_free(void);

bench-driver.c

#include <generic.h>
#include <runner.h>
#include <driver/bench-driver.h>

int bench_init(void *object)
{
	struct runner_config *config = (struct runner_config *)object;
    struct generic_driver_op *op = &config->op;
    
    op->runner = bench_runner;
    op->get_interval = bench_get_interval;
    op->get_total = bench_get_total;
    op->free = bench_free;
}

Register the driver

This section describes how to register the driver to the runner.

  1. First of all, you have to add BENCH_DRIVER=1 to generic.h's enumeration variable which contains TRACE_REPLAY_DRIVER=0. you must not use the number which other drivers already have taken.
  2. Next, you add the "key, value" to the driver_name_tbl variable in generic.c. This value will be used in JSON's "driver" key. For example, you can add the value like [BENCH_DRIVER] = "bench" to driver_name_tbl
  3. Finally, you add the [BENCH_DRIVER] = bench_init to driver_init_tbl variable in generic.c.

Notes

  1. <BENCHMARK>_init function only does the memory allocation and basic configuration. The real running sequence must be implemented in the <BENCHMAKR>_runner.
  2. Highly suggest to refer to the tr-driver and docker-driver to create a driver.
  3. Basically, if you can run scons(NOT scons test) then automatically generate compile_commands.json. If you use this with coc and ccls in neovim then you can more easily develop our program.
  4. If you want to analyze our source code, then you check this link and run Sourcetrail with compile_commands.json.