aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2014-10-22 19:09:13 +0200
committerHans Nilsson <[email protected]>2014-10-22 19:10:59 +0200
commit812f99c991409dc97b7d3ab0ef85220e61e2fca5 (patch)
treee76b8f23ef4f1c8d97b4fb84492b70258ac955d9 /lib
parent9fa393fc78ab769963f804b10c3abf0b4c4f21b7 (diff)
downloadotp-812f99c991409dc97b7d3ab0ef85220e61e2fca5.tar.gz
otp-812f99c991409dc97b7d3ab0ef85220e61e2fca5.tar.bz2
otp-812f99c991409dc97b7d3ab0ef85220e61e2fca5.zip
ssh: Print supervisor tree (on demand).
Diffstat (limited to 'lib')
-rw-r--r--lib/ssh/src/ssh_info.erl51
1 files changed, 50 insertions, 1 deletions
diff --git a/lib/ssh/src/ssh_info.erl b/lib/ssh/src/ssh_info.erl
index 073a9c7d28..9ed598b3ab 100644
--- a/lib/ssh/src/ssh_info.erl
+++ b/lib/ssh/src/ssh_info.erl
@@ -38,6 +38,7 @@ print() ->
io:nl(),
underline("Server part", $=),
print_servers(),
+ io:nl(),
%% case os:type() of
%% {unix,_} ->
%% io:nl(),
@@ -49,7 +50,9 @@ print() ->
%% catch io:format(os:cmd("netstat -tpn"));
%% _ -> ok
%% end,
- ok
+ underline("Supervisors", $=),
+ walk_sups(ssh_sup),
+ io:nl()
catch
_:_ ->
io:format("Ssh not found~n",[])
@@ -117,6 +120,52 @@ print_channel(Other) ->
io:format(" [[Other 5: ~p]]~n",[Other]).
%%%================================================================
+-define(inc(N), (N+4)).
+
+walk_sups(StartPid) ->
+ io:format("Start at ~p, ~s.~n",[StartPid,dead_or_alive(StartPid)]),
+ walk_sups(children(StartPid), _Indent=?inc(0)).
+
+walk_sups([H={_,Pid,SupOrWorker,_}|T], Indent) ->
+ indent(Indent), io:format('~200p ~p is ~s~n',[H,Pid,dead_or_alive(Pid)]),
+ case SupOrWorker of
+ supervisor -> walk_sups(children(Pid), ?inc(Indent));
+ _ -> ok
+ end,
+ walk_sups(T, Indent);
+walk_sups([], _) ->
+ ok.
+
+dead_or_alive(Name) when is_atom(Name) ->
+ case whereis(Name) of
+ undefined ->
+ "**UNDEFINED**";
+ Pid ->
+ dead_or_alive(Pid)
+ end;
+dead_or_alive(Pid) when is_pid(Pid) ->
+ case process_info(Pid) of
+ undefined -> "**DEAD**";
+ _ -> "alive"
+ end.
+
+indent(I) -> io:format('~*c',[I,$ ]).
+
+children(Pid) ->
+ Parent = self(),
+ Helper = spawn(fun() ->
+ Parent ! {self(),supervisor:which_children(Pid)}
+ end),
+ receive
+ {Helper,L} when is_list(L) ->
+ L
+ after
+ 2000 ->
+ catch exit(Helper, kill),
+ []
+ end.
+
+%%%================================================================
underline(Str) ->
underline(Str, $-).