User's Guide
Reference Manual
Release Notes
PDF
Top

Tools
Reference Manual
Version 2.6.5.1

Expand All
Contract All

Table of Contents

- cover
  - Top of manual page
  - start/0
  - start/1
  - compile/1
  - compile/2
  - compile_module/1
  - compile_module/2
  - compile_directory/0
  - compile_directory/1
  - compile_directory/2
  - compile_beam/1
  - compile_beam_directory/0
  - compile_beam_directory/1
  - analyse/1
  - analyse/2
  - analyse/2
  - analyse/3
  - analyse_to_file/1
  - analyse_to_file/2
  - analyse_to_file/2
  - analyse_to_file/3
  - modules/0
  - imported_modules/0
  - imported/0
  - which_nodes/0
  - is_compiled/1
  - reset/1
  - reset/0
  - export/1
  - export/2
  - import/1
  - stop/0
  - stop/1
- 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
  - start/0
  - start_profiling/1
  - profile/1
  - stop_profiling/0
  - profile/2
  - profile/4
  - analyse/0
  - total_analyse/0
  - log/1
  - stop/0
- erlang.el
- fprof
  - Top of manual page
  - start/0
  - stop/0
  - stop/1
  - apply/2
  - apply/3
  - apply/3
  - apply/4
  - trace/2
  - trace/2
  - trace/2
  - trace/1
  - trace/1
  - trace/1
  - trace/1
  - profile/0
  - profile/2
  - profile/1
  - profile/1
  - profile/1
  - analyse/0
  - analyse/2
  - analyse/1
  - analyse/1
  - analyse/1
- instrument
  - Top of manual page
  - allocator_descr/2
  - block_header_size/1
  - class_descr/2
  - descr/1
  - holes/1
  - mem_limits/1
  - memory_data/0
  - memory_status/1
  - read_memory_data/1
  - read_memory_status/1
  - sort/1
  - store_memory_data/1
  - store_memory_status/1
  - sum_blocks/1
  - type_descr/2
  - type_no_range/1
- lcnt
  - Top of manual page
  - start/0
  - stop/0
  - collect/0
  - collect/1
  - clear/0
  - clear/1
  - conflicts/0
  - conflicts/1
  - locations/0
  - locations/1
  - inspect/1
  - inspect/2
  - information/0
  - swap_pid_keys/0
  - load/1
  - save/1
  - apply/1
  - apply/2
  - apply/3
  - pid/2
  - pid/3
  - port/1
  - port/2
  - rt_collect/0
  - rt_collect/1
  - rt_clear/0
  - rt_clear/1
  - rt_opt/1
  - rt_opt/2
- make
  - Top of manual page
  - all/0
  - all/1
  - files/1
  - files/2
- tags
  - Top of manual page
  - file/1
  - files/1
  - dir/1
  - dirs/1
  - subdir/1
  - subdirs/1
  - root/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.

The instrument module interface was slightly changed in Erlang/OTP R9C.

To start an Erlang runtime system with instrumentation, use the +Mi* set of command-line arguments to the erl command (see the erts_alloc(3) and erl(1) man pages).

The basic object of study in the case of memory allocation is a memory allocation map. A memory allocation map contains a list of descriptors for each allocated memory block. Currently, a descriptor is a 4-tuple

            {TypeNo, Address, Size, PidDesc}

where TypeNo is the memory block type number, Address is its place in memory, and Size is its size, in bytes. PidDesc is either a tuple {X,Y,Z} identifying the process which was executing when the block was allocated, or undefined if no process was executing. The pid tuple {X,Y,Z} can be transformed into a real pid by usage of the c:pid/3 function.

Various details about memory allocation:

Memory blocks are allocated both on the heap segment and on other memory segments. This can cause the instrumentation functionality to report very large holes. Currently the instrumentation functionality doesn't provide any support for distinguishing between holes between memory segments, and holes between allocated blocks inside memory segments. The current size of the process cannot be obtained from within Erlang, but can be seen with one of the system statistics tools, e.g., ps or top. The Solaris utility pmap can be useful. It reports currently mapped memory segments.

Overhead for instrumentation: When the emulator has been started with the "+Mim true" flag, each block is preceded by a 24 bytes large header on a 32-bit machine and a 48 bytes large header on a 64-bit machine. When the emulator has been started with the "+Mis true" flag, each block is preceded by an 8 bytes large header. These are the header sizes used by the Erlang 5.3/OTP R9C emulator. Other versions of the emulator may use other header sizes. The function block_header_size/1 can be used for retrieving the header size used for a specific memory allocation map. The time overhead for managing the instrumentation data is small.

Sizes presented by the instrumentation functionality are (by the emulator) requested sizes, i.e. neither instrumentation headers nor headers used by allocators are included.

### EXPORTS

allocator_descr(MemoryData, TypeNo) -> AllocDescr | invalid_type | "unknown"

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined
TypeNo = int()
AllocDescr = atom() | string()

Returns the allocator description of the allocator that manages memory blocks of type number TypeNo used in MemoryData. Valid TypeNos are in the range returned by type_no_range/1 on this specific memory allocation map. If TypeNo is an invalid integer, invalid_type is returned.

block_header_size(MemoryData) -> int()

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined

Returns the memory block header size used by the emulator that generated the memory allocation map. The block header size may differ between different emulators.

class_descr(MemoryData, TypeNo) -> ClassDescr | invalid_type | "unknown"

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined
TypeNo = int()
ClassDescr = atom() | string()

Returns the class description of the class that the type number TypeNo used in MemoryData belongs to. Valid TypeNos are in the range returned by type_no_range/1 on this specific memory allocation map. If TypeNo is an invalid integer, invalid_type is returned.

