Copyright © (C) 2019-2022, Maxim Fedorov
Behaviours: gen_server.
Job runner, taking care of init/done, workers added and removed. Works just like a simple_one_for_one supervisor (children are temporary runners). There are two benchmarking modes: continuous (activated by setting non-zero concurrency), and sample-based (activated manually and deactivated after runner does requested amount of iterations).
Job is defined with 4 functions (code map):callable() = mfargs() | [mfargs()] | function() | fun((term()) -> term()) | string()
code_map() = #{runner := callable(), init => callable(), init_runner => callable(), done => callable()}
exec() = #exec{name = atom(), source = [string()], binary = binary(), init = fun(() -> term()), init_runner = fun((term()) -> term()), runner = {fun((term()) -> term()), non_neg_integer()}, sample_runner = {fun((non_neg_integer(), term()) -> term()), non_neg_integer()}, done = fun((term()) -> term())}
handle() = {module(), non_neg_integer()}
mfargs() = {module(), atom(), [term()]}
server_ref() = gen_server:server_ref()
state() = #erlperf_job_state{exec = exec(), init_result = term(), workers = [pid()], sample_workers = #{pid() => {pid(), reference()}}}
concurrency/1 | |
handle/1 | Returns the sampling handle for the job. |
handle_call/3 | |
handle_cast/2 | |
handle_info/2 | |
init/1 | |
measure/2 | Executes the runner SampleCount times, returns time in microseconds it took to execute. |
sample/1 | Returns the current sample for the job, or undefined if the job has stopped. |
set_concurrency/2 | Change concurrency setting for this job. |
source/1 | Returns the source code that was generated for this job. |
start/1 | Starts the benchmark instance. |
start_link/1 | Starts the benchmark instance and links it to caller. |
terminate/2 |
concurrency(JobId::server_ref()) -> Concurrency::non_neg_integer()
handle(JobId::server_ref()) -> handle()
Returns the sampling handle for the job.
handle_call(X1::term(), From::{pid(), reference()}, Erlperf_job_state::state()) -> {reply, term(), state()}
handle_cast(Request, State) -> any()
init(Exec) -> any()
measure(JobId::server_ref(), SampleCount::non_neg_integer()) -> TimeUs::non_neg_integer() | already_started
Executes the runner SampleCount times, returns time in microseconds it
took to execute. Similar to timer:tc
. Has less overhead compared to
continuous benchmarking, therefore can be used even for very fast functions.
sample(X1::handle()) -> non_neg_integer() | undefined
Returns the current sample for the job, or undefined if the job has stopped.
set_concurrency(JobId::server_ref(), Concurrency::non_neg_integer()) -> ok
Change concurrency setting for this job. Does not reset counting.
source(JobId::handle()) -> [string()]
Returns the source code that was generated for this job.
start(Code::code_map()) -> {ok, pid()} | {error, term()}
Starts the benchmark instance. Job starts with no workers, use set_concurrency/2 to start some.
start_link(Code::code_map()) -> {ok, pid()} | {error, term()}
Starts the benchmark instance and links it to caller. Job starts with no workers, use set_concurrency/2 to start some.
terminate(Reason::term(), Erlperf_job_state::state()) -> ok
Generated by EDoc