User's Guide
Reference Manual
Release Notes
PDF
Top

Tools
Reference Manual
Version 2.8.2

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/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
  - 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
  - flush/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
  - start_profiling/2
  - start_profiling/3
  - stop_profiling/0
  - profile/1
  - profile/2
  - profile/1
  - profile/2
  - profile/3
  - profile/4
  - profile/5
  - profile/6
  - analyze/0
  - analyze/1
  - analyze/2
  - 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

# lcnt

### MODULE

lcnt

### MODULE SUMMARY

A runtime system Lock Profiling tool.

### DESCRIPTION

The lcnt module is used to profile the internal ethread locks in the Erlang Runtime System. With lcnt enabled, Internal counters in the runtime system are updated each time a lock is taken. The counters stores information about the number of acquisition tries and the number of collisions that has occurred during the acquisition tries. The counters also record the waiting time a lock has caused for a blocked thread when a collision has occurred.

The data produced by the lock counters will give an estimate on how well the runtime system will behave from a parallelizable view point for the scenarios tested. This tool was mainly developed to help erlang runtime developers iron out potential and generic bottlenecks.

Locks in the emulator are named after what type of resource they protect and where in the emulator they are initialized, those are lock 'classes'. Most of those locks are also instantiated several times, and given unique identifiers, to increase locking granularity. Typically an instantiated lock protects a disjunct set of the resource, i.e ets-tables, processes or ports. In other cases it protects a specific range of a resource, e.g. pix_lock which protects index to process mappings, and is given a unique number within the class. A unique lock in lcnt is referenced by a name (class) and an identifier, {Name, Id}.

Some locks in the system are static and protects global resources, for example bif_timers and the run_queue locks. Other locks are dynamic and not necessarily long lived, for example process locks and ets-table locks. The statistics data from short lived locks can be stored separately when the locks are deleted. This behavior is by default turned off to save memory but can be turned on via lcnt:rt_opt({copy_save, true}). The lcnt:apply/1,2,3 functions enables this behavior during profiling.

### EXPORTS

start() -> {ok, Pid} | {error, {already_started, Pid}}

Types:

Pid = pid()

Starts the lock profiler server. The server only act as a medium for the user and performs filtering and printing of data collected by lcnt:collect/1.

stop() -> ok

Stops the lock profiler server.

collect() -> ok

Same as collect(node()).

collect(Node) -> ok

Types:

Node = node()

Collects lock statistics from the runtime system. The function starts a server if it is not already started. It then populates the server with lock statistics. If the server held any lock statistics data before the collect then that data is lost.

Note

When collection occurs the runtime system transitions to a single thread, blocking all other threads. No other tasks will be scheduled during this operation. Depending on the size of the data this might take a long time (several seconds) and cause timeouts in the system.

clear() -> ok

Same as clear(node()).

clear(Node) -> ok

Types:

Node = node()

Clears the internal lock statistics from the runtime system. This does not clear the data on the server only on runtime system. All counters for static locks are zeroed, all dynamic locks currently alive are zeroed and all saved locks now destroyed are removed. It also resets the duration timer.

conflicts() -> ok

Same as conflicts([]).

conflicts([Option]) -> ok

Types:

Option = {sort, Sort} | {reverse, bool()} | {thresholds, [Thresholds]} | {print, [Print | {Print, integer()}]} | {max_locks, MaxLocks} | {combine, bool()}
Sort = name | id | type | tries | colls | ratio | time | entry
Thresholds = {tries, integer()} | {colls, integer()} | {time, integer()}
Print = name | id | type | entry | tries | colls | ratio | time | duration
MaxLocks = integer() | none

Prints a list of internal locks and its statistics.

For option description, see lcnt:inspect/2.

locations() -> ok

Same as locations([]).

locations([Option]) -> ok

Types:

Option = {sort, Sort} | {thresholds, [Thresholds]} | {print, [Print | {Print, integer()}]} | {max_locks, MaxLocks} | {combine, bool()}
Sort = name | id | type | tries | colls | ratio | time | entry
Thresholds = {tries, integer()} | {colls, integer()} | {time, integer()}
Print = name | id | type | entry | tries | colls | ratio | time | duration
MaxLocks = integer() | none

Prints a list of internal lock counters by source code locations.

For option description, see lcnt:inspect/2.

inspect(Lock) -> ok

Same as inspect(Lock, []).

inspect(Lock, [Option]) -> ok

Types:

Lock = Name | {Name, Id | [Id]}
Name = atom() | pid() | port()
Id = atom() | integer() | pid() | port()
Option = {sort, Sort} | {thresholds, [Thresholds]} | {print, [Print | {Print, integer()}]} | {max_locks, MaxLocks} | {combine, bool()} | {locations, bool()}
Sort = name | id | type | tries | colls | ratio | time
Thresholds = {tries, integer()} | {colls, integer()} | {time, integer()}
Print = name | id | type | entry | tries | colls | ratio | time | duration
MaxLocks = integer() | none