descr(MemoryData) -> DescrMemoryData

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined
DescrMemoryData = {term(), DescrAllocList}
DescrAllocList = [DescrDesc]
DescrDesc = {TypeDescr, int(), int(), DescrPidDesc}
TypeDescr = atom() | string()
DescrPidDesc = pid() | undefined

Returns a memory allocation map where the type numbers (first element of Desc) have been replaced by type descriptions, and pid tuples (fourth element of Desc) have been replaced by real pids.

holes(MemoryData) -> ok

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined

Prints out the size of each hole (i.e., the space between allocated blocks) on the terminal. NOTE: Really large holes are probably holes between memory segments. The memory allocation map has to be sorted (see sort/1).

mem_limits(MemoryData) -> {Low, High}

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined
Low = High = int()

Returns a tuple {Low, High} indicating the lowest and highest address used. The memory allocation map has to be sorted (see sort/1).

memory_data() -> MemoryData | false

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined

Returns MemoryData (a the memory allocation map) if the emulator has been started with the "+Mim true" command-line argument; otherwise, false. NOTE:memory_data/0 blocks execution of other processes while the data is collected. The time it takes to collect the data can be substantial.

memory_status(StatusType) -> [StatusInfo] | false

Types:

StatusType = total | allocators | classes | types
StatusInfo = {About, [Info]}
About = atom()
Info = {InfoName, Current, MaxSinceLast, MaxEver}
InfoName = sizes|blocks
Current = int()
MaxSinceLast = int()
MaxEver = int()

Returns a list of StatusInfo if the emulator has been started with the "+Mis true" or "+Mim true" command-line argument; otherwise, false.

See the read_memory_status/1 function for a description of the StatusInfo term.

read_memory_data(File) -> MemoryData | {error, Reason}

Types:

File = string()
MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined

Reads a memory allocation map from the file File and returns it. The file is assumed to have been created by store_memory_data/1. The error codes are the same as for file:consult/1.

read_memory_status(File) -> MemoryStatus | {error, Reason}

Types:

File = string()
MemoryStatus = [{StatusType, [StatusInfo]}]
StatusType = total | allocators | classes | types
StatusInfo = {About, [Info]}
About = atom()
Info = {InfoName, Current, MaxSinceLast, MaxEver}
InfoName = sizes|blocks
Current = int()
MaxSinceLast = int()
MaxEver = int()

Reads memory allocation status from the file File and returns it. The file is assumed to have been created by store_memory_status/1. The error codes are the same as for file:consult/1.

When StatusType is allocators, About is the allocator that the information is about. When StatusType is types, About is the memory block type that the information is about. Memory block types are not described other than by their name and may vary between emulators. When StatusType is classes, About is the memory block type class that information is presented about. Memory block types are classified after their use. Currently the following classes exist:

process_data
  Erlang process specific data.
binary_data
  Erlang binaries.
atom_data
  Erlang atoms.
code_data
  Erlang code.
system_data
  Other data used by the system

When InfoName is sizes, Current, MaxSinceLast, and MaxEver are, respectively, current size, maximum size since last call to store_memory_status/1 or memory_status/1 with the specific StatusType, and maximum size since the emulator was started. When InfoName is blocks, Current, MaxSinceLast, and MaxEver are, respectively, current number of blocks, maximum number of blocks since last call to store_memory_status/1 or memory_status/1 with the specific StatusType, and maximum number of blocks since the emulator was started.

NOTE:A memory block is accounted for at "the first level" allocator. E.g. fix_alloc allocates its memory pools via ll_alloc. When a fix_alloc block is allocated, neither the block nor the pool in which it resides are accounted for as memory allocated via ll_alloc even though it is.

sort(MemoryData) -> MemoryData

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined

Sorts a memory allocation map so that the addresses are in ascending order.

store_memory_data(File) -> true|false

Types:

File = string()

Stores the current memory allocation map on the file File. Returns true if the emulator has been started with the "+Mim true" command-line argument, and the map was successfuly stored; otherwise, false. The contents of the file can later be read using read_memory_data/1. NOTE:store_memory_data/0 blocks execution of other processes while the data is collected. The time it takes to collect the data can be substantial.

store_memory_status(File) -> true|false

Types:

File = string()

Stores the current memory status on the file File. Returns true if the emulator has been started with the "+Mis true", or "+Mim true" command-line arguments, and the data was successfuly stored; otherwise, false. The contents of the file can later be read using read_memory_status/1.

sum_blocks(MemoryData) -> int()

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined

Returns the total size of the memory blocks in the list.

type_descr(MemoryData, TypeNo) -> TypeDescr | invalid_type

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined
TypeNo = int()
TypeDescr = atom() | string()

Returns the type description of a type number used in MemoryData. Valid TypeNos are in the range returned by type_no_range/1 on this specific memory allocation map. If TypeNo is an invalid integer, invalid_type is returned.

type_no_range(MemoryData) -> {Min, Max}

Types:

MemoryData = {term(), AllocList}
AllocList = [Desc]
Desc = {int(), int(), int(), PidDesc}
PidDesc = {int(), int(), int()} | undefined
Min = int()
Max = int()

Returns the memory block type number range used in MemoryData. When the memory allocation map was generated by an Erlang 5.3/OTP R9C or newer emulator, all integers T that satisfy Min <= T <= Max are valid type numbers. When the memory allocation map was generated by a pre Erlang 5.3/OTP R9C emulator, all integers in the range are not valid type numbers.

### See Also

erts_alloc(3), erl(1)