Permalink
Browse files

Enable Trace measurements in tests.

  • Loading branch information...
1 parent 282bcba commit bf74541e8c7702f6ac8983b4d6a7209d5e4abdc5 @jlouis committed Dec 25, 2012
Showing with 65 additions and 6 deletions.
  1. +2 −2 ct/test.config
  2. +2 −2 src/sv_codel.erl
  3. +53 −0 src/sv_tracer.erl
  4. +8 −2 test/sv_SUITE.erl
View
@@ -8,8 +8,8 @@
{concurrency, 3}
]},
{test_queue_1_codel, [
- {hz, 1000},
- {rate, 5},
+ {hz, 200},
+ {rate, 1},
{token_limit, 15},
{size, 60},
{concurrency, 3},
View
@@ -132,12 +132,12 @@ control_law(T, I, C) ->
dodequeue(Now, #state { queue = Q } = State) ->
case ?Q:out(Now, Q) of
{empty, [], NQ} ->
- sv:report(Now, {dodequeue, 0, 0}),
+ sv:report(Now div 1000, {dodequeue, 0, 0}),
{nodrop, empty, State#state { first_above_time = 0, queue = NQ }};
{{Pkt, InT}, [], NQ} ->
Sojourn = Now - InT,
- sv:report(Now, {dodequeue, ?Q:len(NQ), Sojourn / 1000}),
+ sv:report(Now div 1000, {dodequeue, ?Q:len(NQ), Sojourn div 1000}),
dodequeue_(Now, Pkt, Sojourn, State#state { queue = NQ })
end.
View
@@ -0,0 +1,53 @@
+-module(sv_tracer).
+
+-behaviour(gen_server).
+
+-export([start_link/1, stop/0]).
+-export([init/1, handle_call/3, handle_cast/2, terminate/2, handle_info/2, code_change/3]).
+
+-export([write_event/2]).
+
+-record(state, { fd, tracer }).
+
+start_link(Filename) ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [Filename], []).
+
+stop() ->
+ gen_server:call(?MODULE, stop).
+
+write_event({trace, _Pid, call, {sv, report, [Now, {dodequeue, QSize, Sojourn}]}, _}, {Start, Fd}) ->
+ file:write(Fd, [integer_to_list(Now - Start), $,, integer_to_list(QSize), $,, integer_to_list(Sojourn), $\n]),
+ {Start, Fd}.
+
+%% Callbacks
+init([Filename]) ->
+ {ok, Fd} = file:open(Filename, [write, binary, delayed_write]),
+ file:write(Fd, header()),
+ T = sv:timestamp(),
+ {ok, Tracer} = dbg:tracer(process, {fun write_event/2, {T div 1000, Fd}}),
+ dbg:p(all, [c]),
+ dbg:tp(sv, report, 2, c),
+ {ok, #state { fd = Fd, tracer = Tracer}}.
+
+handle_call(stop, _From, State) ->
+ {stop, normal, ok, State}.
+
+handle_cast(Cast, State) ->
+ lager:error("Unknown cast: ~p", [Cast]),
+ {noreply, State}.
+
+
+handle_info(Info, State) ->
+ lager:error("Unknown info: ~p", [Info]),
+ {noreply, State}.
+
+terminate(_Reason, #state { fd = Fd }) ->
+ file:close(Fd),
+ dbg:stop_clear(),
+ ok.
+
+code_change(_OldVsn, State, _Aux) ->
+ {ok, State}.
+
+header() ->
+ ["Time, QSize, Sojourn\n"].
View
@@ -30,6 +30,9 @@ end_per_suite(_Config) ->
App <- lists:reverse([syntax_tools, compiler, lager, safetyvalve])],
ok.
+init_per_testcase(many_through_codel, Config) ->
+ sv_tracer:start_link(filename:join(?config(priv_dir, Config), "trace.out")),
+ Config;
init_per_testcase(not_applicable, Config) ->
dbg:tracer(),
dbg:tpl({sv_queue_ets, in, 2}, cx),
@@ -39,6 +42,9 @@ init_per_testcase(not_applicable, Config) ->
init_per_testcase(_Case, Config) ->
Config.
+end_per_testcase(many_through_codel, _Config) ->
+ sv_tracer:stop(),
+ ok;
end_per_testcase(not_applicable, _Config) ->
dbg:stop(),
ok;
@@ -71,7 +77,7 @@ many_through_ets(_Config) ->
{ok, ok} -> Parent ! {done, self()};
{error, overload} -> Parent ! {overload, self()}
end
- end) || _ <- lists:seq(1, 20)],
+ end) || _ <- lists:seq(1, 60)],
{ok, Overloads} = collect(Pids, 0),
ct:log("Overloads: ~B", [Overloads]),
true = Overloads == 0.
@@ -83,7 +89,7 @@ many_through_codel(_Config) ->
{ok, ok} -> Parent ! {done, self()};
{error, overload} -> Parent ! {overload, self()}
end
- end) || _ <- lists:seq(1, 20)],
+ end) || _ <- lists:seq(1, 60)],
{ok, Overloads} = collect(Pids, 0),
ct:log("Overloads: ~B", [Overloads]),
true = Overloads > 0.

0 comments on commit bf74541

Please sign in to comment.