patch for sys:get_status to call format_status/2

Steve Vinoski vinoski@REDACTED
Fri Nov 27 19:31:14 CET 2009


Since I never got a response on the patch below that I submitted in August,
I've just resubmitted the patch below via a fork and a pull request on
github.com. Let me know if anything's missing or if more is needed. For
example, this is undocumented, and I wasn't sure if this should be
documented in sys, gen_server, gen_fsm, or all the above so I left it
undocumented.

The primary thing to keep in mind about this patch is that it's simply
reconnecting pieces of code that are already there.

--steve

On Wed, Aug 26, 2009 at 8:12 AM, Steve Vinoski <vinoski@REDACTED> wrote:

> [I've been trying to send this patch to erlang-bugs and erlang-questions
> for the past few days, but it hasn't shown up. Trying erlang-patches this
> time.]
>
> Back in March of this year the following thread appeared in
> erlang-questions regarding the undocumented format_status/2 function that
> apparently used to be called by sys:get_status if provided by a behavior
> module:
>
> <http://erlang.org/pipermail/erlang-questions/2009-March/042242.html>
>
> I searched back all the way to version R6B but found no code that made
> that call except within SASL's si_sasl_supp module, yet I see that
> various modules such as gen_server, gen_event, gen_fsm, and os_mon's disksup
> and memsup each provide a format_status/2 function, plus the generic
> behaviors also check to see if modules implementing them also provide
> a format_status/2 function, calling it if they do and thus allowing you
> to format how sys:get_status prints out your gen_server, gen_fsm, etc.
> state. Seems like a shame to let that code go to waste! :-) I agree with
> the originator of that thread that being allowed to provide a
> special format_status/2 when implementing a behavior can be very handy, so
> below find a simple patch for R13B01 that implements it.
>
> --steve
>
> --- lib/stdlib/src/sys.erl~ 2009-03-12 08:18:15.000000000 -0400
> +++ lib/stdlib/src/sys.erl 2009-08-26 01:25:13.000000000 -0400
> @@ -245,8 +245,17 @@
>      {SysState, {error, {unknown_system_msg, Other}}, Debug, Misc}.
>
>  get_status(SysState, Parent, Mod, Debug, Misc) ->
> +    PDict = get(),
> +    FmtMisc =
> +        case erlang:function_exported(Mod, format_status, 2) of
> +            true ->
> +                FmtArgs = [PDict, SysState, Parent, Debug, Misc],
> +                Mod:format_status(normal, FmtArgs);
> +            _ ->
> +                Misc
> +        end,
>      {status, self(), {module, Mod},
> -     [get(), SysState, Parent, Debug, Misc]}.
> +     [PDict, SysState, Parent, Debug, FmtMisc]}.
>
>  %%-----------------------------------------------------------------
>  %% These are the system debug commands.
>
>


More information about the erlang-patches mailing list