~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/et/doc/src/et_examples.xml

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0" encoding="latin1" ?>
2
 
<!DOCTYPE chapter SYSTEM "chapter.dtd">
3
 
 
4
 
<chapter>
5
 
  <header>
6
 
    <copyright>
7
 
      <year>2002</year><year>2009</year>
8
 
      <holder>Ericsson AB. All Rights Reserved.</holder>
9
 
    </copyright>
10
 
    <legalnotice>
11
 
      The contents of this file are subject to the Erlang Public License,
12
 
      Version 1.1, (the "License"); you may not use this file except in
13
 
      compliance with the License. You should have received a copy of the
14
 
      Erlang Public License along with this software. If not, it can be
15
 
      retrieved online at http://www.erlang.org/.
16
 
    
17
 
      Software distributed under the License is distributed on an "AS IS"
18
 
      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
 
      the License for the specific language governing rights and limitations
20
 
      under the License.
21
 
    
22
 
    </legalnotice>
23
 
 
24
 
    <title>Examples</title>
25
 
    <prepared>H&aring;kan Mattsson</prepared>
26
 
    <responsible>H&aring;kan Mattsson</responsible>
27
 
    <docno></docno>
28
 
    <approved>H&aring;kan Mattsson</approved>
29
 
    <checked></checked>
30
 
    <date></date>
31
 
    <rev>%VSN%</rev>
32
 
    <file>et_examples.xml</file>
33
 
  </header>
34
 
 
35
 
  <section>
36
 
    <title>A simulated Mnesia transaction</title>
37
 
    <p>The Erlang code for running the simulated Mnesia transaction example
38
 
      in the previous chapter is included in the <c>et/examples/et_demo.erl</c> file:
39
 
      </p>
40
 
    <p></p>
41
 
    <codeinclude file="../../examples/et_demo.erl" tag="%sim_trans" type="erl"></codeinclude>
42
 
    <p></p>
43
 
    <codeinclude file="../../examples/et_demo.erl" tag="%mgr_actors" type="erl"></codeinclude>
44
 
    <p>If you invoke the <c>et_demo:sim_trans()</c> function a viewer
45
 
      window will pop up and the sequence trace will be almost the same as
46
 
      if the following Mnesia transaction would have been run:</p>
47
 
    <p></p>
48
 
    <code type="none">
49
 
         mnesia:transaction(fun() -> mnesia:write({my_tab, key, val}) end).
50
 
    </code>
51
 
    <p>And the viewer window will look like:</p>
52
 
    <p></p>
