performance

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Portable client performance evidence

This package records bounded, payload-free client performance measurements. It implements the Go portion of the presentation.client.performance_evidence v1 service. Use it when adding a client probe; it does not record conversation content.

Provider and recorder lifecycle

The client composition runtime mounts a Provider through a MountScope and injects a source-scoped Recorder into each selected probe plugin. Identities, source bindings, configuration, and mount generation are frozen before a recorder exists. Recorder calls accept only metric/dimension enums and unsigned integers. There is deliberately no field or method for arbitrary labels, payloads, URLs, host names, session/response/item IDs, paths, device names, or diagnostic strings.

Duration buckets

Durations use these fixed inclusive, non-cumulative bucket upper bounds (ns):

100000, 250000, 500000, 1000000, 2000000, 5000000, 10000000,
20000000, 50000000, 100000000, 250000000, 500000000, 1000000000,
2000000000, 5000000000, 10000000000, 30000000000, 60000000000,
300000000000, 3600000000000, 86400000000000

Sampling and snapshots

Sampling hashes the schema identity, seed, generation, canonical source index, metric, canonical dimensions, and zero-based attempt ordinal with SHA-256. The first big-endian 64 bits modulo the denominator are compared with the numerator. This specifies deterministic behavior for a future shared corpus; this Go slice does not claim JavaScript or Swift parity.

Snapshots are payload-free, recursively cloned, fingerprinted over compact canonical JSON, and bounded by both the selected configuration and the absolute 256-KiB ceiling. DecodeSnapshot accepts only the exact bytes emitted by MarshalSnapshot, including its single trailing newline.

Documentation

Overview

Package performance implements the portable, payload-free client performance-evidence service described by docs/composable-presentation.md.

The package is deliberately independent of any view toolkit. A client runtime mounts a collector with exact immutable identities and injects a scoped Recorder into selected plugins. Recording callers can supply only closed enums and integers; they cannot attach labels, event payloads, URLs, session identifiers, or diagnostics.

Index

Constants

View Source
const (
	SchemaIdentity              = "openrealtime/presentation/client-performance-evidence/v1"
	ConfigurationSchemaIdentity = "openrealtime/presentation/client-performance-evidence-config/v1"
	SnapshotFormatVersion       = uint64(1)
	ConfigurationVersion        = uint64(1)

	MaxSources               = uint16(128)
	MaxSeries                = uint16(256)
	MaxDimensionsPerSeries   = uint8(4)
	MaxPendingSpans          = uint16(256)
	MaxObservationsPerSeries = uint32(4096)
	MaxSnapshotBytes         = 256 << 10
	MaxDurationNS            = uint64(24 * 60 * 60 * 1_000_000_000)
)
View Source
const (
	DimensionTransport DimensionName = "transport"
	DimensionMedia     DimensionName = "media"
	DimensionQueue     DimensionName = "queue"
	DimensionRender    DimensionName = "render"

	ValueWebSocket       DimensionValue = "websocket"
	ValueWebRTC          DimensionValue = "webrtc"
	ValueAudio           DimensionValue = "audio"
	ValueVideo           DimensionValue = "video"
	ValueData            DimensionValue = "data"
	ValueOutboundMessage DimensionValue = "outbound_messages"
	ValueOutboundBytes   DimensionValue = "outbound_bytes"
	ValueAudioPlayout    DimensionValue = "audio_playout"
	ValueVideoCapture    DimensionValue = "video_capture"
	ValueConversation    DimensionValue = "conversation"
	ValueLiveSnapshot    DimensionValue = "live_snapshot"
	ValueDelta           DimensionValue = "delta"
	ValueTrace           DimensionValue = "trace"
)

Variables

View Source
var ErrProviderUnavailable = errors.New("performance evidence provider unavailable")

Functions

func CollectorDescriptor

func CollectorDescriptor() plugin.Descriptor

CollectorDescriptor returns the immutable semantic descriptor for the portable collector. Implementations and their artifacts remain deployment bindings and are not smuggled into this descriptor.

func CollectorDescriptorIdentity

func CollectorDescriptorIdentity() (plugin.Identity, error)

CollectorDescriptorIdentity is convenient for descriptor locks and runtime registration tests.

func ConfigurationContract

func ConfigurationContract() plugin.Contract

