Skip to content

Commit

Permalink
Merge pull request #39 from max-au/erlperf/fix-zero-avg
Browse files Browse the repository at this point in the history
Fix incorrect behavriour when the call takes longer than sampling period
  • Loading branch information
max-au authored May 17, 2024
2 parents 1640b14 + e878c63 commit 4aab3af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/erlperf_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ format_report_line(MaxAvg, #{mode := timed, code := #{runner := Code}, result :=

format_report_line(MaxAvg, #{code := #{runner := Code}, result := #{average := Avg, stddev := StdDev,
iteration_time := IterationTime, p99 := P99, median := Median, samples := Samples},
run_options := #{concurrency := Concurrency}}, _ReportFormat) ->
run_options := #{concurrency := Concurrency}}, _ReportFormat) when Avg > 0.5 ->
[
format_code(Code),
integer_to_list(Concurrency),
Expand All @@ -429,6 +429,20 @@ format_report_line(MaxAvg, #{code := #{runner := Code}, result := #{average := A
erlperf_file_log:format_number(P99),
erlperf_file_log:format_duration(IterationTime),
integer_to_list(erlang:round(Avg * 100 / MaxAvg)) ++ "%"
];

format_report_line(_MaxAvg, #{code := #{runner := Code}, result := #{samples := Samples},
run_options := #{concurrency := Concurrency}}, _ReportFormat) ->
[
format_code(Code),
integer_to_list(Concurrency),
integer_to_list(length(Samples) - 1),
"0",
"inf",
"0",
"0",
"inf",
"0%"
].

%% generic table formatter routine, accepting list of lists
Expand Down
15 changes: 13 additions & 2 deletions test/erlperf_cli_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-export([suite/0, all/0]).

-export([
simple/1, concurrent/1, verbose/1, compare/1,
simple/1, concurrent/1, verbose/1, zero/1, compare/1,
usage/1, init/1,
double/1, triple/1, pg/1, mfa/1,
full_report/1, basic_timed_report/1, full_timed_report/1,
Expand All @@ -26,7 +26,7 @@ suite() ->
[{timetrap, {seconds, 20}}].

all() ->
[simple, concurrent, verbose, compare, squeeze, step, usage, init, double,
[simple, concurrent, verbose, zero, compare, squeeze, step, usage, init, double,
triple, pg, mfa, full_report, basic_timed_report, full_timed_report, recorded, init_all].

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -70,6 +70,9 @@ parse_out(Out) ->
["Code", "||", "QPS", "Time", "Rel"] ->
[begin
case filtersplit(Ln, " ") of
[Code, ConcT, "0", "inf", Rel] ->
{Code, list_to_integer(ConcT), 0, infinity,
list_to_integer(lists:droplast(Rel))};
[Code, ConcT, QPST, TT, TTU, Rel] ->
{Code, list_to_integer(ConcT), parse_qps(QPST, ""), parse_duration(TT, TTU),
list_to_integer(lists:droplast(Rel))};
Expand Down Expand Up @@ -151,6 +154,14 @@ verbose(Config) when is_list(Config) ->
?assert(C > 250 andalso C < 1101, {qps, C}),
?assert(T > 1000000 andalso T < 3000000, {time, T}).

% erlperf 'timer:sleep(100).' 'timer:sleep(200).' -d 10
zero(Config) when is_list(Config) ->
Out = capture_io(fun () -> erlperf_cli:main(["timer:sleep(100).", "timer:sleep(200).", "-d", "10"]) end),
% Code Concurrency Throughput Time Rel
% timer:sleep(200). 1 0 inf 0%
% timer:sleep(100). 1 0 inf 0%
[{_Code, 1, 0, infinity, 0}, {_Code2, 1, 0, infinity, 0}] = parse_out(Out).

% erlperf 'timer:sleep(1).' 'timer:sleep(2).' -d 100 -s 5 -w 1 -c 2
compare(Config) when is_list(Config) ->
Out = capture_io(
Expand Down

0 comments on commit 4aab3af

Please sign in to comment.