go-perf: github.com/aclements/go-perf/perffile Index | Examples | Files

package perffile

import "github.com/aclements/go-perf/perffile"

Package perffile is a parser for Linux perf.data profiles.

Parsing a perf.data profile starts with a call to New or Open to open a perf.data file. A perf.data file consists of a sequence of records, which can be retrieved with File.Records, as well as several metadata fields, which can be retrieved with other methods of File.

Code:

f, err := Open("perf.data")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

rs := f.Records(RecordsTimeOrder)
for rs.Next() {
    switch r := rs.Record.(type) {
    case *RecordSample:
        fmt.Printf("sample: %+v\n", r)
    }
}
if err := rs.Err(); err != nil {
    log.Fatal(err)
}

Index

Examples

Package Files

auxflags_string.go branchflags_string.go branchsampletype_string.go breakpointop_string.go buf.go bufdecoder.go cpumode_string.go cpuset.go datasrclevel_string.go datasrclevelnum_string.go datasrclock_string.go datasrcop_string.go datasrcsnoop_string.go datasrctlb_string.go eventflags_string.go eventhardware_string.go eventprecision_string.go events.go eventtype_string.go format.go meta.go package.go reader.go readformat_string.go records.go recordsorder_string.go recordtype_string.go sampleformat_string.go sampleregsabi_string.go transaction_string.go

Constants

const (
    BreakpointOpR  BreakpointOp = 1
    BreakpointOpW               = 2
    BreakpointOpRW              = BreakpointOpR | BreakpointOpW
    BreakpointOpX               = 4
)
const (
    CallchainHV          uint64 = 0xffffffffffffffe0 // -32
    CallchainKernel             = 0xffffffffffffff80 // -128
    CallchainUser               = 0xfffffffffffffe00 // -512
    CallchainGuest              = 0xfffffffffffff800 // -2048
    CallchainGuestKernel        = 0xfffffffffffff780 // -2176
    CallchainGuestUser          = 0xfffffffffffff600 // -2560
)

Special markers used in RecordSample.Callchain to mark boundaries between types of stacks.

These correspond to PERF_CONTEXT_* from include/uapi/linux/perf_event.h

const (
    DataSrcLevelNumL1       DataSrcLevelNum = 0x01 // L1
    DataSrcLevelNumL2                       = 0x02 // L2
    DataSrcLevelNumL3                       = 0x03 // L3
    DataSrcLevelNumL4                       = 0x04 // L4
    DataSrcLevelNumAnyCache                 = 0x0b // Any cache
    DataSrcLevelNumLFB                      = 0x0c // LFB
    DataSrcLevelNumRAM                      = 0x0d // RAM
    DataSrcLevelNumPMEM                     = 0x0e // PMEM
    DataSrcLevelNumNA                       = 0x0f // N/A
)

type AuxFlags Uses

type AuxFlags uint64

AuxFlags gives flags for an RecordAux event.

const (
    // Record was truncated to fit in the ring buffer.
    AuxFlagTruncated AuxFlags = 1 << iota

    // AUX data was collected in overwrite mode, so the AUX buffer
    // was treated as a circular ring buffer.
    AuxFlagOverwrite

    // Record contains gaps.
    AuxFlagPartial

    // Sample collided with another.
    AuxFlagCollision
)

func (AuxFlags) String Uses

func (i AuxFlags) String() string

type BranchFlags Uses

type BranchFlags uint64
const (
    // BranchFlagMispredicted indicates branch target was mispredicted.
    BranchFlagMispredicted BranchFlags = 1 << iota

    // BranchFlagPredicted indicates branch target was predicted.
    // In case predicted/mispredicted information is unavailable,
    // both flags will be unset.
    BranchFlagPredicted

    // BranchFlagInTransaction indicates the branch occurred in a
    // transaction.
    BranchFlagInTransaction

    // BranchFlagAbort indicates the branch is a transaction abort.
    BranchFlagAbort
)

func (BranchFlags) String Uses

func (i BranchFlags) String() string

type BranchRecord Uses

type BranchRecord struct {
    From, To uint64
    Flags    BranchFlags

    Cycles uint16 // Cycle count to last branch (or 0)

    // Type is the type of branch instruction that caused this
    // branch. If supported, this is set by the kernel by
    // disassembling the branch instruction, since the binary
    // itself may not be available at decoding time. This is only
    // set if EventAttr.BranchSampleType&BranchSampleTypeSave is
    // set in the event.
    Type BranchType
}

A BranchRecord records a single branching event in a sample.

type BranchSampleType Uses

type BranchSampleType uint64

BranchSampleType is a bit-field of the types of branches to record in the branch stack.

This can include privilege levels to record, which can be different from the privilege levels of the event being sampled. If none of the privilege level bits are set, it defaults to the privilege levels of the event.

This corresponds to the perf_branch_sample_type enum from include/uapi/linux/perf_event.h

