File 0339-Fix-sys-s-debug-statistics.patch of Package erlang

From 4b97ff92a8d2d429370da40c9845199c2a68f12d Mon Sep 17 00:00:00 2001
From: Boshan Sun <boshan@subsplash.com>
Date: Thu, 22 Mar 2018 19:47:04 -0700
Subject: [PATCH] Fix sys's debug statistics.

Currently, in sys:stat/2, the message out only count for system events with format
{out, Msg, To}. However, the gen_server:reply/5 will call sys:handle_debug/4
with format {out, Reply, To, State}. That will make the message out count fail
to pattern matching.

Also update sys_SUITE.erl and relevant docs.
---
 lib/stdlib/doc/src/sys.xml                 | 2 +-
 lib/stdlib/src/sys.erl                     | 2 ++
 lib/stdlib/test/sys_SUITE.erl              | 2 +-
 system/doc/design_principles/spec_proc.xml | 2 +-
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/stdlib/doc/src/sys.xml b/lib/stdlib/doc/src/sys.xml
index 64d8789016..8930087555 100644
--- a/lib/stdlib/doc/src/sys.xml
+++ b/lib/stdlib/doc/src/sys.xml
@@ -102,7 +102,7 @@
       then treated in the debug function. For example, <c>trace</c>
       formats the system events to the terminal.
       </p>
-    <p>Three predefined system events are used when a
+    <p>Four predefined system events are used when a
       process receives or sends a message. The process can also define its
       own system events. It is always up to the process itself
       to format these events.</p>
diff --git a/lib/stdlib/src/sys.erl b/lib/stdlib/src/sys.erl
index 0c578acf21..b1177ece48 100644
--- a/lib/stdlib/src/sys.erl
+++ b/lib/stdlib/src/sys.erl
@@ -44,6 +44,7 @@
 -type system_event() :: {'in', Msg :: _}
                       | {'in', Msg :: _, From :: _}
                       | {'out', Msg :: _, To :: _}
+                      | {'out', Msg :: _, To :: _, State :: _}
                         | term().
 -opaque dbg_opt()    :: {'trace', 'true'}
                       | {'log',
@@ -573,6 +574,7 @@ get_stat(_) ->
 stat({in, _Msg}, {Time, Reds, In, Out}) -> {Time, Reds, In+1, Out};
 stat({in, _Msg, _From}, {Time, Reds, In, Out}) -> {Time, Reds, In+1, Out};
 stat({out, _Msg, _To}, {Time, Reds, In, Out}) -> {Time, Reds, In, Out+1};
+stat({out, _Msg, _To, _State}, {Time, Reds, In, Out}) -> {Time, Reds, In, Out+1};
 stat(_, StatData) -> StatData.
 
 trim(N, LogData) ->
diff --git a/lib/stdlib/test/sys_SUITE.erl b/lib/stdlib/test/sys_SUITE.erl
index b44df0fbda..a28eca513f 100644
--- a/lib/stdlib/test/sys_SUITE.erl
+++ b/lib/stdlib/test/sys_SUITE.erl
@@ -84,7 +84,7 @@ stats(Config) when is_list(Config) ->
     {ok,-44} = public_call(44),
     {ok,Stats} = sys:statistics(?server,get),
     true = lists:member({messages_in,1}, Stats),
-    true = lists:member({messages_out,0}, Stats),
+    true = lists:member({messages_out,1}, Stats),
     ok = sys:statistics(?server,false),
     {status,_Pid,{module,_Mod},[_PDict,running,Self,_,_]} =
 	sys:get_status(?server),
diff --git a/system/doc/design_principles/spec_proc.xml b/system/doc/design_principles/spec_proc.xml
index 5f4e7ac685..f910c3dba3 100644
--- a/system/doc/design_principles/spec_proc.xml
+++ b/system/doc/design_principles/spec_proc.xml
@@ -312,7 +312,7 @@ sys:handle_debug(Deb, Func, Info, Event) => Deb1</code>
             define what a system event is and how it is to be
             represented. Typically at least incoming and outgoing
             messages are considered system events and represented by
-            the tuples <c>{in,Msg[,From]}</c> and <c>{out,Msg,To}</c>,
+            the tuples <c>{in,Msg[,From]}</c> and <c>{out,Msg,To[,State]}</c>,
             respectively.</item>
       </list>
       <p><c>handle_debug</c> returns an updated debug structure
-- 
2.16.3

openSUSE Build Service is sponsored by