Erlang -- instrument

Tools

Reference Manual

Version 3.1

- User's Guide
- Reference Manual
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- cover
  - Top of manual page
  - analyse/0
  - analyse/1
  - analyse/1
  - analyse/1
  - analyse/2
  - analyse/2
  - analyse/2
  - analyse/3
  - analyse_to_file/0
  - analyse_to_file/1
  - analyse_to_file/1
  - analyse_to_file/2
  - async_analyse_to_file/1
  - async_analyse_to_file/2
  - async_analyse_to_file/2
  - async_analyse_to_file/3
  - compile/1
  - compile/2
  - compile_beam/1
  - compile_beam_directory/0
  - compile_beam_directory/1
  - compile_directory/0
  - compile_directory/1
  - compile_directory/2
  - compile_module/1
  - compile_module/2
  - export/1
  - export/2
  - flush/1
  - import/1
  - imported/0
  - imported_modules/0
  - is_compiled/1
  - modules/0
  - reset/1
  - reset/0
  - start/0
  - start/1
  - stop/0
  - stop/1
  - which_nodes/0
- cprof
  - Top of manual page
  - analyse/0
  - analyse/1
  - analyse/1
  - analyse/2
  - pause/0
  - pause/1
  - pause/2
  - pause/3
  - restart/0
  - restart/1
  - restart/2
  - restart/3
  - start/0
  - start/1
  - start/2
  - start/3
  - stop/0
  - stop/1
  - stop/2
  - stop/3
- eprof
  - Top of manual page
  - analyze/0
  - analyze/1
  - analyze/2
  - log/1
  - profile/1
  - profile/2
  - profile/1
  - profile/2
  - profile/3
  - profile/4
  - profile/5
  - profile/6
  - start/0
  - start_profiling/1
  - start_profiling/2
  - start_profiling/3
  - stop/0
  - stop_profiling/0
- erlang.el
- fprof
  - Top of manual page
  - analyse/0
  - analyse/2
  - analyse/1
  - analyse/1
  - analyse/1
  - apply/2
  - apply/3
  - apply/3
  - apply/4
  - profile/0
  - profile/2
  - profile/1
  - profile/1
  - profile/1
  - start/0
  - stop/0
  - stop/1
  - trace/2
  - trace/2
  - trace/2
  - trace/1
  - trace/1
  - trace/1
  - trace/1
- instrument
  - Top of manual page
  - allocations/0
  - allocations/1
  - carriers/0
  - carriers/1
- lcnt
  - Top of manual page
  - apply/1
  - apply/2
  - apply/3
  - clear/0
  - clear/1
  - collect/0
  - collect/1
  - conflicts/0
  - conflicts/1
  - information/0
  - inspect/1
  - inspect/2
  - load/1
  - locations/0
  - locations/1
  - pid/2
  - pid/3
  - port/1
  - port/2
  - rt_clear/0
  - rt_clear/1
  - rt_collect/0
  - rt_collect/1
  - rt_mask/0
  - rt_mask/1
  - rt_mask/1
  - rt_mask/2
  - rt_opt/1
  - rt_opt/2
  - save/1
  - start/0
  - stop/0
  - swap_pid_keys/0
- make
  - Top of manual page
  - all/0
  - all/1
  - files/1
  - files/2
- tags
  - Top of manual page
  - dir/1
  - dirs/1
  - file/1
  - files/1
  - root/1
  - subdir/1
  - subdirs/1
- xref
  - Top of manual page
  - add_application/2
  - add_directory/2
  - add_module/2
  - add_release/2
  - analyze/2
  - d/1
  - forget/1
  - forget/2
  - format_error/1
  - get_default/1
  - get_default/2
  - get_library_path/1
  - info/1
  - info/2
  - info/3
  - m/1
  - m/1
  - q/2
  - remove_application/2
  - remove_module/2
  - remove_release/2
  - replace_application/3
  - replace_module/3
  - set_default/3
  - set_default/2
  - set_library_path/2
  - start/1
  - start/2
  - stop/1
  - update/1
  - variables/1

# instrument

### Module

instrument

### Module Summary

Analysis and Utility Functions for Instrumentation

### Description

The module instrument contains support for studying the resource usage in an Erlang runtime system. Currently, only the allocation of memory can be studied.

Note

Note that this whole module is experimental, and the representations used as well as the functionality is likely to change in the future.

### Data Types

block_histogram() = tuple()

A histogram of block sizes where each interval's upper bound is twice as high as the one before it.

The upper bound of the first interval is provided by the function that returned the histogram, and the last interval has no upper bound.

