patch for sys:get_status to call format_status/2

Steve Vinoski <>
Wed Aug 26 16:49:22 CEST 2009


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