TelemetryRegistry

class TelemetryRegistry @JvmOverloads constructor(val timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic, val origin: ComparableTimeMark = timeSource.markNow())(source)

The set of TelemetryBackends that logged values are routed to, plus the clock that stamps them.

Most code uses Telemetry, which wraps one shared registry. This is a class so a test can build its own with a kotlin.time.TestTimeSource and a mock backend without affecting anything else.

Timestamps

Every value is stamped in microseconds since origin, as measured by timeSource. Give the same source and origin to a log writer and a server and they agree with this registry on every timestamp.

Backends

A registered backend receives every value, or only the values whose path is under the prefixes it was registered with. Backends can change while other threads are logging. Handles notice the change on their next value and ask the new set of backends for their entries.

Warnings

Telemetry reports a wrong type, a value it can't log, or a backend that threw through warningHandler, then carries on, so a bad value can't crash an OpMode. Each distinct message is reported once, so a bad value logged every loop doesn't flood the output.

Parameters

timeSource

The clock that stamps values

origin

The moment timestamp zero refers to, a mark from timeSource. The default is the moment the registry is created.

Throws

if origin isn't from timeSource, or is in the future

Constructors

Link copied to clipboard
constructor(timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic, origin: ComparableTimeMark = timeSource.markNow())

Properties

Link copied to clipboard

How many backends are registered.

Link copied to clipboard

The handlers that log values of types that can't log themselves. By default this includes one for Measure.

Link copied to clipboard
Link copied to clipboard

The root table, whose path is empty.

Link copied to clipboard

Builds and keeps the schemas of the classes that are logged as structs. By default this includes the control geometry types.

Link copied to clipboard
Link copied to clipboard

Where warnings go. The default prints to standard error. A handler must not throw, and may be called from any thread.

Functions

Link copied to clipboard
fun now(): Long

Returns the current time as a timestamp in microseconds since origin.

Link copied to clipboard
fun register(backend: TelemetryBackend, vararg prefixes: String)

Adds backend. It receives every value logged after this call, including on paths that were already being logged.

Link copied to clipboard
fun reset()

Closes and removes every backend, and forgets which warnings have been reported.

Link copied to clipboard

Returns the table name under the root, creating it if needed.

Link copied to clipboard

Returns mark as a timestamp in microseconds since origin.

Link copied to clipboard

Removes backend without closing it.

Link copied to clipboard
fun warn(message: String)

Reports message to warningHandler, unless this exact message has been reported before. After 1000 distinct messages, new ones are dropped.