Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: jlouis-more-r-…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 51 lines (42 sloc) 1.649 kb
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
#!/usr/bin/env escript
%% -*- erlang -*-
%%! +K true

-mode(compile).

main([LogFile, SecondsStr, Server, PortStr, ClientsStr]) ->
    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),
    spawn(fun() -> report_loop(erlang:now(), Seconds) end),

    {ok, _} = wsdemo_stats:start_link(Server, Port, Clients),
    io:format("Running~n", []),
    timer:sleep(timer:seconds(Seconds)),
    io:format("Finished~n", []),
    wsdemo_logger:close(),
    ok;
main([LogFile, SecondsStr, ClientsStr]) ->
    main([LogFile, SecondsStr, "localhost", "8000", ClientsStr]);
main(_) ->
    usage().

usage() ->
    io:format("usage: ~n"
     "runtest LogFile::string() Seconds::integer() ClientCount::integer() | ~n"
     "runtest LogFile::string() Seconds::integer() Server::string() Port::integer() ClientCount::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.
Something went wrong with that request. Please try again.