aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--erts/doc/src/erlang.xml33
-rw-r--r--erts/emulator/beam/erl_bif_trace.c40
-rw-r--r--erts/emulator/test/trace_SUITE.erl5
-rw-r--r--erts/preloaded/src/erlang.erl8
4 files changed, 70 insertions, 16 deletions
diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml
index f42923a009..5af4f0bd66 100644
--- a/erts/doc/src/erlang.xml
+++ b/erts/doc/src/erlang.xml
@@ -9015,16 +9015,16 @@ timestamp() ->
<type name="trace_info_flag"/>
<type name="trace_match_spec"/>
<desc>
- <p>Returns trace information about a port, process or function.</p>
- <p>To get information about a port or process,
- <c><anno>PidPortOrFunc</anno></c> is to
+ <p>Returns trace information about a port, process, function or event.</p>
+ <p><em>To get information about a port or process</em>,
+ <c><anno>PidPortFuncEvent</anno></c> is to
be a process identifier (pid), port identifier or one of
the atoms <c>new</c>, <c>new_processes</c>, <c>new_ports</c>.
The atom <c>new</c> or <c>new_processes</c> means that the default trace
state for processes to be created is returned. The atom <c>new_ports</c>
means that the default trace state for ports to be created is returned.
</p>
- <p>The following <c>Item</c>s are valid:</p>
+ <p>The following <c>Item</c>s are valid for ports and processes:</p>
<taglist>
<tag><c>flags</c></tag>
<item>
@@ -9048,12 +9048,15 @@ timestamp() ->
value is <c>[]</c>.</p>
</item>
</taglist>
- <p>To get information about a function, <c><anno>PidPortOrFunc</anno></c> is to
+ <p><em>To get information about a function</em>, <c><anno>PidPortFuncEvent</anno></c> is to
be the three-element tuple <c>{Module, Function, Arity}</c> or
the atom <c>on_load</c>. No wild cards are allowed. Returns
<c>undefined</c> if the function does not exist, or
- <c>false</c> if the function is not traced.</p>
- <p>The following <c>Item</c>s are valid::</p>
+ <c>false</c> if the function is not traced. If <c><anno>PidPortFuncEvent</anno></c>
+ is <c>on_load</c>, the information returned refers to
+ the default value for code that will be loaded.</p>
+
+ <p>The following <c>Item</c>s are valid for functions:</p>
<taglist>
<tag><c>traced</c></tag>
<item>
@@ -9112,13 +9115,21 @@ timestamp() ->
is active for this function.</p>
</item>
</taglist>
+ <p><em>To get information about an event</em>, <c><anno>PidPortFuncEvent</anno></c> is to
+ be one of the atoms <c>send</c> or <c>'receive'</c>.</p>
+ <p>The only valid <c>Item</c> for events is:</p>
+ <taglist>
+ <tag><c>match_spec</c></tag>
+ <item>
+ <p>Returns the match specification for this event, if it
+ has one, or <c>true</c> if no match specification has been
+ set.</p>
+ </item>
+ </taglist>
<p>The return value is <c>{<anno>Item</anno>, Value}</c>, where
<c>Value</c> is the requested information as described earlier.
If a pid for a dead process was given, or the name of a
non-existing function, <c>Value</c> is <c>undefined</c>.</p>
- <p>If <c><anno>PidPortOrFunc</anno></c> is <c>on_load</c>, the information
- returned refers to the default value for code that will be
- loaded.</p>
</desc>
</func>
@@ -9237,7 +9248,7 @@ timestamp() ->
</item>
<tag><c>false</c></tag>
<item>
- <p>Disables tracing for all sent messages.
+ <p>Disables tracing for all received messages.
Any match specification is removed.</p>
</item>
</taglist>
diff --git a/erts/emulator/beam/erl_bif_trace.c b/erts/emulator/beam/erl_bif_trace.c
index ffc0afda58..b65c0e303f 100644
--- a/erts/emulator/beam/erl_bif_trace.c
+++ b/erts/emulator/beam/erl_bif_trace.c
@@ -81,6 +81,8 @@ static void new_seq_trace_token(Process* p); /* help func for seq_trace_2*/
static Eterm trace_info_pid(Process* p, Eterm pid_spec, Eterm key);
static Eterm trace_info_func(Process* p, Eterm pid_spec, Eterm key);
static Eterm trace_info_on_load(Process* p, Eterm key);
+static Eterm trace_info_event(Process* p, Eterm event, Eterm key);
+
static void reset_bif_trace(void);
static void setup_bif_trace(void);
@@ -814,6 +816,8 @@ Eterm trace_info_2(BIF_ALIST_2)
if (What == am_on_load) {
res = trace_info_on_load(p, Key);
+ } else if (What == am_send || What == am_receive) {
+ res = trace_info_event(p, What, Key);
} else if (is_atom(What) || is_pid(What) || is_port(What)) {
res = trace_info_pid(p, What, Key);
} else if (is_tuple(What)) {
@@ -1303,6 +1307,42 @@ trace_info_on_load(Process* p, Eterm key)
}
}
+static Eterm
+trace_info_event(Process* p, Eterm event, Eterm key)
+{
+ ErtsTracingEvent* te;
+ Eterm retval;
+ Eterm* hp;
+
+ switch (event) {
+ case am_send: te = erts_send_tracing; break;
+ case am_receive: te = erts_receive_tracing; break;
+ default:
+ goto error;
+ }
+
+ if (key != am_match_spec)
+ goto error;
+
+ te = &te[erts_active_bp_ix()];
+
+ if (te->on) {
+ if (!te->match_spec)
+ retval = am_true;
+ else
+ retval = copy_object(MatchSetGetSource(te->match_spec), p);
+ }
+ else
+ retval = am_false;
+
+ hp = HAlloc(p, 3);
+ return TUPLE2(hp, key, retval);
+
+ error:
+ BIF_ERROR(p, BADARG);
+}
+
+
#undef FUNC_TRACE_NOEXIST
#undef FUNC_TRACE_UNTRACED
#undef FUNC_TRACE_GLOBAL_TRACE
diff --git a/erts/emulator/test/trace_SUITE.erl b/erts/emulator/test/trace_SUITE.erl
index 1930332691..3d7cb41fc0 100644
--- a/erts/emulator/test/trace_SUITE.erl
+++ b/erts/emulator/test/trace_SUITE.erl
@@ -495,7 +495,10 @@ send_trace(Config) when is_list(Config) ->
ok.
set_trace_pattern(_, no, _) -> 0;
-set_trace_pattern(MSA, Pat, Flg) -> erlang:trace_pattern(MSA, Pat, Flg).
+set_trace_pattern(MFA, Pat, Flg) ->
+ R = erlang:trace_pattern(MFA, Pat, Flg),
+ {match_spec, Pat} = erlang:trace_info(MFA, match_spec),
+ R.
%% Test trace(Pid, How, [procs]).
procs_trace(Config) when is_list(Config) ->
diff --git a/erts/preloaded/src/erlang.erl b/erts/preloaded/src/erlang.erl
index d09958032b..90fd536b15 100644
--- a/erts/preloaded/src/erlang.erl
+++ b/erts/preloaded/src/erlang.erl
@@ -1749,16 +1749,16 @@ trace_delivered(_Tracee) ->
erlang:nif_error(undefined).
%% trace_info/2
--spec erlang:trace_info(PidPortOrFunc, Item) -> Res when
- PidPortOrFunc :: pid() | port() | new | new_processes | new_ports
- | {Module, Function, Arity} | on_load,
+-spec erlang:trace_info(PidPortFuncEvent, Item) -> Res when
+ PidPortFuncEvent :: pid() | port() | new | new_processes | new_ports
+ | {Module, Function, Arity} | on_load | send | 'receive',
Module :: module(),
Function :: atom(),
Arity :: arity(),
Item :: flags | tracer | traced | match_spec
| meta | meta_match_spec | call_count | call_time | all,
Res :: trace_info_return().
-trace_info(_PidPortOrFunc, _Item) ->
+trace_info(_PidPortFuncEvent, _Item) ->
erlang:nif_error(undefined).
%% trunc/1