Permalink
Browse files

-add function for Debug message only (not executed unless compiled wi…

…th -DDEBUG)

-no more ts_profile (useless)
+ other fixes

SVN Revision: 184
  • Loading branch information...
1 parent 074e6f3 commit 8ac455b46c6829645dd6350017ee659fc16aedad @nniclausse nniclausse committed Jan 15, 2004
View
@@ -66,16 +66,21 @@
%% errors messages
--define(DEBUG, TRUE).
+-define(LOGF(Msg, Args, Level),
+ ts_utils:debug(?MODULE, Msg, Args, Level)).
+-define(LOG(Msg, Level),
+ ts_utils:debug(?MODULE, Msg, Level)).
+
+%% Debug messages can be completely disabled if DEBUG is not defined
-ifdef(DEBUG).
- -define(LOGF(Msg, Args, Level),
- ts_utils:debug(?MODULE, Msg, Args, Level)).
- -define(LOG(Msg, Level),
- ts_utils:debug(?MODULE, Msg, Level)).
+ -define(DebugF(Msg, Args),
+ ts_utils:debug(?MODULE, Msg, Args, ?DEB)).
+ -define(Debug(Msg),
+ ts_utils:debug(?MODULE, Msg, ?DEB)).
-else.
- -define(LOGF(Msg, Args, Level), ok).
- -define(LOG(Msg, Level), ok).
+ -define(DebugF(Msg, Args), ok).
+ -define(Debug(Msg), ok).
-endif.
-define(EMERG, 0). % The system is unusable.
View
@@ -59,17 +59,17 @@
%% Start a new session
start(Opts) ->
- ?LOGF("Starting with opts: ~p~n",[Opts],?DEB),
+ ?DebugF("Starting with opts: ~p~n",[Opts]),
gen_fsm:start_link(?MODULE, Opts, []).
%%----------------------------------------------------------------------
%% Func: close/1
%% Purpose: the connection was closed by the server
%%----------------------------------------------------------------------
%% close after an error, send_all_state
-close({Reason, Pid}) when atom(Reason) ->
+close({Reason, Pid}) when is_atom(Reason) ->
gen_fsm:send_all_state_event(Pid, {closed, Reason, Pid});
-close({Reason, Pid}) when list(Reason) ->
+close({Reason, Pid}) when is_list(Reason) ->
gen_fsm:send_all_state_event(Pid, {closed, list_to_atom(Reason), Pid});
close({Reason, Pid}) ->
gen_fsm:send_all_state_event(Pid, {closed, close_unknown, Pid});
@@ -103,15 +103,15 @@ init({Session=#session{id = Profile,
persistent = Persistent,
messages_ack = PType,
type = CType}, Count, IP}) ->
- ?LOGF("Init ... started with count = ~p ~n",[Count],?DEB),
- %%init seed
- %% random:seed(ts_utils:init_seed()),
+ ?DebugF("Init ... started with count = ~p ~n",[Count]),
+ ts_utils:init_seed(),
{ServerName, Port, Protocol} = get_server_cfg({Profile,1}),
-
+ ?DebugF("Get dynparams for ~p ~n",[CType]),
+ Dyndata = CType:init_dynparams(),
% open connection
Opts = protocol_options(Protocol) ++ [{ip, IP}],
- ?LOGF("Got first message, connect to ~p with options ~p ~n",
- [{ServerName, Port, Protocol},Opts],?DEB),
+ ?DebugF("Got first message, connect to ~p with options ~p ~n",
+ [{ServerName, Port, Protocol},Opts]),
StartTime= now(),
case Protocol:connect(ServerName, Port, Opts, ?config(connect_timeout)) of
{ok, Socket} ->
@@ -123,7 +123,7 @@ init({Session=#session{id = Profile,
PType,
?config(monitoring)}) of
{ok, Pid} ->
- ?LOG("rcv server started ~n",?DEB),
+ ?Debug("rcv server started ~n"),
controlling_process(Protocol, Socket, Pid),
Connected = now(),
Elapsed = ts_utils:elapsed(StartTime, Connected),
@@ -139,15 +139,15 @@ init({Session=#session{id = Profile,
monitor = ?config(monitoring),
count = Count,
ip = IP,
- maxcount = Count
+ maxcount = Count,
+ dyndata = Dyndata
}};
{error, Reason} ->
- ?LOGF("Can't start rcv process ~p~n",
- [Reason],?ERR),
+ ?LOGF("Can't start rcv process ~p~n", [Reason],?ERR),
{stop, Reason}
end;
{error, Reason} ->
- ?LOGF("Connect Error: ~p~n",[Reason],?ERR),
+ ?LOGF("Connect Error: ~p~n",[Reason], ?ERR),
CountName="conn_err_" ++ atom_to_list(Reason),
ts_mon:add({ count, list_to_atom(CountName) }),
{stop, normal}
@@ -188,11 +188,11 @@ handle_sync_event(Event, From, StateName, StateData) ->
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
wait_ack({next_msg, DynData}, State) ->
- ?LOGF("next_msg, count is ~p~n", [State#state.count], ?DEB),
+ ?DebugF("next_msg, count is ~p~n", [State#state.count]),
NewState = State#state{dyndata=DynData},
handle_next_action(NewState);
wait_ack({next_msg, DynData, Close}, State) ->
- ?LOGF("next_msg, count is ~p, close is ~p~n", [State#state.count, Close], ?DEB),
+ ?DebugF("next_msg, count is ~p, close is ~p~n", [State#state.count, Close]),
case Close of
true ->
NewState = State#state{dyndata=DynData, socket=none};
@@ -272,7 +272,7 @@ handle_info(timeout, StateName, State ) ->
ts_mon:add({ count, timeout }),
{stop, normal, State};
handle_info(Msg, StateName, State ) ->
- ?LOGF("Error: Unkonwn msg receive in state ~p, stop ~p~n", [Msg,StateName], ?ERR),
+ ?LOGF("Error: Unknown msg ~p receive in state ~p, stop~n", [Msg,StateName], ?ERR),
ts_mon:add({ count, unknown_msg }),
{stop, normal, State}.
@@ -312,7 +312,7 @@ handle_next_action(State) ->
Count = State#state.count-1,
case set_profile(State#state.maxcount,State#state.count,State#state.profile) of
{thinktime, Think} ->
- ?LOGF("Starting new thinktime ~p~n", [Think], ?DEB),
+ ?DebugF("Starting new thinktime ~p~n", [Think]),
set_thinktime(Think),
{next_state, think, State#state{count=Count}};
{transaction, start, Tname} ->
@@ -350,7 +350,7 @@ get_server_cfg({Profile, Id}) ->
%% Func: get_server_cfg/3
%%----------------------------------------------------------------------
get_server_cfg(#message{host=undefined, port=undefined, scheme=undefined},P,_)->
- ?LOG("Server not configured in msg, get global conf ~n", ?DEB),
+ ?Debug("Server not configured in msg, get global conf ~n"),
%% get global server profile
ts_config_server:get_server_config();
get_server_cfg(#message{host=ServerName, port= Port, scheme= Protocol},P,Id) ->
@@ -378,9 +378,9 @@ handle_next_request(Profile, State) ->
[] ->
Param = Profile#message.param;
DynData -> % add dynamic info (cookie for ex.) to request parameters
- Param = ts_profile:add_dynparams(Type, Profile#message.param, DynData)
+ Param = Type:add_dynparams(Profile#message.param, DynData)
end,
- Message = ts_profile:get_message(Type , Param),
+ Message = Type:get_message(Param),
Now = now(),
%% does the next message change the server setup ?
@@ -394,7 +394,7 @@ handle_next_request(Profile, State) ->
{Host, Port, Protocol} -> % server setup unchanged
Socket = State#state.socket;
_ ->
- ?LOG("Change server configuration inside a session ~n",?DEB),
+ ?Debug("Change server configuration inside a session ~n"),
ts_utils:close_socket(State#state.protocol, State#state.socket),
Socket = none
end
@@ -421,15 +421,16 @@ handle_next_request(Profile, State) ->
handle_close_while_sending(State);
{error, Reason} ->
?LOGF("Error: Unable to send data, reason: ~p~n",[Reason],?ERR),
- CountName="send_err_"++atom_to_list(Reason),
+ CountName="error_send_"++atom_to_list(Reason),
ts_mon:add({ count, list_to_atom(CountName) }),
{stop, normal, State};
{'EXIT', {noproc, _Rest}} ->
handle_close_while_sending(State);
Exit ->
?LOGF("EXIT Error: Unable to send data, reason: ~p~n",
[Exit], ?ERR),
- {stop, senderror, State}
+ ts_mon:add({ count, error_send }),
+ {stop, normal, State}
end;
_Error ->
{stop, normal, State} %% already log in reconnect
@@ -465,7 +466,7 @@ handle_close_while_sending(State) ->
%% Func: set_profile/2
%% Args: MaxCount, Count (integer), ProfileId (integer)
%%----------------------------------------------------------------------
-set_profile(MaxCount, Count, ProfileId) when integer(ProfileId) ->
+set_profile(MaxCount, Count, ProfileId) when is_integer(ProfileId) ->
ts_session_cache:get_req(ProfileId, MaxCount-Count+1).
%%----------------------------------------------------------------------
@@ -485,7 +486,7 @@ new_timeout(_Else, _Count, Thinktime) -> infinity.
%% purpose: try to reconnect if this is needed (when the socket is set to none)
%%----------------------------------------------------------------------
reconnect(none, ServerName, Port, Protocol, IP, Pid) ->
- ?LOGF("Try to reconnect to: ~p (~p)~n",[ServerName, Pid], ?DEB),
+ ?DebugF("Try to reconnect to: ~p (~p)~n",[ServerName, Pid]),
Opts = protocol_options(Protocol) ++ [{ip, IP}],
case Protocol:connect(ServerName, Port, Opts) of
{ok, Socket} ->
@@ -557,4 +558,5 @@ set_thinktime({random, Think}) ->
set_thinktime(Think) ->
%% dot not use timer:send_after because it does not scale well:
%% http://www.erlang.org/ml-archive/erlang-questions/200202/msg00024.html
+ ?DebugF("thinktime of ~p~n",[Think]),
erlang:start_timer(Think, self(), end_thinktime ).
View
@@ -60,7 +60,7 @@ wait_ack({Pid, Ack, When, EndPage, Socket, Protocol}) ->
init([{CType, PPid, Socket, Protocol, Timeout, Ack, Monitor}]) ->
{ok, #state_rcv{socket = Socket, timeout= Timeout, ack = Ack,
ppid= PPid, clienttype = CType, protocol= Protocol,
- session = ts_profile:new_session(CType, Ack),
+ session = CType:new_session(),
monitor = Monitor }}.
%%----------------------------------------------------------------------
@@ -86,7 +86,7 @@ handle_call(Request, From, State) ->
%% ack value -> wait
handle_cast({wait_ack, Ack, When, EndPage, Socket, Protocol}, State) ->
- ?LOGF("receive wait_ack: ~p , endpage=~p~n",[Ack, EndPage], ?DEB),
+ ?DebugF("receive wait_ack: ~p , endpage=~p~n",[Ack, EndPage]),
case State#state_rcv.page_timestamp of
0 -> %first request of a page
NewPageTimestamp = When;
@@ -159,6 +159,7 @@ handle_info(timeout, State) ->
{noreply, State};
handle_info(Data, State) ->%% test if client implement parse ?
+ ?LOGF("Unknown data received ~p~n",[Data], ?WARN),
{NewState, Opts} = handle_data_msg(Data, State),
Socket = NewState#state_rcv.socket,
ts_utils:inet_setopts(State#state_rcv.protocol, Socket,
@@ -187,17 +188,17 @@ handle_data_msg(Data, State=#state_rcv{ack=no_ack}) ->
ts_mon:rcvmes({State#state_rcv.monitor, self(), Data}),
{State, []};
-handle_data_msg(Data, State=#state_rcv{ack=parse}) ->
+handle_data_msg(Data, State=#state_rcv{ack=parse, clienttype=Type}) ->
ts_mon:rcvmes({State#state_rcv.monitor, self(), Data}),
- {NewState, Opts, Close} =
- ts_profile:parse(State#state_rcv.clienttype, Data, State),
+
+ {NewState, Opts, Close} = Type:parse(Data, State),
case NewState#state_rcv.ack_done of
true ->
- ?LOGF("Response done:~p~n", [NewState#state_rcv.datasize], ?DEB),
+ ?DebugF("Response done:~p~n", [NewState#state_rcv.datasize]),
PageTimeStamp = update_stats(NewState, Close),
case Close of
true ->
- ?LOG("Close connection required by protocol~n", ?DEB),
+ ?Debug("Close connection required by protocol~n"),
ts_utils:close_socket(State#state_rcv.protocol,State#state_rcv.socket),
{NewState#state_rcv{endpage = false, % reinit in case of
page_timestamp = PageTimeStamp,
@@ -207,7 +208,7 @@ handle_data_msg(Data, State=#state_rcv{ack=parse}) ->
page_timestamp = PageTimeStamp}, Opts}
end;
_ ->
- ?LOGF("Response: continue:~p~n",[NewState#state_rcv.datasize],?DEB),
+ ?DebugF("Response: continue:~p~n",[NewState#state_rcv.datasize]),
{NewState, Opts}
end;
@@ -235,9 +236,8 @@ handle_data_msg(Data, State=#state_rcv{ack_done=false}) ->
update_stats(State, Close) ->
Now = now(),
Elapsed = ts_utils:elapsed(State#state_rcv.ack_timestamp, Now),
-% Stats= [{ sample, response_time, Elapsed},
-% { sum, size, State#state_rcv.datasize}],
- Stats=[],
+ Stats= [{ sample, response_time, Elapsed},
+ { sum, size, State#state_rcv.datasize}],
case State#state_rcv.endpage of
true -> % end of a page, compute page reponse time
PageElapsed = ts_utils:elapsed(State#state_rcv.page_timestamp, Now),
@@ -246,7 +246,7 @@ update_stats(State, Close) ->
State#state_rcv.dyndata, Close),
0;
_ ->
-% ts_mon:add(Stats),
+ ts_mon:add(Stats),
doack(State#state_rcv.ack, State#state_rcv.ppid,
State#state_rcv.dyndata, Close),
State#state_rcv.page_timestamp
View
@@ -66,6 +66,10 @@ init([]) ->
{ts_client,{ts_client, start, []},
temporary,2000,worker,[ts_client]}
],
+% fprof:start(),
+% Res = fprof:trace(start, "/tmp/tsunami.fprof"),
+% ?LOGF("starting profiler: ~p~n",[Res], ?WARN),
+
{ok, {SupFlags, ChildSpec}}.
View
@@ -37,7 +37,8 @@
-export([read/1,
getAttr/2,
getAttr/3,
- parse/2
+ parse/2,
+ get_default/3
]).
%%%----------------------------------------------------------------------
@@ -135,9 +136,10 @@ parse(Element = #xmlElement{name=ip},
parse(Element = #xmlElement{name=arrivalphase},
Conf = #config{arrivalphases=AList}) ->
- Phase = getAttr(Element#xmlElement.attributes, phase),
+ PhaseStr = getAttr(Element#xmlElement.attributes, phase),
+ {ok, [{integer,1,Phase}],1} = erl_scan:string(PhaseStr),
Duration = getAttr(Element#xmlElement.attributes, duration),
- Unit = getAttr(Element#xmlElement.attributes, duration, "seconds"),
+ Unit = getAttr(Element#xmlElement.attributes, unit, "second"),
{ok, [{integer,1,IDuration}],1} = erl_scan:string(Duration),
D = to_seconds(Unit, IDuration),
lists:foldl(fun parse/2,
@@ -151,16 +153,21 @@ parse(Element = #xmlElement{name=arrivalphase},
parse(Element = #xmlElement{name=users},
Conf = #config{arrivalphases=[CurA | AList]}) ->
- MaxVal = getAttr(Element#xmlElement.attributes, maxnumber, infinity),
- ?LOGF("Maximum number of users ~p~n",[MaxVal],?INFO),
- {ok, [{integer,1,MaxNumber}],1} = erl_scan:string(MaxVal),
+ MaxNumber = case getAttr(Element#xmlElement.attributes, maxnumber, infinity) of
+ infinity ->
+ infinity;
+ Val ->
+ {ok, [{integer,1,Max}],1} = erl_scan:string(Val),
+ Max
+ end,
+ ?LOGF("Maximum number of users ~p~n",[MaxNumber],?INFO),
InterArrival =
case erl_scan:string(getAttr(Element#xmlElement.attributes, interarrival)) of
{ok, [{integer,1,I}],1} -> I;
{ok, [{float,1,F}],1} -> F
end,
- Unit = getAttr(Element#xmlElement.attributes, duration, "seconds"),
+ Unit = getAttr(Element#xmlElement.attributes, unit, "second"),
Intensity= 1/(1000 * to_seconds(Unit,InterArrival)),
lists:foldl(fun parse/2,
@@ -340,3 +347,12 @@ to_seconds("millisecond", Val)-> Val/1000.
build_list(String) -> build_list(String, "%").
build_list(String, Sep) ->
string:tokens(String, Sep).
+
+%%
+get_default(Tab, Key,ConfigName) ->
+ case ets:lookup(Tab,{Key, value}) of
+ [] ->
+ ?config(ConfigName);
+ [{_Key, SName}] ->
+ SName
+ end.
Oops, something went wrong.

0 comments on commit 8ac455b

Please sign in to comment.