diff options
author | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
commit | 84adefa331c4159d432d22840663c38f155cd4c1 (patch) | |
tree | bff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/sasl/src/si.erl | |
download | otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2 otp-84adefa331c4159d432d22840663c38f155cd4c1.zip |
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/sasl/src/si.erl')
-rw-r--r-- | lib/sasl/src/si.erl | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/lib/sasl/src/si.erl b/lib/sasl/src/si.erl new file mode 100644 index 0000000000..eeed7a9f55 --- /dev/null +++ b/lib/sasl/src/si.erl @@ -0,0 +1,168 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%%----------------------------------------------------------------- +%% l(format_lib_supp), l(si_sasl_supp), l(si), l(si_ms_aos_supp), l(misc_supp). +%% c(format_lib_supp), c(si_sasl_supp), c(si), c(si_ms_aos_supp), c(misc_supp). +%%----------------------------------------------------------------- + + +%%-------------------------------------------------- +%% Description: +%% Status Inspection, main module. +%%-------------------------------------------------- + +-module(si). + + +%% External exports +-export([h/0, help/0, start/0, start/1, start_log/1, stop_log/0, + abbrevs/0, pi/1, pi/2, pi/3, pi/4, ppi/1, ppi/3, stop/0]). + +%% Internal exports +-export([pi_impl/2, test/0]). + + +%%-------------------------------------------------- +%% Table of contents +%% 1. Interface +%% 2. Implementation + + +-import(si_sasl_supp, [status_info/1, make_pid/1, p/1]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% 1. Interface +%%-------------------------------------------------- + +h() -> print_help(). +help() -> print_help(). + +start() -> si_sasl_supp:start(). +start(Options) -> si_sasl_supp:start(Options). + +stop() -> si_sasl_supp:stop(). + +start_log(FileName) -> + si_sasl_supp:start_log(FileName). + +stop_log() -> + si_sasl_supp:stop_log(). + +%%%----------------------------------------------------------------- +%%% All functions can be called with an option 'normal' or 'all'; +%%% default is 'normal'. +%%%----------------------------------------------------------------- + +abbrevs() -> + io:format("~p", [lists:append(si_sasl_supp:process_abbrevs(), + process_abbrevs())]). + +%%----------------------------------------------------------------- +%% Process Info that tries to determine processtype (=Module), then +%% it uses this Module:format_info to format data from status_info/1. +%%----------------------------------------------------------------- +pi(XPid) -> + si_sasl_supp:si_exec({si, pi_impl}, [normal, XPid]). + +pi(Opt, XPid) -> + si_sasl_supp:si_exec({si, pi_impl}, [si_sasl_supp:valid_opt(Opt), XPid]). + +pi(A, B, C) when is_integer(A), is_integer(B), is_integer(C) -> + si_sasl_supp:si_exec({si, pi_impl}, [normal, {A, B, C}]). + +pi(Opt, A, B, C) when is_integer(A), is_integer(B), is_integer(C) -> + si_sasl_supp:si_exec({si, pi_impl}, [si_sasl_supp:valid_opt(Opt), {A, B, C}]). + +%%----------------------------------------------------------------- +%% Pretty print Process_Info. +%%----------------------------------------------------------------- +ppi(XPid) -> + si_sasl_supp:ppi(XPid). +ppi(A, B, C) -> + si_sasl_supp:ppi(A, B, C). + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% 2. Implementation +%%-------------------------------------------------- + +print_help() -> + p("~nStatus Inspection tool - usage"), + p("=============================="), + p(" For all these functions, Opt is an optional argument"), + p(" which can be 'normal' or 'all'; default is 'normal'."), + p(" If 'all', all information will be printed."), + p(" A Pid can be: \"<A.B.C>\", {A, B, C}, B, a registered_name or an abbrev."), + p("ANY PROCESS"), + p("si:pi([Opt,] Pid) - Formatted information about any process that"), + p(" SI recognises."), + p("si:pi([Opt,] A,B,C) - Same as si:pi({A, B, C})."), + p("si:ppi(Pid) - Pretty formating of process_info."), + p(" Works for any process."), + p("MISC"), + p("si:abbrevs() - Lists valid abbreviations."), + p("si:start_log(Filename) - Logging to file."), + p("si:stop_log()"), + p("si:start() - Starts Status Inspection (the si_server)."), + p("si:start([{start_log, FileName}])"), + p("si:stop() - Shut down SI."). + + +%%-------------------------------------------------- +%% Copied (and modified) code from si_sasl_supp. +%%-------------------------------------------------- +pi_impl(Opt, XPid) -> + case make_pid(try_local_expand_abbrev(XPid)) of + Pid when is_pid(Pid) -> + case status_info(Pid) of + {status_info, Pid, {module, Module}, Data} -> + si_sasl_supp:do_best_printout(Opt, Pid, Module, Data); + {error, Reason} -> + si_sasl_supp:ppi_impl(Pid), + {error, {"can not get status info from process:", + XPid, + Reason}}; + Else -> + {error, {"unknown status info", Else}} + end; + {error, Reason} -> + {error, Reason} + end. + +%%-------------------------------------------------- +%% Functions for handling of abbreviations +%%-------------------------------------------------- +try_local_expand_abbrev(Abbrev) -> + case si_sasl_supp:expand_abbrev(Abbrev, process_abbrevs()) of + {value, {_, RealName}} -> RealName; + _ -> Abbrev + end. + +process_abbrevs() -> + []. + +%% Test get_status_info/format_status_info for all implemented servers. +test() -> + lists:foreach(fun test_all_registered/1, + lists:append(si_sasl_supp:process_abbrevs(), + process_abbrevs())). + +test_all_registered({Al, _Ful}) -> + si:pi(all, Al). |