Skip to content

Commit

Permalink
Added handling of -n flag to riak-admin top command in order to allow…
Browse files Browse the repository at this point in the history
… specification of iteration count
  • Loading branch information
Christian Dahlqvist authored and Christian Dahlqvist committed Oct 16, 2013
1 parent 9359155 commit bd54b5d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/etop_txt.erl
Expand Up @@ -71,12 +71,25 @@ init(Config) ->
loop(Config).

loop(Config) ->
N = get_n_value(),
loop(Config, N).

loop(Config, 1) ->
do_update(Config),
stopped;
loop(Config, N) ->
Info = do_update(Config),
Nnext = case N of
N when is_integer(N) andalso N > 1 ->
N-1;
_ ->
undefined
end,
receive
stop -> stopped;
{dump,Fd} -> do_update(Fd,Info,Config), loop(Config);
{config,_,Config1} -> loop(Config1)
after Config#opts.intv-500 -> loop(Config)
{dump,Fd} -> do_update(Fd,Info,Config), loop(Config, Nnext);
{config,_,Config1} -> loop(Config1, Nnext)
after Config#opts.intv-500 -> loop(Config, Nnext)
end.

do_update(Config) ->
Expand Down Expand Up @@ -133,3 +146,15 @@ writepinfo(Fd,[#etop_proc_info{pid=Pid,
writepinfo(_Fd,[]) ->
ok.

get_n_value() ->
case init:get_argument(n) of
{ok,[[Nstr]]} ->
try
list_to_integer(Nstr)
catch
_:_ -> undefined
end;
_ ->
undefined
end.

0 comments on commit bd54b5d

Please sign in to comment.