View Source msacc (runtime_tools v2.1)

Convenience functions for microstate accounting

This module implements some convenience functions for analyzing microstate accounting data. For details about how to use the basic API and what the different states represent, see erlang:statistics(microstate_accounting).

Basic Scenario

1> msacc:start(1000).
ok
2> msacc:print().
Average thread real-time    : 1000513 us
Accumulated system run-time :    2213 us
Average scheduler run-time  :    1076 us

        Thread      aux check_io emulator       gc    other     port    sleep

Stats per thread:
     async( 0)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
     async( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
       aux( 1)    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%   99.99%
 scheduler( 1)    0.00%    0.03%    0.13%    0.00%    0.01%    0.00%   99.82%
 scheduler( 2)    0.00%    0.00%    0.00%    0.00%    0.03%    0.00%   99.97%

Stats per type:
         async    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
           aux    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%   99.99%
     scheduler    0.00%    0.02%    0.06%    0.00%    0.02%    0.00%   99.89%
ok

This first command enables microstate accounting for 1000 milliseconds. See start/0, stop/0, reset/0, and start/1 for more details. The second command prints the statistics gathered during that time. First three general statistics are printed.

  • Average real-time - The average time spent collecting data in the threads. This should be close to the time which data was collected.

  • System run-time - The total run-time of all threads in the system. This is what you get if you call msacc:stats(total_runtime,Stats).

  • Average scheduler run-time - The average run-time for the schedulers. This is the average amount of time the schedulers did not sleep.

Then one column per state is printed with a the percentage of time this thread spent in the state out of it's own real-time. After the thread specific time, the accumulated time for each type of thread is printed in a similar format.

Since we have the average real-time and the percentage spent in each state we can easily calculate the time spent in each state by multiplying Average thread real-time with Thread state %, that is, to get the time Scheduler 1 spent in the emulator state we do 1000513us * 0.13% = 1300us.

Summary

Types

A map containing the different microstate accounting states and the number of microseconds spent in it.

The different options that can be given to print/2.

The different states that a thread can be in. See erlang:statistics(microstate_accounting) for details.

A map containing the different microstate accounting states. Each value in the map contains another map with the percentage of time that this thread has spent in the specific state. Both the percentage of system time and the time for that specific thread is part of the map.

A map containing information about a specific thread. The percentages in the map can be either run-time or real-time depending on if runtime or realtime was requested from stats/2. system is the percentage of total system time for this specific thread.

Functions

This function checks whether microstate accounting is available or not.

Read a file dump produced by to_file(Filename).

Prints the current microstate accounting to standard out. Equivalent to msacc:print(msacc:stats(), #{}).

Print the given microstate statistics values to standard out. With many states this can be verbose. See the top of this reference manual for a brief description of what the fields mean.

Print the given microstate statistics values to the given file or device. The other arguments behave the same way as for print/2.

Reset microstate accounting counters. Returns whether is was enabled or disabled.

Start microstate accounting. Returns whether it was previously enabled or disabled.

Resets all counters and then starts microstate accounting for the given milliseconds.

Returns a runtime system independent version of the microstate statistics data presented by erlang:statistics(microstate_accounting). All counters have been normalized to be in microsecond resolution.

Returns the system time for the given microstate statistics values. System time is the accumulated time of all threads.

Stop microstate accounting. Returns whether is was previously enabled or disabled.

Dumps the current microstate statistics counters to a file that can be parsed with file:consult/1.

Types

Link to this type

msacc_data()

View Source (not exported) (since OTP 19.0)
-type msacc_data() :: [msacc_data_thread()].
Link to this type

msacc_data_counters()

View Source (not exported) (since OTP 19.0)
-type msacc_data_counters() :: #{msacc_state() => non_neg_integer()}.

A map containing the different microstate accounting states and the number of microseconds spent in it.

Link to this type

msacc_data_thread()

View Source (not exported) (since OTP 19.0)
-type msacc_data_thread() ::
          #{'$type' := msacc_data,
            type := msacc_type(),
            id := msacc_id(),
            counters := msacc_data_counters()}.
Link to this type

msacc_id()

View Source (not exported) (since OTP 19.0)
-type msacc_id() :: non_neg_integer().
Link to this type

msacc_print_options()

View Source (not exported) (since OTP 19.0)
-type msacc_print_options() :: #{system => boolean()}.

The different options that can be given to print/2.

Link to this type

msacc_state()

View Source (not exported) (since OTP 19.0)
-type msacc_state() ::
          alloc | aux | bif | busy_wait | check_io | emulator | ets | gc | gc_fullsweep | nif | other |
          port | send | sleep | timers.

The different states that a thread can be in. See erlang:statistics(microstate_accounting) for details.

Link to this type

msacc_stats()

View Source (not exported) (since OTP 19.0)
-type msacc_stats() :: [msacc_stats_thread()].
Link to this type

msacc_stats_counters()

View Source (not exported) (since OTP 19.0)
-type msacc_stats_counters() :: #{msacc_state() => #{thread := float(), system := float()}}.

A map containing the different microstate accounting states. Each value in the map contains another map with the percentage of time that this thread has spent in the specific state. Both the percentage of system time and the time for that specific thread is part of the map.

Link to this type

msacc_stats_thread()

View Source (not exported) (since OTP 19.0)
-type msacc_stats_thread() ::
          #{'$type' := msacc_stats,
            type := msacc_type(),
            id := msacc_id(),
            system := float(),
            counters := msacc_stats_counters()}.