ConfigurationContract identifies the separately fingerprinted collector configuration schema used by descriptor/profile compilation.

func DurationBucketUpperBoundsNS

func DurationBucketUpperBoundsNS() []uint64

func MarshalSnapshot

func MarshalSnapshot(snapshot Snapshot) ([]byte, error)

func ServiceContract

func ServiceContract() plugin.Contract

ServiceContract returns a copy of the exact service contract used by client profile dependency resolution. Returning a value, rather than exporting a mutable package variable, prevents callers from changing the identity seen by later registrations.

Types

type ClientPlatform

type ClientPlatform string
const (
	PlatformHeadless ClientPlatform = "headless"
	PlatformBrowser  ClientPlatform = "browser"
	PlatformMacOS    ClientPlatform = "macos"
)

type ClockDomain

type ClockDomain string
const (
	ClockVirtualInteger   ClockDomain = "virtual_integer_ns"
	ClockProcessMonotonic ClockDomain = "process_monotonic_ns"
	ClockBrowserMonotonic ClockDomain = "browser_monotonic_ns"
	ClockMachContinuous   ClockDomain = "mach_continuous_ns"
)

type ClockIdentity

type ClockIdentity struct {
	Domain                ClockDomain     `json:"domain"`
	ResolutionNS          uint64          `json:"resolution_ns"`
	Provenance            ClockProvenance `json:"provenance"`
	CrossHostSynchronized bool            `json:"cross_host_synchronized"`
	CrossHostErrorBoundNS uint64          `json:"cross_host_error_bound_ns,omitempty"`
}

type ClockProvenance

type ClockProvenance string
const (
	ClockFromFixture      ClockProvenance = "deterministic_fixture"
	ClockFromGoMonotonic  ClockProvenance = "go_monotonic"
	ClockFromBrowserAPI   ClockProvenance = "browser_performance_api"
	ClockFromMachClock    ClockProvenance = "mach_continuous_time"
	ClockFromSynchronized ClockProvenance = "bounded_cross_host_sync"
)

type Configuration

type Configuration struct {
	FormatVersion uint64            `json:"format_version"`
	Mode          ObservabilityMode `json:"mode"`
	Sampling      Sampling          `json:"sampling"`
	Limits        Limits            `json:"limits"`
	Fingerprint   string            `json:"fingerprint"`
}

func DefaultConfiguration

func DefaultConfiguration(mode ObservabilityMode) (Configuration, error)

func FreezeConfiguration

func FreezeConfiguration(source Configuration) (Configuration, error)

func (Configuration) Validate

func (configuration Configuration) Validate() error

type CounterAggregate

type CounterAggregate struct {
	Value        uint64 `json:"value"`
	Observations uint64 `json:"observations"`
}

type Coverage

type Coverage string
const (
	CoverageMeasured    Coverage = "measured"
	CoverageSimulated   Coverage = "simulated"
	CoverageUnsupported Coverage = "unsupported"
)

type CoverageReason

type CoverageReason string
const (
	CoverageReasonNone                  CoverageReason = "none"
	CoverageReasonPlatformUnavailable   CoverageReason = "platform_unavailable"
	CoverageReasonCapabilityUnavailable CoverageReason = "capability_unavailable"
	CoverageReasonSensorUnavailable     CoverageReason = "sensor_unavailable"
	CoverageReasonPermissionUnavailable CoverageReason = "permission_unavailable"
	CoverageReasonClockUnsynchronized   CoverageReason = "clock_unsynchronized"
)

type Dimension

type Dimension struct {
	Name  DimensionName  `json:"name"`
	Value DimensionValue `json:"value"`
}

type DimensionName

type DimensionName string

DimensionName and DimensionValue are separate closed vocabularies. Only the name/value pairs in dimensionPairs are valid.

type DimensionValue

type DimensionValue string

type DropCounter

type DropCounter struct {
	Reason DropReason `json:"reason"`
	Count  uint64     `json:"count"`
}

type DropReason

type DropReason string
const DropDeterministicSampling DropReason = "deterministic_sampling"

type DurationHistogram

type DurationHistogram struct {
	Count        uint64   `json:"count"`
	SumNS        uint64   `json:"sum_ns"`
	MinNS        uint64   `json:"min_ns"`
	MaxNS        uint64   `json:"max_ns"`
	BucketCounts []uint64 `json:"bucket_counts"`
}