Prints a list of internal lock counters for a specific lock.

Lock Name and Id for ports and processes are interchangeable with the use of lcnt:swap_pid_keys/0 and is the reason why pid() and port() options can be used in both Name and Id space. Both pids and ports are special identifiers with stripped creation and can be recreated with lcnt:pid/2,3 and lcnt:port/1,2.

Option description:

{combine, bool()}
  Combine the statistics from different instances of a lock class.
  Default: true
{locations, bool()}
  Print the statistics by source file and line numbers.
  Default: false
{max_locks, MaxLocks}
  Maximum number of locks printed or no limit with none.
  Default: 20
{print, PrintOptions}
  Printing options:
  name
    Named lock or named set of locks (classes). The same name used for initializing the lock in the VM.
  id
    Internal id for set of locks, not always unique. This could be table name for ets tables (db_tab), port id for ports, integer identifiers for allocators, etc.
  type
    Type of lock: rw_mutex, mutex, spinlock, rw_spinlock or proclock.
  entry
    In combination with {locations, true} this option prints the lock operations source file and line number entry-points along with statistics for each entry.
  tries
    Number of acquisitions of this lock.
  colls
    Number of collisions when a thread tried to acquire this lock. This is when a trylock is EBUSY, a write try on read held rw_lock, a try read on write held rw_lock, a thread tries to lock an already locked lock. (Internal states supervises this).
  ratio
    The ratio between the number of collisions and the number of tries (acquisitions) in percentage.
  time
    Accumulated waiting time for this lock. This could be greater than actual wall clock time, it is accumulated for all threads. Trylock conflicts does not accumulate time.
  duration
    Percentage of accumulated waiting time of wall clock time. This percentage can be higher than 100% since accumulated time is from all threads.
  Default: [name,id,tries,colls,ratio,time,duration]
{reverse, bool()}
  Reverses the order of sorting.
  Default: false
{sort, Sort}
  Column sorting orders.
  Default: time
{thresholds, Thresholds}
  Filtering thresholds. Anything values above the threshold value are passed through.
  Default: [{tries, 0}, {colls, 0}, {time, 0}]

information() -> ok

Prints lcnt server state and generic information about collected lock statistics.

swap_pid_keys() -> ok

Swaps places on Name and Id space for ports and processes.

load(Filename) -> ok

Types:

Filename = filename()

Restores previously saved data to the server.

save(Filename) -> ok

Types:

Filename = filename()

Saves the collected data to file.

### Convenience functions

The following functions are used for convenience.

### EXPORTS

apply(Fun) -> term()

Same as apply(Fun, []).

apply(Fun, Args) -> term()

Types:

Fun = fun()
Args = [term()]

Clears the lock counters and then setups the instrumentation to save all destroyed locks. After setup the fun is called, passing the elements in Args as arguments. When the fun returns the statistics are immediately collected to the server. After the collection the instrumentation is returned to its previous behavior. The result of the applied fun is returned.

apply(Module, Function, Args) -> term()

Types:

Module = atom()
Function = atom()
Args = [term()]

Clears the lock counters and then setups the instrumentation to save all destroyed locks. After setup the function is called, passing the elements in Args as arguments. When the function returns the statistics are immediately collected to the server. After the collection the instrumentation is returned to its previous behavior. The result of the applied function is returned.

pid(Id, Serial) -> pid()

Same as pid(node(), Id, Serial).

pid(Node, Id, Serial) -> pid()

Types:

Node = node()
Id = integer()
Serial = integer()

Creates a process id with creation 0. Example:

port(Id) -> port()

Same as port(node(), Id).

port(Node, Id) -> port()

Types:

Node = node()
Id = integer()

Creates a port id with creation 0.

### Internal runtime lock counter controllers

The following functions control the behavior of the internal counters.

### EXPORTS

rt_collect() -> [lock_counter_data()]

Same as rt_collect(node()).

rt_collect(Node) -> [lock_counter_data()]

Types:

Node = node()

Returns a list of raw lock counter data.

rt_clear() -> ok

Same as rt_clear(node()).

rt_clear(Node) -> ok

Types:

Node = node()

Clear the internal counters. Same as lcnt:clear(Node).

rt_opt({Type, bool()}) -> bool()

Same as rt_opt(node(), {Type, Opt}).

rt_opt(Node, {Type, bool()}) -> bool()

Types:

Node = node()
Type = copy_save | process_locks

Changes the lock counter behavior and returns the previous behaviour.

Option description:

{copy_save, bool()}
  Enable statistics saving from destroyed locks by copying. This might consume a lot of memory.
  Default: false
{process_locks, bool()}
  Profile process locks.
  Default: true

### See Also

LCNT User's Guide