allocation_summary() =
{HistogramStart :: integer() >= 0,
UnscannedSize :: integer() >= 0,
Allocations ::
#{Origin :: atom() =>
#{Type :: atom() => block_histogram()}}}

A summary of allocated block sizes (including their headers) grouped by their Origin and Type.

Origin is generally which NIF or driver that allocated the blocks, or 'system' if it could not be determined.

Type is the allocation category that the blocks belong to, e.g. db_term, message or binary.

If one or more carriers could not be scanned in full without harming the responsiveness of the system, UnscannedSize is the number of bytes that had to be skipped.

carrier_info_list() =
{HistogramStart :: integer() >= 0,
Carriers ::
[{AllocatorType :: atom(),
TotalSize :: integer() >= 0,
UnscannedSize :: integer() >= 0,
AllocatedSize :: integer() >= 0,
AllocatedCount :: integer() >= 0,
InPool :: boolean(),
FreeBlocks :: block_histogram()}]}

AllocatorType is the type of the allocator that employs this carrier.

TotalSize is the total size of the carrier, including its header.

AllocatedSize is the combined size of the carrier's allocated blocks, including their headers.

AllocatedCount is the number of allocated blocks in the carrier.

InPool is whether the carrier is in the migration pool.

FreeBlocks is a histogram of the free block sizes in the carrier.

If the carrier could not be scanned in full without harming the responsiveness of the system, UnscannedSize is the number of bytes that had to be skipped.

### Exports

allocations() -> {ok, Result} | {error, Reason} | OTP 21.0

### Types

Result = allocation_summary()
Reason = not_enabled

Shorthand for allocations(#{}).

allocations(Options) -> {ok, Result} | {error, Reason} | OTP 21.0

### Types

Result = allocation_summary()
Reason = not_enabled
Options =
#{scheduler_ids => [integer() >= 0],
allocator_types => [atom()],
histogram_start => integer() >= 1,
histogram_width => integer() >= 1}

Returns a summary of all tagged allocations in the system, optionally filtered by allocator type and scheduler id.

Only binaries and allocations made by NIFs and drivers are tagged by default, but this can be configured an a per-allocator basis with the +M<S>atags emulator option.

If tagged allocations are not enabled on any of the specified allocator types, the call will fail with {error, not_enabled}.

The following options can be used:

allocator_types

  The allocator types that will be searched. Defaults to all alloc_util allocators.

scheduler_ids

  The scheduler ids whose allocator instances will be searched. A scheduler id of 0 will refer to the global instance that is not tied to any particular scheduler. Defaults to all schedulers and the global instance.

histogram_start

  The upper bound of the first interval in the allocated block size histograms. Defaults to 128.

histogram_width

  The number of intervals in the allocated block size histograms. Defaults to 18.

Example:

    > instrument:allocations(#{ histogram_start => 128, histogram_width => 15 }).
    {ok,{128,0,
         #{udp_inet =>
               #{driver_event_state => {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}},
           system =>
               #{heap => {0,0,0,0,20,4,2,2,2,3,0,1,0,0,1},
                 db_term => {271,3,1,52,80,1,0,0,0,0,0,0,0,0,0},
                 code => {0,0,0,5,3,6,11,22,19,20,10,2,1,0,0},
                 binary => {18,0,0,0,7,0,0,1,0,0,0,0,0,0,0},
                 message => {0,40,78,2,2,0,0,0,0,0,0,0,0,0,0},
                 ... }
           spawn_forker =>
               #{driver_select_data_state =>
                     {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
           ram_file_drv => #{drv_binary => {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}},
           prim_file =>
               #{process_specific_data => {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 nif_trap_export_entry => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 monitor_extended => {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 drv_binary => {0,0,0,0,0,0,1,0,3,5,0,0,0,1,0},
                 binary => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0}},
           prim_buffer =>
               #{nif_internal => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 binary => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0}}}}}

carriers() -> {ok, Result} | {error, Reason} | OTP 21.0

### Types

Result = carrier_info_list()
Reason = not_enabled

Shorthand for carriers(#{}).

carriers(Options) -> {ok, Result} | {error, Reason} | OTP 21.0

### Types

Result = carrier_info_list()
Reason = not_enabled
Options =
#{scheduler_ids => [integer() >= 0],
allocator_types => [atom()],
histogram_start => integer() >= 1,
histogram_width => integer() >= 1}

Returns a summary of all carriers in the system, optionally filtered by allocator type and scheduler id.

If the specified allocator types are not enabled, the call will fail with {error, not_enabled}.

The following options can be used:

allocator_types

  The allocator types that will be searched. Defaults to all alloc_util allocators.

scheduler_ids

  The scheduler ids whose allocator instances will be searched. A scheduler id of 0 will refer to the global instance that is not tied to any particular scheduler. Defaults to all schedulers and the global instance.

histogram_start

  The upper bound of the first interval in the free block size histograms. Defaults to 512.

histogram_width

  The number of intervals in the free block size histograms. Defaults to 14.

Example:

    > instrument:carriers(#{ histogram_start => 512, histogram_width => 8 }).
    {ok,{512,
         [{ll_alloc,1048576,0,1048344,71,false,{0,0,0,0,0,0,0,0}},
          {binary_alloc,1048576,0,324640,13,false,{3,0,0,1,0,0,0,2}},
          {eheap_alloc,2097152,0,1037200,45,false,{2,1,1,3,4,3,2,2}},
          {fix_alloc,32768,0,29544,82,false,{22,0,0,0,0,0,0,0}},
          {...}|...]}}

### See Also

erts_alloc(3), erl(1)