Current section

Files

Jump to
dqe src dqe_hist_percentile.erl
Raw

src/dqe_hist_percentile.erl

-module(dqe_hist_percentile).
-behaviour(dqe_fun).
-include_lib("mmath/include/mmath.hrl").
-export([spec/0, describe/1, init/1, chunk/1, resolution/2, run/2, help/0]).
-record(state, {percentile}).
init([Percentile]) ->
#state{percentile = Percentile}.
chunk(#state{}) ->
1.
resolution(_Resolution, State) ->
{1, State}.
describe(#state{percentile = Percentile}) ->
["percentile(", float_to_list(Percentile), ")"].
spec() ->
{<<"percentile">>, [histogram, float], none, metric}.
run([Data], S = #state{percentile = Percentile}) ->
R = mmath_bin:from_list([hdr_histogram:percentile(H, Percentile) || H <- Data]),
{R, S}.
help() ->
<<"Calculates the percentile value for a histogram.">>.