Skip to content

Commit

Permalink
make edoc happy (TSUN-12)
Browse files Browse the repository at this point in the history
SVN Revision: 950
  • Loading branch information
nniclausse committed Nov 18, 2008
1 parent da37bee commit 4cec511
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 77 deletions.
23 changes: 15 additions & 8 deletions src/tsung/ts_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@
%%% API
%%%----------------------------------------------------------------------

%% Start a new session
%% @doc Start a new session
start(Opts) ->
?DebugF("Starting with opts: ~p~n",[Opts]),
gen_fsm:start_link(?MODULE, Opts, []).

%%----------------------------------------------------------------------
%% Func: next/1
%% Purpose: continue with the next request (used for global ack)
%% next/1
%% @doc Purpose: continue with the next request (used for global ack)
%% @end
%%----------------------------------------------------------------------
next({Pid}) ->
gen_fsm:send_event(Pid, next_msg).
Expand Down Expand Up @@ -348,7 +349,7 @@ handle_next_action(State) ->

%%----------------------------------------------------------------------
%% @spec set_dynvars (Type::erlang|random|urandom|file, Args::tuple(),
%% Variables::List(), DynData:record(dyndata)) -> List()
%% Variables::list(), DynData::#dyndata{}) -> list()
%% @doc setting the value of several dynamic variables at once.
%%----------------------------------------------------------------------
set_dynvars(erlang,{Module,Callback},_Vars,DynData) ->
Expand All @@ -372,10 +373,15 @@ set_dynvars(file,{iter,FileId,Delimiter},_Vars,_DynData) ->
{ok,Line} = ts_file_server:get_next_line(FileId),
string:tokens(Line,Delimiter).