type EvidenceClass

type EvidenceClass string

EvidenceClass says what environment can truthfully support the evidence.

const (
	EvidenceDeterministicFixture EvidenceClass = "deterministic_fixture"
	EvidenceBrowserRuntime       EvidenceClass = "browser_runtime"
	EvidenceMacOSNative          EvidenceClass = "macos_native"
)

type GaugeAggregate

type GaugeAggregate struct {
	Value        int64  `json:"value"`
	Min          int64  `json:"min"`
	Max          int64  `json:"max"`
	Observations uint64 `json:"observations"`
}

type Limits

type Limits struct {
	MaxSources               uint16 `json:"max_sources"`
	MaxSeries                uint16 `json:"max_series"`
	MaxDimensionsPerSeries   uint8  `json:"max_dimensions_per_series"`
	MaxPendingSpans          uint16 `json:"max_pending_spans"`
	MaxObservationsPerSeries uint32 `json:"max_observations_per_series"`
	MaxArtifactBytes         uint32 `json:"max_artifact_bytes"`
}

func DefaultLimits

func DefaultLimits() Limits

type Metric

type Metric string

Metric is the complete v1 metric vocabulary. Units and families are fixed by metricSpecifications; a caller cannot rename or reinterpret a series.

const (
	MetricEndpointToFirstRenderedAudio Metric = "endpoint_to_first_rendered_audio_ns"
	MetricServerOutputToRenderedAudio  Metric = "server_output_to_rendered_audio_ns"
	MetricAudioScheduled               Metric = "audio_scheduled_ns"
	MetricAudioCompleted               Metric = "audio_completed_ns"
	MetricVideoCaptureToAdmissionAck   Metric = "video_capture_to_admission_ack_ns"
	MetricReconnectDetection           Metric = "reconnect_detection_ns"
	MetricReconnectRecovery            Metric = "reconnect_recovery_ns"
	MetricReducerToViewCommit          Metric = "reducer_publish_to_view_commit_ns"
	MetricLongTask                     Metric = "long_task_ns"
	MetricMainLoopStall                Metric = "main_loop_stall_ns"
	MetricLiveSnapshotRender           Metric = "live_snapshot_render_ns"
	MetricDeltaRender                  Metric = "delta_render_ns"
	MetricTraceRender                  Metric = "trace_render_ns"

	MetricAudioGap           Metric = "audio_gap_count"
	MetricAudioUnderflow     Metric = "audio_underflow_count"
	MetricAudioOverrun       Metric = "audio_overrun_count"
	MetricAudioCaptureDrop   Metric = "audio_capture_drop_count"
	MetricVideoCaptureDrop   Metric = "video_capture_drop_count"
	MetricReconnectLostEvent Metric = "reconnect_lost_event_count"
	MetricReconnectDuplicate Metric = "reconnect_duplicate_event_count"

	MetricClientMessageQueue Metric = "client_message_queue_depth"
	MetricClientByteQueue    Metric = "client_byte_queue_bytes"
	MetricMemoryBaseline     Metric = "memory_baseline_bytes"
	MetricMemoryCurrent      Metric = "memory_current_bytes"
	MetricMemoryHighWater    Metric = "memory_high_water_bytes"
	MetricMemoryGrowth       Metric = "memory_growth_bytes"
)

type MetricFamily

type MetricFamily string
const (
	FamilyDuration MetricFamily = "duration_ns"
	FamilyCounter  MetricFamily = "counter"
	FamilyGauge    MetricFamily = "gauge"
)

func FamilyOf

func FamilyOf(metric Metric) (MetricFamily, bool)

type MountScope

type MountScope struct {
	// contains filtered or unexported fields
}

func NewMountScope

func NewMountScope() *MountScope

func (*MountScope) Lose

func (scope *MountScope) Lose(provider *Provider) error

Lose invalidates every recorder and pending span created by provider. It is idempotent for the provider that was most recently lost. A later Mount gets a fresh generation and an entirely separate aggregate.

func (*MountScope) Mount

func (scope *MountScope) Mount(binding RuntimeBinding, configuration Configuration) (*Provider, error)

type ObservabilityMode

type ObservabilityMode string

ObservabilityMode is part of the frozen collector configuration. Disabled is a closed vocabulary member but cannot be mounted: a disabled profile must omit both collector and probes so it remains a valid overhead baseline.

