perf

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 19, 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

func AddKprobe

func AddKprobe(name string, address string, onReturn bool, output string) (string, error)

func GetAvailableTraceEvents

func GetAvailableTraceEvents() ([]string, error)

func GetTraceEventFormat

func GetTraceEventFormat(name string) (uint16, map[string]TraceEventField, error)

func GetTraceEventID

func GetTraceEventID(name string) (uint16, error)

func ReadTraceEventFormat

func ReadTraceEventFormat(name string, reader io.Reader) (uint16, map[string]TraceEventField, error)

func ReadTraceEventID

func ReadTraceEventID(name string, reader io.Reader) (uint16, error)

func RemoveKprobe

func RemoveKprobe(name string) error

Types

type BranchEntry

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

type CommRecord

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

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
}

func NewEventMonitor

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

func (*EventMonitor) Close

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

func (*EventMonitor) Disable

func (monitor *EventMonitor) Disable(eventid uint64)

func (*EventMonitor) DisableAll

func (monitor *EventMonitor) DisableAll()

func (*EventMonitor) Enable

func (monitor *EventMonitor) Enable(eventid uint64)

func (*EventMonitor) EnableAll

func (monitor *EventMonitor) EnableAll()

func (*EventMonitor) RegisterKprobe

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

func (*EventMonitor) RegisterTracepoint

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

func (*EventMonitor) Run

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

func (*EventMonitor) SetFilter

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

func (*EventMonitor) Stop

func (monitor *EventMonitor) Stop(wait bool)

func (*EventMonitor) UnregisterEvent

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

type EventMonitorOption

type EventMonitorOption func(*eventMonitorOptions)

func WithCgroup

func WithCgroup(cgroup string) EventMonitorOption

func WithCgroups

func WithCgroups(cgroups []string) EventMonitorOption

func WithDefaultEventAttr

func WithDefaultEventAttr(defaultEventAttr *EventAttr) EventMonitorOption

func WithFlags

func WithFlags(flags uintptr) EventMonitorOption

func WithPerfEventDir

func WithPerfEventDir(dir string) EventMonitorOption

func WithPid

func WithPid(pid int) EventMonitorOption

func WithPids

func WithPids(pids []int) EventMonitorOption

func WithRingBufferNumPages

func WithRingBufferNumPages(numPages int) EventMonitorOption

type ExitRecord

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

type ForkRecord

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

type LostRecord

type LostRecord struct {
	Id   uint64
	Lost uint64
}

type RegisterEventOption

type RegisterEventOption func(*registerEventOptions)

func WithEventAttr

func WithEventAttr(eventAttr *EventAttr) RegisterEventOption

func WithEventsDisabled

func WithEventsDisabled() RegisterEventOption

func WithEventsEnabled

func WithEventsEnabled() RegisterEventOption

func WithFilter

func WithFilter(filter string) RegisterEventOption

type Sample

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

type SampleDispatchFn

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

type SampleID

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

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
}

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)

type TraceEventDecoderMap

type TraceEventDecoderMap struct {
	sync.Mutex // used only by writers
	// contains filtered or unexported fields
}

func NewTraceEventDecoderMap

func NewTraceEventDecoderMap() *TraceEventDecoderMap

func (*TraceEventDecoderMap) AddDecoder

func (m *TraceEventDecoderMap) AddDecoder(name string, fn TraceEventDecoderFn) (uint16, error)

Add a decoder safely. Proper synchronization is used to prevent multiple writers from stomping on each other while allowing readers to always operate without locking

func (*TraceEventDecoderMap) DecodeSample

func (m *TraceEventDecoderMap) DecodeSample(sample *SampleRecord) (interface{}, error)

func (*TraceEventDecoderMap) RemoveDecoder

func (m *TraceEventDecoderMap) RemoveDecoder(name string)

Remove a decoder safely. Proper synchronization is used to prevent multiple writers from stomping on each other while allowing readers to always operate without locking

type TraceEventField

type TraceEventField struct {
	FieldName string
	TypeName  string
	Offset    int
	Size      int
	IsSigned  bool
	// contains filtered or unexported fields
}

type TraceEventSampleData

type TraceEventSampleData map[string]interface{}

Jump to

Keyboard shortcuts

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