ObserverWeb.Tracer.Tool.Duration (Observer Web v0.2.5)

View Source

Measures how long traced functions take to run, per process, optionally reduced through an aggregation mode (:sum, :avg, :min, :max, :dist).

Ported and adapted from https://github.com/gabiz/tracer's Tracer.Tool.Duration:

  • Fixes a typo in the upstream aggregation lookup that maps the atom :mix (instead of :min) to Enum.min/1 - upstream's :min mode is unreachable and raises.
  • Upstream streams each duration live as it completes when no aggregation mode is selected, and only reports finalized aggregates through handle_stop/1 otherwise. Observer Web's tool sessions only ever produce a single report at the end (see ObserverWeb.Tracer.Server), so this always collects every sample and reports them all at once - individually when there's no aggregation mode, reduced when there is.
  • Requires return_trace() in the match spec to see :return_from events - ObserverWeb.Tracer.Tool.forced_match_spec_keys/1 forces this in regardless of the match specs selected in the UI.

Samples are grouped (and, when an aggregation mode is selected, reduced) by the reporting node in addition to {mod, fun, arity} and the raw message value, so tracing the same function across multiple nodes doesn't collapse their durations together - matching how Live Tracing identifies which node ("service") each event came from.

Summary

Types

aggregation()

@type aggregation() :: :sum | :avg | :min | :max | :dist | nil

t()

@type t() :: %ObserverWeb.Tracer.Tool.Duration{
  aggregation: aggregation(),
  collect: ObserverWeb.Tracer.Tool.Collect.t(),
  stacks: %{optional(pid()) => list()}
}

Functions

handle_event(state, arg2)

@spec handle_event(
  t(),
  struct()
) :: t()

handle_stop(duration)

@spec handle_stop(t()) :: [{tuple(), term()}]

new(opts \\ %{})

@spec new(map()) :: t()