Documentation
¶
Overview ¶
Package fxt is a library for creating [Fuschia Trace Format](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md) files.
FXT is a file format for storing trace / counter events in a compact binary format. These trace files can then be viewed with an interactive web-based UI: https://ui.perfetto.dev/
FXT was created by Google for use in their experimental operating system [Fuschia](https://fuchsia.dev/fuchsia-src). It's very well documented, simple to write, and can express lots of different types of events and data.
There are lots of other tracing file formats out there.
* [chrome://tracing](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview)
- chrome://tracing is extremely simple and you just need a Chrome browser to view it.
- But it is json-based. So the file can quickly explode in size for large traces.
* [Perfetto](https://perfetto.dev/)
- Perfetto is the successor to chrome://tracing and has many improvements.
- It's protobuf-based, so it's much smaller / compact.
- However, protobuf can be a pain to use. You generally want to use the .proto file to generate a generator/parser, but that's a lot of extra steps / maintenance
* [Speedscope](https://github.com/jlfwong/speedscope/wiki/Importing-from-custom-sources#speedscopes-file-format)
- Speedscope is a web-based trace visualizer like Perfetto UI
- It can view quite a few different formats
- In addition, it has its own json-based trace format
- Which, unfortunately, has the same issues as chrome://tracing
* Many many more
FXT is a simple format to write, and it's binary. So it's a bit of the best of both worlds
Index ¶
- Constants
- type AsyncBeginEventRecord
- type AsyncEndEventRecord
- type AsyncInstantEventRecord
- type BlobRecord
- type BlobType
- type ContextSwitchRecord
- type CounterEventRecord
- type DurationBeginEventRecord
- type DurationCompleteEventRecord
- type DurationEndEventRecord
- type FlowBeginEvent
- type FlowEndEvent
- type FlowStepEvent
- type InstantEventRecord
- type KernelObjectID
- type KernelObjectRecord
- type KernelObjectType
- type LargeBlobNoMetadataRecord
- type LargeBlobWithMetadataRecord
- type LogRecord
- type ProcessState
- type ProviderEventType
- type ProviderID
- type ProviderRecordState
- type Record
- type RecordStateByProvider
- type Span
- type SpansByProcess
- type Thread
- type ThreadSpans
- type ThreadState
- type ThreadStateType
- type ThreadWakeupRecord
- type UserspaceObjectRecord
- type Writer
- func (w *Writer) AddAsyncBeginEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddAsyncBeginEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddAsyncEndEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddAsyncEndEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddAsyncInstantEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddAsyncInstantEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddBlobRecord(name string, data []byte, blobType BlobType) error
- func (w *Writer) AddContextSwitchRecord(cpuNumber uint16, outgoingThreadState uint8, outgoingThreadId KernelObjectID, ...) error
- func (w *Writer) AddContextSwitchRecordWithArgs(cpuNumber uint16, outgoingThreadState uint8, outgoingThreadId KernelObjectID, ...) error
- func (w *Writer) AddCounterEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddDurationBeginEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddDurationBeginEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddDurationCompleteEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddDurationCompleteEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddDurationEndEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddDurationEndEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddFlowBeginEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddFlowBeginEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddFlowEndEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddFlowEndEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddFlowStepEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddFlowStepEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddInitializationRecord(numTicksPerSecond uint64) error
- func (w *Writer) AddInstantEvent(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddInstantEventWithArgs(category string, name string, processId KernelObjectID, ...) error
- func (w *Writer) AddProviderEventRecord(providerId uint32, eventType ProviderEventType) error
- func (w *Writer) AddProviderInfoRecord(providerId uint32, providerName string) error
- func (w *Writer) AddProviderSectionRecord(providerId uint32) error
- func (w *Writer) AddThreadWakeupRecord(cpuNumber uint16, wakingThreadId KernelObjectID, timestamp uint64) error
- func (w *Writer) AddThreadWakeupRecordWithArgs(cpuNumber uint16, wakingThreadId KernelObjectID, timestamp uint64, ...) error
- func (w *Writer) AddUserspaceObjectRecord(name string, processId KernelObjectID, threadId KernelObjectID, ...) error
- func (w *Writer) Close() error
- func (w *Writer) SetProcessName(processId KernelObjectID, name string) error
- func (w *Writer) SetThreadName(processId KernelObjectID, threadId KernelObjectID, name string) error
Constants ¶
const ( ThreadStateTypeNew = 0 ThreadStateTypeRunning = 1 ThreadStateTypeSuspended = 2 ThreadStateTypeBlocked = 3 ThreadStateTypeDying = 4 ThreadStateTypeDead = 5 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncBeginEventRecord ¶ added in v0.6.0
type AsyncEndEventRecord ¶ added in v0.6.0
type AsyncInstantEventRecord ¶ added in v0.6.0
type BlobRecord ¶ added in v0.6.0
type ContextSwitchRecord ¶ added in v0.6.0
type ContextSwitchRecord struct {
TimestampNS uint64
CPUID uint16
OutgoingThreadID KernelObjectID
OutgoingThreadState ThreadStateType
IncomingThreadID KernelObjectID
Args map[string]any
}
type CounterEventRecord ¶ added in v0.6.0
type DurationBeginEventRecord ¶ added in v0.6.0
type DurationCompleteEventRecord ¶ added in v0.6.0
type DurationEndEventRecord ¶ added in v0.6.0
type FlowBeginEvent ¶ added in v0.6.0
type FlowEndEvent ¶ added in v0.6.0
type FlowStepEvent ¶ added in v0.6.0
type InstantEventRecord ¶ added in v0.6.0
type KernelObjectID ¶
type KernelObjectID uint64
KernelObjectID is a unique identifier for a kernel object for example, a process or thread
type KernelObjectRecord ¶ added in v0.6.0
type KernelObjectRecord struct {
Type KernelObjectType
ID KernelObjectID
Name string
Args map[string]any
}
type KernelObjectType ¶ added in v0.6.0
type KernelObjectType uint8
type LargeBlobNoMetadataRecord ¶ added in v0.6.0
type LargeBlobWithMetadataRecord ¶ added in v0.6.0
type ProcessState ¶ added in v0.7.0
type ProcessState struct {
Name string
Threads map[KernelObjectID]*ThreadState
}
type ProviderEventType ¶ added in v0.6.0
type ProviderEventType uint8
const (
ProviderEventTypeBufferFilledUp ProviderEventType = 0
)
type ProviderID ¶ added in v0.6.0
type ProviderID uint32
type ProviderRecordState ¶ added in v0.7.0
type ProviderRecordState struct {
Name string
Records []Record
Events []ProviderEventType
}
type Record ¶ added in v0.7.0
type Record interface {
// contains filtered or unexported methods
}
Record is a way to constrain what types can be returned in the record stream
type RecordStateByProvider ¶ added in v0.7.0
type RecordStateByProvider map[ProviderID]*ProviderRecordState
func ParseRecords ¶ added in v0.6.0
type SpansByProcess ¶ added in v0.7.0
type SpansByProcess map[KernelObjectID]*ProcessState
func TransformRecordsToSpans ¶ added in v0.7.0
func TransformRecordsToSpans(records []Record) (SpansByProcess, error)
type Thread ¶
type Thread struct {
ProcessID KernelObjectID
ThreadID KernelObjectID
}
Thread uniquely identifies a thread within a process
type ThreadSpans ¶ added in v0.7.0
type ThreadSpans struct {
ThreadID KernelObjectID
Spans []*Span
}
type ThreadState ¶ added in v0.7.0
type ThreadStateType ¶ added in v0.6.0
type ThreadStateType uint8
type ThreadWakeupRecord ¶ added in v0.6.0
type ThreadWakeupRecord struct {
TimestampNS uint64
CPUID uint16
WakingThreadID KernelObjectID
Args map[string]any
}
type UserspaceObjectRecord ¶ added in v0.6.0
type UserspaceObjectRecord struct {
Name string
ProcessID KernelObjectID
Pointer uintptr
Args map[string]any
}
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a struct for writing an FXT file. It has methods for adding records to the file
func NewWriter ¶
NewWriter creates a new FXT file at `filePath` and initializes it with the FXT header It returns a Writer instance which can be used to add records to the file
func (*Writer) AddAsyncBeginEvent ¶ added in v0.2.0
func (w *Writer) AddAsyncBeginEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, asyncCorrelationId uint64) error
AddAsyncBeginEvent adds an async begin event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddAsyncBeginEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddAsyncBeginEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, asyncCorrelationId uint64, arguments map[string]interface{}) error
AddAsyncBeginEventWithArgs is the same as AddAsyncBeginEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddAsyncEndEvent ¶ added in v0.2.0
func (w *Writer) AddAsyncEndEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, asyncCorrelationId uint64) error
AddAsyncEndEvent adds an async end event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddAsyncEndEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddAsyncEndEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, asyncCorrelationId uint64, arguments map[string]interface{}) error
AddAsyncEndEventWithArgs is the same as AddAsyncEndEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddAsyncInstantEvent ¶ added in v0.2.0
func (w *Writer) AddAsyncInstantEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, asyncCorrelationId uint64) error
AddAsyncInstantEvent adds an async instant event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddAsyncInstantEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddAsyncInstantEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, asyncCorrelationId uint64, arguments map[string]interface{}) error
AddAsyncInstantEventWithArgs is the same as AddAsyncInstantEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddBlobRecord ¶ added in v0.3.0
AddBlobRecord adds a blob record to the file
func (*Writer) AddContextSwitchRecord ¶ added in v0.3.0
func (w *Writer) AddContextSwitchRecord(cpuNumber uint16, outgoingThreadState uint8, outgoingThreadId KernelObjectID, incomingThreadId KernelObjectID, timestamp uint64) error
AddContextSwitchRecord adds a context switch scheduling record to the file
func (*Writer) AddContextSwitchRecordWithArgs ¶ added in v0.3.0
func (w *Writer) AddContextSwitchRecordWithArgs(cpuNumber uint16, outgoingThreadState uint8, outgoingThreadId KernelObjectID, incomingThreadId KernelObjectID, timestamp uint64, arguments map[string]interface{}) error
AddContextSwitchRecordWithArgs is the same as AddContextSwitchRecord, but it allows you to additionally include arguments within the scheduling record
func (*Writer) AddCounterEvent ¶ added in v0.2.0
func (w *Writer) AddCounterEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, arguments map[string]interface{}, counterId uint64) error
AddCounterEvent adds a counter event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddDurationBeginEvent ¶ added in v0.2.0
func (w *Writer) AddDurationBeginEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64) error
AddDurationBeginEvent adds a duration begin event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddDurationBeginEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddDurationBeginEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, arguments map[string]interface{}) error
AddDurationBeginEventWithArgs is the same as AddDurationBeginEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddDurationCompleteEvent ¶ added in v0.2.0
func (w *Writer) AddDurationCompleteEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, beginTimestamp uint64, endTimestamp uint64) error
AddDurationCompleteEvent adds a duration complete event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddDurationCompleteEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddDurationCompleteEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, beginTimestamp uint64, endTimestamp uint64, arguments map[string]interface{}) error
AddDurationCompleteEventWithArgs is the same as AddDurationCompleteEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddDurationEndEvent ¶ added in v0.2.0
func (w *Writer) AddDurationEndEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64) error
AddDurationEndEvent adds a duration end event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddDurationEndEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddDurationEndEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, arguments map[string]interface{}) error
AddDurationEndEventWithArgs is the same as AddDurationEndEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddFlowBeginEvent ¶ added in v0.2.0
func (w *Writer) AddFlowBeginEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, flowCorrelationId uint64) error
AddFlowBeginEvent adds an flow begin event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddFlowBeginEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddFlowBeginEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, flowCorrelationId uint64, arguments map[string]interface{}) error
AddFlowBeginEventWithArgs is the same as AddFlowBeginEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddFlowEndEvent ¶ added in v0.2.0
func (w *Writer) AddFlowEndEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, flowCorrelationId uint64) error
AddFlowEndEvent adds an flow end event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddFlowEndEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddFlowEndEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, flowCorrelationId uint64, arguments map[string]interface{}) error
AddFlowEndEventWithArgs is the same as AddFlowEndEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddFlowStepEvent ¶ added in v0.2.0
func (w *Writer) AddFlowStepEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, flowCorrelationId uint64) error
AddFlowStepEvent adds an flow step event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddFlowStepEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddFlowStepEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, flowCorrelationId uint64, arguments map[string]interface{}) error
AddFlowStepEventWithArgs is the same as AddFlowStepEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddInitializationRecord ¶
AddInitializationRecord adds an initialization record to the file
This specifies the number of ticks per second for all event records after this
func (*Writer) AddInstantEvent ¶ added in v0.2.0
func (w *Writer) AddInstantEvent(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64) error
AddInstantEvent adds an instant event record to the file
If strings and/or process/thread IDs aren't already in the string / thread tables respectively, string and thread records will be automatically created. Any future events will use the table references.
https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#string-record https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/docs/reference/tracing/trace-format.md#thread-record
func (*Writer) AddInstantEventWithArgs ¶ added in v0.3.0
func (w *Writer) AddInstantEventWithArgs(category string, name string, processId KernelObjectID, threadId KernelObjectID, timestamp uint64, arguments map[string]interface{}) error
AddInstantEventWithArgs is the same as AddInstantEvent, but it allows you to additionally include arguments within the event record
func (*Writer) AddProviderEventRecord ¶
func (w *Writer) AddProviderEventRecord(providerId uint32, eventType ProviderEventType) error
AddProviderEventRecord adds a provider event metadata record to the file
func (*Writer) AddProviderInfoRecord ¶
AddProviderInfoRecord adds a provider info metadata record to the file
func (*Writer) AddProviderSectionRecord ¶
AddProviderSectionRecord adds a provider section metadata record to the file
func (*Writer) AddThreadWakeupRecord ¶ added in v0.3.0
func (w *Writer) AddThreadWakeupRecord(cpuNumber uint16, wakingThreadId KernelObjectID, timestamp uint64) error
AddContextSwitchRecord adds a thread wakeup scheduling record to the file
func (*Writer) AddThreadWakeupRecordWithArgs ¶ added in v0.3.0
func (w *Writer) AddThreadWakeupRecordWithArgs(cpuNumber uint16, wakingThreadId KernelObjectID, timestamp uint64, arguments map[string]interface{}) error
AddThreadWakeupRecordWithArgs is the same as AddThreadWakeupRecord, but it allows you to additionally include arguments within the scheduling record
func (*Writer) AddUserspaceObjectRecord ¶ added in v0.3.0
func (w *Writer) AddUserspaceObjectRecord(name string, processId KernelObjectID, threadId KernelObjectID, pointerValue uintptr, arguments map[string]interface{}) error
AddUserspaceObjectRecord adds a userspace object record to the file
func (*Writer) SetProcessName ¶ added in v0.2.0
func (w *Writer) SetProcessName(processId KernelObjectID, name string) error
SetProcessName adds a kernel object record to give a human-readable name to a process ID
func (*Writer) SetThreadName ¶ added in v0.2.0
func (w *Writer) SetThreadName(processId KernelObjectID, threadId KernelObjectID, name string) error
SetThreadName adds a kernel object record