Skip to content
Browse files

put macros in a separated header file; add NOW macro

  • Loading branch information...
1 parent b34e756 commit 583ea5e3defde2f6c3df6df489cd28a62ee883d7 @nniclausse nniclausse committed Aug 22, 2012
Showing with 160 additions and 124 deletions.
  1. +2 −0 include/ts_config.hrl
  2. +74 −0 include/ts_macros.hrl
  3. +1 −51 include/ts_profile.hrl
  4. +13 −13 src/tsung/ts_client.erl
  5. +1 −1 src/tsung/ts_client_sup.erl
  6. +1 −1 src/tsung/ts_cport.erl
  7. +1 −0 src/tsung/ts_fs.erl
  8. +1 −0 src/tsung/ts_http.erl
  9. +1 −2 src/tsung/ts_ip_scan.erl
  10. +1 −0 src/tsung/ts_jabber.erl
  11. +1 −0 src/tsung/ts_jabber_common.erl
  12. +3 −2 src/tsung/ts_job.erl
  13. +9 −8 src/tsung/ts_launcher.erl
  14. +1 −0 src/tsung/ts_launcher_mgr.erl
  15. +2 −2 src/tsung/ts_launcher_static.erl
  16. +1 −0 src/tsung/ts_ldap.erl
  17. +1 −1 src/tsung/ts_mon_cache.erl
  18. +1 −0 src/tsung/ts_mysql.erl
  19. +1 −0 src/tsung/ts_pgsql.erl
  20. +1 −0 src/tsung/ts_search.erl
  21. +1 −1 src/tsung/ts_session_cache.erl
  22. +1 −1 src/tsung/ts_sup.erl
  23. +6 −2 src/tsung/ts_utils.erl
  24. +1 −1 src/tsung/tsung.erl
  25. +1 −1 src/tsung_controller/ts_config.erl
  26. +3 −3 src/tsung_controller/ts_config_server.erl
  27. +1 −1 src/tsung_controller/ts_controller_sup.erl
  28. +0 −1 src/tsung_controller/ts_file_server.erl
  29. +4 −4 src/tsung_controller/ts_job_notify.erl
  30. +0 −1 src/tsung_controller/ts_match_logger.erl
  31. +8 −9 src/tsung_controller/ts_mon.erl
  32. +1 −1 src/tsung_controller/ts_msg_server.erl
  33. +1 −1 src/tsung_controller/ts_os_mon.erl
  34. +1 −1 src/tsung_controller/ts_os_mon_erlang.erl
  35. +1 −1 src/tsung_controller/ts_os_mon_munin.erl
  36. +1 −1 src/tsung_controller/ts_os_mon_snmp.erl
  37. +1 −1 src/tsung_controller/ts_os_mon_sup.erl
  38. +0 −1 src/tsung_controller/ts_stats_mon.erl
  39. +1 −1 src/tsung_controller/ts_timer.erl
  40. +1 −1 src/tsung_controller/ts_user_server.erl
  41. +1 −1 src/tsung_controller/tsung_controller.erl
  42. +1 −1 src/tsung_recorder/ts_client_proxy.erl
  43. +1 −1 src/tsung_recorder/ts_client_proxy_sup.erl
  44. +1 −1 src/tsung_recorder/ts_proxy_http.erl
  45. +1 −1 src/tsung_recorder/ts_proxy_listener.erl
  46. +1 −1 src/tsung_recorder/ts_proxy_pgsql.erl
  47. +1 −1 src/tsung_recorder/ts_proxy_recorder.erl
  48. +1 −1 src/tsung_recorder/ts_recorder_sup.erl
  49. +1 −1 src/tsung_recorder/tsung_recorder.erl
