Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
4  ct/test.config
@@ -8,8 +8,8 @@
8 8
                   {concurrency, 3}
9 9
 	]},
10 10
      {test_queue_1_codel, [
11  
-     		{hz, 1000},
12  
-     		{rate, 5},
  11
+     		{hz, 200},
  12
+     		{rate, 1},
13 13
      		{token_limit, 15},
14 14
      		{size, 60},
15 15
      		{concurrency, 3},
6  src/sv.erl
@@ -2,6 +2,8 @@
2 2
 
3 3
 -export([timestamp/0]).
4 4
 -export([run/2]).
  5
+%% Internal API
  6
+-export([report/2]).
5 7
 
6 8
 %% @doc Enqueue a job on a queue
7 9
 %% <p>Try to run `Fun' on queue `Name'. The `Fun' is run at time `TP'.
@@ -30,6 +32,10 @@ run(Name, Fun) ->
30 32
             {error, Reason}
31 33
     end.
32 34
 
  35
+%% @private
  36
+report(_T, _Event) ->
  37
+    hopefully_traced.
  38
+
33 39
 %% @doc Construct a timestamp in a canonical way for Safetyvalve.
34 40
 -spec timestamp() -> term().
35 41
 timestamp() ->
2  src/sv_codel.erl
@@ -132,10 +132,12 @@ control_law(T, I, C) ->
132 132
 dodequeue(Now, #state { queue = Q } = State) ->
133 133
   case ?Q:out(Now, Q) of
134 134
     {empty, [], NQ} ->
  135
+      sv:report(Now div 1000, {dodequeue, 0, 0}),
135 136
       {nodrop, empty, State#state { first_above_time = 0, queue = NQ }};
136 137
     {{Pkt, InT}, [], NQ} ->
137 138
       Sojourn = Now - InT,
138 139
       
  140
+      sv:report(Now div 1000, {dodequeue, ?Q:len(NQ), Sojourn div 1000}),
139 141
       dodequeue_(Now, Pkt, Sojourn, State#state { queue = NQ })
140 142
   end.
141 143
 
53  src/sv_tracer.erl
... ...
@@ -0,0 +1,53 @@
  1
+-module(sv_tracer).
  2
+
  3
+-behaviour(gen_server).
  4
+
  5
+-export([start_link/1, stop/0]).
  6
+-export([init/1, handle_call/3, handle_cast/2, terminate/2, handle_info/2, code_change/3]).
  7
+
  8
+-export([write_event/2]).
  9
+
  10
+-record(state, { fd, tracer }).
  11
+
  12
+start_link(Filename) ->
  13
+    gen_server:start_link({local, ?MODULE}, ?MODULE, [Filename], []).
  14
+    
  15
+stop() ->
  16
+    gen_server:call(?MODULE, stop).
  17
+    
  18
+write_event({trace, _Pid, call, {sv, report, [Now, {dodequeue, QSize, Sojourn}]}, _}, {Start, Fd}) ->
  19
+    file:write(Fd, [integer_to_list(Now - Start), $,, integer_to_list(QSize), $,, integer_to_list(Sojourn), $\n]),
  20
+    {Start, Fd}.
  21
+
  22
+%% Callbacks
  23
+init([Filename]) ->
  24
+	{ok, Fd} = file:open(Filename, [write, binary, delayed_write]),
  25
+	file:write(Fd, header()),
  26
+	T = sv:timestamp(),
  27
+         {ok, Tracer} = dbg:tracer(process, {fun write_event/2, {T div 1000, Fd}}),
  28
+         dbg:p(all, [c]),
  29
+         dbg:tp(sv, report, 2, c),
  30
+	{ok, #state { fd = Fd,  tracer = Tracer}}.
  31
+	
  32
+handle_call(stop, _From, State) ->
  33
+    {stop, normal, ok, State}.
  34
+    
  35
+handle_cast(Cast, State) ->
  36
+    lager:error("Unknown cast: ~p", [Cast]),
  37
+    {noreply, State}.
  38
+    
  39
+
  40
+handle_info(Info, State) ->
  41
+    lager:error("Unknown info: ~p", [Info]),
  42
+    {noreply, State}.
  43
+    
  44
+terminate(_Reason, #state { fd = Fd }) ->
  45
+    file:close(Fd),
  46
+    dbg:stop_clear(),
  47
+    ok.
  48
+
  49
+code_change(_OldVsn, State, _Aux) ->
  50
+    {ok, State}.
  51
+
  52
+header() ->
  53
+    ["Time, QSize, Sojourn\n"].
10  test/sv_SUITE.erl
@@ -30,6 +30,9 @@ end_per_suite(_Config) ->
30 30
         App <- lists:reverse([syntax_tools, compiler, lager, safetyvalve])],
31 31
     ok.
32 32
 
  33
+init_per_testcase(many_through_codel, Config) ->
  34
+    sv_tracer:start_link(filename:join(?config(priv_dir, Config), "trace.out")),
  35
+    Config;
33 36
 init_per_testcase(not_applicable, Config) ->
34 37
     dbg:tracer(),
35 38
     dbg:tpl({sv_queue_ets, in, 2}, cx),
@@ -39,6 +42,9 @@ init_per_testcase(not_applicable, Config) ->
39 42
 init_per_testcase(_Case, Config) ->
40 43
     Config.
41 44
 
  45
+end_per_testcase(many_through_codel, _Config) ->
  46
+    sv_tracer:stop(),
  47
+    ok;
42 48
 end_per_testcase(not_applicable, _Config) ->
43 49
     dbg:stop(),
44 50
     ok;
@@ -71,7 +77,7 @@ many_through_ets(_Config) ->
71 77
     	    {ok, ok} -> Parent ! {done, self()};
72 78
     	    {error, overload} -> Parent ! {overload, self()}
73 79
     	end
74  
-      end) || _ <- lists:seq(1, 20)],
  80
+      end) || _ <- lists:seq(1, 60)],
75 81
     {ok, Overloads} = collect(Pids, 0),
76 82
     ct:log("Overloads: ~B", [Overloads]),
77 83
     true = Overloads == 0.
@@ -83,7 +89,7 @@ many_through_codel(_Config) ->
83 89
             {ok, ok} -> Parent ! {done, self()};
84 90
             {error, overload} -> Parent ! {overload, self()}
85 91
         end
86  
-      end) || _ <- lists:seq(1, 20)],
  92
+      end) || _ <- lists:seq(1, 60)],
87 93
     {ok, Overloads} = collect(Pids, 0),
88 94
     ct:log("Overloads: ~B", [Overloads]),
89 95
     true = Overloads > 0.

No commit comments for this range

Something went wrong with that request. Please try again.