Skip to content

Commit 289d4d2

Browse files
Merge pull request #44 from cloudant/107-add-ops-col-view-query
Add extra col to represent no. of ops
2 parents 70d3c71 + 730ba67 commit 289d4d2

File tree

2 files changed

+49
-34
lines changed

2 files changed

+49
-34
lines changed

src/basho_bench_stats.erl

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ op_complete(Op, {ok, Units}, ElapsedUs) ->
7272
folsom_metrics:notify_existing_metric({latencies, Op}, ElapsedUs, histogram),
7373
folsom_metrics:notify_existing_metric({overall_latencies, Op}, ElapsedUs, histogram),
7474
folsom_metrics:notify_existing_metric({overall_units, Op}, {inc, Units}, counter),
75-
folsom_metrics:notify_existing_metric({units, Op}, {inc, Units}, counter)
75+
folsom_metrics:notify_existing_metric({units, Op}, {inc, Units}, counter),
76+
folsom_metrics:notify_existing_metric({overall_ops, Op}, {inc, 1}, counter),
77+
folsom_metrics:notify_existing_metric({ops, Op}, {inc, 1}, counter)
7678
end,
7779
ok;
7880
op_complete(Op, Result, ElapsedUs) ->
@@ -114,7 +116,9 @@ init([]) ->
114116
folsom_metrics:new_histogram({latencies, Op}, slide, basho_bench_config:get(report_interval)),
115117
folsom_metrics:new_histogram({overall_latencies, Op}, uniform, 16384),
116118
folsom_metrics:new_counter({overall_units, Op}),
117-
folsom_metrics:new_counter({units, Op})
119+
folsom_metrics:new_counter({units, Op}),
120+
folsom_metrics:new_counter({overall_ops, Op}),
121+
folsom_metrics:new_counter({ops, Op})
118122
end || Op <- Ops ++ Measurements],
119123