View
2 include/ts_config.hrl
@@ -27,6 +27,8 @@
-vc('$Id$ ').
-author('nicolas.niclausse@niclux.org').
+-include("ts_macros.hrl").
+
-define(TSUNGPATH, "TSUNGPATH").
-define(SESSION_POP_ERROR_MSG, "Total sum of session popularity is not equal to 100").
View
74 include/ts_macros.hrl
@@ -0,0 +1,74 @@
+%%%
+%%% Copyright 2012 © nicolas niclausse
+%%%
+%%% Author : Nicolas Niclausse <nicolas@niclux.org>
+%%% Created: 22 août 2012 by Nicolas Niclausse <nicolas@niclux.org>
+%%%
+%%% This program is free software; you can redistribute it and/or modify
+%%% it under the terms of the GNU General Public License as published by
+%%% the Free Software Foundation; either version 2 of the License, or
+%%% (at your option) any later version.
+%%%
+%%% This program is distributed in the hope that it will be useful,
+%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+%%% GNU General Public License for more details.
+%%%
+%%% You should have received a copy of the GNU General Public License
+%%% along with this program; if not, write to the Free Software
+%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+%%%
+
+-vc('$Id: ts_macros.hrl,v 0.0 2012/08/22 09:07:50 nniclaus Exp $ ').
+-author('nniclaus@sophia.inria.fr').
+
+-define(NOW, now()).
+
+-define(CRLF, "\r\n").
+-define(CR,13).
+-define(LF,10).
+
+%% retry sending message after this timeout (in microsec.)
+-define(config(Var), ts_utils:get_val(Var)).
+
+%% errors messages
+
+-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(TRACE, [{debug, [trace]}]).
+ -define(DebugF(Msg, Args),
+ ts_utils:debug(?MODULE, Msg, Args, ?DEB)).
+ -define(Debug(Msg),
+ ts_utils:debug(?MODULE, Msg, ?DEB)).
+-else.
+ -define(TRACE, []).
+ -define(DebugF(Msg, Args), ok).
+ -define(Debug(Msg), ok).
+-endif.
+
+-define(EMERG, 0). % The system is unusable.
+-define(ALERT, 1). % Action should be taken immediately to address the problem.
+-define(CRIT, 2). % A critical condition has occurred.
+-define(ERR, 3). % An error has occurred.
+-define(WARN, 4). % A significant event that may require attention has occurred.
+-define(NOTICE, 5).% An event that does not affect system operation has occurred.
+-define(INFO, 6). % An normal operation has occurred.
+-define(DEB, 7). % Debugging info
+
+-define(TIMEOUT_PARALLEL_SPAWN, 60000).
+-define(MAX_PHASE_EXCEED_PERCENT, 20).
+-define(MAX_PHASE_EXCEED_NUSERS, 10).
+
+
+-define(restart_sleep, 2000).
+-define(infinity_timeout, 15000).
+-define(config_timeout, 60000).
+-define(check_noclient_timeout, 60000).
+-define(retries, 4).
+
+
View
52 include/ts_profile.hrl
@@ -72,8 +72,8 @@
last_packet_date = 0,
current_size = 0
}).
-
-define(size_mon_thresh, 524288). % 512KB
+-define(short_timeout, 1).
% state of ts_client gen_server
-record(state_rcv,
@@ -116,14 +116,6 @@
}).
--define(restart_sleep, 2000).
--define(infinity_timeout, 15000).
--define(short_timeout, 1).
--define(config_timeout, 60000).
--define(check_noclient_timeout, 60000).
--define(retries, 4).
-
-
-record(launcher,
{nusers,
phases =[],
@@ -141,46 +133,4 @@
}).
--define(TIMEOUT_PARALLEL_SPAWN, 60000).
--define(MAX_PHASE_EXCEED_PERCENT, 20).
--define(MAX_PHASE_EXCEED_NUSERS, 10).
-
--define(CRLF, "\r\n").
--define(CR,13).
--define(LF,10).
-
-%% retry sending message after this timeout (in microsec.)
--define(config(Var), ts_utils:get_val(Var)).
-
--define(messages_intensity, 1/(ts_utils:get_val(messages_interarrival)*1000)).
--define(clients_intensity, 1/(ts_utils:get_val(interarrival)*1000)).
-
-
-%% errors messages
-
--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(TRACE, [{debug, [trace]}]).
- -define(DebugF(Msg, Args),
- ts_utils:debug(?MODULE, Msg, Args, ?DEB)).
- -define(Debug(Msg),
- ts_utils:debug(?MODULE, Msg, ?DEB)).
--else.
- -define(TRACE, []).
- -define(DebugF(Msg, Args), ok).
- -define(Debug(Msg), ok).
--endif.
--define(EMERG, 0). % The system is unusable.
--define(ALERT, 1). % Action should be taken immediately to address the problem.
--define(CRIT, 2). % A critical condition has occurred.
--define(ERR, 3). % An error has occurred.
--define(WARN, 4). % A significant event that may require attention has occurred.
--define(NOTICE, 5).% An event that does not affect system operation has occurred.
--define(INFO, 6). % An normal operation has occurred.
--define(DEB, 7). % Debugging info
View
26 src/tsung/ts_client.erl
@@ -34,8 +34,8 @@
%%% to the client at anytime (full bidirectional protocol, as jabber
%%% for ex)
--include("ts_profile.hrl").
-include("ts_config.hrl").
+-include("ts_profile.hrl").
-define(MAX_RETRIES,3). % max number of connection retries
-define(RETRY_TIMEOUT,10000). % waiting time between retries (msec)
@@ -105,7 +105,7 @@ init(#session{ id = SessionId,
NewDynVars = ts_dynvars:set(tsung_userid,Id,
DynData#dyndata.dynvars),
NewDynData = DynData#dyndata{dynvars=NewDynVars},
- StartTime= now(),
+ StartTime= ?NOW,
set_thinktime(?short_timeout),
?DebugF("IP param: ~p~n",[IP]),
NewIP = case IP of
@@ -212,8 +212,8 @@ handle_info({NetEvent, _Socket, Data}, wait_ack, State=#state_rcv{rate_limit=Tok
undefined ->
undefined;
#token_bucket{rate=R,burst=Burst,current_size=S0, last_packet_date=T0} ->
- {S1,_Wait}=token_bucket(R,Burst,S0,T0,size(Data),now(),true),
- TokenParam#token_bucket{current_size=S1, last_packet_date=now()}
+ {S1,_Wait}=token_bucket(R,Burst,S0,T0,size(Data),?NOW,true),
+ TokenParam#token_bucket{current_size=S1, last_packet_date=?NOW}
end,
{NewState, Opts} = handle_data_msg(Data, State),
NewSocket = ts_utils:inet_setopts(NewState#state_rcv.protocol,
@@ -400,14 +400,14 @@ handle_next_action(State) ->
{next_state, think, State#state_rcv{count=Count}}
end;
{transaction, start, Tname} ->
- Now = now(),
+ Now = ?NOW,
?LOGF("Starting new transaction ~p (now~p)~n", [Tname,Now], ?INFO),
TrList = State#state_rcv.transactions,
NewState = State#state_rcv{transactions=[{Tname,Now}|TrList],
count=Count},
handle_next_action(NewState);
{transaction, stop, Tname} ->
- Now = now(),
+ Now = ?NOW,
?LOGF("Stopping transaction ~p (~p)~n", [Tname, Now], ?INFO),
TrList = State#state_rcv.transactions,
{value, {_, Tr}} = lists:keysearch(Tname, 1, TrList),
@@ -449,7 +449,7 @@ handle_next_action(State) ->
handle_next_action(NewState);
{set_option, undefined, rate_limit, {Rate, Burst}} ->
?LOGF("Set rate limits for client: rate=~p, burst=~p~n",[Rate,Burst],?DEB),
- RateConf=#token_bucket{rate=Rate,burst=Burst,last_packet_date=now()},
+ RateConf=#token_bucket{rate=Rate,burst=Burst,last_packet_date=?NOW},
Thresh=lists:min([Burst,State#state_rcv.size_mon_thresh]),
handle_next_action(State#state_rcv{size_mon=Thresh,size_mon_thresh=Thresh,rate_limit=RateConf,count=Count});
{set_option, Type, Name, Args} ->
@@ -701,7 +701,7 @@ handle_next_request(Request, State) ->
end,
{Message, NewSession} = Type:get_message(Param,State),
- Now = now(),
+ Now = ?NOW,
%% reconnect if needed
Proto = {Protocol,State#state_rcv.proto_opts},
@@ -785,7 +785,7 @@ size_msg({_Mod,_Fun,_Args,Size}) -> Size.
%% Args: State
%%----------------------------------------------------------------------
finish_session(State) ->
- Now = now(),
+ Now = ?NOW,
set_connected_status(false),
Elapsed = ts_utils:elapsed(State#state_rcv.starttime, Now),
case State#state_rcv.transactions of
@@ -856,10 +856,10 @@ reconnect(none, ServerName, Port, {Protocol, Proto_opts}, {IP,CPort, Try}) when
?DebugF("Try to (re)connect to: ~p:~p from ~p using protocol ~p~n",
[ServerName,Port,IP,Protocol]),
Opts = protocol_options(Protocol, Proto_opts) ++ socket_opts(IP, CPort, Protocol),
- Before= now(),
+ Before= ?NOW,
case connect(Protocol,ServerName, Port, Opts) of
{ok, Socket} ->
- Elapsed = ts_utils:elapsed(Before, now()),
+ Elapsed = ts_utils:elapsed(Before, ?NOW),
ts_mon:add({ sample, connect, Elapsed }),
set_connected_status(true),
?Debug("(Re)connected~n"),
@@ -1146,7 +1146,7 @@ set_connected_status(false, Old) when Old==undefined; Old==false ->
%% Purpose: update the statistics for no_ack requests
%%----------------------------------------------------------------------
update_stats_noack(#state_rcv{page_timestamp=PageTime,request=Request}) ->
- Now = now(),
+ Now = ?NOW,
Stats= [{ count, request_noack}], % count and not sample because response time is not defined in this case
case Request#ts_request.endpage of
true -> % end of a page, compute page reponse time
@@ -1165,7 +1165,7 @@ update_stats_noack(#state_rcv{page_timestamp=PageTime,request=Request}) ->
%% Purpose: update the statistics
%%----------------------------------------------------------------------
update_stats(State=#state_rcv{size_mon_thresh=T,page_timestamp=PageTime,send_timestamp=SendTime}) ->
- Now = now(),
+ Now = ?NOW,
Elapsed = ts_utils:elapsed(SendTime, Now),
Stats = case State#state_rcv.size_mon > T of
true ->
View
2 src/tsung/ts_client_sup.erl
@@ -28,7 +28,7 @@
-behaviour(supervisor).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%% External exports
-export([start_link/0, start_child/1, active_clients/0]).
View
2 src/tsung/ts_cport.erl
@@ -29,7 +29,7 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%% API
-export([start_link/1, get_port/2]).
View
1 src/tsung/ts_fs.erl
@@ -29,6 +29,7 @@
-behavior(ts_plugin).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_fs.hrl").
-include_lib("kernel/include/file.hrl").
View
1 src/tsung/ts_http.erl
@@ -28,6 +28,7 @@
-behavior(ts_plugin).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_http.hrl").
View
3 src/tsung/ts_ip_scan.erl
@@ -31,8 +31,7 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
--include("ts_config.hrl").
+-include("ts_macros.hrl").
%% API
-export([start_link/0, get_ip/1]).
View
1 src/tsung/ts_jabber.erl
@@ -32,6 +32,7 @@
-behavior(ts_plugin).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_jabber.hrl").
View
1 src/tsung/ts_jabber_common.erl
@@ -29,6 +29,7 @@
-export([ get_message/1
]).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_jabber.hrl").
View
5 src/tsung/ts_job.erl
@@ -29,6 +29,7 @@
-behaviour(ts_plugin).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_job.hrl").
-include_lib("kernel/include/file.hrl").
@@ -165,7 +166,7 @@ parse({os, cmd, _Args, Res},State=#state_rcv{session=S,dump=Dump}) when is_list(
case lists:last(Lines) of
"OAR_JOB_ID="++ID ->
?LOGF("OK,job id is ~p",[ID],?INFO),
- ts_job_notify:monitor({ID,self(),S#job_session.submission_time, now(),Dump}),
+ ts_job_notify:monitor({ID,self(),S#job_session.submission_time, ?NOW,Dump}),
{State#state_rcv{ack_done=true,datasize=length(Res)}, [], false};
_ ->
{State#state_rcv{ack_done=true,datasize=length(Res)}, [], false}
@@ -214,4 +215,4 @@ get_message(#job{type=oar,user=U,req=submit, name=N,script=S, resources=R, queue
++"\""++S++" "++D++"\"",
?LOGF("Will run ~p",[Cmd],?INFO),
Message = {os, cmd, [Cmd], length(Cmd) },
- {Message, Session#job_session{submission_time=now()}}.
+ {Message, Session#job_session{submission_time=?NOW}}.
View
17 src/tsung/ts_launcher.erl
@@ -33,6 +33,7 @@
-author('nicolas.niclausse@niclux.org').
-include("ts_profile.hrl").
+-include("ts_config.hrl").
% wait up to 10ms after an error
-define(NEXT_AFTER_FAILED_TIMEOUT, 10).
@@ -141,7 +142,7 @@ wait({launch, {[{Intensity, Users, Duration}| Rest], Max}, Seed}, State) ->
{next_state, launcher, State#launcher{phases = Rest, nusers = Users,
phase_nusers = Users,
phase_duration=Duration,
- phase_start = now(),
+ phase_start = ?NOW,
intensity = Intensity, maxusers=Max},
State#launcher.short_timeout};
wait({static,0}, State) ->
@@ -161,7 +162,7 @@ wait_static({static, Static}, State=#launcher{maxusers=Max,intensity=Intensity,
WarmTimeout = set_warm_timeout(StartDate)+round(ts_stats:exponential(Intensity)),
Warm = lists:min([WarmTimeout,?config(max_warm_delay)]),
?LOGF("Activate launcher (~p users) in ~p msec ~n",[Users, Warm], ?NOTICE),
- PhaseStart = ts_utils:add_time(now(), Warm div 1000),
+ PhaseStart = ts_utils:add_time(?NOW, Warm div 1000),
NewMax = case Max > Static of
true ->
Max-Static;
@@ -183,7 +184,7 @@ launcher(timeout, State=#launcher{nusers = Users,
phases = Phases,
started_users = Started,
intensity = Intensity}) ->
- BeforeLaunch = now(),
+ BeforeLaunch = ?NOW,
case do_launch({Intensity,State#launcher.myhostname}) of
{ok, Wait} ->
case check_max_raised(State) of
@@ -204,13 +205,13 @@ launcher(timeout, State=#launcher{nusers = Users,
nusers = NewUsers,
phase_nusers = NewUsers,
phase_duration=PhaseLength,
- phase_start = now(),
+ phase_start = ?NOW,
intensity = NewIntensity},
round(Wait)};
{stop} ->
{stop, normal, State};
{continue} ->
- Now=now(),
+ Now=?NOW,
LaunchDuration = ts_utils:elapsed(BeforeLaunch, Now),
%% to keep the rate of new users as expected,
%% remove the time to launch a client to the next
@@ -306,7 +307,7 @@ skip_empty_phase(State=#launcher{phases=Phases,phase_duration=Duration})->
nusers = NewUsers,
phase_nusers = NewUsers,
phase_duration=PhaseLength,
- phase_start = now(),
+ phase_start = ?NOW,
intensity = NewIntensity}, 1}
end.
@@ -354,7 +355,7 @@ change_phase(_N, _, _Current, {_Total, _}) ->
check_max_raised(State=#launcher{phases=Phases,maxusers=Max,nusers=Users,
started_users=Started, phase_start=Start, phase_duration=Duration,
intensity=Intensity}) when Started >= Max ->
- PendingDuration = Duration - ts_utils:elapsed(Start, now()),
+ PendingDuration = Duration - ts_utils:elapsed(Start, ?NOW),
ActiveClients = ts_client_sup:active_clients(),
?DebugF("Current active clients on beam: ~p (max is ~p)~n", [ActiveClients, State#launcher.maxusers]),
case ActiveClients >= Max of
@@ -397,7 +398,7 @@ do_launch({Intensity, MyHostName})->
end.
set_warm_timeout(StartDate)->
- case ts_utils:elapsed(now(), StartDate) of
+ case ts_utils:elapsed(?NOW, StartDate) of
WaitBeforeStart when WaitBeforeStart>0 ->
round(WaitBeforeStart);
_Neg ->
View
1 src/tsung/ts_launcher_mgr.erl
@@ -27,6 +27,7 @@
-vc('$Id: ts_launcher_mgr.erl,v 0.0 2009/12/09 11:54:33 nniclaus Exp $ ').
-author('nicolas.niclausse@niclux.org').
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-behaviour(gen_server).
View
4 src/tsung/ts_launcher_static.erl
@@ -123,7 +123,7 @@ wait({stop}, State) ->
{stop, normal, State}.
launcher(timeout, State=#state{ users = [{OldWait,Session}|Users]}) ->
- BeforeLaunch = now(),
+ BeforeLaunch = ?NOW,
?LOGF("Launch static user using session ~p ~n", [Session],?DEB),
do_launch({Session,State#state.myhostname}),
Wait = set_waiting_time(BeforeLaunch, Users, OldWait),
@@ -138,7 +138,7 @@ launcher(timeout, State=#state{ users = [{OldWait,Session}|Users]}) ->
set_waiting_time(_Before, [] , _Previous) -> 0; % last user
set_waiting_time(Before , [{Next,_}|_], Previous) ->
- LaunchDuration = ts_utils:elapsed(now(), Before),
+ LaunchDuration = ts_utils:elapsed(?NOW, Before),
%% to keep the rate of new users as expected, remove the time to
%% launch a client to the next wait.
NewWait = Next - Previous - LaunchDuration,
View
1 src/tsung/ts_ldap.erl
@@ -38,6 +38,7 @@
new_session/0
]).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_ldap.hrl").
-include("ELDAPv3.hrl").
View
2 src/tsung/ts_mon_cache.erl
@@ -54,7 +54,7 @@
-define(DUMP_STATS_INTERVAL, 500). % in milliseconds
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%%====================================================================
%% External functions
View
1 src/tsung/ts_mysql.erl
@@ -33,6 +33,7 @@
-behavior(ts_plugin).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_mysql.hrl").
View
1 src/tsung/ts_pgsql.erl
@@ -35,6 +35,7 @@
-behavior(ts_plugin).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
-include("ts_pgsql.hrl").
View
1 src/tsung/ts_search.erl
@@ -33,6 +33,7 @@
-export([subst/2, match/5, parse_dynvar/2]).
+-include("ts_macros.hrl").
-include("ts_profile.hrl").
%% @type dynvar() = {Key::atom(), Value::string()} | [].
View
2 src/tsung/ts_session_cache.erl
@@ -50,7 +50,7 @@
-define(DUMP_STATS_INTERVAL, 500). % in milliseconds
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%%====================================================================
%% External functions
View
2 src/tsung/ts_sup.erl
@@ -27,7 +27,7 @@
-vc('$Id$ ').
-author('nicolas.niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-behaviour(supervisor).
View
8 src/tsung/ts_utils.erl
@@ -26,7 +26,7 @@
-vc('$Id$ ').
-author('nicolas.niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%% to get file_info record definition
-include_lib("kernel/include/file.hrl").
@@ -120,7 +120,11 @@ debug(From, Message, Args, Level) ->
elapsed({Before1, Before2, Before3}, {After1, After2, After3}) ->
After = After1 * 1000000000 + After2 * 1000 + After3/1000,
Before = Before1 * 1000000000 + Before2 * 1000 + Before3/1000,
- After - Before.
+ case After - Before of
+ Neg when Neg < 0 -> % time duration must not be negative
+ 0;
+ Val -> Val
+ end.
%%----------------------------------------------------------------------
%% Func: chop/1
View
2 src/tsung/tsung.erl
@@ -29,7 +29,7 @@
-export([start/2, stop/1]).
-behaviour(application).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%%----------------------------------------------------------------------
%% Func: start/2
View
2 src/tsung_controller/ts_config.erl
@@ -1027,7 +1027,7 @@ get_dynvar_name(VarNameStr) ->
%% check if we are using popularity or weights; keep the total up to date.
get_popularity(Proba,Weight,_,_) when is_number(Proba), Proba > 0, is_number(Weight), Weight > 0 ->
erlang:error({"can't mix probabilites and weights", Proba, Weight} );
-get_popularity(Proba, Weight, true,_) when is_number(Proba), Proba > 0->
+get_popularity(Proba, _Weight, true,_) when is_number(Proba), Proba > 0->
erlang:error({"can't use probability when using weight"});
get_popularity(_, Weight, false,_) when is_number(Weight), Weight > 0->
erlang:error({"can't use weights when using probabilities"});
View
6 src/tsung_controller/ts_config_server.erl
@@ -260,7 +260,7 @@ handle_call({get_user_param, HostName}, _From, State=#state{users=UserId}) ->
Config = State#state.config,
{value, Client} = lists:keysearch(HostName, #client.host, Config#config.clients),
{IPParam, Server} = get_user_param(Client,Config),
- ts_mon:newclient({static,now()}),
+ ts_mon:newclient({static,?NOW}),
{reply, {ok, { IPParam, Server, UserId,Config#config.dump,Config#config.seed}}, State#state{users=UserId+1}};
%% get a new session id and user parameters for the given node
@@ -271,7 +271,7 @@ handle_call({get_next_session, HostName}, _From, State=#state{users=Users}) ->
case choose_session(Config#config.sessions, Config#config.total_popularity) of
{ok, Session=#session{id=Id}} ->
?LOGF("Session ~p choosen~n",[Id],?INFO),
- ts_mon:newclient({Id,now()}),
+ ts_mon:newclient({Id,?NOW}),
{IPParam, Server} = get_user_param(Client,Config),
{reply, {ok, Session#session{client_ip= IPParam, server=Server,userid=Users,
dump=Config#config.dump, seed=Config#config.seed}},
@@ -465,7 +465,7 @@ is_vm_local('localhost',_,true) -> true;
is_vm_local(_,_,_) -> false.
set_start_date(undefined)->
- ts_utils:add_time(now(), ?config(warm_time));
+ ts_utils:add_time(?NOW, ?config(warm_time));
set_start_date(Date) -> Date.
get_user_param(Client,Config)->
View
2 src/tsung_controller/ts_controller_sup.erl
@@ -25,7 +25,7 @@
-vc('$Id$ ').
-author('nicolas.niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-behaviour(supervisor).
View
1 src/tsung_controller/ts_file_server.erl
@@ -56,7 +56,6 @@
-define(DICT, dict).
--include("ts_profile.hrl").
-include("ts_config.hrl").
-include("xmerl.hrl").
View
8 src/tsung_controller/ts_job_notify.erl
@@ -34,7 +34,7 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_job.hrl").
%% API
@@ -214,7 +214,7 @@ handle_info({tcp, Socket, Data}, State=#state{jobs=Jobs}) ->
[] ->
?LOGF("Job owner of ~p is unknown",[Id],?NOTICE);
[Job] ->
- Now=now(),
+ Now=?NOW,
Queued=ts_utils:elapsed(Job#job_session.queue_time,Now),
ts_mon:add([{sample,tr_job_wait,Queued},{sum,job_running,1}, {sum,job_queued,-1}]),
ets:update_element(Jobs,Id,{#job_session.start_time,Now})
@@ -229,7 +229,7 @@ handle_info({tcp, Socket, Data}, State=#state{jobs=Jobs}) ->
ets:delete_object(Jobs,Job),
check_jobs(Jobs,Job#job_session.owner);
[Job]->
- Now=now(),
+ Now=?NOW,
Duration=ts_utils:elapsed(Job#job_session.start_time,Now),
ts_mon:add([{sample,tr_job_duration,Duration},{sum,job_running,-1}, {sum,ok_job ,1}]),
ts_job:dump(Job#job_session.dump,{none,Job#job_session{end_time=Now,status="ok"},Name,undefined,undefined}),
@@ -246,7 +246,7 @@ handle_info({tcp, Socket, Data}, State=#state{jobs=Jobs}) ->
ets:delete_object(Jobs,Job),
check_jobs(Jobs,Job#job_session.owner);
[Job]->
- Now=now(),
+ Now=?NOW,
Duration=ts_utils:elapsed(Job#job_session.start_time,Now),
ts_mon:add([{sample,tr_job_duration,Duration},{sum,job_running,-1}, {sum,error_job,1}]),
ts_job:dump(Job#job_session.dump,{none,Job#job_session{end_time=Now,status="error"},Name,undefined,undefined}),
View
1 src/tsung_controller/ts_match_logger.erl
@@ -34,7 +34,6 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
-include("ts_config.hrl").
-define(DELAYED_WRITE_SIZE,524288). % 512KB
View
17 src/tsung_controller/ts_mon.erl
@@ -37,7 +37,6 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
-include("ts_config.hrl").
%% External exports
@@ -109,7 +108,7 @@ add(Data) ->
add_match(Data,{UserId,SessionId,RequestId,Tr}) ->
add_match(Data,{UserId,SessionId,RequestId,[],Tr});
add_match(Data=[Head|_],{UserId,SessionId,RequestId,Bin,Tr}) ->
- TimeStamp=now(),
+ TimeStamp=?NOW,
put(last_match,Head),
ts_mon_cache:add_match(Data,{UserId,SessionId,RequestId,TimeStamp, Bin,Tr}).
@@ -131,17 +130,17 @@ endclient({Who, When, Elapsed}) ->
sendmes({none, _, _}) -> skip;
sendmes({protocol, _, _}) -> skip;
sendmes({_Type, Who, What}) ->
- gen_server:cast({global, ?MODULE}, {sendmsg, Who, now(), What}).
+ gen_server:cast({global, ?MODULE}, {sendmsg, Who, ?NOW, What}).
rcvmes({none, _, _}) -> skip;
rcvmes({protocol, _, _})-> skip;
rcvmes({_, _, closed}) -> skip;
rcvmes({_Type, Who, What}) ->
- gen_server:cast({global, ?MODULE}, {rcvmsg, Who, now(), What}).
+ gen_server:cast({global, ?MODULE}, {rcvmsg, Who, ?NOW, What}).
dump({none, _, _})-> skip;
dump({_Type, Who, What}) ->
- gen_server:cast({global, ?MODULE}, {dump, Who, now(), What}).
+ gen_server:cast({global, ?MODULE}, {dump, Who, ?NOW, What}).
launcher_is_alive() ->
gen_server:cast({global, ?MODULE}, {launcher_is_alive}).
@@ -164,7 +163,7 @@ init([LogDir]) ->
State=#state{ dump_interval = ?config(dumpstats_interval),
log_dir = LogDir,
stats = Stats,
- lastdate = now(),
+ lastdate = ?NOW,
laststats = Stats
},
case ?config(mon_file) of
@@ -197,7 +196,7 @@ handle_call({start_logger, Machines, DumpType, Backend}, From, State) ->
%%% get status
handle_call({status}, _From, State) ->
Request = ts_stats_mon:status(request),
- Interval = ts_utils:elapsed(State#state.lastdate, now()) / 1000,
+ Interval = ts_utils:elapsed(State#state.lastdate, ?NOW) / 1000,
Phase = ts_stats_mon:status(newphase,sum),
Connected = case ts_stats_mon:status(connected,sum) of
{ok, Val} -> Val;
@@ -284,7 +283,7 @@ handle_cast({dumpstats}, State=#state{stats=Stats}) ->
NewSessions = ts_stats_mon:reset_all_stats(Stats#stats.session),
NewOSmon = ts_stats_mon:reset_all_stats(Stats#stats.os_mon),
NewStats = Stats#stats{session=NewSessions, os_mon=NewOSmon},
- {noreply, State#state{laststats = Stats, stats=NewStats,lastdate=now()}};
+ {noreply, State#state{laststats = Stats, stats=NewStats,lastdate=?NOW}};
handle_cast({sendmsg, _, _, _}, State = #state{type = none}) ->
@@ -369,7 +368,7 @@ terminate(Reason, State) ->
json ->
io:format(State#state.log,"]}]}~n",[]);
_ ->
- io:format(State#state.log,"EndMonitor:~w~n",[now()])
+ io:format(State#state.log,"EndMonitor:~w~n",[?NOW])
end,
case State#state.log of
standard_io -> ok;
View
2 src/tsung_controller/ts_msg_server.erl
@@ -28,7 +28,7 @@
-export([get_id/0, get_id/1, reset/0]).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-behaviour(gen_server).
View
2 src/tsung_controller/ts_os_mon.erl
@@ -33,7 +33,7 @@
%%--------------------------------------------------------------------
%% Include files
%%--------------------------------------------------------------------
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_os_mon.hrl").
%%--------------------------------------------------------------------
View
2 src/tsung_controller/ts_os_mon_erlang.erl
@@ -28,7 +28,7 @@
-author('nicolas.niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_os_mon.hrl").
-export([start/1, updatestats/2, client_start/0]).
View
2 src/tsung_controller/ts_os_mon_munin.erl
@@ -35,7 +35,7 @@
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_os_mon.hrl").
-define(READ_TIMEOUT,2500). % 2.5 sec
View
2 src/tsung_controller/ts_os_mon_snmp.erl
@@ -30,7 +30,7 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_os_mon.hrl").
-include_lib("snmp/include/snmp_types.hrl").
View
2 src/tsung_controller/ts_os_mon_sup.erl
@@ -25,7 +25,7 @@
-behaviour(supervisor).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%% External exports
-export([start_link/1, start_child/2]).
View
1 src/tsung_controller/ts_stats_mon.erl
@@ -35,7 +35,6 @@
-behaviour(gen_server).
--include("ts_profile.hrl").
-include("ts_config.hrl").
%% External exports, API
View
2 src/tsung_controller/ts_timer.erl
@@ -26,7 +26,7 @@
-author('jflecomte@IDEALX.com').
-modifiedby('nicolas@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-behaviour(gen_fsm).
View
2 src/tsung_controller/ts_user_server.erl
@@ -26,7 +26,7 @@
-vc('$Id$ ').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%%-compile(export_all).
-export([reset/1,
View
2 src/tsung_controller/tsung_controller.erl
@@ -29,7 +29,7 @@
-export([start/2, start_phase/3, stop/1, stop_all/1, status/1]).
-behaviour(application).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include_lib("kernel/include/file.hrl").
%%----------------------------------------------------------------------
View
2 src/tsung_recorder/ts_client_proxy.erl
@@ -40,7 +40,7 @@
%%--------------------------------------------------------------------
%% Include files
%%--------------------------------------------------------------------
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_recorder.hrl").
%%--------------------------------------------------------------------
View
2 src/tsung_recorder/ts_client_proxy_sup.erl
@@ -27,7 +27,7 @@
-behaviour(supervisor).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%% External exports
-export([start_link/0, start_child/1, active_clients/0]).
View
2 src/tsung_recorder/ts_proxy_http.erl
@@ -27,7 +27,7 @@
-vc('$Id$ ').
-author('Nicolas.Niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_http.hrl").
-include("ts_recorder.hrl").
View
2 src/tsung_recorder/ts_proxy_listener.erl
@@ -40,7 +40,7 @@
%%--------------------------------------------------------------------
%% Include files
%%--------------------------------------------------------------------
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_recorder.hrl").
%% gen_server callbacks
View
2 src/tsung_recorder/ts_proxy_pgsql.erl
@@ -27,7 +27,7 @@
-vc('$Id$ ').
-author('Nicolas.Niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_pgsql.hrl").
-include("ts_recorder.hrl").
View
2 src/tsung_recorder/ts_proxy_recorder.erl
@@ -35,7 +35,7 @@
%%--------------------------------------------------------------------
%% Include files
%%--------------------------------------------------------------------
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-include("ts_http.hrl").
-include("ts_recorder.hrl").
View
2 src/tsung_recorder/ts_recorder_sup.erl
@@ -34,7 +34,7 @@
-vc('$Id$ ').
-author('nicolas.niclausse@niclux.org').
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
-behaviour(supervisor).
View
2 src/tsung_recorder/tsung_recorder.erl
@@ -37,7 +37,7 @@
-export([start/2,stop/1, stop_all/1]).
-behaviour(application).
--include("ts_profile.hrl").
+-include("ts_macros.hrl").
%%----------------------------------------------------------------------
%% Func: start/2

0 comments on commit 583ea5e

Please sign in to comment.
Something went wrong with that request. Please try again.