const (
    BranchSampleUser   BranchSampleType = 1 << iota // User branches
    BranchSampleKernel                              // Kernel branches
    BranchSampleHV                                  // Hypervisor branches

    BranchSampleAny       // Any branch types
    BranchSampleAnyCall   // Any call branch
    BranchSampleAnyReturn // Any return branch
    BranchSampleIndCall   // Indirect calls
    BranchSampleAbortTX   // Transaction aborts
    BranchSampleInTX      // In transaction
    BranchSampleNoTX      // Not in transaction
    BranchSampleCond      // Conditional branches

    BranchSampleCallStack // Call/ret stack
    BranchSampleIndJump   // Indirect jumps
    BranchSampleCall      // Direct call

    BranchSampleNoFlags  // Don't set BranchRecord.Flags
    BranchSampleNoCycles // Don't set BranchRecord.Cycles
    BranchSampleTypeSave // Do set BranchRecord.Type
)

func (BranchSampleType) String Uses

func (i BranchSampleType) String() string

type BranchType Uses

type BranchType uint8
const (
    BranchTypeUnknown  BranchType = iota // unknown
    BranchTypeCond                       // conditional
    BranchTypeUncond                     // unconditional
    BranchTypeInd                        // indirect
    BranchTypeCall                       // function call
    BranchTypeIndCall                    // indirect function call
    BranchTypeRet                        // function return
    BranchTypeSyscall                    // syscall
    BranchTypeSysret                     // syscall return
    BranchTypeCondCall                   // conditional function call
    BranchTypeCondRet                    // conditional function return
)

type BreakpointOp Uses

type BreakpointOp uint32

BreakpointOp is a type of memory access that can trigger a breakpoint event.

This corresponds to the HW_BREAKPOINT_* constants from include/uapi/linux/hw_breakpoint.h

func (BreakpointOp) String Uses

func (i BreakpointOp) String() string

type BuildID Uses

type BuildID []byte

func (BuildID) String Uses

func (b BuildID) String() string

type BuildIDInfo Uses

type BuildIDInfo struct {
    CPUMode  CPUMode
    PID      int // Usually -1; for VM kernels
    BuildID  BuildID
    Filename string
}

A BuildIDInfo records the mapping between a single build ID and the path of an executable with that build ID.

type CPUMode Uses

type CPUMode uint16

A CPUMode indicates the privilege level of a sample or event.

This corresponds to PERF_RECORD_MISC_CPUMODE from include/uapi/linux/perf_event.h

const (
    CPUModeUnknown CPUMode = iota
    CPUModeKernel
    CPUModeUser
    CPUModeHypervisor
    CPUModeGuestKernel
    CPUModeGuestUser
)

func (CPUMode) String Uses

func (i CPUMode) String() string

type CPUSet Uses

type CPUSet []int

A CPUSet represents a set of CPUs by CPU index.

func (CPUSet) String Uses

func (c CPUSet) String() string

type Count Uses

type Count struct {
    Value       uint64     // Event counter value
    TimeEnabled uint64     // if ReadFormatTotalTimeEnabled
    TimeRunning uint64     // if ReadFormatTotalTimeRunning
    EventAttr   *EventAttr // if ReadFormatID
}

A Count records the raw value of an event counter.

Typically only a subset of the fields are used. Which fields are set can be determined from the bitmask in the sample's EventAttr.ReadFormat.

This corresponds to perf_event_read_format from include/uapi/linux/perf_event.h

type DataSrc Uses

type DataSrc struct {
    Op       DataSrcOp
    Miss     bool // if true, Level specifies miss, rather than hit
    Level    DataSrcLevel
    Snoop    DataSrcSnoop
    Locked   DataSrcLock
    TLB      DataSrcTLB
    LevelNum DataSrcLevelNum
    Remote   bool
}

type DataSrcLevel Uses

type DataSrcLevel int
const (
    DataSrcLevelL1  DataSrcLevel = 1 << iota
    DataSrcLevelLFB              // Line fill buffer
    DataSrcLevelL2
    DataSrcLevelL3
    DataSrcLevelLocalRAM     // Local DRAM
    DataSrcLevelRemoteRAM1   // Remote DRAM (1 hop)
    DataSrcLevelRemoteRAM2   // Remote DRAM (2 hops)
    DataSrcLevelRemoteCache1 // Remote cache (1 hop)
    DataSrcLevelRemoteCache2 // Remote cache (2 hops)
    DataSrcLevelIO           // I/O memory
    DataSrcLevelUncached

    DataSrcLevelNA DataSrcLevel = 0
)

func (DataSrcLevel) String Uses

func (i DataSrcLevel) String() string

type DataSrcLevelNum Uses

type DataSrcLevelNum int

func (DataSrcLevelNum) String Uses

func (i DataSrcLevelNum) String() string

type DataSrcLock Uses

type DataSrcLock int
const (
    DataSrcLockNA DataSrcLock = iota
    DataSrcLockUnlocked
    DataSrcLockLocked
)

func (DataSrcLock) String Uses

func (i DataSrcLock) String() string

type DataSrcOp Uses

type DataSrcOp int
const (
    DataSrcOpLoad DataSrcOp = 1 << iota
    DataSrcOpStore
    DataSrcOpPrefetch
    DataSrcOpExec

    DataSrcOpNA DataSrcOp = 0
)

func (DataSrcOp) String Uses

func (i DataSrcOp) String() string

type DataSrcSnoop Uses

