1instrument(3) Erlang Module Definition instrument(3)
2
3
4
6 instrument - Analysis and Utility Functions for Instrumentation
7
9 The module instrument contains support for studying the resource usage
10 in an Erlang runtime system. Currently, only the allocation of memory
11 can be studied.
12
13 Note:
14 Note that this whole module is experimental, and the representations
15 used as well as the functionality is likely to change in the future.
16
17
19 block_histogram() = tuple()
20
21 A histogram of block sizes where each interval's upper bound is
22 twice as high as the one before it.
23
24 The upper bound of the first interval is provided by the func‐
25 tion that returned the histogram, and the last interval has no
26 upper bound.
27
28 allocation_summary() =
29 {HistogramStart :: integer() >= 0,
30 UnscannedSize :: integer() >= 0,
31 Allocations ::
32 #{Origin :: atom() =>
33 #{Type :: atom() => block_histogram()}}}
34
35 A summary of allocated block sizes (including their headers)
36 grouped by their Origin and Type.
37
38 Origin is generally which NIF or driver that allocated the
39 blocks, or 'system' if it could not be determined.
40
41 Type is the allocation category that the blocks belong to, e.g.
42 db_term, message or binary.
43
44 If one or more carriers could not be scanned in full without
45 harming the responsiveness of the system, UnscannedSize is the
46 number of bytes that had to be skipped.
47
48 carrier_info_list() =
49 {HistogramStart :: integer() >= 0,
50 Carriers ::
51 [{AllocatorType :: atom(),
52 InPool :: boolean(),
53 TotalSize :: integer() >= 0,
54 UnscannedSize :: integer() >= 0,
55 Allocations ::
56 {Type :: atom(),
57 Count :: integer() >= 0,
58 Size :: integer() >= 0},
59 FreeBlocks :: block_histogram()}]}
60
61 AllocatorType is the type of the allocator that employs this
62 carrier.
63
64 InPool is whether the carrier is in the migration pool.
65
66 TotalSize is the total size of the carrier, including its
67 header.
68
69 Allocations is a summary of the allocated blocks in the carrier.
70
71 FreeBlocks is a histogram of the free block sizes in the car‐
72 rier.
73
74 If the carrier could not be scanned in full without harming the
75 responsiveness of the system, UnscannedSize is the number of
76 bytes that had to be skipped.
77
79 allocations() -> {ok, Result} | {error, Reason}
80
81 Types:
82
83 Result = allocation_summary()
84 Reason = not_enabled
85
86 Shorthand for allocations(#{}).
87
88 allocations(Options) -> {ok, Result} | {error, Reason}
89
90 Types:
91
92 Result = allocation_summary()
93 Reason = not_enabled
94 Options =
95 #{scheduler_ids => [integer() >= 0],
96 allocator_types => [atom()],
97 histogram_start => integer() >= 1,
98 histogram_width => integer() >= 1}
99
100 Returns a summary of all tagged allocations in the system, op‐
101 tionally filtered by allocator type and scheduler id.
102
103 Only binaries and allocations made by NIFs and drivers are
104 tagged by default, but this can be configured an a per-allocator
105 basis with the +M<S>atags emulator option.
106
107 If the specified allocator types are not enabled, the call will
108 fail with {error, not_enabled}.
109
110 The following options can be used:
111
112 allocator_types:
113 The allocator types that will be searched. Note that blocks
114 can move freely between allocator types, so restricting the
115 search to certain allocators may return unexpected types
116 (e.g. process heaps when searching binary_alloc), or hide
117 blocks that were migrated out.
118
119 Defaults to all alloc_util allocators.
120
121 scheduler_ids:
122 The scheduler ids whose allocator instances will be
123 searched. A scheduler id of 0 will refer to the global in‐
124 stance that is not tied to any particular scheduler. De‐
125 faults to all schedulers and the global instance.
126
127 histogram_start:
128 The upper bound of the first interval in the allocated block
129 size histograms. Defaults to 128.
130
131 histogram_width:
132 The number of intervals in the allocated block size his‐
133 tograms. Defaults to 18.
134
135 Example:
136
137 > instrument:allocations(#{ histogram_start => 128, histogram_width => 15 }).
138 {ok,{128,0,
139 #{udp_inet =>
140 #{driver_event_state => {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}},
141 system =>
142 #{heap => {0,0,0,0,20,4,2,2,2,3,0,1,0,0,1},
143 db_term => {271,3,1,52,80,1,0,0,0,0,0,0,0,0,0},
144 code => {0,0,0,5,3,6,11,22,19,20,10,2,1,0,0},
145 binary => {18,0,0,0,7,0,0,1,0,0,0,0,0,0,0},
146 message => {0,40,78,2,2,0,0,0,0,0,0,0,0,0,0},
147 ... }
148 spawn_forker =>
149 #{driver_select_data_state =>
150 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
151 ram_file_drv => #{drv_binary => {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}},
152 prim_file =>
153 #{process_specific_data => {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
154 nif_trap_export_entry => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0},
155 monitor_extended => {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
156 drv_binary => {0,0,0,0,0,0,1,0,3,5,0,0,0,1,0},
157 binary => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0}},
158 prim_buffer =>
159 #{nif_internal => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0},
160 binary => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0}}}}}
161
162
163 carriers() -> {ok, Result} | {error, Reason}
164
165 Types:
166
167 Result = carrier_info_list()
168 Reason = not_enabled
169
170 Shorthand for carriers(#{}).
171
172 carriers(Options) -> {ok, Result} | {error, Reason}
173
174 Types:
175
176 Result = carrier_info_list()
177 Reason = not_enabled
178 Options =
179 #{scheduler_ids => [integer() >= 0],
180 allocator_types => [atom()],
181 histogram_start => integer() >= 1,
182 histogram_width => integer() >= 1}
183
184 Returns a summary of all carriers in the system, optionally fil‐
185 tered by allocator type and scheduler id.
186
187 If the specified allocator types are not enabled, the call will
188 fail with {error, not_enabled}.
189
190 The following options can be used:
191
192 allocator_types:
193 The allocator types that will be searched. Defaults to all
194 alloc_util allocators.
195
196 scheduler_ids:
197 The scheduler ids whose allocator instances will be
198 searched. A scheduler id of 0 will refer to the global in‐
199 stance that is not tied to any particular scheduler. De‐
200 faults to all schedulers and the global instance.
201
202 histogram_start:
203 The upper bound of the first interval in the free block size
204 histograms. Defaults to 512.
205
206 histogram_width:
207 The number of intervals in the free block size histograms.
208 Defaults to 14.
209
210 Example:
211
212 > instrument:carriers(#{ histogram_start => 512, histogram_width => 8 }).
213 {ok,{512,
214 [{ll_alloc,1048576,0,1048344,71,false,{0,0,0,0,0,0,0,0}},
215 {binary_alloc,1048576,0,324640,13,false,{3,0,0,1,0,0,0,2}},
216 {eheap_alloc,2097152,0,1037200,45,false,{2,1,1,3,4,3,2,2}},
217 {fix_alloc,32768,0,29544,82,false,{22,0,0,0,0,0,0,0}},
218 {...}|...]}}
219
220
222 erts_alloc(3), erl(1)
223
224
225
226Ericsson AB tools 3.5.1 instrument(3)