aboutsummaryrefslogtreecommitdiffstats
path: root/lib/et/examples
diff options
context:
space:
mode:
authorHÃ¥kan Mattsson <[email protected]>2010-02-03 08:59:06 +0000
committerErlang/OTP <[email protected]>2010-02-03 08:59:06 +0000
commit43f3482adf5eee657e5ba922733dfff6600c4e14 (patch)
tree7ea7b32a171de1a7690102c403a8a946e8a382a8 /lib/et/examples
parent768da5a5f6312496b9b8a09cca5ea1d6b89a2c1c (diff)
downloadotp-43f3482adf5eee657e5ba922733dfff6600c4e14.tar.gz
otp-43f3482adf5eee657e5ba922733dfff6600c4e14.tar.bz2
otp-43f3482adf5eee657e5ba922733dfff6600c4e14.zip
OTP-8058 The GUI parts are rewritten to use wxWidgets. Thanks Olle
Mattsson! For the time being it is still possible to use the old GS based version of the tool, but it is deprecated. The wxWidgets based version is started by default. A new tutorial has been added to the documentation. It is based on Jayson Vantuyl's article http://souja.net/2009/04/making-sense-of-erlangs-event-tracer.htm l. The functions et:trace_me/4 and et:trace_me/5 has been introduced in order to replace the deprecated functions et:report_event/4 and et:report_event/5. Hopefully the new names makes it a little more obvious what the intended usage of the functions are. A print function has been added to the GUI, in order to enable printing of sequence charts. More functionality for hiding unwanted events has been added to the GUI. The max_events, hide_unknown and display_mode configuration parameters to et_viewer is not used any more. Now the event cache in the Viewer only contains those events that actually are displayed in the GUI.
Diffstat (limited to 'lib/et/examples')
-rw-r--r--lib/et/examples/Makefile14
-rw-r--r--lib/et/examples/et_demo.erl103
-rw-r--r--lib/et/examples/et_display_demo.erl32
-rw-r--r--lib/et/examples/et_trace_demo.erl38
4 files changed, 151 insertions, 36 deletions
diff --git a/lib/et/examples/Makefile b/lib/et/examples/Makefile
index 553fe55f3b..67a6536fdf 100644
--- a/lib/et/examples/Makefile
+++ b/lib/et/examples/Makefile
@@ -1,19 +1,19 @@
#
# %CopyrightBegin%
-#
-# Copyright Ericsson AB 2002-2009. All Rights Reserved.
-#
+#
+# Copyright Ericsson AB 2002-2010. 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%
#
@@ -38,7 +38,9 @@ RELSYSDIR = $(RELEASE_PATH)/lib/et-$(VSN)
MODULES = \
- et_demo
+ et_demo \
+ et_display_demo \
+ et_trace_demo
ERL_FILES= $(MODULES:=.erl)
diff --git a/lib/et/examples/et_demo.erl b/lib/et/examples/et_demo.erl
index 57e7e77246..e439e6882c 100644
--- a/lib/et/examples/et_demo.erl
+++ b/lib/et/examples/et_demo.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2002-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 2002-2010. 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%
%%
%%----------------------------------------------------------------------
@@ -23,24 +23,29 @@
-module(et_demo).
-export([
- sim_trans/0,
+ sim_trans/0, sim_trans/1,
+ live_trans/0, live_trans/1,
mgr_actors/1,
- live_trans/0,
- start/0,
- start/1,
+ start/0, start/1,
filters/0,
trace_mnesia/0
]).
+%% Test
+-export([s/0, t/0, t/1, init/0, gen/3]).
+
-include_lib("et/include/et.hrl").
%%----------------------------------------------------------------------
%sim_trans
sim_trans() ->
+ sim_trans([]).
+
+sim_trans(ExtraOptions) ->
Options = [{dict_insert, {filter, mgr_actors}, fun mgr_actors/1}],
- {ok, Viewer} = et_viewer:start_link(Options),
- Collector = et_viewer:get_collector_pid(Viewer),
+ {ok, Viewer} = et_viewer:start_link(Options ++ ExtraOptions),
+ Collector = et_viewer:get_collector_pid(Viewer),
et_collector:report_event(Collector, 60, my_shell, mnesia_tm, start_outer,
"Start outer transaction"),
et_collector:report_event(Collector, 40, mnesia_tm, my_shell, new_tid,
@@ -56,11 +61,13 @@ sim_trans() ->
et_collector:report_event(Collector, 60, my_shell, mnesia_tm, delete_transaction,
"End of outer transaction"),
et_collector:report_event(Collector, 20, my_shell, end_outer,
- "Transaction returned {atomic, ok}").
+ "Transaction returned {atomic, ok}"),
+ {collector, Collector}.
+
%sim_trans
%mgr_actors
-mgr_actors(E) when record(E, event) ->
+mgr_actors(E) when is_record(E, event) ->
Actor = fun(A) ->
case A of
mnesia_tm -> trans_mgr;
@@ -94,9 +101,13 @@ start(ExtraOptions) ->
%live_trans
live_trans() ->
- et_demo:start([{title, "Mnesia tracer"},
- {hide_actions, true},
- {active_filter, named_process_info_nolink}]),
+ live_trans([]).
+
+live_trans(ExtraOptions) ->
+ Options = [{title, "Mnesia tracer"},
+ {hide_actions, true},
+ {active_filter, named_process_info_nolink}],
+ et_demo:start(Options ++ ExtraOptions),
mnesia:start(),
mnesia:create_table(my_tab, [{ram_copies, [node()]}]),
et_demo:trace_mnesia(),
@@ -146,7 +157,7 @@ filters() ->
%filters
%module_as_actor
-module_as_actor(E) when record(E, event) ->
+module_as_actor(E) when is_record(E, event) ->
case lists:keysearch(mfa, 1, E#event.contents) of
{value, {mfa, {M, F, _A}}} ->
case lists:keysearch(pam_result, 1, E#event.contents) of
@@ -163,7 +174,7 @@ module_as_actor(E) when record(E, event) ->
%%----------------------------------------------------------------------
%plain_process_info
-plain_process_info(E) when record(E, event) ->
+plain_process_info(E) when is_record(E, event) ->
case E#event.label of
send -> true;
send_to_non_existing_process -> true;
@@ -182,7 +193,7 @@ plain_process_info(E) when record(E, event) ->
%plain_process_info
%plain_process_info_nolink
-plain_process_info_nolink(E) when record(E, event) ->
+plain_process_info_nolink(E) when is_record(E, event) ->
(E#event.label /= link) and
(E#event.label /= unlink) and
(E#event.label /= getting_linked) and
@@ -191,7 +202,7 @@ plain_process_info_nolink(E) when record(E, event) ->
%%----------------------------------------------------------------------
-named_process_info(E) when record(E, event) ->
+named_process_info(E) when is_record(E, event) ->
case plain_process_info(E) of
true ->
{true, E#event{to = pid_to_name(E#event.to),
@@ -201,7 +212,7 @@ named_process_info(E) when record(E, event) ->
false
end.
-named_process_info_nolink(E) when record(E, event) ->
+named_process_info_nolink(E) when is_record(E, event) ->
case plain_process_info_nolink(E) of
true ->
{true, E#event{to = pid_to_name(E#event.to),
@@ -211,7 +222,7 @@ named_process_info_nolink(E) when record(E, event) ->
false
end.
-pid_to_name(Pid) when pid(Pid) ->
+pid_to_name(Pid) when is_pid(Pid) ->
case process_info(Pid, registered_name) of
{registered_name, Name} ->
Name;
@@ -225,7 +236,7 @@ pid_to_name(Other) ->
%%----------------------------------------------------------------------
-node_process_info(E) when record(E, event) ->
+node_process_info(E) when is_record(E, event) ->
case plain_process_info(E) of
true ->
{true, E#event{to = pid_to_node(E#event.to),
@@ -234,7 +245,7 @@ node_process_info(E) when record(E, event) ->
false ->
false
end.
-node_process_info_nolink(E) when record(E, event) ->
+node_process_info_nolink(E) when is_record(E, event) ->
case plain_process_info_nolink(E) of
true ->
{true, E#event{to = pid_to_node(E#event.to),
@@ -244,21 +255,21 @@ node_process_info_nolink(E) when record(E, event) ->
false
end.
-pid_to_node(Pid) when pid(Pid) ->
+pid_to_node(Pid) when is_pid(Pid) ->
node(Pid);
-pid_to_node(Name) when atom(Name) ->
+pid_to_node(Name) when is_atom(Name) ->
node();
-pid_to_node({_Name, Node}) when atom(Node) ->
+pid_to_node({_Name, Node}) when is_atom(Node) ->
Node.
%%----------------------------------------------------------------------
-application_as_actor(E) when record(E, event) ->
+application_as_actor(E) when is_record(E, event) ->
{true, E#event{to = pid_to_application(E#event.to),
from = pid_to_application(E#event.from),
label = msg_to_label(E)}}.
-pid_to_application(Pid) when pid(Pid) ->
+pid_to_application(Pid) when is_pid(Pid) ->
case application:get_application(Pid) of
{ok, Name} ->
Name;
@@ -268,7 +279,7 @@ pid_to_application(Pid) when pid(Pid) ->
%%----------------------------------------------------------------------
-msg_to_label(E) when record(E, event) ->
+msg_to_label(E) when is_record(E, event) ->
case lists:keysearch(msg, 1, E#event.contents) of
{value, {msg, Msg}} ->
mnesia_msg_to_label(Msg, E#event.label);
@@ -349,3 +360,35 @@ mnesia_msg_to_label(Msg, Label) ->
_ -> Label
end.
+%%----------------------------------------------------------------------
+
+s() ->
+ spawn(fun() -> t(), timer:sleep(infinity) end).
+
+t() ->
+ t(500).
+
+t(N) ->
+ Collector = init(),
+ gen(Collector, 1, N),
+ Collector.
+
+init() ->
+ EvenFilter =
+ fun(#event{label = Label}) ->
+ case catch (list_to_integer(Label) div 10) rem 2 of
+ 0 ->
+ false;
+ _ ->
+ true
+ end
+ end,
+ OddFilter = fun(E) -> not EvenFilter(E) end,
+ {ok, Viewer} = et_viewer:start_link([{dict_insert, {filter, odd_tens}, EvenFilter},
+ {dict_insert, {filter, even_tens}, OddFilter},
+ {active_filter, odd_tens}]),
+ et_viewer:get_collector_pid(Viewer).
+
+gen(Collector, From, To) ->
+ [et_collector:report_event(Collector, 20, from, to, integer_to_list(I), [I]) || I <- lists:seq(From, To)],
+ ok.
diff --git a/lib/et/examples/et_display_demo.erl b/lib/et/examples/et_display_demo.erl
new file mode 100644
index 0000000000..ebcbc2e816
--- /dev/null
+++ b/lib/et/examples/et_display_demo.erl
@@ -0,0 +1,32 @@
+%%
+%% %CopyrightBegin%
+%% %CopyrightEnd%
+%%
+
+%module
+-module(et_display_demo).
+
+-export([test/0]).
+
+test() ->
+ {ok, Viewer} = et_viewer:start([{title,"Coffee Order"}, {max_actors,10}]),
+ Drink = {drink,iced_chai_latte},
+ Size = {size,grande},
+ Milk = {milk,whole},
+ Flavor = {flavor,vanilla},
+ C = et_viewer:get_collector_pid(Viewer),
+ et_collector:report_event(C,99,customer,barrista1,place_order,[Drink,Size,Milk,Flavor]),
+ et_collector:report_event(C,80,barrista1,register,enter_order,[Drink,Size,Flavor]),
+ et_collector:report_event(C,80,register,barrista1,give_total,"$5"),
+ et_collector:report_event(C,80,barrista1,barrista1,get_cup,[Drink,Size]),
+ et_collector:report_event(C,80,barrista1,barrista2,give_cup,[]),
+ et_collector:report_event(C,90,barrista1,customer,request_money,"$5"),
+ et_collector:report_event(C,90,customer,barrista1,pay_money,"$5"),
+ et_collector:report_event(C,80,barrista2,barrista2,get_chai_mix,[]),
+ et_collector:report_event(C,80,barrista2,barrista2,add_flavor,[Flavor]),
+ et_collector:report_event(C,80,barrista2,barrista2,add_milk,[Milk]),
+ et_collector:report_event(C,80,barrista2,barrista2,add_ice,[]),
+ et_collector:report_event(C,80,barrista2,barrista2,swirl,[]),
+ et_collector:report_event(C,80,barrista2,customer,give_tasty_beverage,[Drink,Size]),
+ ok.
+%module
diff --git a/lib/et/examples/et_trace_demo.erl b/lib/et/examples/et_trace_demo.erl
new file mode 100644
index 0000000000..5c16d4b77c
--- /dev/null
+++ b/lib/et/examples/et_trace_demo.erl
@@ -0,0 +1,38 @@
+%%
+%% %CopyrightBegin%
+%% %CopyrightEnd%
+%%
+
+%module
+-module(et_trace_demo).
+
+-export([test/0]).
+
+test() ->
+ et_viewer:start([
+ {title,"Coffee Order"},
+ {trace_global,true},
+ {trace_pattern,{et,max}},
+ {max_actors,10}
+ ]),
+ %% dbg:p(all,call),
+ %% dbg:tpl(et, trace_me, 5, []),
+ Drink = {drink,iced_chai_latte},
+ Size = {size,grande},
+ Milk = {milk,whole},
+ Flavor = {flavor,vanilla},
+ et:trace_me(99,customer,barrista1,place_order,[Drink,Size,Milk,Flavor]),
+ et:trace_me(80,barrista1,register,enter_order,[Drink,Size,Flavor]),
+ et:trace_me(80,register,barrista1,give_total,"$5"),
+ et:trace_me(80,barrista1,barrista1,get_cup,[Drink,Size]),
+ et:trace_me(80,barrista1,barrista2,give_cup,[]),
+ et:trace_me(90,barrista1,customer,request_money,"$5"),
+ et:trace_me(90,customer,barrista1,pay_money,"$5"),
+ et:trace_me(80,barrista2,barrista2,get_chai_mix,[]),
+ et:trace_me(80,barrista2,barrista2,add_flavor,[Flavor]),
+ et:trace_me(80,barrista2,barrista2,add_milk,[Milk]),
+ et:trace_me(80,barrista2,barrista2,add_ice,[]),
+ et:trace_me(80,barrista2,barrista2,swirl,[]),
+ et:trace_me(80,barrista2,customer,give_tasty_beverage,[Drink,Size]),
+ ok.
+%module