1msacc(3)                   Erlang Module Definition                   msacc(3)
2
3
4

NAME

6       msacc - Convenience functions for microstate accounting
7

DESCRIPTION

9       This   module  implements  some  convenience  functions  for  analyzing
10       microstate accounting data. For details about how to use the basic  api
11       and   what   the   different   states   represent  see   erlang:statis‐
12       tics(microstate_accounting).
13
14       Basic Scenario
15
16       1> msacc:start(1000).
17       ok
18       2> msacc:print().
19       Average thread real-time    : 1000513 us
20       Accumulated system run-time :    2213 us
21       Average scheduler run-time  :    1076 us
22
23               Thread      aux check_io emulator       gc    other     port    sleep
24
25       Stats per thread:
26            async( 0)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
27            async( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
28              aux( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%   99.99%
29        scheduler( 1)    0.00%    0.03%    0.13%    0.00%    0.01%    0.00%   99.82%
30        scheduler( 2)    0.00%    0.00%    0.00%    0.00%    0.03%    0.00%   99.97%
31
32       Stats per type:
33                async    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
34                  aux    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%   99.99%
35            scheduler    0.00%    0.02%    0.06%    0.00%    0.02%    0.00%   99.89%
36       ok
37
38
39       This first command enables microstate accounting for 1000 milliseconds.
40       See  start/0,  stop/0, reset/0 and start/1 for more details. The second
41       command prints the statistics gathered during that  time.  First  three
42       general statistics are printed.
43
44         Average real-time:
45           The  average time spent collecting data in the threads. This should
46           be close to the time which data was collected.
47
48         System run-time:
49           The total run-time of all threads in the system. This is  what  you
50           get if you call msacc:stats(total_runtime,Stats).
51
52         Average scheduler run-time:
53           The average run-time for the schedulers. This is the average amount
54           of time the schedulers did not sleep.
55
56       Then one column per state is printed with a the percentage of time this
57       thread  spent  in the state out of it's own real-time. After the thread
58       specific time, the accumulated time for each type of thread is  printed
59       in a similar format.
60
61       Since  we  have  the average real-time and the percentage spent in each
62       state we can easily calculate the time spent in each state by multiply‐
63       ing  Average thread real-time with Thread state %, i.e. to get the time
64       Scheduler 1 spent in the emulator state  we  do  1000513us  *  0.13%  =
65       1300us.
66

DATA TYPES

68       msacc_data() = [msacc_data_thread()]
69
70       msacc_data_thread() =
71           #{'$type' := msacc_data,
72             type := msacc_type(),
73             id := msacc_id(),
74             counters := msacc_data_counters()}
75
76       msacc_data_counters() = #{msacc_state() => integer() >= 0}
77
78              A  map containing the different microstate accounting states and
79              the number of microseconds spent in it.
80
81       msacc_stats() = [msacc_stats_thread()]
82
83       msacc_stats_thread() =
84           #{'$type' := msacc_stats,
85             type := msacc_type(),
86             id := msacc_id(),
87             system := float(),
88             counters := msacc_stats_counters()}
89
90              A map containing information about a specific thread.  The  per‐
91              centages  in the map can be either run-time or real-time depend‐
92              ing on if runtime or realtime was requested from stats/2. system
93              is the percentage of total system time for this specific thread.
94
95       msacc_stats_counters() =
96           #{msacc_state() => #{thread := float(), system := float()}}
97
98              A  map  containing  the  different microstate accounting states.
99              Each value in the map contains another map with  the  percentage
100              of  time  that this thread has spent in the specific state. Both
101              the percentage of system time and the  time  for  that  specific
102              thread is part of the map.
103
104       msacc_type() = scheduler | aux | async
105
106       msacc_id() = integer() >= 0
107
108       msacc_state() =
109           alloc |
110           aux |
111           bif |
112           busy_wait |
113           check_io |
114           emulator |
115           ets |
116           gc |
117           gc_fullsweep |
118           nif |
119           other |
120           port |
121           send |
122           sleep |
123           timers
124
125              The  different  states that a thread can be in. See  erlang:sta‐
126              tistics(microstate_accounting) for details.
127
128       msacc_print_options() = #{system => boolean()}
129
130              The different options that can be given to print/2.
131