type DataSrcSnoop int
const (
    DataSrcSnoopNone DataSrcSnoop = 1 << iota
    DataSrcSnoopHit
    DataSrcSnoopMiss
    DataSrcSnoopHitM // Snoop hit modified
    DataSrcSnoopFwd

    DataSrcSnoopNA DataSrcSnoop = 0
)

func (DataSrcSnoop) String Uses

func (i DataSrcSnoop) String() string

type DataSrcTLB Uses

type DataSrcTLB int
const (
    DataSrcTLBHit DataSrcTLB = 1 << iota
    DataSrcTLBMiss
    DataSrcTLBL1
    DataSrcTLBL2
    DataSrcTLBHardwareWalker
    DataSrcTLBOSFaultHandler

    DataSrcTLBNA DataSrcTLB = 0
)

func (DataSrcTLB) String Uses

func (i DataSrcTLB) String() string

type Event Uses

type Event interface {
    // Generic returns the generic representation of this Event.
    Generic() EventGeneric
}

Event describes a specific performance monitoring event.

Events are quite general. They can be hardware events such as cycles or cache misses. They can be kernel software events such as page faults. They can be user or kernel trace-points, or many other things. All events happen at some instant and can be counted.

type EventAttr Uses

type EventAttr struct {
    // Event describes the event that will be (or was) counted or
    // sampled.
    Event Event

    // SamplePeriod, if non-zero, is the approximate number of
    // events between each sample.
    //
    // For a sampled event, SamplePeriod will be set if
    // Flags&EventFlagsFreq == 0. See also SampleFreq.
    SamplePeriod uint64

    // SampleFreq, if non-zero, is the approximate number of
    // samples to record per second per core. This is approximated
    // by dynamically adjusting the event sampling period (see
    // perf_calculate_period) and thus is not particularly
    // accurate (and even less accurate for events that don't
    // happen at a regular rate). If SampleFormat includes
    // SampleFormatPeriod, each sample includes the number of
    // events until the next sample on the same CPU.
    //
    // For a sampled event, SampleFreq will be set if
    // Flags&EventFlagsFreq != 0. See also SamplePeriod.
    SampleFreq uint64

    // The format of RecordSamples
    SampleFormat SampleFormat

    // The format of SampleRead
    ReadFormat ReadFormat

    Flags EventFlags

    // Precise indicates the precision of instruction pointers
    // recorded by this event.
    Precise EventPrecision

    // WakeupEvents specifies to wake up every WakeupEvents
    // events. Either this or WakeupWatermark will be non-zero,
    // depending on Flags&EventFlagWakeupWatermark.
    WakeupEvents uint32
    // WakeupWatermark specifies to wake up every WakeupWatermark
    // bytes.
    WakeupWatermark uint32

    // BranchSampleType specifies the types of branches to record
    // in the branch stack if SampleFormat&SampleFormatBranchStack
    // is set, as well as what information to record about each
    // branch.
    BranchSampleType BranchSampleType

    // SampleRegsUser is a bitmask of user-space registers
    // captured at each sample in RecordSample.RegsUser. The
    // hardware register corresponding to each bit depends on the
    // register ABI.
    SampleRegsUser uint64

    // Size of user stack to dump on samples
    SampleStackUser uint32

    // SampleRegsIntr is a bitmask of registers captured at each
    // sample in RecordSample.RegsIntr. If Precise ==
    // EventPrecisionArbitrarySkid, these registers are captured
    // at the PMU interrupt. Otherwise, these registers are
    // captured by the hardware when it samples an instruction.
    SampleRegsIntr uint64

    // AuxWatermark is the watermark for the AUX area in bytes at
    // which user space is woken up to collect the AUX area.
    AuxWatermark uint32

    // SampleMaxStack is the maximum number of frame pointers in a
    // callchain. Should be < /proc/sys/kernel/perf_event_max_stack.
    SampleMaxStack uint16
}

EventAttr describes an event and how that event should be recorded.

This corresponds to the perf_event_attr struct from include/uapi/linux/perf_event.h

type EventBreakpoint Uses

type EventBreakpoint struct {
    // Op specifies what type of access to Addr should trigger
    // this event.
    Op  BreakpointOp
    // Addr is the address to watch for operation Op.
    Addr uint64
    // Len is the number of bytes to watch at Addr. What sizes are
    // supported depends on the hardware, but it generally must be
    // a small power of 2.
    Len uint64
}

EventBreakpoint represents a breakpoint event.

Breakpoint events are triggered by a specific type of access to an address in memory.

func (EventBreakpoint) Generic Uses

func (e EventBreakpoint) Generic() EventGeneric

type EventFlags Uses

type EventFlags uint64

EventFlags is a bitmask of boolean properties of an event.

This corresponds to the perf_event_attr enum from include/uapi/linux/perf_event.h