53
 
    <code type="none"><![CDATA[
54
 
          $ erl -pa ../examples
55
 
          Erlang (BEAM) emulator version 2002.10.08 [source]
56
 
 
57
 
          Eshell V2002.10.08  (abort with ^G)
58
 
          1> et_demo:sim_trans().
59
 
          {ok,{table_handle,<0.30.0>,11,trace_ts,#Fun<et_collector.0.83904657>}}
60
 
          2>
61
 
    ]]></code>
62
 
    <p></p>
63
 
    <image file="sim_trans.gif">
64
 
      <icaption>A simulated Mnesia transaction which writes one record</icaption>
65
 
    </image>
66
 
  </section>
67
 
 
68
 
  <section>
69
 
    <title>Some convenient functions used in the Mnesia transaction example</title>
70
 
    <p>The <c>module_as_actor</c> filter converts the event-records so
71
 
      the module names becomes actors and the invoked functions becomes
72
 
      labels. If the information about who the caller was it will be
73
 
      displayed as an arrow directed from the caller to the callee. The
74
 
      <c>[{message, {caller}}, {return_trace}]</c> options to <c>dbg:tpl/2</c>
75
 
      function will imply the necessary information in the Erlang traces.
76
 
      Here follows the <c>module_as_actor</c> filter:</p>
77
 
    <p></p>
78
 
    <codeinclude file="../../examples/et_demo.erl" tag="%module_as_actor" type="erl"></codeinclude>
79
 
    <p>The <c>plain_process_info</c> filter does not alter the event-records.
80
 
      It merely ensures that the event not related to processes are skipped:</p>
81
 
    <p></p>
82
 
    <codeinclude file="../../examples/et_demo.erl" tag="%plain_process_info" type="erl"></codeinclude>
83
 
    <p>The <c>plain_process_info_nolink</c> filter does not alter the
84
 
      event-records. It do makes use of the <c>plain_process_info</c> , but
85
 
      do also ensure that the process info related to linking and unlinking
86
 
      is skipped:</p>
87
 
    <p></p>
88
 
    <codeinclude file="../../examples/et_demo.erl" tag="%plain_process_info_nolink" type="erl"></codeinclude>
89
 
    <p>In order to simplify the startup of an <c>et_viewer</c> process
90
 
      with the filters mentioned above, plus some others (that also are
91
 
      found in <c>et/examples/et_demo.erl</c> src/et_collector.erl the
92
 
      <c>et_demo:start/0,1</c> functions can be used:</p>
93
 
    <p></p>
94
 
    <codeinclude file="../../examples/et_demo.erl" tag="%start" type="erl"></codeinclude>
95
 
    <p>A simple one-liner starts the tool:</p>
96
 
    <code type="none">
97
 
          erl -pa ../examples -s et_demo
98
 
    </code>
99
 
    <p>The filters are included by the following parameters:</p>
100
 
    <p></p>
101
 
    <codeinclude file="../../examples/et_demo.erl" tag="%filters" type="erl"></codeinclude>
102
 
  </section>
103
 
 
104
 
  <section>
105
 
    <title>Erlang trace of a Mnesia transaction</title>
106
 
    <p>The following piece of code <c>et_demo:trace_mnesia/0</c>
107
 
      activates call tracing of both local and external function calls for
108
 
      all modules in the Mnesia application. The call traces are configured
109
 
      cover all processes (both existing and those that are spawned in the
110
 
      future) and include timestamps for trace data. It do also activate
111
 
      tracing of process related events for Mnesia's static processes plus
112
 
      the calling process (that is your shell). Please, observe that the
113
 
      <c>whereis/1</c> call in the following code requires that both the
114
 
      traced Mnesia application and the <c>et_viewer</c>is running on the
115
 
      same node:</p>
116
 
    <p></p>
117
 
    <codeinclude file="../../examples/et_demo.erl" tag="%trace_mnesia" type="erl"></codeinclude>
118
 
    <p>The <c>et_demo:live_trans/0</c> function starts the a global
119
 
      controller, starts a viewer, starts Mnesia, creates a local table,
120
 
      activates tracing (as described above) and registers the shell
121
 
      process is as 'my_shell' for clarity. Finally the a simple Mnesia
122
 
      transaction that writes a single record is run:</p>
123
 
    <p></p>
124
 
    <codeinclude file="../../examples/et_demo.erl" tag="%live_trans" type="erl"></codeinclude>
125
 
    <p>Now we run the <c>et_demo:live_trans/0</c> function:</p>
126
 
    <p></p>
127
 
    <code type="none">
128
 
       erl -pa ../examples -s et_demo live_trans
129
 
       Erlang (BEAM) emulator version 2002.10.08 [source]
130
 
 
131
 
       Eshell V2002.10.08  (abort with ^G)
132
 
       1>
133
 
    </code>
134
 
    <p>Please, explore the different filters in order to see how the traced
135
 
      transaction can be seen from different point of views:</p>
136
 
    <p></p>
137
 
    <image file="live_trans.gif">
138
 
      <icaption>A real Mnesia transaction which writes one record</icaption>
139
 
    </image>
140
 
  </section>
141
 
 
142
 
  <section>
143
 
    <title>Erlang trace of Megaco startup</title>
144
 
    <p>The Event Tracer (ET) tool was initially written in order to
145
 
      demonstrate how messages where sent over the Megaco protocol. This
146
 
      were back in the old days before the standard bodies of IETF and ITU
147
 
      had approved Megaco (also called H.248) as an international
148
 
      standard.</p>
149
 
    <p>In the Megaco application of Erlang/OTP, the code is carefully
150
 
      instrumented with calls to <c>et:report_event/5</c>. For call a detail
151
 
      level is set in order to dynamically control the trace level in a
152
 
      simple manner.</p>
153
 
    <p>The <c>megaco_filter</c> module implements a customized filter
154
 
      for Megaco messages. It does also make use of <c>trace_global</c>
155
 
      combined with usage of the <c>trace_pattern</c>:</p>
156
 
    <p></p>
157
 
    <code type="none">
158
 
       -module(megaco_filter).
159
 
       -export([start/0]).
160
 
 
161
 
       start() ->
162
 
           Options =
163
 
               [{event_order, event_ts},
164
 
                {scale, 3},
165
 
                {max_actors, infinity},
166
 
                {trace_pattern, {megaco, max}},
167
 
                {trace_global, true},
168
 
                {dict_insert, {filter, megaco_filter}, fun filter/1},
169
 
                {active_filter, megaco_filter},
170
 
                {title, "Megaco tracer - Erlang/OTP"}],
171
 
           et_viewer:start(Options).
172
 
    </code>
173
 
    <p>First we start an Erlang node with the a global collector and
174
 
      its viewer. The <c>et_viewer: search for: [] ++ ["gateway_tt"]</c>
175
 
      printout is caused by a click on the "gateway_tt" actor name in the
176
 
      viewer. It means that only events with that actor will be displayed
177
 
      in the viewer.</p>
178
 
    <p></p>
179
 
    <code type="none">
180
 
          erl -sname observer -s megaco_filter
181
 
          Erlang (BEAM) emulator version 2002.10.08 [source]
182
 
 
183
 
          Eshell V2002.10.08  (abort with ^G)
184
 
          (observer@amrod)1> et_viewer: search for: [] ++ ["gateway_tt"]
185
 
    </code>
186
 
    <p>Secondly we start another Erlang node which we connect the
187
 
      observer node, before we start the application that we want to
188
 
      trace. In this case we start a Media Gateway Controller that listens
189
 
      for both TCP and UDP on the text and binary ports for Megaco:</p>
190
 
    <p></p>
191
 
    <code type="none">
192
 
          erl -sname mgc -pa ../../megaco/examples/simple
193
 
          Erlang (BEAM) emulator version 2002.10.08 [source]
194
 
 
195
 
          Eshell V2002.10.08  (abort with ^G)
196
 
          (mgc@amrod)1> net:ping(observer@amrod). 
197
 
          pong
198
 
          (mgc@amrod)2> megaco:start().
199
 
          ok
200
 
          (mgc@amrod)3> megaco_simple_mgc:start().
201
 
          {ok,[{ok,2944,
202
 
                   {megaco_receive_handle,{deviceName,"controller"},
203
 
                                          megaco_pretty_text_encoder,
204
 
                                          [],
205
 
                                          megaco_tcp}},
206
 
               {ok,2944,
207
 
                   {megaco_receive_handle,{deviceName,"controller"},
208
 
                                          megaco_pretty_text_encoder,
209
 
                                          [],
210
 
                                          megaco_udp}},
211
 
               {ok,2945,
212
 
                   {megaco_receive_handle,{deviceName,"controller"},
213
 
                                          megaco_binary_encoder,
214
 
                                          [],
215
 
                                          megaco_tcp}},
216
 
               {ok,2945,
217
 
                   {megaco_receive_handle,{deviceName,"controller"},
218
 
                                          megaco_binary_encoder,
219
 
                                          [],
220
 
                                          megaco_udp}}]}
221
 
          (mgc@amrod)4> 
222
 
    </code>
223
 
    <p>And finally we start an Erlang node for the Media Gateways and
224
 
      connect to the observer node. Each Media Gateway connects to the
225
 
      controller and sends an initial Service Change message. The controller
226
 
      accepts the gateways and sends a reply to each one using the same
227
 
      transport mechanism and message encoding according to the preference
228
 
      of each gateway. That is all combinations of TCP/IP transport, UDP/IP
229
 
      transport, text encoding and ASN.1 BER encoding:</p>
230
 
    <p></p>
231
 
    <code type="none">
232
 
          erl -sname mg -pa ../../megaco/examples/simple
233
 
          Erlang (BEAM) emulator version 2002.10.08 [source]
234
 
 
235
 
          Eshell V2002.10.08  (abort with ^G)
236
 
          (mg@amrod)1> net:ping(observer@amrod). 
237
 
          pong
238
 
          (mg@amrod)2> megaco_simple_mg:start(). 
239
 
          [{{deviceName,"gateway_tt"},{error,{start_user,megaco_not_started}}},
240
 
           {{deviceName,"gateway_tb"},{error,{start_user,megaco_not_started}}},
241
 
           {{deviceName,"gateway_ut"},{error,{start_user,megaco_not_started}}},
242
 
           {{deviceName,"gateway_ub"},{error,{start_user,megaco_not_started}}}]
243
 
          (mg@amrod)3> megaco:start().
244
 
          ok
245
 
          (mg@amrod)4>  megaco_simple_mg:start().
246
 
          [{{deviceName,"gateway_tt"},
247
 
            {1,
248
 
             {ok,[{'ActionReply',0,
249
 
                                 asn1_NOVALUE,
250
 
                                 asn1_NOVALUE,
251
 
                                 [{serviceChangeReply,
252
 
                                      {'ServiceChangeReply',
253
 
                                          [{megaco_term_id,false,["root"]}],
254
 
                                          {serviceChangeResParms,
255
 
                                              {'ServiceChangeResParm',
256
 
                                                  {deviceName|...},
257
 
                                                  asn1_NOVALUE|...}}}}]}]}}},
258
 
           {{deviceName,"gateway_tb"},
259
 
            {1,
260
 
             {ok,[{'ActionReply',0,
261
 
                                 asn1_NOVALUE,
262
 
                                 asn1_NOVALUE,
263
 
                                 [{serviceChangeReply,
264
 
                                      {'ServiceChangeReply',
265
 
                                          [{megaco_term_id,false,["root"]}],
266
 
                                          {serviceChangeResParms,
267
 
                                              {'ServiceChangeResParm',
268
 
                                                  {...}|...}}}}]}]}}},
269
 
           {{deviceName,"gateway_ut"},
270
 
            {1,
271
 
             {ok,[{'ActionReply',0,
272
 
                                 asn1_NOVALUE,
273
 
                                 asn1_NOVALUE,
274
 
                                 [{serviceChangeReply,
275
 
                                      {'ServiceChangeReply',
276
 
                                          [{megaco_term_id,false,["root"]}],
277
 
                                          {serviceChangeResParms,
278
 
                                              {'ServiceChangeResParm',{...}|...}}}}]}]}}},
279
 
           {{deviceName,"gateway_ub"},
280
 
            {1,
281
 
             {ok,[{'ActionReply',0,
282
 
                                 asn1_NOVALUE,
283
 
                                 asn1_NOVALUE,
284
 
                                 [{serviceChangeReply,
285
 
                                      {'ServiceChangeReply',
286
 
                                          [{megaco_term_id,false,["root"]}],
287
 
                                          {serviceChangeResParms,
288
 
                                              {'ServiceChangeResParm'|...}}}}]}]}}}]
289
 
          (mg@amrod)5> 
290
 
    </code>
291
 
    <p>The Megaco adopted viewer looks like this, when we have clicked
292
 
      on the "gateway_tt" actor name in order to only display the events
293
 
      regarding that actor:</p>
294
 
    <p></p>
295
 
    <image file="megaco_tracer.gif">
296
 
      <icaption>The viewer adopted for Megaco</icaption>
297
 
    </image>
298
 
    <p>A pretty printed Megaco message looks like this:</p>
299
 
    <p></p>
300
 
    <image file="megaco_filter.gif">
301
 
      <icaption>A textual Megaco message</icaption>
302
 
    </image>
303
 
    <p>And the corresponding internal form for the same Megaco message
304
 
      looks like this:</p>
305
 
    <p></p>
306
 
    <image file="megaco_collector.gif">
307
 
      <icaption>The internal form of a Megaco message</icaption>
308
 
    </image>
309
 
  </section>
310
 
</chapter>
311