Documentation
¶
Overview ¶
Package tracecontract defines portable trace binding and artifact contracts shared across CUDA profiling and telemetry pipelines.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Example ¶
member, _ := Digest("perfetto_manifest.json", "manifest", "", []byte("manifest"))
fmt.Println(member.Path, member.Bytes)
Output: perfetto_manifest.json 8
Index ¶
- Constants
- func ValidateTracks(tracks []Track) error
- func WriteFindings(writer *host_perfetto.Writer, trackUUID, timestamp uint64, findings []Finding) error
- type Admission
- type Backend
- type Bindings
- type CaptureBounds
- type CorrelationOutcome
- type EvidenceContext
- type Finding
- type FindingClass
- type Gate
- type Interval
- type InterventionReceipt
- type Loss
- type Member
- type ProbeCoverage
- type Receipt
- type Requirement
- type Source
- type Track
Examples ¶
Constants ¶
const ( // ReasonAdmitted indicates all required evidence was satisfied. ReasonAdmitted = "admitted" // ReasonMissingReturn indicates a call lacks its matching return/exit event. ReasonMissingReturn = "missing_return" // ReasonClockDomainMismatch indicates mismatched or incompatible clock domains. ReasonClockDomainMismatch = "clock_domain_mismatch" // ReasonClockUncertaintyExceeded indicates clock uncertainty exceeds the allowable threshold. ReasonClockUncertaintyExceeded = "clock_uncertainty_exceeded" // ReasonUnknownLoss indicates unquantified record loss in a required family. ReasonUnknownLoss = "unknown_loss" // ReasonLossExceeded indicates dropped records exceeded the threshold for this requirement. ReasonLossExceeded = "loss_exceeded" // ReasonStreamTruncated indicates the record stream ended prematurely. ReasonStreamTruncated = "stream_truncated" // ReasonCaptureBoundsExceeded indicates interval falls outside the qualified capture bounds. ReasonCaptureBoundsExceeded = "capture_bounds_exceeded" // ReasonIdentityMismatch indicates artifact digest, process, thread, device, or workload mismatch. ReasonIdentityMismatch = "identity_mismatch" // ReasonBackendUnsupported indicates required backend is not in the admitted backend list. ReasonBackendUnsupported = "backend_unsupported" // ReasonBackendVersionMismatch indicates backend version does not satisfy the requirement. ReasonBackendVersionMismatch = "backend_version_mismatch" // ReasonProbeMissing indicates a required probe was not enabled or present. ReasonProbeMissing = "probe_missing" // ReasonProbeCoverageInsufficient indicates probe observation ratio is below the required threshold. ReasonProbeCoverageInsufficient = "probe_coverage_insufficient" // ReasonCorrelationUnmatched indicates required correlation between records was not established. ReasonCorrelationUnmatched = "correlation_unmatched" // ReasonInterventionMissing indicates experimental confirmation lacks an intervention receipt. ReasonInterventionMissing = "intervention_missing" // ReasonControlMissing indicates experimental confirmation lacks a control receipt. ReasonControlMissing = "control_missing" // ReasonControlVerificationFailed indicates control/intervention comparison did not confirm the mechanism. ReasonControlVerificationFailed = "control_verification_failed" ReasonEvidenceUnavailable = "evidence_unavailable" )
Reason codes for admission and refusal.
Variables ¶
This section is empty.
Functions ¶
func ValidateTracks ¶
ValidateTracks refuses duplicate UUIDs, missing parents and duplicated canonical representations of the same arm/journal/device/scope aggregation.
Example ¶
tracks := []Track{{UUID: 1, Name: "device", Role: "device", Clock: "monotonic", Provenance: "observed", Aggregation: "none"}, {UUID: 2, Parent: 1, Name: "token", Role: "token", Clock: "monotonic", Scope: "token:0", Provenance: "observed", Aggregation: "elapsed", Canonical: true}}
fmt.Println(ValidateTracks(tracks))
Output: <nil>
func WriteFindings ¶
func WriteFindings(writer *host_perfetto.Writer, trackUUID, timestamp uint64, findings []Finding) error
WriteFindings writes a sequence of findings onto a dedicated findings track.
Example ¶
var buf bytes.Buffer
writer := host_perfetto.NewWriter(&buf)
findings := []Finding{{
ID: "f1",
Rule: "launch_count",
Class: FindingObserved,
Admission: Admission{Admitted: true, Status: "admitted", ReasonCode: ReasonAdmitted},
}}
err := WriteFindings(writer, 1, 0, findings)
fmt.Println(err, buf.Len() > 0)
Output: <nil> true
Types ¶
type Admission ¶
type Admission struct {
Admitted bool `json:"admitted"`
Status string `json:"status"` // "admitted" or "withheld"
ReasonCode string `json:"reason_code"`
Reason string `json:"reason"`
Gates map[string]Gate `json:"gates"`
}
Admission records the evaluated qualification of evidence for a finding.
Example ¶
admission := Admission{Admitted: true, Status: "admitted", ReasonCode: ReasonAdmitted}
fmt.Println(admission.Admitted, admission.Status, admission.ReasonCode)
Output: true admitted admitted
func EvaluateRequirements ¶
func EvaluateRequirements(reqs []Requirement, ev EvidenceContext) Admission
EvaluateRequirements evaluates a set of requirements deterministically against the provided evidence.
type Backend ¶
type Backend struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
SHA256 string `json:"sha256,omitempty"`
}
Backend describes a backend actually used. Version and SHA256 remain empty when unavailable; native processing does not claim an external importer ran.
Example ¶
backend := Backend{Name: "native"}
fmt.Println(backend.Name)
Output: native
type Bindings ¶
type Bindings struct {
Version int `json:"version"`
Schema string `json:"schema"`
Members []Member `json:"members"`
}
Bindings hashes exact comparison artifacts, including the official manifest and alignment receipt. The index is stored as .cudaprof-bindings.json, outside the Perfetto manifest's trace files. Internal hash consistency is not an authenticity signature; consumers also hash the exact archive bytes parsed. The zero value is not an index; Version and Schema must identify v1.
Example ¶
bindings, _ := bindingFixture() fmt.Println(bindings.Schema)
Output: cudaprof.bindings.v1
func (Bindings) JSON ¶
JSON returns a canonical member index sorted by path. Duplicate paths, unsupported versions and absent manifest/alignment members are refused.
Example ¶
bindings, _ := bindingFixture() _, err := bindings.JSON() fmt.Println(err)
Output: <nil>
type CaptureBounds ¶
type CaptureBounds struct {
Start int64 `json:"start_ns"`
End int64 `json:"end_ns"`
Clock string `json:"clock,omitempty"`
}
CaptureBounds defines the closed time interval [Start, End] in nanoseconds.
Example ¶
bounds := CaptureBounds{Start: 1000, End: 5000, Clock: "monotonic"}
fmt.Println(bounds.Start, bounds.End, bounds.Clock)
Output: 1000 5000 monotonic
type CorrelationOutcome ¶
type CorrelationOutcome struct {
Matched uint64 `json:"matched"`
Unmatched uint64 `json:"unmatched"`
Ambiguous uint64 `json:"ambiguous"`
Missing uint64 `json:"missing"`
Status string `json:"status,omitempty"`
}
CorrelationOutcome summarizes correlation between submission calls and device activities.
type EvidenceContext ¶
type EvidenceContext struct {
Receipt Receipt
Artifacts []string
Intervals []Interval
HasReturn bool
ClockDomain string
Intervention *InterventionReceipt
Correlation *CorrelationOutcome
}
EvidenceContext provides the surrounding trace receipt, raw artifacts, and runtime observations against which finding requirements are evaluated.
type Finding ¶
type Finding struct {
ID string `json:"id"`
Rule string `json:"rule"`
Class FindingClass `json:"class"`
Admission Admission `json:"admission"`
Artifacts []string `json:"artifacts"`
Intervals []Interval `json:"intervals,omitempty"`
Requirements []Requirement `json:"requirements"`
Message string `json:"message"`
Value *float64 `json:"value,omitempty"`
Unit string `json:"unit,omitempty"`
Intervention *InterventionReceipt `json:"intervention,omitempty"`
}
Finding represents a deterministic diagnostic finding whose validity is computed from the evidence it actually requires.
Example ¶
finding := Finding{
ID: "finding-001",
Rule: "launch_count",
Class: FindingObserved,
Admission: Admission{
Admitted: true,
Status: "admitted",
ReasonCode: ReasonAdmitted,
},
}
fmt.Println(finding.ID, finding.Rule, finding.Class, finding.Admission.Admitted)
Output: finding-001 launch_count observed true
func Admit ¶
func Admit(id, rule string, targetClass FindingClass, msg string, value *float64, unit string, reqs []Requirement, ev EvidenceContext) Finding
Admit evaluates candidate requirements against evidence and returns a fully attributed Finding. If admission fails, the returned Finding has Class FindingUnavailable, Admission.Admitted false, and the stable ReasonCode.
Example ¶
receipt := receiptFixture()
receipt.LostRecords = map[string]Loss{"activity": {Dropped: 0, Total: 10}}
ev := EvidenceContext{Receipt: receipt}
reqs := []Requirement{{Name: "activity_loss", Family: "activity", MaxLoss: 0}}
val := 10.0
finding := Admit("f1", "launch_count", FindingObserved, "observed 10 launches", &val, "launches", reqs, ev)
fmt.Println(finding.Class, finding.Admission.Admitted, *finding.Value)
Output: observed true 10
func (Finding) CheckClaim ¶
func (f Finding) CheckClaim(expectedClass FindingClass) error
CheckClaim verifies that the finding was admitted with the expected class. It checks the finding representation, not the authenticity of imported data. Imported or modified findings must be recomputed from their source evidence; prose summaries are not evidence.
func (Finding) Write ¶
func (f Finding) Write(writer *host_perfetto.Writer, trackUUID, timestamp uint64) error
Write emits one official TrackEvent instant for the finding on the specified track. Perfetto args expose debug.cudaprof_finding_* annotations, with complete finding JSON in debug.cudaprof_finding_json.
type FindingClass ¶
type FindingClass string
FindingClass classifies how a diagnostic finding was established.
const ( // FindingObserved indicates a conclusion established directly from complete primary observations. FindingObserved FindingClass = "observed" // FindingAssociated indicates a conclusion linked through temporal correlation, external linkage, or heuristic attribution. FindingAssociated FindingClass = "associated" // FindingExperimentallyConfirmed indicates a conclusion validated by an active intervention against an explicit control receipt. FindingExperimentallyConfirmed FindingClass = "experimentally_confirmed" FindingUnavailable FindingClass = "unavailable" )
type Gate ¶
type Gate struct {
Disposition string `json:"disposition"`
Reason string `json:"reason"`
Provenance string `json:"provenance"`
}
Gate preserves one independent evidence disposition. Disposition is passed, failed, unavailable, unchecked or unsupported. An unavailable gate must not be promoted by another gate's success.
Example ¶
gate := Gate{Disposition: "unchecked", Reason: "no independent workload invariant", Provenance: "caller options"}
fmt.Println(gate.Disposition)
Output: unchecked
type Interval ¶
type Interval struct {
Start int64 `json:"start_ns"`
End int64 `json:"end_ns"`
Clock string `json:"clock,omitempty"`
}
Interval defines a closed time span [Start, End] in nanoseconds within an identified clock domain.
type InterventionReceipt ¶
type InterventionReceipt struct {
// TestedRule and workload/operation identities scope confirmation. Legacy
// receipts lacking these fields cannot confirm a workload-specific mechanism.
TestedRule string `json:"tested_rule,omitempty"`
WorkloadSHA256 string `json:"workload_sha256,omitempty"`
OperationID string `json:"operation_id,omitempty"`
InterventionOperationID string `json:"intervention_operation_id,omitempty"`
InterventionSHA256 string `json:"intervention_sha256"`
ControlSHA256 string `json:"control_sha256"`
InterventionName string `json:"intervention_name"`
ControlName string `json:"control_name"`
Outcome string `json:"outcome"`
Verified bool `json:"verified"`
}
InterventionReceipt references evidence from an active intervention and its paired control.
type Loss ¶
type Loss struct {
Dropped uint64 `json:"dropped"`
Total uint64 `json:"total"`
Unknown bool `json:"unknown,omitempty"`
}
Loss records dropped and total records for a record family. Unknown indicates unquantified loss where dropped records or their total cannot be bounded. When Unknown is false, Total includes dropped records, including measured zero.
Example ¶
loss := Loss{Dropped: 0, Total: 100, Unknown: false}
fmt.Println(loss.Dropped, loss.Total, loss.Unknown)
Output: 0 100 false
type Member ¶
type Member struct {
Path string `json:"path"`
Kind string `json:"kind"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
CaptureSHA256 string `json:"capture_sha256,omitempty"`
}
Member binds the bytes of one archive member. Kind describes the member; CaptureSHA256 names its source capture when applicable. No member hashes itself.
Example ¶
member, _ := Digest("base.pftrace", "trace", strings.Repeat("0", 64), []byte("trace"))
fmt.Println(member.Kind, member.Bytes)
Output: trace 5
type ProbeCoverage ¶
ProbeCoverage records observation presence and coverage ratio for a probe. Ratio is bounded in [0.0, 1.0].
Example ¶
coverage := ProbeCoverage{Present: true, Ratio: 1.0}
fmt.Println(coverage.Present, coverage.Ratio)
Output: true 1
type Receipt ¶
type Receipt struct {
Version int `json:"version"`
Command string `json:"command"`
Options map[string]string `json:"options"`
InputPath string `json:"input"`
InputSHA256 string `json:"input_sha256"`
Kind string `json:"detected_type"`
ProducerVersion string `json:"producer_version,omitempty"`
ConsumerVersion string `json:"consumer_version,omitempty"`
ProducerSchema string `json:"producer_schema,omitempty"`
Backends []Backend `json:"backends"`
Gates map[string]Gate `json:"gates"`
Warnings []string `json:"warnings"`
Limits map[string]int64 `json:"limits"`
Partial bool `json:"partial"`
ProjectedRows map[string]int64 `json:"projected_rows_by_kind,omitempty"`
RawDeviceRecords map[string]int64 `json:"raw_device_records_by_kind,omitempty"`
CollectorActivityRecords *uint64 `json:"collector_activity_records,omitempty"`
ProbeCoverage map[string]ProbeCoverage `json:"probe_coverage,omitempty"`
LostRecords map[string]Loss `json:"lost_records_by_family,omitempty"`
CaptureBounds *CaptureBounds `json:"capture_bounds,omitempty"`
Correlation *CorrelationOutcome `json:"correlation_outcome,omitempty"`
ClockDomain string `json:"clock_domain,omitempty"`
ClockProvenance string `json:"clock_provenance,omitempty"`
ClockUncertaintyNS *int64 `json:"clock_uncertainty_ns,omitempty"`
Uncertainty *float64 `json:"uncertainty,omitempty"`
}
Receipt is bounded trace-analysis metadata. Gates must contain collector, import, workload, stationarity, shape and correctness independently. InputSHA256 hashes the exact input bytes parsed; Kind is capture, pftrace or comparison_archive. Schema and tool versions are retained separately from evidence dispositions. The zero value is not a receipt; Version must be 1 and identities supplied.
Example ¶
receipt := receiptFixture() fmt.Println(receipt.Version, receipt.Partial)
Output: 1 true
func (Receipt) JSON ¶
JSON validates the receipt and returns deterministic versioned JSON. It refuses metadata exceeding 64 KiB; large evidence belongs in source records.
Example ¶
_, err := receiptFixture().JSON() fmt.Println(err)
Output: <nil>
func (Receipt) LossFor ¶
LossFor returns the loss record for the named family. If loss was not reported in this receipt, ok is false (unassessed).
func (Receipt) ProbeCoverageFor ¶
func (r Receipt) ProbeCoverageFor(probe string) (ProbeCoverage, bool)
ProbeCoverageFor returns probe coverage for the named probe. If probe coverage was not reported, ok is false (unassessed).
func (Receipt) Write ¶
func (r Receipt) Write(writer *host_perfetto.Writer, uuid, timestamp uint64) error
Write emits one official TrackEvent instant on a caller-registered receipt track. cudaprof.receipt_json retains the complete receipt; individual gate dispositions are also directly available through Perfetto's args table.
Example ¶
var buffer bytes.Buffer writer := host_perfetto.NewWriter(&buffer) writer.WriteTrackDescriptor(1, "evidence receipt", 0) err := receiptFixture().Write(writer, 1, 0) fmt.Println(err, buffer.Len() > 0)
Output: <nil> true
type Requirement ¶
type Requirement struct {
// ReceiptGate names an independent qualification gate required by this rule.
ReceiptGate string `json:"receipt_gate,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Family string `json:"family,omitempty"`
Backend string `json:"backend,omitempty"`
MinVersion string `json:"min_version,omitempty"`
MaxLoss uint64 `json:"max_loss,omitempty"`
AllowUnknownLoss bool `json:"allow_unknown_loss,omitempty"`
Probe string `json:"probe,omitempty"`
MinProbeCoverage float64 `json:"min_probe_coverage,omitempty"`
ClockDomain string `json:"clock_domain,omitempty"`
MaxUncertaintyNS int64 `json:"max_uncertainty_ns,omitempty"`
RequireReturn bool `json:"require_return,omitempty"`
RequireCorrelation bool `json:"require_correlation,omitempty"`
RequireControl bool `json:"require_control,omitempty"`
ArtifactDigest string `json:"artifact_digest,omitempty"`
}
Requirement defines one rule-specific evidence prerequisite.
Example ¶
req := Requirement{Name: "complete_activity", Family: "activity", MaxLoss: 0}
fmt.Println(req.Name, req.Family, req.MaxLoss)
Output: complete_activity activity 0
type Source ¶
type Source struct {
CaptureSHA256 string `json:"capture_sha256"`
Journal string `json:"journal"`
Kind string `json:"kind"`
Sequence uint64 `json:"sequence,omitempty"`
Index *uint64 `json:"index,omitempty"`
}
Source identifies retained evidence in the exact capture bytes parsed. Sequence is a raw journal sequence. Index is available only when an older record has no sequence; its Kind identifies the indexed decoder collection. Exactly one of Sequence and Index must be supplied. The zero value lacks the identity required for encoding.
Example ¶
source := Source{CaptureSHA256: strings.Repeat("0", 64), Journal: "process-1", Kind: "activity", Sequence: 7}
text, _ := source.String()
fmt.Println(text)
Output: {"capture_sha256":"0000000000000000000000000000000000000000000000000000000000000000","journal":"process-1","kind":"activity","sequence":7}
func (Source) String ¶
String returns compact, deterministic JSON for a stable source reference. It rejects missing identity rather than referring to an imported slice ID.
Example ¶
source := Source{CaptureSHA256: strings.Repeat("0", 64), Journal: "process-1", Kind: "api", Sequence: 8}
_, err := source.String()
fmt.Println(err)
Output: <nil>
type Track ¶
type Track struct {
UUID uint64 `json:"uuid"`
Parent uint64 `json:"parent_uuid,omitempty"`
Name string `json:"name"`
Role string `json:"role"`
Clock string `json:"clock"`
Machine string `json:"machine,omitempty"`
Arm string `json:"arm,omitempty"`
CaptureSHA256 string `json:"capture_sha256,omitempty"`
Journal string `json:"journal,omitempty"`
Device *uint32 `json:"device,omitempty"`
Scope string `json:"scope_id,omitempty"`
Level int `json:"hierarchy_level"`
Provenance string `json:"evidence_provenance"`
Aggregation string `json:"aggregation"`
Canonical bool `json:"canonical"`
}
Track identifies a semantic track independently of its display name. Arm scopes independently aligned runs; Journal scopes process generations. Device is optional so device zero remains distinct from unavailable identity. Canonical marks the sole counting representation for one scope/aggregation; child hierarchy tracks and raw references must not repeat that total. The zero value lacks the identity required by Write.
Example ¶
track := Track{UUID: 1, Name: "recorded GPU union", Role: "gpu_union", Clock: "arm:monotonic", Scope: "token:0", Provenance: "observed", Aggregation: "gpu_union", Canonical: true}
fmt.Println(track.Role, track.Canonical)
Output: gpu_union true
func (Track) Write ¶
func (t Track) Write(writer *host_perfetto.Writer, timestamp uint64) error
Write registers the descriptor and one SQL-visible metadata instant. The official TrackEvent debug_annotations encode cudaprof.track.v1 on this UUID. Timestamp must be a valid position in the caller's exported clock domain.
Example ¶
var buffer bytes.Buffer
writer := host_perfetto.NewWriter(&buffer)
track := Track{UUID: 1, Name: "device activity", Role: "raw_activity", Clock: "capture:journal:monotonic", Provenance: "observed", Aggregation: "none"}
err := track.Write(writer, 0)
fmt.Println(err, buffer.Len() > 0)
Output: <nil> true