%% @spec ctrl_struct(CtrlData::term(),State::record(state_rcv),Count::integer)
%% @spec ctrl_struct(CtrlData::term(),State::#state_rcv{},Count::integer) ->
%% {next_state, NextStateName::atom(), NextState::#state_rcv{}} |
%% {next_state, NextStateName::atom(), NextState::#state_rcv{},
%% Timeout::integer() | infinity} |
%% {stop, Reason::term(), NewState::#state_rcv{}}
%% @doc Common code for flow control actions (repeat,for)
%% Count is the next action-id, if this action doesn't result
%% in a jump to another place
%% @end
ctrl_struct(CtrlData,State,Count) ->
case ctrl_struct_impl(CtrlData,State#state_rcv.dyndata) of
{next,NewDynData} ->
Expand All @@ -393,11 +399,12 @@ ctrl_struct(CtrlData,State,Count) ->


%%----------------------------------------------------------------------
%% @spec ctrl_struct_impl(ControlStruct::term(),DynData:record(dyndata)) -> Result
%% @type Result = {next,NewDynData::record(dyndata)}
%% | {jump,Target::integer(),NewDynData::record(dyndata)}
%% @spec ctrl_struct_impl(ControlStruct::term(),DynData::#dyndata{}) ->
%% {next,NewDynData::#dyndata{}} |
%% {jump, Target::integer(), NewDynData::#dyndata{}}
%% @doc return {next,NewDynData} to continue with the sequential flow,
%% {jump,Target,NewDynData} to jump to action number 'Target'
%% @end
%%----------------------------------------------------------------------
ctrl_struct_impl({for_start,InitialValue,VarName},DynData=#dyndata{dynvars=DynVars}) ->
NewDynVars = ts_dynvars:set(VarName,InitialValue,DynVars),
Expand Down
16 changes: 8 additions & 8 deletions src/tsung/ts_client_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%%% 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.
%%%
%%%

%%% In addition, as a special exception, you have the permission to
%%% link the code of this program with any library released under
Expand All @@ -40,7 +40,7 @@
%%% API
%%%----------------------------------------------------------------------
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
supervisor:start_link({local, ?MODULE}, ?MODULE, []).

start_child(Profile) ->
supervisor:start_child(?MODULE,[Profile]).
Expand All @@ -62,15 +62,15 @@ active_clients()->
%% Func: init/1
%% Returns: {ok, {SupFlags, [ChildSpec]}} |
%% ignore |
%% {error, Reason}
%% {error, Reason}
%%----------------------------------------------------------------------
init([]) ->
?LOG("Starting ~n", ?INFO),
?LOG("Starting ~n", ?INFO),
SupFlags = {simple_one_for_one,1, ?restart_sleep},
ChildSpec = [
{ts_client,{ts_client, start, []},
temporary,2000,worker,[ts_client]}
],
ChildSpec = [
{ts_client,{ts_client, start, []},
temporary,2000,worker,[ts_client]}
],
% fprof:start(),
% Res = fprof:trace(start, "/tmp/tsung.fprof"),
% ?LOGF("starting profiler: ~p~n",[Res], ?WARN),
Expand Down
19 changes: 13 additions & 6 deletions src/tsung/ts_dynvars.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
%%%

%%% @copyright (C) 2008 Pablo Polvorin <pablo.polvorin@process-one.net>
%%% @author Pablo Polvorin <pablo.polvorin@process-one.net>
%%% @author Nicolas Niclausse <nicolas@niclux.org>
%%% @doc functions to manipulate dynamic variables, sort of Abstract Data Type
%%% @end

%%% created on 2008-08-22
%%% modified by Nicolas Niclausse: Add merge and multi keys/values (new, set)

Expand All @@ -27,7 +31,10 @@

-define(IS_DYNVARS(X),is_list(X)).

%%@spec new() -> DynVars()
%% @type dynvar() = {Key::atom(), Value::string()} | [].
%% @type dynvars() = [dynvar()]

%% @spec new() -> [dynvar()]
new() ->
[].

Expand All @@ -37,7 +44,7 @@ new(VarNames, Values) when is_list(VarNames),is_list(Values)->
%% FIXME: check if VarNames is a list of atoms
lists:zip(VarNames,Values).

%% @spec lookup(Key::atom(),DynVar()) -> {ok,Value:term()} | false
%% @spec lookup(Key::atom(), Dynvar::dynvars()) -> {ok,Value::term()} | false
lookup(Key, []) when is_atom(Key)->
false;
lookup(Key, DynVars) when ?IS_DYNVARS(DynVars), is_atom(Key)->
Expand All @@ -54,7 +61,7 @@ lookup(Key, DynVars, Default) when ?IS_DYNVARS(DynVars), is_atom(Key)->
R -> R
end.

%% @spec set(Key:atom(), Value::term, DynVars()) -> DynVars()
%% @spec set(Key::atom(), Value::term(), DynVars::dynvars()) -> dynvars()
set(Key,Value,DynVars) when ?IS_DYNVARS(DynVars),is_atom(Key) ->
merge([{Key, Value}],DynVars);

Expand All @@ -70,8 +77,8 @@ set(Keys,Values,DynVars) when ?IS_DYNVARS(DynVars),is_list(Keys),is_list(Values)
entries(DynVars) when ?IS_DYNVARS(DynVars) ->
DynVars.

%% @spec map(Fun,Key::atom(),Default::term(),DynVars()) -> DynVars
%% @type Fun : term() -> term()
%% @spec map(Fun::function(),Key::atom(),Default::term(),DynVars::dynvars())
%% -> dynvars()
%% @doc The value associated to key Key is replaced with
%% the result of applying function Fun to its previous value.
%% If there is no such previous value, Fun is applied to the default
Expand All @@ -91,7 +98,7 @@ do_map(Fun,Key,Default,[H|Rest], Acc) ->
do_map(Fun,Key,Default,Rest, [H|Acc]).


%% @spec merge(DynVars(),DynVars()) -> DynVars
%% @spec merge(DynVars::dynvars(),DynVars::dynvars()) -> dynvars()
%% @doc merge two set of dynamic variables
merge(DynVars1, DynVars2) when ?IS_DYNVARS(DynVars1),?IS_DYNVARS(DynVars2) ->
ts_utils:keyumerge(1,DynVars1,DynVars2).
6 changes: 4 additions & 2 deletions src/tsung/ts_http_common.erl
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ authenticate(UserId,Passwd)->
["Authorization: Basic ",AuthStr,?CRLF].

%%----------------------------------------------------------------------
%% @spec set_header(Name::string, Val::string | undefined, Headers::List, Default::string)
%% @doc If headers is defined in <headers>, print this one, otherwise,
%% @spec set_header(Name::string, Val::string | undefined, Headers::List,
%% Default::string) -> list()
%% @doc If header Name is defined in Headers, print this one, otherwise,
%% print the given Value (or the default one if undefined)
%% @end
%%----------------------------------------------------------------------
set_header(Name, Value, Headers, Default) when length(Headers) > 0 ->
case lists:keysearch(Name, 1, Headers) of
Expand Down
4 changes: 2 additions & 2 deletions src/tsung/ts_jabber_common.erl
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ message(Dest, #jabber{data=Data, username=User}, Service) when is_list(Data) ->
"'><body>",Data, "</body></message>"]).

%%----------------------------------------------------------------------
%% @spec garbage/1
%% @depracated use {@link ts_utils:randomstr/1} or
%% @spec garbage(Size::integer()) -> string()
%% @deprecated use {@link ts_utils:randomstr/1} or
%% {@link ts_utils:randomstr_noflat/1} instead
%%----------------------------------------------------------------------
garbage(Size)->
Expand Down
13 changes: 7 additions & 6 deletions src/tsung/ts_search.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ extract_function([H|Tail],DynVar, Acc, Mod, Fun) ->
extract_function(Tail, DynVar, Acc, Mod, [H|Fun]).

%%----------------------------------------------------------------------
%% Func: match/3
%% Args: RegExp, Data, Request Counter
%% Returns: New Counter ( not changed if match )
%% Purpose: search for regexp in Data; send result to ts_mon
%% @spec match(Match::#match{}, Data::binary() | list, Counts::integer())
%% -> Count::integer()
%% @doc search for regexp in Data; send result to ts_mon
%% @end
%%----------------------------------------------------------------------
match([], _Data, {Count, _MaxC}) -> Count;
match(Match, Data, Counts) when is_binary(Data)->
Expand All @@ -120,7 +120,8 @@ match(Match, Data, Counts) when is_binary(Data)->
match(Match, Data, Counts) ->
match(Match, Data, Counts, []).

%% Func: match/4
%% @spec match(Match::#match{}, Data::binary() | list(), Counts::integer(), Stats::list())
%% -> Count::integer()
match([], _Data, {Count, _MaxC}, Stats) ->
%% all matches done, add stats, and return Count unchanged (continue)
ts_mon:add(Stats),
Expand Down Expand Up @@ -150,7 +151,7 @@ match([Match=#match{regexp=RegExp, do=Action, 'when'=When}| Tail], String, Count
end,
match(Tail, String, Counts,[{count, nomatch} | Stats]);
{error,_Error} ->
?LOGF("Error while matching: bad REGEXP (~p)~n", [RegExp], ?WARN),
?LOGF("Error while matching: bad REGEXP (~p)~n", [RegExp], ?ERR),
match(Tail, String, Counts,[{count, badregexp} | Stats])
end.

Expand Down
2 changes: 1 addition & 1 deletion src/tsung/ts_session_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
stats=[] % cache stats msgs
}).

-define(DUMP_STATS_INTERVAL, 500).
-define(DUMP_STATS_INTERVAL, 500). % in milliseconds

-include("ts_profile.hrl").

Expand Down
13 changes: 9 additions & 4 deletions src/tsung/ts_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ from_https(String) when is_list(String)->
update_content_length(NewString,Count+Location)
end.

%% @spec update_content_length(String) -> {ok, String}
%% @spec update_content_length(string(), Count::integer()) -> {ok, String::string()}
%% @doc since the length of URL is changed (https:// to http://ssl- )
%% we must recalculate Content-Length if it is defined.
update_content_length(String,0) -> {ok, String } ;
Expand Down Expand Up @@ -609,9 +609,10 @@ resolve(Ip, Cache) ->
end.

%%----------------------------------------------------------------------
%% @spec urandomstr_noflat/1
%% @spec urandomstr_noflat(Size::integer()) ->string()
%% @doc generate pseudo-random list of given size. Implemented by
%% duplicating list of fixed size to be faster. unflatten version
%% @end
%%----------------------------------------------------------------------
urandomstr_noflat(Size) when is_integer(Size) , Size >= ?DUPSTR_SIZE ->
Msg= lists:duplicate(Size div ?DUPSTR_SIZE,?DUPSTR),
Expand All @@ -625,15 +626,17 @@ urandomstr_noflat(Size) when is_integer(Size), Size >= 0 ->
lists:nthtail(?DUPSTR_SIZE-Size, ?DUPSTR).

%%----------------------------------------------------------------------
%% @spec urandomstr/1
%% @spec urandomstr(Size::integer()) ->string()
%% @doc same as urandomstr_noflat/1, but returns a flat list.
%% @end
%%----------------------------------------------------------------------
urandomstr(Size) when is_integer(Size), Size >= 0 ->
lists:flatten(urandomstr_noflat(Size)).

%%----------------------------------------------------------------------
%% @spec randomstr/1
%% @spec randomstr(Size::integer()) ->string()
%% @doc returns a random string. slow if Size is high.
%% @end
%%----------------------------------------------------------------------
randomstr(Size) when is_integer(Size), Size >= 0 ->
lists:map(fun (_) -> random:uniform(25) + $a end, lists:seq(1,Size)).
Expand All @@ -642,6 +645,7 @@ randomstr(Size) when is_integer(Size), Size >= 0 ->
%%----------------------------------------------------------------------
%% @spec eval(string()) -> term()
%% @doc evaluate strings as Erlang code at runtime
%% @end
%%----------------------------------------------------------------------
eval(Code) ->
{ok, Scanned, _} = erl_scan:string(Code),
Expand All @@ -652,6 +656,7 @@ eval(Code) ->
%%----------------------------------------------------------------------
%% @spec list_to_number(string()) -> integer() | float()
%% @doc convert a 'number' to either int or float
%% @end
%%----------------------------------------------------------------------
list_to_number(Number) ->
try list_to_integer(Number) of
Expand Down
23 changes: 10 additions & 13 deletions src/tsung/tsung.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%%% 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.
%%%
%%%

%%% In addition, as a special exception, you have the permission to
%%% link the code of this program with any library released under
Expand All @@ -35,32 +35,29 @@
%% Func: start/2
%% Returns: {ok, Pid} |
%% {ok, Pid, State} |
%% {error, Reason}
%% {error, Reason}
%%----------------------------------------------------------------------
start(_Type, _StartArgs) ->
% error_logger:tty(false),
% error_logger:tty(false),
?LOG("open logfile ~n",?DEB),
LogFileEnc = ts_config_server:decode_filename(?config(log_file)),
LogFile = filename:join(LogFileEnc, atom_to_list(node()) ++ ".log"),
LogDir = filename:dirname(LogFile),
ok = ts_utils:make_dir_rec(LogDir),
error_logger:logfile({open, LogFile}),
error_logger:logfile({open, LogFile}),
?LOG("ok~n",?DEB),
case ts_sup:start_link() of
{ok, Pid} ->
{ok, Pid};
Error ->
?LOGF("Can't start ! ~p ~n",[Error],?ERR),
Error
{ok, Pid} ->
{ok, Pid};
Error ->
?LOGF("Can't start ! ~p ~n",[Error],?ERR),
Error
end.


%%----------------------------------------------------------------------
%% Func: stop/1
%% Returns: any
%% Returns: any
%%----------------------------------------------------------------------
stop(_State) ->
stop.



Loading

0 comments on commit 4cec511

Please sign in to comment.