const (
    // Event is disabled by default
    EventFlagDisabled EventFlags = 1 << iota
    // Children inherit this event
    EventFlagInherit
    // Event must always be on the PMU
    EventFlagPinned
    // Event is only group on PMU
    EventFlagExclusive
    // Don't count events in user/kernel/hypervisor/when idle
    EventFlagExcludeUser
    EventFlagExcludeKernel
    EventFlagExcludeHypervisor
    EventFlagExcludeIdle
    // Include mmap data
    EventFlagMmap
    // Include comm data
    EventFlagComm
    // Use frequency, not period
    EventFlagFreq
    // Per task counts
    EventFlagInheritStat
    // Next exec enables this event
    EventFlagEnableOnExec
    // Trace fork/exit
    EventFlagTask
    // WakeupWatermark is set rather than WakeupEvents.
    EventFlagWakeupWatermark

    // Non-exec mmap data
    EventFlagMmapData EventFlags = 1 << (2 + iota)
    // All events have SampleField fields
    EventFlagSampleIDAll
    // Don't count events in host/guest
    EventFlagExcludeHost
    EventFlagExcludeGuest
    // Don't include kernel/user callchains
    EventFlagExcludeCallchainKernel
    EventFlagExcludeCallchainUser
    // Include inode data in mmap events
    EventFlagMmapInodeData
    // Flag comm events that are due to an exec
    EventFlagCommExec
    // Use clock specified by clockid for time fields
    EventFlagClockID
    // Record context switch data. Enables RecordTypeSwitch and
    // RecordTypeSwitchCPUWide events.
    EventFlagContextSwitch
    // Write ring buffer from end to beginning.
    EventFlagWriteBackward
    // Include namespaces data.
    EventFlagNamespaces
)

func (EventFlags) String Uses

func (i EventFlags) String() string

type EventGeneric Uses

type EventGeneric struct {
    // Type specifies the major type of this event, such as
    // hardware event, software event, or tracepoint.
    Type EventType

    // ID is the specific event within the class described by
    // Type.
    //
    // In perf_event_attr, this corresponds to either
    // perf_event_attr.config or, if Type == EventTypeBreakpoint,
    // perf_event_attr.bp_type.
    ID  uint64

    // Config gives additional configuration specific to the event
    // described by Type and ID.
    //
    // In perf_event_attr, this corresponds to
    // perf_event_attr.config1 and config2.
    Config []uint64
}

EventGeneric is a generic representation of a performance event.

Any perf event can be represented by EventGeneric, but some encoding is generally necessary. Hence, EventGeneric can be translated back and forth between specific Event* types.

func (*EventGeneric) Decode Uses

func (g *EventGeneric) Decode() Event

Decode decodes a generic event g into a specific event type.

type EventHWCache Uses

type EventHWCache struct {
    Level  HWCache
    Op     HWCacheOp
    Result HWCacheResult
}

EventHWCache represents a hardware cache event.

func (EventHWCache) Generic Uses

func (e EventHWCache) Generic() EventGeneric

type EventHardware Uses

type EventHardware uint64

EventHardware represents a hardware event.

This corresponds to the perf_hw_id enum from include/uapi/linux/perf_event.h

const (
    EventHardwareCPUCycles EventHardware = iota
    EventHardwareInstructions
    EventHardwareCacheReferences
    EventHardwareCacheMisses
    EventHardwareBranchInstructions
    EventHardwareBranchMisses
    EventHardwareBusCycles
    EventHardwareStalledCyclesFrontend
    EventHardwareStalledCyclesBackend
    EventHardwareRefCPUCycles
)

func (EventHardware) Generic Uses

func (e EventHardware) Generic() EventGeneric

func (EventHardware) String Uses

func (i EventHardware) String() string

type EventID Uses

type EventID uint64

An EventID combined with an EventType describes a specific event.

type EventPrecision Uses

type EventPrecision int

An EventPrecision indicates the precision of instruction pointers recorded by an event. This can vary depending on the exact method used to capture IPs.

const (
    EventPrecisionArbitrarySkid EventPrecision = iota
    EventPrecisionConstantSkid
    EventPrecisionTryZeroSkid
    EventPrecisionZeroSkip
)

func (EventPrecision) String Uses

func (i EventPrecision) String() string

type EventRaw Uses

type EventRaw uint64

EventRaw represents a "raw" hardware PMU event in a CPU-specific format.

func (EventRaw) Generic Uses

func (e EventRaw) Generic() EventGeneric

type EventSoftware Uses

type EventSoftware uint64

EventSoftware represents a software event.

This corresponds to the perf_sw_ids enum from include/uapi/linux/perf_event.h

const (
    EventSoftwareCPUClock EventSoftware = iota
    EventSoftwareTaskClock
    EventSoftwarePageFaults
    EventSoftwareContextSwitches
    EventSoftwareCPUMigrations
    EventSoftwarePageFaultsMin
    EventSoftwarePageFaultsMaj
    EventSoftwareAlignmentFaults
    EventSoftwareEmulationFaults
    EventSoftwareDummy
    EventSoftwareBpfOutput
)

func (EventSoftware) Generic Uses

func (e EventSoftware) Generic() EventGeneric

func (EventSoftware) String Uses

func (i EventSoftware) String() string

type EventTracepoint Uses

type EventTracepoint uint64

EventTracepoint represents a kernel tracepoint event.

The IDs of the tracepoint events are given by the tracing/events/*/*/id files under debugfs.

func (EventTracepoint) Generic Uses

func (e EventTracepoint) Generic() EventGeneric

type EventType Uses

type EventType uint32

An EventType is a general class of performance event.

This corresponds to the perf_type_id enum from include/uapi/linux/perf_event.h

const (
    EventTypeHardware EventType = iota
    EventTypeSoftware
    EventTypeTracepoint
    EventTypeHWCache
    EventTypeRaw
    EventTypeBreakpoint
)

