Skip to content

Commit

Permalink
Brought back the folsom histograms
Browse files Browse the repository at this point in the history
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
ericmoritz committed Jul 9, 2012
1 parent bf3f016 commit fecf213
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions bin/compile_stats
Expand Up @@ -69,9 +69,17 @@ update_elapsed_time(Metric, DField,
write_elapsed_time_head(FH) -> write_elapsed_time_head(FH) ->
io:format(FH, "type, timestamp, elapsed~n", []). 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) -> write_elapsed_time(Metric, Start, End, State) ->
FH = element(Metric, State), FH = element(metric_field(Metric), State),
Elapsed = timer:now_diff(End, Start), Elapsed = timer:now_diff(End, Start),

folsom_metrics:notify({Metric, Elapsed}),

io:format(FH, "\"~s\",~w,~w~n", io:format(FH, "\"~s\",~w,~w~n",
[State#state.type, timestamp(End), Elapsed]). [State#state.type, timestamp(End), Elapsed]).


Expand All @@ -84,23 +92,23 @@ inc_count(Field, Counts) ->
setelement(Field, Counts, Current + 1). setelement(Field, Counts, Current + 1).


reducer({Start, {ws_init, Pid}}, State) -> reducer({Start, {ws_init, Pid}}, State) ->
State2 = update_elapsed_time(#state.handshake_times, State2 = update_elapsed_time(handshake_times,
#state.clients, #state.clients,
Pid, Start, undefined, State), Pid, Start, undefined, State),
State2#state{counts=inc_count(#counts.clients, State#state.counts)}; State2#state{counts=inc_count(#counts.clients, State#state.counts)};
reducer({End, {ws_onopen, Pid}}, State) -> reducer({End, {ws_onopen, Pid}}, State) ->
State2 = update_elapsed_time(#state.handshake_times, State2 = update_elapsed_time(handshake_times,
#state.clients, #state.clients,
Pid, undefined, End, State), Pid, undefined, End, State),
State2#state{counts=inc_count(#counts.handshakes, State#state.counts)}; State2#state{counts=inc_count(#counts.handshakes, State#state.counts)};
reducer({Start, {send_message, Pid, Ref}}, State) -> reducer({Start, {send_message, Pid, Ref}}, State) ->
State2 = update_elapsed_time(#state.message_latencies, State2 = update_elapsed_time(message_latencies,
#state.messages, #state.messages,
{Pid, Ref}, Start, undefined, State), {Pid, Ref}, Start, undefined, State),


State2#state{counts=inc_count(#counts.messages_sent, State#state.counts)}; State2#state{counts=inc_count(#counts.messages_sent, State#state.counts)};
reducer({End, {recv_message, Pid, Ref}}, State) -> reducer({End, {recv_message, Pid, Ref}}, State) ->
State2 = update_elapsed_time(#state.message_latencies, State2 = update_elapsed_time(message_latencies,
#state.messages, #state.messages,
{Pid, Ref}, undefined, End, State), {Pid, Ref}, undefined, End, State),
State2#state{counts=inc_count(#counts.messages_recv, State#state.counts)}; State2#state{counts=inc_count(#counts.messages_recv, State#state.counts)};
Expand All @@ -121,32 +129,51 @@ reducer(E, State) ->


main([Type, LogFile]) -> main([Type, LogFile]) ->
code:add_paths(["ebin", code:add_paths(["ebin",
"deps/bear/ebin",
"deps/folsom/ebin",
"deps/eleveldb/ebin"]), "deps/eleveldb/ebin"]),


application:start(folsom),

{ok, HSFH} = file:open(filename:join(LogFile, "handshake_times.csv"), {ok, HSFH} = file:open(filename:join(LogFile, "handshake_times.csv"),
[write]), [write]),
{ok, MLFH} = file:open(filename:join(LogFile, "message_latencies.csv"), {ok, MLFH} = file:open(filename:join(LogFile, "message_latencies.csv"),
[write]), [write]),
{ok, CountsFH} = file:open(filename:join(LogFile, "counts.csv"), {ok, CountsFH} = file:open(filename:join(LogFile, "counts.csv"),
[write]), [write]),


{ok, HistogramFH} = file:open(filename:join(LogFile, "histogram.config"),
[write]),

write_stats_head(CountsFH), write_stats_head(CountsFH),
write_elapsed_time_head(HSFH), write_elapsed_time_head(HSFH),
write_elapsed_time_head(MLFH), write_elapsed_time_head(MLFH),


folsom_metrics:new_histogram(handshake_times),
folsom_metrics:new_histogram(message_latencies),

State = #state{type=Type, State = #state{type=Type,
clients=dict:new(), clients=dict:new(),
messages=dict:new(), messages=dict:new(),
handshake_times=HSFH, handshake_times=HSFH,
message_latencies=MLFH}, message_latencies=MLFH},

io:format("Aggregating stats~n", []), io:format("Aggregating stats~n", []),
State2 = wsdemo_logger:foldl(fun reducer/2, State, LogFile), 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), write_stats(CountsFH, State2),
io:format(HistogramFH, "~w.", [{Type, HistogramData}]),

ok = file:close(HSFH), ok = file:close(HSFH),
ok = file:close(MLFH), ok = file:close(MLFH),
ok = file:close(CountsFH), ok = file:close(CountsFH),
ok = file:close(HistogramFH),
ok; ok;
main(_) -> main(_) ->
usage(). usage().
Expand Down

0 comments on commit fecf213

Please sign in to comment.