120124
StatsWriter = basho_bench_config:get(stats, csv),
@@ -162,10 +166,13 @@ handle_cast({Op, {ok, Units}, ElapsedUs}, State = #state{last_write_time = LWT,
162166
folsom_metrics:notify_existing_metric({overall_latencies, Op}, ElapsedUs, histogram),
163167
folsom_metrics:notify_existing_metric({overall_units, Op}, {inc, Units}, counter),
164168
folsom_metrics:notify_existing_metric({units, Op}, {inc, Units}, counter),
169+
folsom_metrics:notify_existing_metric({overall_ops, Op}, {inc, 1}, counter),
170+
folsom_metrics:notify_existing_metric({ops, Op}, {inc, 1}, counter),
165171
{noreply, NewState};
166172
handle_cast(_, State) ->
167173
{noreply, State}.
168174

175+
169176
handle_info(report, State) ->
170177
consume_report_msgs(),
171178
Now = os:timestamp(),
@@ -251,19 +258,21 @@ process_stats(Now, #state{stats_writer=Module}=State) ->
251258
Window = timer:now_diff(Now, State#state.last_write_time) / 1000000,
252259

253260
%% Time to report latency data to our CSV files
254-
{Oks, Errors, OkOpsRes} =
255-
lists:foldl(fun(Op, {TotalOks, TotalErrors, OpsResAcc}) ->
256-
{Oks, Errors} = report_latency(State, Elapsed, Window, Op),
257-
{TotalOks + Oks, TotalErrors + Errors,
258-
[{Op, Oks}|OpsResAcc]}
259-
end, {0,0,[]}, State#state.ops),
261+
{Ops, Oks, Errors, OkOpsRes} =
262+
lists:foldl(fun(Op, {TotalOps, TotalOks, TotalErrors, OpsResAcc}) ->
263+
{Ops, Oks, Errors} = report_latency(State, Elapsed, Window, Op),
264+
{TotalOps + Ops, TotalOks + Oks, TotalErrors + Errors,
265+
[{Op, Oks, Ops}|OpsResAcc]}
266+
end, {0,0,0,[]}, State#state.ops),
260267

261268
%% Reset units
262-
[folsom_metrics_counter:dec({units, Op}, OpAmount) || {Op, OpAmount} <- OkOpsRes],
269+
[folsom_metrics_counter:dec({units, Op}, OksAmount) || {Op, OksAmount, _} <- OkOpsRes],
270+
%% Reset Ops
271+
[folsom_metrics_counter:dec({ops, Op}, OpsAmount) || {Op, _, OpsAmount} <- OkOpsRes],
263272

264273
%% Write summary
265274
Module:process_summary(State#state.stats_writer_data,
266-
Elapsed, Window, Oks, Errors),
275+
Elapsed, Window, Ops, Oks, Errors),
267276

268277
%% Dump current error counts to console
269278
case (State#state.errors_since_last_report) of
@@ -285,7 +294,8 @@ process_global_stats(#state{stats_writer=Module}=State) ->
285294
Stats = folsom_metrics:get_histogram_statistics({overall_latencies, Op}),
286295
Errors = error_counter(Op),
287296
Units = folsom_metrics:get_metric_value({overall_units, Op}),
288-
Module:report_global_stats(Op, Stats, Errors, Units)
297+
Ops = folsom_metrics:get_metric_value({overall_ops, Op}),
298+
Module:report_global_stats(Op, Stats, Errors, Units, Ops)
289299
end, State#state.ops).
290300

291301
%%
@@ -296,12 +306,13 @@ report_latency(#state{stats_writer=Module}=State, Elapsed, Window, Op) ->
296306
Stats = folsom_metrics:get_histogram_statistics({latencies, Op}),
297307
Errors = error_counter(Op),
298308
Units = folsom_metrics:get_metric_value({units, Op}),
309+
Ops = folsom_metrics:get_metric_value({ops, Op}),
299310

300311
Module:report_latency({State#state.stats_writer,
301312
State#state.stats_writer_data},
302313
Elapsed, Window, Op,
303-
Stats, Errors, Units),
304-
{Units, Errors}.
314+
Stats, Errors, Units, Ops),
315+
{Ops, Units, Errors}.
305316

306317
report_total_errors(#state{stats_writer=Module}=State) ->
307318
case ets:tab2list(basho_bench_total_errors) of
@@ -349,14 +360,14 @@ get_worker_ops() ->
349360
Workers = basho_bench_config:get(workers, []),
350361
case Workers of
351362
%% No workers reverts to original case is fine as long as we stick with 2-tuples
352-
[] ->
363+
[] ->
353364
lists:map(
354365
fun({OpTag, _Count}) -> {OpTag, OpTag};
355366
({Label, OpTag, _Count}) -> {Label, OpTag};
356367
({Label, OpTag, _Count, _OptionsList}) -> {Label, OpTag}
357368
end, basho_bench_config:get(operations, []));
358369
%% Use workers to determine active worker types for current config
359-
_ ->
370+
_ ->
360371
get_worker_ops(Workers, basho_bench_config:get(worker_types), [])
361372
end.
362373

@@ -374,7 +385,7 @@ get_worker_ops([{WorkerType, _Count} | RestWorkers], WorkerTypes, Acc) ->
374385
end,
375386

376387
Ops = lists:map(
377-
fun({OpTag, _Count2}) ->
388+
fun({OpTag, _Count2}) ->
378389
{ worker_op_name(WorkerType, OpTag), worker_op_name(WorkerType, OpTag)};
379390
({Label, OpTag, _Count2}) ->
380391
{ worker_op_name(WorkerType, Label), worker_op_name(WorkerType, OpTag)}
@@ -383,7 +394,7 @@ get_worker_ops([{WorkerType, _Count} | RestWorkers], WorkerTypes, Acc) ->
383394

384395

385396
worker_op_name(Worker,Op) ->
386-
case Worker of
397+
case Worker of
387398
single_worker ->
388399
Op;
389400
_ ->

src/basho_bench_stats_writer_csv.erl

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333

3434
-export([new/2,
3535
terminate/1,
36-
process_summary/5,
36+
process_summary/6,
3737
report_error/3,
38-
report_global_stats/4,
39-
report_latency/7]).
38+
report_global_stats/5,
39+
report_latency/8]).
4040

4141
-include("basho_bench.hrl").
4242

@@ -57,7 +57,7 @@ new(Ops, Measurements) ->
5757
filename:join([TestDir, "summary.csv"]),
5858
[raw, binary, write]
5959
),
60-
file:write(SummaryFile, <<"elapsed, window, total, successful, failed\n">>),
60+
file:write(SummaryFile, <<"elapsed, window, total_operations, total_units, successful, failed\n">>),
6161

6262
%% Setup errors file w/counters for each error. Embedded commas likely
6363
%% in the error messages so quote the columns.
@@ -82,13 +82,14 @@ terminate({SummaryFile, ErrorsFile}) ->
8282
ok.
8383

8484
process_summary({SummaryFile, _ErrorsFile},
85-
Elapsed, Window, Oks, Errors) ->
85+
Elapsed, Window, Ops, Oks, Errors) ->
8686
file:write(SummaryFile,
87-
io_lib:format("~w, ~w, ~w, ~w, ~w\n",
87+
io_lib:format("~w, ~w, ~w, ~w, ~w, ~w\n",
8888
[Elapsed,
8989
Window,
90-
Oks + Errors,
90+
Ops + Errors,
9191
Oks,
92+
Ops,
9293
Errors])).
9394

9495
report_error({_SummaryFile, ErrorsFile},
@@ -97,8 +98,8 @@ report_error({_SummaryFile, ErrorsFile},
9798
io_lib:format("\"~w\",\"~w\"\n",
9899
[Key, Count])).
99100

100-
report_global_stats({Op,_}, Stats, Errors, Units) ->
101-
%% Build up JSON structure representing statistices collected in folsom
101+
report_global_stats({Op,_}, Stats, Errors, Units, Ops) ->
102+
%% Build up JSON structure representing statistics collected in folsom
102103
P = proplists:get_value(percentile, Stats),
103104
JsonElements0 = lists:foldl(fun(K, Acc) ->
104105
case K of
@@ -132,21 +133,25 @@ report_global_stats({Op,_}, Stats, Errors, Units) ->
132133
%% insert error counts
133134
JsonElements2 = [{basho_errors, Errors} | JsonElements1],
134135

136+
%% insert Ops counts
137+
JsonElements3 = [{'ops', Ops} | JsonElements2],
138+
135139
JsonMetrics0 = erlang:get(run_metrics),
136-
JsonMetrics = lists:keyreplace(Op, 1, JsonMetrics0, {Op, {JsonElements2}}),
140+
JsonMetrics = lists:keyreplace(Op, 1, JsonMetrics0, {Op, {JsonElements3}}),
137141
%?DEBUG("Generated Json:\n~w",[JsonElements]),
138142
erlang:put(run_metrics, JsonMetrics).
139143

140144
report_latency({_SummaryFile, _ErrorsFile},
141145
Elapsed, Window, Op,
142-
Stats, Errors, Units) ->
146+
Stats, Errors, Units, Ops) ->
143147
case proplists:get_value(n, Stats) > 0 of
144148
true ->
145149
P = proplists:get_value(percentile, Stats),
146-
Line = io_lib:format("~w, ~w, ~w, ~w, ~.1f, ~w, ~w, ~w, ~w, ~w, ~w\n",
150+
Line = io_lib:format("~w, ~w, ~w, ~w, ~w, ~.1f, ~w, ~w, ~w, ~w, ~w, ~w\n",
147151
[Elapsed,
148152
Window,
149153
Units,
154+
Ops,
150155
proplists:get_value(min, Stats),
151156
proplists:get_value(arithmetic_mean, Stats),
152157
proplists:get_value(median, Stats),
@@ -157,7 +162,7 @@ report_latency({_SummaryFile, _ErrorsFile},
157162
Errors]);
158163
false ->
159164
?WARN("No data for op: ~p\n", [Op]),
160-
Line = io_lib:format("~w, ~w, 0, 0, 0, 0, 0, 0, 0, 0, ~w\n",
165+
Line = io_lib:format("~w, ~w, 0, 0, 0, 0, 0, 0, 0, 0, 0, ~w\n",
161166
[Elapsed,
162167
Window,
163168
Errors])
@@ -172,7 +177,7 @@ op_csv_file({Label, _Op}) ->
172177
TestDir = basho_bench:get_test_dir(),
173178
Fname = filename:join([TestDir, normalize_label(Label) ++ "_latencies.csv"]),
174179
{ok, F} = file:open(Fname, [raw, binary, write]),
175-
ok = file:write(F, <<"elapsed, window, n, min, mean, median, 95th, 99th, 99_9th, max, errors\n">>),
180+
ok = file:write(F, <<"elapsed, window, n, ops, min, mean, median, 95th, 99th, 99_9th, max, errors\n">>),
176181
F.
177182

178183
measurement_csv_file({Label, _Op}) ->
@@ -194,7 +199,7 @@ stringify_stats(_RunStatsType=json, RunMetrics) ->
194199
[ jiffy:encode( {[{recordedMetrics, {RunMetrics}}]}, [pretty] ) ];
195200
stringify_stats(_RunStatsType=csv, RunMetrics) ->
196201
% Ordered output of fields
197-
OrderedFields = [n, mean, geometric_mean, harmonic_mean,
202+
OrderedFields = [n, ops, mean, geometric_mean, harmonic_mean,
198203
variance, standard_deviation, skewness, kurtosis,
199204
median, p75, p90, p95, p99, p999,
200205
min, max, basho_errors],
@@ -223,7 +228,7 @@ write_run_statistics(FileName, Lines)->
223228
FileName,
224229
[raw, binary, write]
225230
),
226-
231+
227232
%% Write lines to file
228233
lists:foreach(fun(Line) ->
229234
ok = file:write(GlobalMetricsFile, Line)
@@ -251,4 +256,3 @@ replace_special_chars([_|T]) ->
251256
[$-|replace_special_chars(T)];
252257
replace_special_chars([]) ->
253258
[].
254-

0 commit comments

Comments
 (0)