View Source Entrace (Entrace v0.1.1)

Base module for starting a GenServer that performs tracing.

Typically you would rather add a module to your project that uses the Entrace.Tracer.

defmodule MyApp.Tracer do
  use Entrace.Tracer
end

And in your application.ex list of children to supervise add:

MyApp.Tracer

It will run as locally registered on it's module name (in this case MyApp.Tracer).

It is not useful to run multiple Tracer instances as the Erlang tracing facility has some limits around how many tracers you can operate.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get a map of trace info for function calls based on patterns.

Get map of trace patterns.

Starts the Tracer linked to the parent process.

Stop tracing the mfa pattern.

Start a trace for a provided pattern and transmission mechanism.

Start a trace across the entire cluster.

Types

@type mfa_pattern() :: {atom(), atom(), atom() | non_neg_integer()}
@type trace_error() :: {:covered_already, mfa_pattern()} | :full_wildcard_rejected
@type trace_result() ::
  {:set, non_neg_integer()} | {:reset_existing, non_neg_integer()}
@type tracer() :: GenServer.server()
@type transmission() :: function() | pid() | mfa()

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec list_trace_info(tracer :: tracer()) :: map()

Get a map of trace info for function calls based on patterns.

The map is keyed by mfas that have been seen during the trace. Trace info includes information from :erlang.trace_info/2. It includes :call_count, :call_memory and :call_time.

Link to this function

list_trace_patterns(tracer)

View Source
@spec list_trace_patterns(tracer :: tracer()) :: map()

Get map of trace patterns.

This should be tidied up, exposes a bit much in terms of internals.

Starts the Tracer linked to the parent process.

Operations can then be performed on the resulting pid or registered name.

All options are passed along to the GenServer.start_link. There is no configuration for the tracer.

@spec stop(tracer :: tracer(), mfa :: mfa_pattern()) :: :ok

Stop tracing the mfa pattern.

Link to this function

trace(tracer, mfa, transmission, opts \\ [])

View Source
@spec trace(
  tracer :: tracer(),
  mfa :: mfa_pattern(),
  transmission :: transmission(),
  opts :: keyword()
) :: {:ok, trace_result()} | {:error, trace_error()}

Start a trace for a provided pattern and transmission mechanism.

The pattern is an mfa tuple, as in {module, function, arity}. For example {File, read, 1} to trace the File.read/1 function. It supports a special underscore atom :_ to indicate a wilcard in the mfa. You can only use wildcards on the function and arity and Erlang's tracing only allows wildcard function if the arity is also a wildcard.

The transmission is one of:

  • a PID to send traces to.
  • a callback function.
  • a callback function provided as {module, function, arity}

Optional options are available. The options are:

  • limit - the maximum number of messages to process before ending the trace on that pattern. Default limit is 200.
  • time_limit - time to leave the trace running. If no limit is specified this will use a larger default limit of 10_000.

Returns information about how setting the trace pattern worked out.

Link to this function

trace_cluster(tracer, mfa, transmission, opts \\ [])

View Source
@spec trace_cluster(
  tracer :: tracer(),
  mfa :: mfa_pattern(),
  transmission :: transmission(),
  opts :: keyword()
) :: [ok: trace_result(), error: trace_error()]

Start a trace across the entire cluster.

See Entrace.trace/4 for details on arguments.