Skip to content
Browse files

Brought back the folsom histograms

I was wrong about how folsom compiles it's histograms.  While it is true
that there is support for windowed histograms, the default configuration
uses the entire dataset.
  • Loading branch information...
1 parent bf3f016 commit fecf2138d37253190859e0d5c474a58abb0e2b21 @ericmoritz committed
Showing with 33 additions and 6 deletions.
  1. +33 −6 bin/compile_stats
View
39 bin/compile_stats
@@ -69,9 +69,17 @@ update_elapsed_time(Metric, DField,
write_elapsed_time_head(FH) ->
io:format(FH, "type, timestamp, elapsed~n", []).
+metric_field(handshake_times) ->
+ #state.handshake_times;
+metric_field(message_latencies) ->
+ #state.message_latencies.
+
write_elapsed_time(Metric, Start, End, State) ->
- FH = element(Metric, State),
+ FH = element(metric_field(Metric), State),
Elapsed = timer:now_diff(End, Start),
+
+ folsom_metrics:notify({Metric, Elapsed}),
+
io:format(FH, "\"~s\",~w,~w~n",
[State#state.type, timestamp(End), Elapsed]).
@@ -84,23 +92,23 @@ inc_count(Field, Counts) ->
setelement(Field, Counts, Current + 1).
reducer({Start, {ws_init, Pid}}, State) ->
- State2 = update_elapsed_time(#state.handshake_times,
+ State2 = update_elapsed_time(handshake_times,
#state.clients,
Pid, Start, undefined, State),
State2#state{counts=inc_count(#counts.clients, State#state.counts)};
reducer({End, {ws_onopen, Pid}}, State) ->
- State2 = update_elapsed_time(#state.handshake_times,
+ State2 = update_elapsed_time(handshake_times,
#state.clients,
Pid, undefined, End, State),
State2#state{counts=inc_count(#counts.handshakes, State#state.counts)};
reducer({Start, {send_message, Pid, Ref}}, State) ->
- State2 = update_elapsed_time(#state.message_latencies,
+ State2 = update_elapsed_time(message_latencies,
#state.messages,
{Pid, Ref}, Start, undefined, State),
State2#state{counts=inc_count(#counts.messages_sent, State#state.counts)};
reducer({End, {recv_message, Pid, Ref}}, State) ->
- State2 = update_elapsed_time(#state.message_latencies,
+ State2 = update_elapsed_time(message_latencies,
#state.messages,
{Pid, Ref}, undefined, End, State),
State2#state{counts=inc_count(#counts.messages_recv, State#state.counts)};
@@ -121,8 +129,12 @@ reducer(E, State) ->
main([Type, LogFile]) ->
code:add_paths(["ebin",
+ "deps/bear/ebin",
+ "deps/folsom/ebin",
"deps/eleveldb/ebin"]),
+ application:start(folsom),
+
{ok, HSFH} = file:open(filename:join(LogFile, "handshake_times.csv"),
[write]),
{ok, MLFH} = file:open(filename:join(LogFile, "message_latencies.csv"),
@@ -130,23 +142,38 @@ main([Type, LogFile]) ->
{ok, CountsFH} = file:open(filename:join(LogFile, "counts.csv"),
[write]),
+ {ok, HistogramFH} = file:open(filename:join(LogFile, "histogram.config"),
+ [write]),
+
write_stats_head(CountsFH),
write_elapsed_time_head(HSFH),
write_elapsed_time_head(MLFH),
+ folsom_metrics:new_histogram(handshake_times),
+ folsom_metrics:new_histogram(message_latencies),
+
State = #state{type=Type,
clients=dict:new(),
messages=dict:new(),
handshake_times=HSFH,
message_latencies=MLFH},
-
io:format("Aggregating stats~n", []),
State2 = wsdemo_logger:foldl(fun reducer/2, State, LogFile),
+
+ HistogramData = [
+ {handshake_times,
+ folsom_metrics:get_histogram_statistics(handshake_times)},
+ {message_latencies,
+ folsom_metrics:get_histogram_statistics(message_latencies)}
+ ],
write_stats(CountsFH, State2),
+ io:format(HistogramFH, "~w.", [{Type, HistogramData}]),
+
ok = file:close(HSFH),
ok = file:close(MLFH),
ok = file:close(CountsFH),
+ ok = file:close(HistogramFH),
ok;
main(_) ->
usage().

0 comments on commit fecf213

Please sign in to comment.
Something went wrong with that request. Please try again.