const (
	ObservabilityDisabled ObservabilityMode = "disabled"
	ObservabilitySampled  ObservabilityMode = "sampled"
	ObservabilityRelease  ObservabilityMode = "release"
)

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

func (*Provider) Identity

func (provider *Provider) Identity() RuntimeIdentity

Identity returns a recursively independent copy of the runtime-injected envelope. Mutating it cannot affect the provider or later snapshots.

func (*Provider) Recorder

func (provider *Provider) Recorder(source uint16) (Recorder, error)

Recorder returns the scoped recorder selected by the runtime's canonical source index. The runtime injects this value into the corresponding plugin; the plugin itself never supplies an identity.

func (*Provider) Snapshot

func (provider *Provider) Snapshot() (Snapshot, error)

Snapshot returns a recursively isolated, immutable aggregate. It remains available after provider loss so a final generation artifact can be saved.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder is a scoped, identity-free recording face. Its fields are private so it cannot be retargeted to another source or generation.

func (Recorder) AddCounter

func (recorder Recorder) AddCounter(metric Metric, delta uint64, dimensions ...Dimension) error

func (Recorder) BeginDuration

func (recorder Recorder) BeginDuration(metric Metric, startNS uint64, dimensions ...Dimension) (Span, error)

func (Recorder) CompleteDuration

func (recorder Recorder) CompleteDuration(span Span, endNS uint64) error

func (Recorder) RecordDuration

func (recorder Recorder) RecordDuration(metric Metric, nanoseconds uint64, dimensions ...Dimension) error

func (Recorder) SetCoverage

func (recorder Recorder) SetCoverage(metric Metric, coverage Coverage, reason CoverageReason, dimensions ...Dimension) error

func (Recorder) SetGauge

func (recorder Recorder) SetGauge(metric Metric, value int64, dimensions ...Dimension) error

type RejectedError

type RejectedError struct {
	Reason RejectionReason
}

func (RejectedError) Error

func (rejection RejectedError) Error() string

func (RejectedError) Is

func (rejection RejectedError) Is(target error) bool

type RejectionCounter

type RejectionCounter struct {
	Reason RejectionReason `json:"reason"`
	Count  uint64          `json:"count"`
}

type RejectionReason

type RejectionReason string
const (
	RejectUnknownEnum         RejectionReason = "unknown_enum"
	RejectWrongMetricFamily   RejectionReason = "wrong_metric_family"
	RejectBackwardTime        RejectionReason = "backward_time"
	RejectTimingOverflow      RejectionReason = "timing_overflow"
	RejectUnmatchedSpan       RejectionReason = "unmatched_span"
	RejectDuplicateSpan       RejectionReason = "duplicate_span"
	RejectSourceBound         RejectionReason = "source_bound"
	RejectSeriesBound         RejectionReason = "series_bound"
	RejectDimensionBound      RejectionReason = "dimension_bound"
	RejectPendingSpanBound    RejectionReason = "pending_span_bound"
	RejectObservationBound    RejectionReason = "observation_bound"
	RejectCounterOverflow     RejectionReason = "counter_overflow"
	RejectCoverageConflict    RejectionReason = "coverage_conflict"
	RejectIdentityMismatch    RejectionReason = "identity_mismatch"
	RejectArtifactBound       RejectionReason = "artifact_bound"
	RejectProviderUnavailable RejectionReason = "provider_unavailable"
)

func RejectionReasonOf

func RejectionReasonOf(err error) (RejectionReason, bool)

RejectionReasonOf extracts the closed reason from a rejected recorder call.

type RuntimeBinding

type RuntimeBinding struct {
	EvidenceClass        EvidenceClass    `json:"evidence_class"`
	Platform             ClientPlatform   `json:"platform"`
	Clock                ClockIdentity    `json:"clock"`
	ProfileFingerprint   string           `json:"profile_fingerprint"`
	LockFingerprint      string           `json:"lock_fingerprint"`
	PlanFingerprint      string           `json:"plan_fingerprint"`
	ManifestFingerprint  string           `json:"manifest_fingerprint"`
	Collector            plugin.Identity  `json:"collector"`
	ImplementationDigest string           `json:"implementation_digest"`
	ConfigurationDigest  string           `json:"configuration_digest"`
	FixtureDigest        string           `json:"fixture_digest,omitempty"`
	Sources              []SourceIdentity `json:"sources"`
}

