-
Notifications
You must be signed in to change notification settings - Fork 58
/
runtest
executable file
·57 lines (46 loc) · 1.68 KB
/
runtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env escript
%% -*- erlang -*-
%%! +K true
-mode(compile).
main([LogFile, ClientsStr, SecondsStr]) ->
main([LogFile, "localhost", "8000", ClientsStr, SecondsStr]);
main([LogFile, Server, PortStr, ClientsStr, SecondsStr]) ->
Port = list_to_integer(PortStr),
Clients = list_to_integer(ClientsStr),
Seconds = list_to_integer(SecondsStr),
code:add_paths([
"deps/eleveldb/ebin",
"ebin"]),
io:format("Running test with ~p clients for ~p seconds~n"
"Data File: ~p~n",
[Clients, Seconds, LogFile]),
{ok, _} = wsdemo_logger:start_link(LogFile),
{ok, _} = wsdemo_stats:start_link(Server, Port, Clients),
spawn(fun() ->
report_loop(now(), Seconds)
end),
erlang:send_after(timer:seconds(Seconds), self(), done),
receive
done ->
wsdemo_stats:stop(),
wsdemo_logger:close(),
done
end;
main(_) ->
usage().
usage() ->
io:format("usage: ~n"
"runtest LogFile::string() ClientCount::integer() Seconds::integer() | ~n"
"runtest LogFile::string() Server::string() Port::integer() ClientCount::integer() Seconds::integer()~n", []).
report_loop(Start, Seconds) ->
case whereis(wsdemo_logger) of
undefined ->
timer:sleep(10),
report_loop(Start, Seconds);
Pid ->
Elapsed = trunc(timer:now_diff(erlang:now(), Start) / 1000000),
{message_queue_len, Len} = process_info(Pid, message_queue_len),
io:format("logger queue: ~w Elapsed: ~ws of ~ws ~n", [Len,Elapsed, Seconds]),
timer:sleep(30000),
report_loop(Start, Seconds)
end.