func (EventType) String Uses

func (i EventType) String() string

type File Uses

type File struct {
    // Meta contains the metadata for this profile, such as
    // information about the hardware.
    Meta FileMeta

    // Events lists all events that may appear in this profile.
    Events []*EventAttr
    // contains filtered or unexported fields
}

A File is a perf.data file. It consists of a sequence of records, which can be retrieved with the Records method, as well as several optional metadata fields.

func New Uses

func New(r io.ReaderAt) (*File, error)

New reads a "perf.data" file from r.

The caller must keep r open as long as it is using the returned *File.

func Open Uses

func Open(name string) (*File, error)

Open opens the named "perf.data" file using os.Open.

The caller must call f.Close() on the returned file when it is done.

func (*File) Close Uses

func (f *File) Close() error

Close closes the File.

If the File was created using New directly instead of Open, Close has no effect.

func (*File) Records Uses

func (f *File) Records(order RecordsOrder) *Records

Records returns an iterator over the records in the profile. The order argument specifies the order for iterating through the records in this File. Callers should choose the least resource-intensive iteration order that satisfies their needs.

type FileMeta Uses

type FileMeta struct {
    // BuildIDs is the list of build IDs for processes and
    // libraries in this profile, or nil if unknown. Note that in
    // "live mode" (e.g., a file written by perf inject), it's
    // possible for build IDs to be introduced in the sample
    // stream itself.
    BuildIDs []BuildIDInfo

    // Hostname is the hostname of the machine that recorded this
    // profile, or "" if unknown.
    Hostname string

    // OSRelease is the OS release of the machine that recorded
    // this profile such as "3.13.0-62", or "" if unknown.
    OSRelease string

    // Version is the perf version that recorded this profile such
    // as "3.13.11", or "" if unknown.
    Version string

    // Arch is the host architecture of the machine that recorded
    // this profile such as "x86_64", or "" if unknown.
    Arch string

    // CPUsOnline and CPUsAvail are the number of online and
    // available CPUs of the machine that recorded this profile,
    // or 0, 0 if unknown.
    CPUsOnline, CPUsAvail int

    // CPUDesc describes the CPU of the machine that recorded this
    // profile such as "Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz",
    // or "" if unknown.
    CPUDesc string

    // CPUID describes the CPU type of the machine that recorded
    // this profile, or "" if unknown. The exact format of this
    // varies between architectures. On x86 architectures, it is a
    // comma-separated list of vendor, family, model, and
    // stepping, such as "GenuineIntel,6,69,1".
    CPUID string

    // TotalMem is the total memory in bytes of the machine that
    // recorded this profile, or 0 if unknown.
    TotalMem int64

    // CmdLine is the list of command line arguments perf was
    // invoked with, or nil if unknown.
    CmdLine []string

    // CoreGroups and ThreadGroups describe the CPU topology of
    // the machine that recorded this profile. Each CPUSet in
    // CoreGroups is a set of CPUs in the same package, and each
    // CPUSet in ThreadGroups is a set of hardware threads in the
    // same core. These will be nil if unkneon.
    CoreGroups, ThreadGroups []CPUSet

    // NUMANodes is the set of NUMA nodes in the NUMA topology of
    // the machine that recorded this profile, or nil if unknown.
    NUMANodes []NUMANode

    // PMUMappings is a map from numerical EventType to name for
    // event classes supported by the machine that recorded this
    // profile, or nil if unknown.
    PMUMappings map[EventType]string

    // Groups is the descriptions of each perf event group in this
    // profile, or nil if unknown.
    Groups []GroupDesc
}

type GroupDesc Uses

type GroupDesc struct {
    Name       string
    Leader     int
    NumMembers int
}

A GroupDesc describes a group of PMU events that are scheduled together.

TODO: Are Leader and NumMembers attribute IDs? If so, we should probably map them to *EventAttrs to make this useful.

type HWCache Uses

type HWCache uint8

HWCache represents a level in the hardware cache.

This corresponds to the perf_hw_cache_id enum from include/uapi/linux/perf_event.h

const (
    HWCacheL1D HWCache = iota
    HWCacheL1I
    HWCacheLL
    HWCacheDTLB
    HWCacheITLB
    HWCacheBPU
    HWCacheNode
)

func (HWCache) String Uses

func (i HWCache) String() string

type HWCacheOp Uses

type HWCacheOp uint8

HWCacheOp represents a type of access to a hardware cache.

This corresponds to the perf_hw_cache_op_id enum from include/uapi/linux/perf_event.h

const (
    HWCacheOpRead HWCacheOp = iota
    HWCacheOpWrite
    HWCacheOpPrefetch
)

func (HWCacheOp) String Uses

func (i HWCacheOp) String() string

type HWCacheResult Uses

type HWCacheResult uint8

HWCacheResult represents the result of a accessing a hardware cache.

This corresponds to the perf_hw_cache_op_result_id enum from include/uapi/linux/perf_event.h

const (
    HWCacheResultAccess HWCacheResult = iota
    HWCacheResultMiss
)

func (HWCacheResult) String Uses

func (i HWCacheResult) String() string

type NUMANode Uses