RuntimeBinding is supplied by the client composition runtime. Generation is intentionally absent: MountScope injects it, and recording callers never receive a setter for any field in the resulting identity.

type RuntimeIdentity

type RuntimeIdentity struct {
	EvidenceClass        EvidenceClass     `json:"evidence_class"`
	Platform             ClientPlatform    `json:"platform"`
	Clock                ClockIdentity     `json:"clock"`
	ProfileFingerprint   string            `json:"profile_fingerprint"`
	LockFingerprint      string            `json:"lock_fingerprint"`
	PlanFingerprint      string            `json:"plan_fingerprint"`
	ManifestFingerprint  string            `json:"manifest_fingerprint"`
	Collector            plugin.Identity   `json:"collector"`
	ImplementationDigest string            `json:"implementation_digest"`
	ConfigurationDigest  string            `json:"configuration_digest"`
	FixtureDigest        string            `json:"fixture_digest,omitempty"`
	ObservabilityMode    ObservabilityMode `json:"observability_mode"`
	Generation           uint64            `json:"generation"`
	Sources              []SourceIdentity  `json:"sources"`
}

func (RuntimeIdentity) Clone

func (identity RuntimeIdentity) Clone() RuntimeIdentity

type Sampling

type Sampling struct {
	Numerator   uint32 `json:"numerator"`
	Denominator uint32 `json:"denominator"`
	Seed        uint64 `json:"seed"`
}

type Series

type Series struct {
	Source          uint16             `json:"source"`
	Metric          Metric             `json:"metric"`
	Family          MetricFamily       `json:"family"`
	Dimensions      []Dimension        `json:"dimensions"`
	Coverage        Coverage           `json:"coverage"`
	CoverageReason  CoverageReason     `json:"coverage_reason"`
	Attempts        uint64             `json:"attempts"`
	SamplingDropped uint64             `json:"sampling_dropped"`
	Duration        *DurationHistogram `json:"duration,omitempty"`
	Counter         *CounterAggregate  `json:"counter,omitempty"`
	Gauge           *GaugeAggregate    `json:"gauge,omitempty"`
}

func (Series) Clone

func (series Series) Clone() Series

type Service

type Service interface {
	SnapshotReader
	Recorder(source uint16) (Recorder, error)
}

Service is the provider face mounted under ServiceContract. Client runtimes inject individual Recorder values into probes and may separately export the narrower SnapshotReader face.

type Snapshot

type Snapshot struct {
	FormatVersion     uint64             `json:"format_version"`
	Schema            string             `json:"schema"`
	Contract          plugin.Contract    `json:"contract"`
	Identity          RuntimeIdentity    `json:"identity"`
	Configuration     Configuration      `json:"configuration"`
	DurationBucketsNS []uint64           `json:"duration_buckets_ns"`
	Series            []Series           `json:"series"`
	Rejections        []RejectionCounter `json:"rejections"`
	Drops             []DropCounter      `json:"drops"`
	Fingerprint       string             `json:"fingerprint"`
}

func DecodeSnapshot

func DecodeSnapshot(reader io.Reader) (Snapshot, error)

DecodeSnapshot accepts only the exact compact canonical representation produced by MarshalSnapshot. Duplicate keys, unknown fields, trailing data, enum drift, ordering drift, fingerprint drift, and oversized artifacts fail closed.

func (Snapshot) Clone

func (snapshot Snapshot) Clone() Snapshot

func (Snapshot) Validate

func (snapshot Snapshot) Validate() error

type SnapshotReader

type SnapshotReader interface {
	Snapshot() (Snapshot, error)
}

SnapshotReader is the narrow read-only face intended for exporters and observability views. It cannot obtain a recorder or mutate collector state.

type SourceIdentity

type SourceIdentity struct {
	EntryFingerprint     string          `json:"entry_fingerprint"`
	Descriptor           plugin.Identity `json:"descriptor"`
	ImplementationDigest string          `json:"implementation_digest"`
	ConfigurationDigest  string          `json:"configuration_digest"`
}

type Span

type Span struct {
	// contains filtered or unexported fields
}

Span is an opaque process-local correlation handle. It has no JSON fields, exposes no token, and is never retained by a snapshot.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL