Cauldron2D.Trace (Cauldron2D v0.1.3)

Copy Markdown View Source

A trace of what happened and when, written as one line per event, and read back for mix cauldron.report.

Cauldron2D.Trace.start()
Cauldron2D.Trace.write(:mouse, x: 37, tile: 13.25)
Cauldron2D.Trace.stop()

start/0 opens the file CAULDRON_TRACE names — 1 for cauldron_trace.log in the current directory — and does nothing when it is unset; every write/2 is then a no-op. A line is t=<ms since start> kind=<kind> key=value ...; floats are written to two places.

read!/1, at/1, summary/1 and latency/3 are what a report is made from.

Summary

Functions

An event's time in milliseconds.

The time from each from event to the next to event after it, as median, p90, max and count.

Whether a trace is open.

The events in a trace file, each a map of its fields as strings; lines with no fields are dropped.

Open the trace and write a start event, if CAULDRON_TRACE is set. Returns whether tracing is on.

Median, p90, max and count of a list of numbers; zeros for none.

Write a stop event, flush and close. A no-op when no trace is open, or when the process that opened it has already gone and closed it with it.

How many events of each kind, and for each kind the gaps between one and the next as median, p90, max and count.

Append one event: kind names it, fields become key=value pairs. A no-op when no trace is open.

Types

event()

@type event() :: %{required(String.t()) => String.t()}

Functions

at(map)

@spec at(event()) :: float()

An event's time in milliseconds.

latency(events, from, to)

@spec latency([event()], String.t(), String.t()) :: map()

The time from each from event to the next to event after it, as median, p90, max and count.

on?()

@spec on?() :: boolean()

Whether a trace is open.

read!(path)

@spec read!(Path.t()) :: [event()]

The events in a trace file, each a map of its fields as strings; lines with no fields are dropped.

start()

@spec start() :: boolean()

Open the trace and write a start event, if CAULDRON_TRACE is set. Returns whether tracing is on.

stats(values)

@spec stats([number()]) :: %{
  median: float(),
  p90: float(),
  max: float(),
  count: non_neg_integer()
}

Median, p90, max and count of a list of numbers; zeros for none.

stop()

@spec stop() :: :ok

Write a stop event, flush and close. A no-op when no trace is open, or when the process that opened it has already gone and closed it with it.

summary(events)

@spec summary([event()]) :: %{
  counts: %{required(String.t()) => non_neg_integer()},
  gaps: %{required(String.t()) => map()}
}

How many events of each kind, and for each kind the gaps between one and the next as median, p90, max and count.

write(kind, fields \\ [])

@spec write(atom(), keyword()) :: :ok

Append one event: kind names it, fields become key=value pairs. A no-op when no trace is open.