EXPORTS

133       available() -> boolean()
134
135              This function checks whether microstate accounting is  available
136              or not.
137
138       start() -> boolean()
139
140              Start  microstate  accounting. Returns whether it was previously
141              enabled or disabled.
142
143       start(Time) -> true
144
145              Types:
146
147                 Time = timeout()
148
149              Resets all counters and then starts  microstate  accounting  for
150              the given milliseconds.
151
152       stop() -> boolean()
153
154              Stop  microstate  accounting.  Returns whether is was previously
155              enabled or disabled.
156
157       reset() -> boolean()
158
159              Reset microstate accounting counters.  Returns  whether  is  was
160              enabled or disabled.
161
162       print() -> ok
163
164              Prints  the  current microstate accounting to standard out. Same
165              as msacc:print(msacc:stats(),#{}).
166
167       print(DataOrStats) -> ok
168
169              Types:
170
171                 DataOrStats = msacc_data() | msacc_stats()
172
173              Print the given microstate statistics values to stdout. Same  as
174              msacc:print(DataOrStats,#{}).
175
176       print(DataOrStats, Options) -> ok
177
178              Types:
179
180                 DataOrStats = msacc_data() | msacc_stats()
181                 Options = msacc_print_options()
182
183              Print  the  given  microstate statistics values to standard out.
184              With many states this can be quite verbose. See the top of  this
185              reference  manual  for  a  brief  description of what the fields
186              mean.
187
188              It is possible to print more specific  types  of  statistics  by
189              first  manipulating  the DataOrStats using stats/2. For instance
190              if you want to print the percentage of run-time for each  thread
191              you can do:
192
193              msacc:print(msacc:stats(runtime,msacc:stats())).
194
195              If you want to only print run-time per thread type you can do:
196
197              msacc:print(msacc:stats(type,msacc:stats(runtime,msacc:stats()))).
198
199              Options
200
201                system:
202                  Print  percentage  of time spent in each state out of system
203                  time as well as thread time. Default: false.
204
205       print(FileOrDevice, DataOrStats, Options) -> ok
206
207              Types:
208
209                 FileOrDevice = file:filename() | io:device()
210                 DataOrStats = msacc_data() | msacc_stats()
211                 Options = msacc_print_options()
212
213              Print the given microstate statistics values to the  given  file
214              or  device.  The  other  arguments  behave  the  same way as for
215              print/2.
216
217       stats() -> msacc_data()
218
219              Returns a runtime system independent version of  the  microstate
220              statistics       data      presented      by      erlang:statis‐
221              tics(microstate_accounting). All counters have  been  normalized
222              to be in microsecond resolution.
223
224       stats(Analysis, Stats) -> integer() >= 0
225
226              Types:
227
228                 Analysis = system_realtime | system_runtime
229                 Stats = msacc_data()
230
231              Returns the system time for the given microstate statistics val‐
232              ues. System time is the accumulated time of all threads.
233
234                realtime:
235                  Returns all time recorded for all threads.
236
237                runtime:
238                  Returns all time spent doing work for all threads, i.e.  all
239                  time not spent in the sleep state.
240
241       stats(Analysis, Stats) -> msacc_stats()
242
243              Types:
244
245                 Analysis = realtime | runtime
246                 Stats = msacc_data()
247
248              Returns  fractions of real-time or run-time spent in the various
249              threads from the given microstate statistics values.
250
251       stats(Analysis, StatsOrData) -> msacc_data() | msacc_stats()
252
253              Types:
254
255                 Analysis = type
256                 StatsOrData = msacc_data() | msacc_stats()
257
258              Returns a list of microstate statistics values where the  values
259              for all threads of the same type has been merged.
260
261       to_file(Filename) -> ok | {error, file:posix()}
262
263              Types:
264
265                 Filename = file:name_all()
266
267              Dumps  the current microstate statistics counters to a file that
268              can be parsed with  file:consult/1.
269
270       from_file(Filename) -> msacc_data()
271
272              Types:
273
274                 Filename = file:name_all()
275
276              Read a file dump produced by  to_file(Filename).
277
278
279
280Ericsson AB                  runtime_tools 1.12.5                     msacc(3)
Impressum