type NUMANode struct {
    // Node is the system identifier of this NUMA node.
    Node int

    // MemTotal and MemFree are the total and free number of bytes
    // of memory in this NUMA node.
    MemTotal, MemFree int64

    // CPUs is the set of CPUs in this NUMA node.
    CPUs CPUSet
}

A NUMANode represents a single hardware NUMA node.

type Namespace Uses

type Namespace struct {
    Dev, Inode uint64
}

type ReadFormat Uses

type ReadFormat uint64

ReadFormat is a bitmask of the fields recorded in the SampleRead field(s) of a sample.

This corresponds to the perf_event_read_format enum from include/uapi/linux/perf_event.h

const (
    ReadFormatTotalTimeEnabled ReadFormat = 1 << iota
    ReadFormatTotalTimeRunning
    ReadFormatID
    ReadFormatGroup
)

func (ReadFormat) String Uses

func (i ReadFormat) String() string

type Record Uses

type Record interface {
    Type() RecordType
    Common() *RecordCommon
}

Record is the common interface implemented by all profile record types.

type RecordAux Uses

type RecordAux struct {
    RecordCommon

    Offset, Size uint64
    Flags        AuxFlags
}

A RecordAux records the data was added to the AUX buffer.

func (*RecordAux) Type Uses

func (r *RecordAux) Type() RecordType

type RecordAuxtrace Uses

type RecordAuxtrace struct {
    // TID and CPU are always filled in.
    RecordCommon

    // Offset is the byte offset of the aux data in the aux mmap.
    // Not meaningful in perf data files.
    Offset uint64

    // Ref is a unique identifier for this auxtrace block.
    //
    // TODO: What's the point of this? Is it cross-referenced
    // against something?
    Ref uint64

    // Idx is the index of the aux mmap region of this data.
    // Not meaningful in perf data files.
    Idx uint32

    // Data is the raw auxiliary data. The encoding of this
    // depends on the latest RecordAuxtraceInfo.
    Data []byte
}

func (*RecordAuxtrace) Type Uses

func (r *RecordAuxtrace) Type() RecordType

type RecordAuxtraceInfo Uses

type RecordAuxtraceInfo struct {
    RecordCommon

    Kind uint32

    Priv []uint64
}

func (*RecordAuxtraceInfo) Type Uses

func (r *RecordAuxtraceInfo) Type() RecordType

type RecordComm Uses

type RecordComm struct {
    // RecordCommon.PID and .TID will always be filled
    RecordCommon

    Exec bool // from header.misc

    Comm string
}

A RecordComm records that a process being profiled called exec. RecordComms can also occur at the beginning of a profile to describe the existing set of processes.

func (*RecordComm) Type Uses

func (r *RecordComm) Type() RecordType

type RecordCommon Uses

type RecordCommon struct {
    // Offset is the byte offset of this event in the perf.data
    // file.
    Offset int64

    // Format is a bit mask of SampleFormat* values that indicate
    // which optional fields of this record are valid.
    Format SampleFormat

    // EventAttr is the event, if any, associated with this record.
    EventAttr *EventAttr

    PID, TID int    // if SampleFormatTID
    Time     uint64 // if SampleFormatTime
    ID       attrID // if SampleFormatID or SampleFormatIdentifier
    StreamID uint64 // if SampleFormatStreamID
    CPU, Res uint32 // if SampleFormatCPU
}

RecordCommon stores fields that are common to all record types, as well as additional metadata. It is not itself a Record.

Many fields are optional and their presence is determined by the bitmask EventAttr.SampleFormat. Some record types guarantee that some of these fields will be filled.

func (*RecordCommon) Common Uses

func (r *RecordCommon) Common() *RecordCommon

type RecordExit Uses

type RecordExit struct {
    // RecordCommon.PID, .TID, and .Time will always be filled
    RecordCommon

    PPID, PTID int
}

A RecordExit records that a process or thread exited.

func (*RecordExit) Type Uses

func (r *RecordExit) Type() RecordType

type RecordFork Uses

type RecordFork struct {
    // RecordCommon.PID, .TID, and .Time will always be filled
    RecordCommon

    PPID, PTID int
}

A RecordFork records that a process called clone to either fork the process or create a new thread.

func (*RecordFork) Type Uses

func (r *RecordFork) Type() RecordType

type RecordItraceStart Uses

type RecordItraceStart struct {
    // PID and TID will always be filled in.
    RecordCommon
}

A RecordItraceStart indicates that an instruction trace started.

func (*RecordItraceStart) Type Uses

func (r *RecordItraceStart) Type() RecordType

type RecordLost Uses

type RecordLost struct {
    // RecordCommon.ID and .EventAttr will always be filled
    RecordCommon

    NumLost uint64
}

A RecordLost records that profiling events were lost because of a buffer overflow.

func (*RecordLost) Type Uses

func (r *RecordLost) Type() RecordType

type RecordLostSamples Uses

type RecordLostSamples struct {
    RecordCommon

    Lost uint64
}

A RecordLostSamples records the number of dropped or lost samples.

func (*RecordLostSamples) Type Uses

func (r *RecordLostSamples) Type() RecordType

type RecordMmap Uses