A map containing information about a specific thread. The percentages in the map can be either run-time or real-time depending on if runtime or realtime was requested from stats/2. system is the percentage of total system time for this specific thread.

Link to this type

msacc_type()

View Source (not exported) (since OTP 19.0)
-type msacc_type() :: aux | async | dirty_cpu_scheduler | dirty_io_scheduler | poll | scheduler.

Functions

Link to this function

available()

View Source (since OTP 19.0)
-spec available() -> boolean().

This function checks whether microstate accounting is available or not.

Link to this function

from_file(Filename)

View Source (since OTP 19.0)
-spec from_file(Filename) -> msacc_data() when Filename :: file:name_all().

Read a file dump produced by to_file(Filename).

Link to this function

print()

View Source (since OTP 19.0)
-spec print() -> ok.

Prints the current microstate accounting to standard out. Equivalent to msacc:print(msacc:stats(), #{}).

Link to this function

print(DataOrStats)

View Source (since OTP 19.0)
-spec print(DataOrStats) -> ok when DataOrStats :: msacc_data() | msacc_stats().

Equivalent to print(DataOrStats, #{}).

Link to this function

print(DataOrStats, Options)

View Source (since OTP 19.0)
-spec print(DataOrStats, Options) -> ok
               when DataOrStats :: msacc_data() | msacc_stats(), Options :: msacc_print_options().

Print the given microstate statistics values to standard out. With many states this can be verbose. See the top of this reference manual for a brief description of what the fields mean.

It is possible to print more specific types of statistics by first manipulating the DataOrStats using stats/2. For instance if you want to print the percentage of run-time for each thread you can do:

msacc:print(msacc:stats(runtime, msacc:stats())).

If you want to only print run-time per thread type you can do:

msacc:print(msacc:stats(type, msacc:stats(runtime, msacc:stats()))).

Options

  • system - Print percentage of time spent in each state out of system time as well as thread time. Default: false.
Link to this function

print(FileOrDevice, DataOrStats, Options)

View Source (since OTP 19.0)
-spec print(FileOrDevice, DataOrStats, Options) -> ok
               when
                   FileOrDevice :: file:filename() | io:device(),
                   DataOrStats :: msacc_data() | msacc_stats(),
                   Options :: msacc_print_options().

Print the given microstate statistics values to the given file or device. The other arguments behave the same way as for print/2.

Link to this function

reset()

View Source (since OTP 19.0)
-spec reset() -> boolean().

Reset microstate accounting counters. Returns whether is was enabled or disabled.

Link to this function

start()

View Source (since OTP 19.0)
-spec start() -> boolean().

Start microstate accounting. Returns whether it was previously enabled or disabled.

Link to this function

start(Time)

View Source (since OTP 19.0)
-spec start(Time) -> true when Time :: timeout().

Resets all counters and then starts microstate accounting for the given milliseconds.

Link to this function

stats()

View Source (since OTP 19.0)
-spec stats() -> msacc_data().

Returns a runtime system independent version of the microstate statistics data presented by erlang:statistics(microstate_accounting). All counters have been normalized to be in microsecond resolution.

Link to this function

stats/2

View Source (since OTP 19.0)
-spec stats(Analysis, Stats) -> non_neg_integer()
               when Analysis :: system_realtime | system_runtime, Stats :: msacc_data();
           (Analysis, Stats) -> msacc_stats() when Analysis :: realtime | runtime, Stats :: msacc_data();
           (Analysis, StatsOrData) -> msacc_data() | msacc_stats()
               when Analysis :: type, StatsOrData :: msacc_data() | msacc_stats().

Returns the system time for the given microstate statistics values. System time is the accumulated time of all threads.

  • realtime - Returns all time recorded for all threads.

  • runtime - Returns all time spent doing work for all threads, i.e. all time not spent in the sleep state.

Returns fractions of real-time or run-time spent in the various threads from the given microstate statistics values.

Returns a list of microstate statistics values where the values for all threads of the same type has been merged.

-spec stop() -> boolean().

Stop microstate accounting. Returns whether is was previously enabled or disabled.

Link to this function

to_file(Filename)

View Source (since OTP 19.0)
-spec to_file(Filename) -> ok | {error, file:posix()} when Filename :: file:name_all().

Dumps the current microstate statistics counters to a file that can be parsed with file:consult/1.