perf

package
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PERF_EVENT_IOC_ENABLE       uintptr = 0x2400 + 0
	PERF_EVENT_IOC_DISABLE              = 0x2400 + 1
	PERF_EVENT_IOC_REFRESH              = 0x2400 + 2
	PERF_EVENT_IOC_RESET                = 0x2400 + 3
	PERF_EVENT_IOC_PERIOD               = 0x40080000 | (0x2400 + 4)
	PERF_EVENT_IOC_SET_OUTPUT           = 0x2400 + 5
	PERF_EVENT_IOC_SET_FILTER           = 0x40080000 | (0x2400 + 6)
	PERF_EVENT_IOC_ID                   = 0x80080000 | (0x2400 + 7)
	PERF_EVENT_IOC_SET_BPF              = 0x40040000 | (0x2400 + 8)
	PERF_EVENT_IOC_PAUSE_OUTPUT         = 0x40040000 | (0x2400 + 9)
)
View Source
const (
	PERF_FLAG_FD_NO_GROUP uintptr = 1 << iota
	PERF_FLAG_FD_OUTPUT
	PERF_FLAG_PID_CGROUP
	PERF_FLAG_FD_CLOEXEC
)
View Source
const (
	PERF_FORMAT_TOTAL_TIME_ENABLED uint64 = 1 << iota
	PERF_FORMAT_TOTAL_TIME_RUNNING
	PERF_FORMAT_ID
	PERF_FORMAT_GROUP
)
View Source
const (
	PERF_TYPE_HARDWARE uint32 = iota
	PERF_TYPE_SOFTWARE
	PERF_TYPE_TRACEPOINT
	PERF_TYPE_HW_CACHE
	PERF_TYPE_RAW
	PERF_TYPE_BREAKPOINT
	PERF_TYPE_MAX
)
View Source
const (
	PERF_COUNT_HW_CPU_CYCLES uint64 = iota
	PERF_COUNT_HW_INSTRUCTIONS
	PERF_COUNT_HW_CACHE_REFERENCES
	PERF_COUNT_HW_CACHE_MISSES
	PERF_COUNT_HW_BRANCH_INSTRUCTIONS
	PERF_COUNT_HW_BRANCH_MISSES
	PERF_COUNT_HW_BUS_CYCLES
	PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
	PERF_COUNT_HW_STALLED_CYCLES_BACKEND
	PERF_COUNT_HW_REF_CPU_CYCLES
	PERF_COUNT_HW_MAX
)
View Source
const (
	PERF_COUNT_HW_CACHE_L1D uint64 = iota
	PERF_COUNT_HW_CACHE_L1I
	PERF_COUNT_HW_CACHE_LL
	PERF_COUNT_HW_CACHE_DTLB
	PERF_COUNT_HW_CACHE_ITLB
	PERF_COUNT_HW_CACHE_BPU
	PERF_COUNT_HW_CACHE_NODE
	PERF_COUNT_HW_CACHE_MAX
)
View Source
const (
	PERF_COUNT_HW_CACHE_OP_READ uint64 = iota
	PERF_COUNT_HW_CACHE_OP_WRITE
	PERF_COUNT_HW_CACHE_OP_PREFETCH
	PERF_COUNT_HW_CACHE_OP_MAX
)
View Source
const (
	PERF_COUNT_HW_CACHE_RESULT_ACCESS uint64 = iota
	PERF_COUNT_HW_CACHE_RESULT_MISS
	PERF_COUNT_HW_CACHE_RESULT_MAX
)
View Source
const (
	PERF_COUNT_SW_CPU_CLOCK uint64 = iota
	PERF_COUNT_SW_TASK_CLOCK
	PERF_COUNT_SW_PAGE_FAULTS
	PERF_COUNT_SW_CONTEXT_SWITCHES
	PERF_COUNT_SW_CPU_MIGRATIONS
	PERF_COUNT_SW_PAGE_FAULTS_MIN
	PERF_COUNT_SW_PAGE_FAULTS_MAJ
	PERF_COUNT_SW_ALIGNMENT_FAULTS
	PERF_COUNT_SW_EMULATION_FAULTS
	PERF_COUNT_SW_DUMMY
	PERF_COUNT_BPF_OUTPUT
	PERF_COUNT_SW_MAX
)
View Source
const (
	PERF_RECORD_INVALID uint32 = iota
	PERF_RECORD_MMAP
	PERF_RECORD_LOST
	PERF_RECORD_COMM
	PERF_RECORD_EXIT
	PERF_RECORD_THROTTLE
	PERF_RECORD_UNTHROTTLE
	PERF_RECORD_FORK
	PERF_RECORD_READ
	PERF_RECORD_SAMPLE
	PERF_RECORD_MMAP2
	PERF_RECORD_AUX
	PERF_RECORD_ITRACE_START
	PERF_RECORD_LOST_SAMPLES
	PERF_RECORD_SWITCH
	PERF_RECORD_SWITCH_CPU_WIDE
	PERF_RECORD_MAX
)
View Source
const (
	PERF_SAMPLE_IP uint64 = 1 << iota
	PERF_SAMPLE_TID
	PERF_SAMPLE_TIME
	PERF_SAMPLE_ADDR
	PERF_SAMPLE_READ
	PERF_SAMPLE_CALLCHAIN
	PERF_SAMPLE_ID
	PERF_SAMPLE_CPU
	PERF_SAMPLE_PERIOD
	PERF_SAMPLE_STREAM_ID
	PERF_SAMPLE_RAW
	PERF_SAMPLE_BRANCH_STACK
	PERF_SAMPLE_REGS_USER
	PERF_SAMPLE_STACK_USER
	PERF_SAMPLE_WEIGHT
	PERF_SAMPLE_DATA_SRC
	PERF_SAMPLE_IDENTIFIER
	PERF_SAMPLE_TRANSACTION
	PERF_SAMPLE_REGS_INTR
	PERF_SAMPLE_MAX
)
View Source
const (
	PERF_EVENT_IOC_FLAG_GROUP uintptr = 1 << iota
)
View Source
const (
	PERF_RECORD_MISC_COMM_EXEC uint16 = (1 << 13)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchEntry

type BranchEntry struct {
	From      uint64
	To        uint64
	Mispred   bool
	Predicted bool
	InTx      bool
	Abort     bool
	Cycles    uint16
}

BranchEntry is a translation of the Linux kernel's struct perf_branch_entry into Go. It may appear in SampleRecord if PERF_SAMPLE_BRANCH_STACK is set.

type CommRecord

type CommRecord struct {
	Pid  uint32
	Tid  uint32
	Comm []byte
}

CommRecord is a translation of the structure used by the Linux kernel for PERF_RECORD_COMM samples into Go.

type CounterGroup

type CounterGroup struct {
	TimeEnabled uint64
	TimeRunning uint64
	Values      []CounterValue
}

CounterGroup represents the read values of a group of counter events

type CounterValue

type CounterValue struct {
	// Globally unique identifier for this counter event. Only
	// present if PERF_FORMAT_ID was specified.
	ID uint64

	// The counter result
	Value uint64
}

CounterValue resepresents the read value of a counter event

type EventAttr

type EventAttr struct {
	Type                   uint32
	Size                   uint32
	Config                 uint64
	SamplePeriod           uint64
	SampleFreq             uint64
	SampleType             uint64
	ReadFormat             uint64
	Disabled               bool
	Inherit                bool
	Pinned                 bool
	Exclusive              bool
	ExclusiveUser          bool
	ExclusiveKernel        bool
	ExclusiveHV            bool
	ExclusiveIdle          bool
	Mmap                   bool
	Comm                   bool
	Freq                   bool
	InheritStat            bool
	EnableOnExec           bool
	Task                   bool
	Watermark              bool
	PreciseIP              uint8
	MmapData               bool
	SampleIDAll            bool
	ExcludeHost            bool
	ExcludeGuest           bool
	ExcludeCallchainKernel bool
	ExcludeCallchainUser   bool
	Mmap2                  bool
	CommExec               bool
	UseClockID             bool
	ContextSwitch          bool
	WakeupEvents           uint32
	WakeupWatermark        uint32
	BPType                 uint32
	BPAddr                 uint64
	Config1                uint64
	BPLen                  uint64
	Config2                uint64
	BranchSampleType       uint64
	SampleRegsUser         uint64
	SampleStackUser        uint32
	ClockID                int32
	SampleRegsIntr         uint64
	AuxWatermark           uint32
	SampleMaxStack         uint16
}

EventAttr is a translation of the Linux kernel's struct perf_event_attr into Go. It provides detailed configuration information for the event being created.

type EventMonitor

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

EventMonitor is a high-level interface to the Linux kernel's perf_event infrastructure.

func NewEventMonitor

func NewEventMonitor(options ...EventMonitorOption) (*EventMonitor, error)

NewEventMonitor creates a new EventMonitor instance in the stopped state. Once an EventMonitor instance is returned from this function, its Close method must be called to clean it up gracefully, even if no events are registered or it is never put into the running state.

func (*EventMonitor) Close

func (monitor *EventMonitor) Close(wait bool) error

Close gracefully cleans up an EventMonitor instance. If the EventMonitor is still running when Close is called, it will first be stopped. After Close completes, the EventMonitor instance cannot be reused.

func (*EventMonitor) Disable

func (monitor *EventMonitor) Disable(eventid uint64)

Disable is used to disable a registered event. The event to disable is specified by its event ID as returned when the event was initially registered with the EventMonitor.

func (*EventMonitor) DisableAll

func (monitor *EventMonitor) DisableAll()

DisableAll disables all events that are registered with the EventMonitor.

func (*EventMonitor) Enable

func (monitor *EventMonitor) Enable(eventid uint64)

Enable is used to enable a registered event. The event to enable is specified by its event ID as returned when the event was initially registered with the EventMonitor.

func (*EventMonitor) EnableAll

func (monitor *EventMonitor) EnableAll()

EnableAll enables all events that are registered with the EventMonitor.

func (*EventMonitor) RegisterKprobe

func (monitor *EventMonitor) RegisterKprobe(address string, onReturn bool, output string,
	fn TraceEventDecoderFn, options ...RegisterEventOption) (uint64, error)

RegisterKprobe is used to register a kprobe with an EventMonitor. The kprobe will first be registered with the kernel, and then registered with the EventMonitor. An event ID is returned that is unqiue to the EventMonitor and is to be used to unregister the event. The event ID will also be passed to the EventMonitor's dispatch function.

func (*EventMonitor) RegisterTracepoint

func (monitor *EventMonitor) RegisterTracepoint(name string,
	fn TraceEventDecoderFn, options ...RegisterEventOption) (uint64, error)

RegisterTracepoint is used to register a tracepoint with an EventMonitor. The tracepoint is selected by name and it must exist in the running Linux kernel. An event ID is returned that is unique to the EventMonitor and is to be used to unregister the event. The event ID will also be passed to the EventMonitor's dispatch function.

func (*EventMonitor) Run

func (monitor *EventMonitor) Run(fn SampleDispatchFn) error

Run puts an EventMonitor into the running state. While an EventMonitor is running, samples will be pulled from event sources, decoded, and dispatched to a function that is specified here.

func (*EventMonitor) SetFilter

func (monitor *EventMonitor) SetFilter(eventid uint64, filter string) error

SetFilter is used to set or remove a filter from a registered event.

func (*EventMonitor) Stop

func (monitor *EventMonitor) Stop(wait bool)

Stop stops a running EventMonitor. If the EventMonitor is not running, this function does nothing. Once an EventMonitor has been stopped, it may be restarted again. Whether Stop waits for the EventMonitor to fully stop is optional, but if the caller does not wait there is no other mechanism by which the caller may learn whether the EventMonitor is stopped.

func (*EventMonitor) UnregisterEvent

func (monitor *EventMonitor) UnregisterEvent(eventid uint64) error

UnregisterEvent is used to remove a previously registered event from an EventMonitor. The event can be of any type and is specified by the event ID that was returned when the event was initially registered with the EventMonitor.

type EventMonitorOption

type EventMonitorOption func(*eventMonitorOptions)

EventMonitorOption is used to implement optional arguments for NewEventMonitor. It must be exported, but it is not typically used directly.

func WithCgroup

func WithCgroup(cgroup string) EventMonitorOption

WithCgroup is used to add a cgroup to the set of sources to monitor.

func WithCgroups

func WithCgroups(cgroups []string) EventMonitorOption

WithCgroups is used to add a list of cgroups to the set of sources to monitor.

func WithDefaultEventAttr

func WithDefaultEventAttr(defaultEventAttr *EventAttr) EventMonitorOption

WithDefaultEventAttr is used to set an optional EventAttr struct to be used by default when registering events and no EventAttr is specified as part of the registration.

func WithFlags

func WithFlags(flags uintptr) EventMonitorOption

WithFlags is used to set optional flags when creating a new EventMonitor. The flags are passed to the low-level perf_event_open() system call.

func WithPerfEventDir

func WithPerfEventDir(dir string) EventMonitorOption

WithPerfEventDir is used to set an optional directory to use for monitoring cgroups. This should only be necessary if the perf_event cgroup fs is not mounted in the usual location.

func WithPid

func WithPid(pid int) EventMonitorOption

WithPid is used to add a pid to the set of sources to monitor.

func WithPids

func WithPids(pids []int) EventMonitorOption

WithPids is used to add a list of pids to the set of sources to monitor.

func WithRingBufferNumPages

func WithRingBufferNumPages(numPages int) EventMonitorOption

WithRingBufferNumPages is used to set the size of the ringbuffers used to retrieve samples from the kernel.

type ExitRecord

type ExitRecord struct {
	Pid  uint32
	Ppid uint32
	Tid  uint32
	Ptid uint32
	Time uint64
}

ExitRecord is a translation of the structure used by the Linux kernel for PERF_RECORD_EXIT samples into Go.

type ForkRecord

type ForkRecord struct {
	Pid  uint32
	Ppid uint32
	Tid  uint32
	Ptid uint32
	Time uint64
}

ForkRecord is a translation of the structure used by the Linux kernel for PERF_RECORD_FORK samples into Go.

type LostRecord

type LostRecord struct {
	ID   uint64
	Lost uint64
}

LostRecord is a translation of the structure used by the Linux kernel for PERF_RECORD_LOST samples into Go.

type RegisterEventOption

type RegisterEventOption func(*registerEventOptions)

RegisterEventOption is used to implement optional arguments for event registration methods. It must be exported, but it is not typically used directly.

func WithEventAttr

func WithEventAttr(eventAttr *EventAttr) RegisterEventOption

WithEventAttr is used to register the event with an EventAttr struct instead of using the EventMonitor's default.

func WithEventDisabled

func WithEventDisabled() RegisterEventOption

WithEventDisabled is used to register the event in a disabled state.

func WithEventEnabled

func WithEventEnabled() RegisterEventOption

WithEventEnabled is used to register the event in an enabled state.

func WithFilter

func WithFilter(filter string) RegisterEventOption

WithFilter is used to set a filter for the event.

type Sample

type Sample struct {
	Record interface{}
	SampleID
	// contains filtered or unexported fields
}

Sample is the representation of a perf_event sample retrieved from the Linux kernel. It includes the header information, a translation of the sample data, and metadata depending on the flags set in the EventAttr used to enable the event that generated the sample.

type SampleDispatchFn

type SampleDispatchFn func(uint64, interface{}, error)

SampleDispatchFn is the signature of a function called to dispatch a sample. The first argument is the event ID, the second is the returned value from the decoder, and the third is the error that may have been returned from the decoder.

type SampleID

type SampleID struct {
	PID      uint32
	TID      uint32
	Time     uint64
	ID       uint64
	StreamID uint64
	CPU      uint32
}

SampleID is a translation of the structure used by the Linux kernel for all samples when SampleIDAll is set in the EventAttr used for a sample.

type SampleRecord

type SampleRecord struct {
	SampleID    uint64
	IP          uint64
	Pid         uint32
	Tid         uint32
	Time        uint64
	Addr        uint64
	ID          uint64
	StreamID    uint64
	CPU         uint32
	Period      uint64
	V           CounterGroup
	IPs         []uint64
	RawData     []byte
	Branches    []BranchEntry
	UserABI     uint64
	UserRegs    []uint64
	StackData   []uint64
	Weight      uint64
	DataSrc     uint64
	Transaction uint64
	IntrABI     uint64
	IntrRegs    []uint64
}

SampleRecord is a translation of the structure used by the Linux kernel for PERF_RECORD_SAMPLE samples into Go.

type TraceEvent

type TraceEvent struct {
	Type         uint16
	Flags        uint8
	PreemptCount uint8
	Pid          int32
}

TraceEvent represents the common header on all trace events

type TraceEventDecoderFn

type TraceEventDecoderFn func(*SampleRecord, TraceEventSampleData) (interface{}, error)

TraceEventDecoderFn is the signature of a function to call to decode a sample. The first argument is the sample to be decoded, and the second is the parsed sample data.

type TraceEventSampleData

type TraceEventSampleData map[string]interface{}

TraceEventSampleData is a type alias for map[string]interface{}, which is the representation of sample data parsed from a Linux kernel sample.

Jump to

Keyboard shortcuts

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