type RecordMmap struct {
    // RecordCommon.PID and .TID will always be filled
    RecordCommon

    Data bool // from header.misc

    // Addr and Len are the virtual address of the start of this
    // mapping and its length in bytes.
    Addr, Len uint64
    // FileOffset is the byte offset in the mapped file of the
    // beginning of this mapping.
    FileOffset         uint64
    Major, Minor       uint32
    Ino, InoGeneration uint64
    Prot, Flags        uint32
    Filename           string
}

A RecordMmap records when a process being profiled called mmap. RecordMmaps can also occur at the beginning of a profile to describe the existing memory layout.

func (*RecordMmap) Type Uses

func (r *RecordMmap) Type() RecordType

type RecordNamespaces Uses

type RecordNamespaces struct {
    // PID and TID are always filled in.
    RecordCommon

    Namespaces []Namespace
}

func (*RecordNamespaces) Type Uses

func (r *RecordNamespaces) Type() RecordType

type RecordSample Uses

type RecordSample struct {
    // RecordCommon.EventAttr will always be filled.
    // RecordCommon.Format descibes the optional fields in this
    // structure, as well as the optional common fields.
    RecordCommon

    CPUMode CPUMode // from header.misc
    ExactIP bool    // from header.misc

    IP   uint64 // if SampleFormatIP
    Addr uint64 // if SampleFormatAddr

    // Period is the number of events on this CPU until the next
    // sample. In frequency sampling mode, this is adjusted
    // dynamically based on the rate of recent events. In period
    // sampling mode, this is fixed.
    Period uint64 // if SampleFormatPeriod

    // SampleRead records raw event counter values. If this is an
    // event group, this slice will have more than one element;
    // otherwise, it will have one element.
    SampleRead []Count // if SampleFormatRead

    // Callchain gives the call stack of the sampled instruction,
    // starting from the sampled instruction itself. The call
    // chain may span several types of stacks (e.g., it may start
    // in a kernel stack, then transition to a user stack). Before
    // the first IP from each stack there will be a Callchain*
    // constant indicating the stack type for the following IPs.
    Callchain []uint64 // if SampleFormatCallchain

    BranchStack []BranchRecord // if SampleFormatBranchStack

    // RegsUserABI and RegsUser record the ABI and values of
    // user-space registers as of this sample. Note that these are
    // the current user-space registers even if this sample
    // occurred at a kernel PC. RegsUser[i] records the value of
    // the register indicated by the i-th set bit of
    // EventAttr.SampleRegsUser.
    RegsUserABI SampleRegsABI // if SampleFormatRegsUser
    RegsUser    []uint64      // if SampleFormatRegsUser

    // RegsIntrABI And RegsIntr record the ABI and values of
    // registers as of this sample. Unlike RegsUser, these can be
    // kernel-space registers if this sample occurs in the kernel.
    // RegsIntr[i] records the value of the register indicated by
    // the i-th set bit of EventAttr.SampleRegsIntr.
    RegsIntrABI SampleRegsABI // if SampleFormatRegsIntr
    RegsIntr    []uint64      // if SampleFormatRegsIntr

    StackUser        []byte // if SampleFormatStackUser
    StackUserDynSize uint64 // if SampleFormatStackUser

    Weight  uint64  // if SampleFormatWeight
    DataSrc DataSrc // if SampleFormatDataSrc

    Transaction Transaction // if SampleFormatTransaction
    AbortCode   uint32      // if SampleFormatTransaction

    PhysAddr uint64 // if SampleFormatPhysAddr
}

A RecordSample records a profiling sample event.

Typically only a subset of the fields are used. Which fields are set can be determined from the bitmask RecordSample.EventAttr.SampleFormat.

func (*RecordSample) Fields Uses

func (r *RecordSample) Fields() []string

Fields returns the list of names of valid fields in r based on r.Format. This is useful for writing custom printing functions.

func (*RecordSample) String Uses

func (r *RecordSample) String() string

func (*RecordSample) Type Uses

func (r *RecordSample) Type() RecordType

type RecordSwitch Uses

type RecordSwitch struct {
    RecordCommon

    // Out indicates this is a switch out. Otherwise, this is a
    // switch in.
    Out bool
}

A RecordSwitch records a context switch in or out of the monitored process. See also RecordSwitchCPUWide.

func (*RecordSwitch) Type Uses

func (r *RecordSwitch) Type() RecordType

type RecordSwitchCPUWide Uses

type RecordSwitchCPUWide struct {
    RecordCommon

    // Out indicates this is a switch out. Otherwise, this is a
    // switch in.
    Out bool

    // Preempt indicates that the preempted thread was in
    // TASK_RUNNING state. That is, this was an involuntary
    // preemption.
    Preempt bool

    // SwitchPID and SwitchTID are the PID and TID of the process
    // being switched in or switched out.
    SwitchPID, SwitchTID int
}

RecordSwitchCPUWide is a CPU-wide version of RecordSwitch.

func (*RecordSwitchCPUWide) Type Uses

func (r *RecordSwitchCPUWide) Type() RecordType

type RecordThrottle Uses

type RecordThrottle struct {
    // RecordCommon.Time, .ID, and .StreamID, and .EventAttr will
    // always be filled
    RecordCommon

    Enable bool
}

A RecordThrottle records that interrupt throttling was enabled or disabled.

