File: README.md

package info (click to toggle)
rabbitmq-server 4.0.5-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 37,948 kB
  • sloc: erlang: 257,835; javascript: 22,466; sh: 2,796; makefile: 2,517; python: 1,966; xml: 646; cs: 335; java: 244; ruby: 212; php: 100; perl: 63; awk: 13
file content (172 lines) | stat: -rw-r--r-- 5,706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
[![Build Status](https://travis-ci.org/massemanet/redbug.svg?branch=master)](https://travis-ci.org/massemanet/redbug)


# DESCRIPTION

redbug is a tool to interact with the Erlang trace facility. It is
intended to be run from the erlang shell, but it can also be run from
an OS shell as an escript (see below). It will instruct the Erlang VM
to generate so-called 'trace messages' when certain events (such as a
particular function being called) occur. It uses a safe subset of the
tracing functionality, and exits if it feels overloaded, e.g. if it
gets flooded by trace messages. It runs in the background, collecting
trace messages, until it reaches one of its termination criteria
(number of messages/file size or elapsed time).

The trace messages are either printed (i.e. human readable) to a file
or to the screen; or written to a trc file.  Using a trc file puts
less stress on the system, but there is no way to count the messages
(so the 'msgs' opt is ignored), and the files can only be read by
special tools (such as 'bread'). Printing and trc files cannot be
combined.  By default (i.e. if the 'file' opt is not given), messages
are printed.

# DOCUMENTATION

Run `erl -run redbug help -run erlang halt`, or `redbug:help().`.

# EXAMPLES

Basic call trace

      1> redbug:start("erlang:demonitor").

      % 18:27:21 <0.188.0>({erlang,apply,2})
      % erlang:demonitor(#Ref<0.2419348116.2832203778.12948>)

      % 18:27:21 <0.188.0>({erlang,apply,2})
      % erlang:demonitor(#Ref<0.2419348116.2832203777.10938>, [flush])

      % 18:27:21 <0.188.0>({erlang,apply,2})
      % erlang:demonitor(#Ref<0.2419348116.2832203777.10939>, [flush])

      % 18:27:21 <0.188.0>({erlang,apply,2})
      % erlang:demonitor(#Ref<0.2419348116.2832203777.10940>, [flush])
      redbug done, timeout - 4


As above, but also print return value. The return value is a separate message.

      2> redbug:start("erlang:demonitor->return",[{msgs,2}]).
      {75,2}

      % 18:31:15 <0.188.0>({erlang,apply,2})
      % erlang:demonitor(#Ref<0.2419348116.2832203780.10535>)

      % 18:31:15 <0.188.0>({erlang,apply,2})
      % erlang:demonitor/1 -> true
      redbug done, msg_count - 1

As above, also print the call stack. Note that not all functions in the
call chain are on the stack, only functions we will return to (this is a
consequence of tail call optimization.)

      3> redbug:start("erlang:demonitor->return,stack",[{msgs,2}]).
      {75,2}

      % 18:32:54 <0.188.0>({erlang,apply,2})
      % erlang:demonitor(#Ref<0.2419348116.2832203778.13012>)
      %   redbug:block_a_little/0 
      %   redbug:start/2 
      %   erl_eval:do_apply/6 
      %   shell:exprs/7 
      %   shell:eval_exprs/7 
      %   shell:eval_loop/3 

As above, but use the 'blocking' opt. redbug:start/2 blocks until end of
trace, and returns the stop reason and a list of trace messages.

    10> spawn(fun()->receive after 2000->ets:tab2list(inet_db) end end).
    <0.540.0>
    11> redbug:start("ets:tab2list(inet_db)",[blocking]).
    {timeout,[{call,{{ets,tab2list,[inet_db]},<<>>},
                    {<0.540.0>,{erlang,apply,2}},
                    {15,50,43,776041}}]}


# ESCRIPT

Run from command line (portable escript archive)

    ./_build/default/bin/redbug [-Opt Value [...]] TargetNode Trc [Trc...]

Examples using the escript

First start a node that we're going to trace:

    erl -sname foo

We'll need to type some commands into the shell for some of the
following traces to trigger.

Start tracing, giving the node name as the first argument. (If the
node name doesn't contain a host name, redbug will create a short
node name by adding the host name.)

    $ redbug foo erlang:demonitor

    % 14:19:29 <5270.91.0>(dead)
    % erlang:demonitor(#Ref<5270.0.4.122>, [flush])

    % 14:19:29 <5270.40.0>({erlang,apply,2})
    % erlang:demonitor(#Ref<5270.0.4.130>, [flush])

    % 14:19:29 <5270.40.0>({erlang,apply,2})
    % erlang:demonitor(#Ref<5270.0.4.131>, [flush])

    % 14:19:29 <5270.40.0>({erlang,apply,2})
    % erlang:demonitor(#Ref<5270.0.4.132>, [flush])
    redbug done, timeout - 4

    %% Limit message count
    $ redbug foo erlang:demonitor -msgs 1

    % 14:22:09 <5276.103.0>(dead)
    % erlang:demonitor(#Ref<5276.0.4.144>, [flush])
    redbug done, msg_count - 1

    %% Print return value. The return value is a separate message.
    $ redbug foo 'erlang:demonitor -> return' -msgs 2

    % 14:23:47 <5276.115.0>(dead)
    % erlang:demonitor(#Ref<5276.0.4.166>, [flush])

    % 14:23:47 <5276.115.0>(dead)
    % erlang:demonitor/2 -> true
    redbug done, msg_count - 1

    %% Also print call stack.
    $ redbug foo 'erlang:demonitor -> return;stack' -msgs 2

    % 14:24:43 <5276.121.0>(dead)
    % erlang:demonitor(#Ref<5276.0.4.177>, [flush])
      shell:'-get_command/5-fun-0-'/1

    % 14:24:43 <5276.121.0>(dead)
    % erlang:demonitor/2 -> true
    redbug done, msg_count - 1

    %% Trace on messages that the 'user_drv' process receives.
    $ redbug foo receive -procs user_drv -msgs 1

    % 14:27:10 <6071.31.0>(user_drv)
    % <<< {#Port<6071.375>,{data,"a"}}
    redbug done, msg_count - 1

    %% As above, but also trace on sends. The two trace patterns
    %% are given as separate arguments.
    $ redbug foo receive send -procs user_drv -msgs 2

    % 17:43:28 <6071.31.0>(user_drv)
    % <<< {#Port<6071.375>,{data,"a"}}

    % 17:43:28 <6071.31.0>(user_drv)
    % <6071.33.0>({group,server,3}) <<< {<6071.31.0>,{data,"a"}}
    redbug done, msg_count - 2

    %% Call trace with a function head match.
    $ redbug foo 'ets:tab2list(inet_db)' -msgs 2

    % 17:45:48 <5276.40.0>({erlang,apply,2})
    % ets:tab2list(inet_db)
    redbug done, timeout - 1