func (*RecordThrottle) Type Uses

func (r *RecordThrottle) Type() RecordType

type RecordType Uses

type RecordType uint32

A RecordType indicates the type of a record in a profile. A record can either be a profiling sample or give information about changes to system state, such as a process calling mmap.

const (
    RecordTypeMmap RecordType = 1 + iota
    RecordTypeLost
    RecordTypeComm
    RecordTypeExit
    RecordTypeThrottle
    RecordTypeUnthrottle
    RecordTypeFork
    RecordTypeRead
    RecordTypeSample

    RecordTypeAux
    RecordTypeItraceStart
    RecordTypeLostSamples // TODO: How does this differ from RecordTypeLost?
    RecordTypeSwitch
    RecordTypeSwitchCPUWide
    RecordTypeNamespaces
)
const (
    RecordTypeAuxtraceInfo RecordType // TODO
    RecordTypeAuxtrace
    RecordTypeAuxtraceError // TODO

)

perf_user_event_type in tools/perf/util/event.h

TODO: Figure out what to do with these. Some of these are only to direct parsing so they should never escape the API. Some of these are only for perf.data pipes.

func (RecordType) String Uses

func (i RecordType) String() string

type RecordUnknown Uses

type RecordUnknown struct {
    RecordCommon

    Data []byte
    // contains filtered or unexported fields
}

A RecordUnknown is a Record of unknown or unimplemented type.

func (*RecordUnknown) Type Uses

func (r *RecordUnknown) Type() RecordType

type Records Uses

type Records struct {
    // The current record. The concrete type of this will be one
    // of the Record* types. Determine which type of record this
    // is using a type switch.
    Record Record
    // contains filtered or unexported fields
}

A Records is an iterator over the records in a "perf.data" file. Each record will be one of the Record* types.

Typical usage is

rs := file.Records()
for rs.Next() {
  switch r := rs.Record.(type) {
  case *perffile.RecordSample:
    ...
  }
}
if rs.Err() { ... }

func (*Records) Err Uses

func (r *Records) Err() error

Err returns the first error encountered by Records.

func (*Records) Next Uses

func (r *Records) Next() bool

Next fetches the next record into r.Record. It returns true if successful, and false if it reaches the end of the record stream or encounters an error.

The record stored in r.Record may be reused by later invocations of Next, so if the caller may need the record after another call to Next, it must make its own copy.

type RecordsOrder Uses

type RecordsOrder int
const (
    // RecordsFileOrder requests records in file order. This is
    // efficient because it allows streaming the records directly
    // from the file, but the records may not be in time-stamp or
    // even causal order.
    RecordsFileOrder RecordsOrder = iota

    // RecordsCausalOrder requests records in causal order. This
    // is weakly time-ordered: any two records will be in
    // time-stamp order *unless* those records are both
    // RecordSamples. This is potentially more efficient than
    // RecordsTimeOrder, though currently the implementation does
    // not distinguish.
    RecordsCausalOrder

    // RecordsTimeOrder requests records in time-stamp order. This
    // is the most expensive iteration order because it requires
    // buffering and/or re-reading potentially large sections of
    // the input file in order to sort the records.
    RecordsTimeOrder
)

func (RecordsOrder) String Uses

func (i RecordsOrder) String() string

type SampleFormat Uses

type SampleFormat uint64

A SampleFormat is a bitmask of the fields recorded by a sample.

This corresponds to the perf_event_sample_format enum from include/uapi/linux/perf_event.h

const (
    SampleFormatIP SampleFormat = 1 << iota
    SampleFormatTID
    SampleFormatTime
    SampleFormatAddr
    SampleFormatRead
    SampleFormatCallchain
    SampleFormatID
    SampleFormatCPU
    SampleFormatPeriod
    SampleFormatStreamID
    SampleFormatRaw
    SampleFormatBranchStack
    SampleFormatRegsUser
    SampleFormatStackUser
    SampleFormatWeight
    SampleFormatDataSrc
    SampleFormatIdentifier
    SampleFormatTransaction
    SampleFormatRegsIntr
    SampleFormatPhysAddr
)

func (SampleFormat) String Uses

func (i SampleFormat) String() string

type SampleRegsABI Uses

type SampleRegsABI uint64

SampleRegsABI indicates the register ABI of a given sample for architectures that support multiple ABIs.

This corresponds to the perf_sample_regs_abi enum from include/uapi/linux/perf_event.h

const (
    SampleRegsABINone SampleRegsABI = iota
    SampleRegsABI32
    SampleRegsABI64
)

func (SampleRegsABI) String Uses

func (i SampleRegsABI) String() string

type Transaction Uses

type Transaction int
const (
    TransactionElision       Transaction = 1 << iota // From elision
    TransactionTransaction                           // From transaction
    TransactionSync                                  // Instruction is related
    TransactionAsync                                 // Instruction is not related
    TransactionRetry                                 // Retry possible
    TransactionConflict                              // Conflict abort
    TransactionCapacityWrite                         // Capactiy write abort
    TransactionCapacityRead                          // Capactiy read abort
)

func (Transaction) String Uses

func (i Transaction) String() string

Package perffile imports 9 packages (graph) and is imported by 8 packages. Updated 2019-03-23. Refresh now. Tools for package owners.