Back to godoc.org
github.com/hodgesds/perf-utils

Package perf

v0.2.5
Latest Go to latest

The latest major version is .

Published: Oct 11, 2020 | License: MIT | Module: github.com/hodgesds/perf-utils

Index

Constants

const (
	// L1DataReadHit is a constant...
	L1DataReadHit = (unix.PERF_COUNT_HW_CACHE_L1D) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// L1DataReadMiss is a constant...
	L1DataReadMiss = (unix.PERF_COUNT_HW_CACHE_L1D) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)
	// L1DataWriteHit is a constant...
	L1DataWriteHit = (unix.PERF_COUNT_HW_CACHE_L1D) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// L1InstrReadMiss is a constant...
	L1InstrReadMiss = (unix.PERF_COUNT_HW_CACHE_L1I) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)

	// LLReadHit is a constant...
	LLReadHit = (unix.PERF_COUNT_HW_CACHE_LL) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// LLReadMiss is a constant...
	LLReadMiss = (unix.PERF_COUNT_HW_CACHE_LL) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)
	// LLWriteHit is a constant...
	LLWriteHit = (unix.PERF_COUNT_HW_CACHE_LL) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// LLWriteMiss is a constant...
	LLWriteMiss = (unix.PERF_COUNT_HW_CACHE_LL) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)

	// DataTLBReadHit is a constant...
	DataTLBReadHit = (unix.PERF_COUNT_HW_CACHE_DTLB) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// DataTLBReadMiss is a constant...
	DataTLBReadMiss = (unix.PERF_COUNT_HW_CACHE_DTLB) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)
	// DataTLBWriteHit is a constant...
	DataTLBWriteHit = (unix.PERF_COUNT_HW_CACHE_DTLB) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// DataTLBWriteMiss is a constant...
	DataTLBWriteMiss = (unix.PERF_COUNT_HW_CACHE_DTLB) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)

	// InstrTLBReadHit is a constant...
	InstrTLBReadHit = (unix.PERF_COUNT_HW_CACHE_ITLB) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// InstrTLBReadMiss is a constant...
	InstrTLBReadMiss = (unix.PERF_COUNT_HW_CACHE_ITLB) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)

	// BPUReadHit is a constant...
	BPUReadHit = (unix.PERF_COUNT_HW_CACHE_BPU) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// BPUReadMiss is a constant...
	BPUReadMiss = (unix.PERF_COUNT_HW_CACHE_BPU) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)

	// NodeCacheReadHit is a constant...
	NodeCacheReadHit = (unix.PERF_COUNT_HW_CACHE_NODE) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// NodeCacheReadMiss is a constant...
	NodeCacheReadMiss = (unix.PERF_COUNT_HW_CACHE_NODE) | (unix.PERF_COUNT_HW_CACHE_OP_READ << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)
	// NodeCacheWriteHit is a constant...
	NodeCacheWriteHit = (unix.PERF_COUNT_HW_CACHE_NODE) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16)
	// NodeCacheWriteMiss is a constant...
	NodeCacheWriteMiss = (unix.PERF_COUNT_HW_CACHE_NODE) | (unix.PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (unix.PERF_COUNT_HW_CACHE_RESULT_MISS << 16)
)
const (
	// DebugFS is the filesystem type for debugfs.
	DebugFS = "debugfs"

	// TraceFS is the filesystem type for tracefs.
	TraceFS = "tracefs"

	// ProcMounts is the mount point for file systems in procfs.
	ProcMounts = "/proc/mounts"

	// PerfMaxStack is the mount point for the max perf event size.
	PerfMaxStack = "/proc/sys/kernel/perf_event_max_stack"

	// PerfMaxContexts is a sysfs mount that contains the max perf contexts.
	PerfMaxContexts = "/proc/sys/kernel/perf_event_max_contexts_per_stack"

	// SyscallsDir is a constant of the default tracing event syscalls directory.
	SyscallsDir = "/sys/kernel/debug/tracing/events/syscalls/"

	// TracingDir is a constant of the default tracing directory.
	TracingDir = "/sys/kernel/debug/tracing"
)
const (
	// PERF_SAMPLE_IDENTIFIER is not defined in x/sys/unix.
	PERF_SAMPLE_IDENTIFIER = 1 << 16

	// PERF_IOC_FLAG_GROUP is not defined in x/sys/unix.
	PERF_IOC_FLAG_GROUP = 1 << 0
)
const (
	// PERF_TYPE_TRACEPOINT is a kernel tracepoint.
	PERF_TYPE_TRACEPOINT = 2
)

Variables

var ErrNoLeader = fmt.Errorf("No leader defined")

ErrNoLeader is returned when a leader of a GroupProfiler is not defined.

var (
	// ErrNoMount is when there is no such mount.
	ErrNoMount = fmt.Errorf("no such mount")
)
var (
	// ErrNoProfiler is returned when no profiler is available for profiling.
	ErrNoProfiler = fmt.Errorf("No profiler available")
)
var (
	// EventAttrSize is the size of a PerfEventAttr
	EventAttrSize = uint32(unsafe.Sizeof(unix.PerfEventAttr{}))
)

func AlignmentFaultsEventAttr

func AlignmentFaultsEventAttr() unix.PerfEventAttr

AlignmentFaultsEventAttr returns a unix.PerfEventAttr configured for AlignmentFaults.

func AvailableEvents

func AvailableEvents() (map[string][]string, error)

AvailableEvents returns a mapping of available subsystems and their corresponding list of available events.

func AvailableSubsystems

func AvailableSubsystems() ([]string, error)

AvailableSubsystems returns a slice of available subsystems.

func AvailableTracers

func AvailableTracers() ([]string, error)

AvailableTracers returns the list of available tracers.

func BPUEventAttr

func BPUEventAttr(op, result int) unix.PerfEventAttr

BPUEventAttr returns a unix.PerfEventAttr configured for BPU events.

func BenchmarkTracepoints

func BenchmarkTracepoints(
	b *testing.B,
	f func(b *testing.B),
	options BenchOpt,
	tracepoints ...string,
)

BenchmarkTracepoints runs benchmark and counts the

func BusCyclesEventAttr

func BusCyclesEventAttr() unix.PerfEventAttr

BusCyclesEventAttr returns a unix.PerfEventAttr configured for BusCycles.

func CPUClockEventAttr

func CPUClockEventAttr() unix.PerfEventAttr

CPUClockEventAttr returns a unix.PerfEventAttr configured for CPUClock.

func CPUCyclesEventAttr

func CPUCyclesEventAttr() unix.PerfEventAttr

CPUCyclesEventAttr returns a unix.PerfEventAttr configured for CPUCycles.

func CPUInstructionsEventAttr

func CPUInstructionsEventAttr() unix.PerfEventAttr

CPUInstructionsEventAttr returns a unix.PerfEventAttr configured for CPUInstructions.

func CPUMigrationsEventAttr

func CPUMigrationsEventAttr() unix.PerfEventAttr

CPUMigrationsEventAttr returns a unix.PerfEventAttr configured for CPUMigrations.

func CPURefCyclesEventAttr

func CPURefCyclesEventAttr() unix.PerfEventAttr

CPURefCyclesEventAttr returns a unix.PerfEventAttr configured for CPURefCycles.

func CPUTaskClockEventAttr

func CPUTaskClockEventAttr() unix.PerfEventAttr

CPUTaskClockEventAttr returns a unix.PerfEventAttr configured for CPUTaskClock.

func CacheMissEventAttr

func CacheMissEventAttr() unix.PerfEventAttr

CacheMissEventAttr returns a unix.PerfEventAttr configured for CacheMisses.

func CacheRefEventAttr

func CacheRefEventAttr() unix.PerfEventAttr

CacheRefEventAttr returns a unix.PerfEventAttr configured for CacheRef.

func ContextSwitchesEventAttr

func ContextSwitchesEventAttr() unix.PerfEventAttr

ContextSwitchesEventAttr returns a unix.PerfEventAttr configured for ContextSwitches.

func CurrentTracer

func CurrentTracer() (string, error)

CurrentTracer returns the current tracer.

func DataTLBEventAttr

func DataTLBEventAttr(op, result int) unix.PerfEventAttr

DataTLBEventAttr returns a unix.PerfEventAttr configured for DataTLB.

func DebugFSMount

func DebugFSMount() (string, error)

DebugFSMount returns the first found mount point of a debugfs file system.

func EmulationFaultsEventAttr

func EmulationFaultsEventAttr() unix.PerfEventAttr

EmulationFaultsEventAttr returns a unix.PerfEventAttr configured for EmulationFaults.

func EventAttrString

func EventAttrString(eventAttr *unix.PerfEventAttr) string

EventAttrString returns a short string representation of a unix.PerfEventAttr.

func GetFSMount

func GetFSMount(mountType string) ([]string, error)

GetFSMount is a helper function to get a mount file system type.

func GetTracepointConfig

func GetTracepointConfig(subsystem, event string) (uint64, error)

GetTracepointConfig is used to get the configuration for a trace event.

func InstructionTLBEventAttr

func InstructionTLBEventAttr(op, result int) unix.PerfEventAttr

InstructionTLBEventAttr returns a unix.PerfEventAttr configured for InstructionTLB.

func L1DataEventAttr

func L1DataEventAttr(op, result int) unix.PerfEventAttr

L1DataEventAttr returns a unix.PerfEventAttr configured for L1Data.

func L1InstructionsEventAttr

func L1InstructionsEventAttr(op, result int) unix.PerfEventAttr

L1InstructionsEventAttr returns a unix.PerfEventAttr configured for L1Instructions.

func LLCacheEventAttr

func LLCacheEventAttr(op, result int) unix.PerfEventAttr

LLCacheEventAttr returns a unix.PerfEventAttr configured for LLCache.

func LockThread

func LockThread(core int) (func(), error)

LockThread locks an goroutine to an OS thread and then sets the affinity of the thread to a processor core.

func MajorPageFaultsEventAttr

func MajorPageFaultsEventAttr() unix.PerfEventAttr

MajorPageFaultsEventAttr returns a unix.PerfEventAttr configured for MajorPageFaults.

func MinorPageFaultsEventAttr

func MinorPageFaultsEventAttr() unix.PerfEventAttr

MinorPageFaultsEventAttr returns a unix.PerfEventAttr configured for MinorPageFaults.

func NodeCacheEventAttr

func NodeCacheEventAttr(op, result int) unix.PerfEventAttr

NodeCacheEventAttr returns a unix.PerfEventAttr configured for NUMA cache operations.

func PageFaultsEventAttr

func PageFaultsEventAttr() unix.PerfEventAttr

PageFaultsEventAttr returns a unix.PerfEventAttr configured for PageFaults.

func RunBenchmarks

func RunBenchmarks(
	b *testing.B,
	f func(b *testing.B),
	options BenchOpt,
	eventAttrs ...unix.PerfEventAttr,
)

RunBenchmarks runs a series of benchmarks for a set of PerfEventAttrs.

func StalledBackendCyclesEventAttr

func StalledBackendCyclesEventAttr() unix.PerfEventAttr

StalledBackendCyclesEventAttr returns a unix.PerfEventAttr configured for StalledBackendCycles.

func StalledFrontendCyclesEventAttr

func StalledFrontendCyclesEventAttr() unix.PerfEventAttr

StalledFrontendCyclesEventAttr returns a unix.PerfEventAttr configured for StalledFrontendCycles.

func TraceFSMount

func TraceFSMount() (string, error)

TraceFSMount returns the first found mount point of a tracefs file system.

func TracepointEventAttr

func TracepointEventAttr(subsystem, event string) (*unix.PerfEventAttr, error)

TracepointEventAttr is used to return an PerfEventAttr for a trace event.

type BPFProfiler

type BPFProfiler interface {
	Profiler
	AttachBPF(int) error
}

BPFProfiler is a Profiler that allows attaching a Berkeley Packet Filter (BPF) program to an existing kprobe tracepoint event. You need CAP_SYS_ADMIN privileges to use this interface. See: https://lwn.net/Articles/683504/

func ProfileTracepoint

func ProfileTracepoint(subsystem, event string, pid, cpu int, opts ...int) (BPFProfiler, error)

ProfileTracepoint is used to profile a kernel tracepoint event for a specific PID. Events can be listed with `perf list` for Tracepoint Events or in the /sys/kernel/debug/tracing/events directory with the kind being the directory and the event being the subdirectory.

type BenchOpt

type BenchOpt uint8

BenchOpt is a benchmark option.

const (
	// BenchLock is used to lock a benchmark to a goroutine.
	BenchLock BenchOpt = 1 << iota
	// BenchStrict is used to fail a benchmark if one or more events can be
	// profiled.
	BenchStrict
)

type CacheProfile

type CacheProfile struct {
	L1DataReadHit      *uint64 `json:"l1_data_read_hit,omitempty"`
	L1DataReadMiss     *uint64 `json:"l1_data_read_miss,omitempty"`
	L1DataWriteHit     *uint64 `json:"l1_data_write_hit,omitempty"`
	L1InstrReadMiss    *uint64 `json:"l1_instr_read_miss,omitempty"`
	LastLevelReadHit   *uint64 `json:"last_level_read_hit,omitempty"`
	LastLevelReadMiss  *uint64 `json:"last_level_read_miss,omitempty"`
	LastLevelWriteHit  *uint64 `json:"last_level_write_hit,omitempty"`
	LastLevelWriteMiss *uint64 `json:"last_level_write_miss,omitempty"`
	DataTLBReadHit     *uint64 `json:"data_tlb_read_hit,omitempty"`
	DataTLBReadMiss    *uint64 `json:"data_tlb_read_miss,omitempty"`
	DataTLBWriteHit    *uint64 `json:"data_tlb_write_hit,omitempty"`
	DataTLBWriteMiss   *uint64 `json:"data_tlb_write_miss,omitempty"`
	InstrTLBReadHit    *uint64 `json:"instr_tlb_read_hit,omitempty"`
	InstrTLBReadMiss   *uint64 `json:"instr_tlb_read_miss,omitempty"`
	BPUReadHit         *uint64 `json:"bpu_read_hit,omitempty"`
	BPUReadMiss        *uint64 `json:"bpu_read_miss,omitempty"`
	NodeReadHit        *uint64 `json:"node_read_hit,omitempty"`
	NodeReadMiss       *uint64 `json:"node_read_miss,omitempty"`
	NodeWriteHit       *uint64 `json:"node_write_hit,omitempty"`
	NodeWriteMiss      *uint64 `json:"node_write_miss,omitempty"`
	TimeEnabled        *uint64 `json:"time_enabled,omitempty"`
	TimeRunning        *uint64 `json:"time_running,omitempty"`
}

CacheProfile is returned by a CacheProfiler.

type CacheProfiler

type CacheProfiler interface {
	Start() error
	Reset() error
	Stop() error
	Close() error
	Profile() (*CacheProfile, error)
}

CacheProfiler is a cache profiler.

func NewCacheProfiler

func NewCacheProfiler(pid, cpu int, opts ...int) CacheProfiler

NewCacheProfiler returns a new cache profiler.

type GroupProfileValue

type GroupProfileValue struct {
	Events      uint64
	TimeEnabled uint64
	TimeRunning uint64
	Values      []uint64
}

GroupProfileValue is returned from a GroupProfiler.

type GroupProfiler

type GroupProfiler interface {
	Start() error
	Reset() error
	Stop() error
	Close() error
	Profile() (*GroupProfileValue, error)
}

GroupProfiler is used to setup a group profiler.

func NewGroupProfiler

func NewGroupProfiler(pid, cpu, opts int, eventAttrs ...unix.PerfEventAttr) (GroupProfiler, error)

NewGroupProfiler returns a GroupProfiler.

type HardwareProfile

type HardwareProfile struct {
	CPUCycles             *uint64 `json:"cpu_cycles,omitempty"`
	Instructions          *uint64 `json:"instructions,omitempty"`
	CacheRefs             *uint64 `json:"cache_refs,omitempty"`
	CacheMisses           *uint64 `json:"cache_misses,omitempty"`
	BranchInstr           *uint64 `json:"branch_instr,omitempty"`
	BranchMisses          *uint64 `json:"branch_misses,omitempty"`
	BusCycles             *uint64 `json:"bus_cycles,omitempty"`
	StalledCyclesFrontend *uint64 `json:"stalled_cycles_frontend,omitempty"`
	StalledCyclesBackend  *uint64 `json:"stalled_cycles_backend,omitempty"`
	RefCPUCycles          *uint64 `json:"ref_cpu_cycles,omitempty"`
	TimeEnabled           *uint64 `json:"time_enabled,omitempty"`
	TimeRunning           *uint64 `json:"time_running,omitempty"`
}

HardwareProfile is returned by a HardwareProfiler. Depending on kernel configuration some fields may return nil.

type HardwareProfiler

type HardwareProfiler interface {
	Start() error
	Reset() error
	Stop() error
	Close() error
	Profile() (*HardwareProfile, error)
}

HardwareProfiler is a hardware profiler.

func NewHardwareProfiler

func NewHardwareProfiler(pid, cpu int, opts ...int) HardwareProfiler

NewHardwareProfiler returns a new hardware profiler.

type ProfileValue

type ProfileValue struct {
	Value       uint64
	TimeEnabled uint64
	TimeRunning uint64
}

ProfileValue is a value returned by a profiler.

func AlignmentFaults

func AlignmentFaults(f func() error) (*ProfileValue, error)

AlignmentFaults is used to profile a function and return the number of alignment faults. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func BPU

func BPU(op, result int, f func() error) (*ProfileValue, error)

BPU is used to profile a function for the Branch Predictor Unit. Use PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func BusCycles

func BusCycles(f func() error) (*ProfileValue, error)

BusCycles is used to profile a function and return the number of bus cycles. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CPUClock

func CPUClock(f func() error) (*ProfileValue, error)

CPUClock is used to profile a function and return the CPU clock timer. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CPUCycles

func CPUCycles(f func() error) (*ProfileValue, error)

CPUCycles is used to profile a function and return the number of CPU cycles. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CPUInstructions

func CPUInstructions(f func() error) (*ProfileValue, error)

CPUInstructions is used to profile a function and return the number of CPU instructions. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CPUMigrations

func CPUMigrations(f func() error) (*ProfileValue, error)

CPUMigrations is used to profile a function and return the number of times the thread has been migrated to a new CPU. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CPURefCycles

func CPURefCycles(f func() error) (*ProfileValue, error)

CPURefCycles is used to profile a function and return the number of CPU references cycles which are not affected by frequency scaling. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CPUTaskClock

func CPUTaskClock(f func() error) (*ProfileValue, error)

CPUTaskClock is used to profile a function and return the CPU clock timer for the running task. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CacheMiss

func CacheMiss(f func() error) (*ProfileValue, error)

CacheMiss is used to profile a function and return the number of cache misses. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func CacheRef

func CacheRef(f func() error) (*ProfileValue, error)

CacheRef is used to profile a function and return the number of cache references. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func ContextSwitches

func ContextSwitches(f func() error) (*ProfileValue, error)

ContextSwitches is used to profile a function and return the number of context switches. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func DataTLB

func DataTLB(op, result int, f func() error) (*ProfileValue, error)

DataTLB is used to profile the data TLB. Use PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func EmulationFaults

func EmulationFaults(f func() error) (*ProfileValue, error)

EmulationFaults is used to profile a function and return the number of emulation faults. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func InstructionTLB

func InstructionTLB(op, result int, f func() error) (*ProfileValue, error)

InstructionTLB is used to profile the instruction TLB. Use PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func L1Data

func L1Data(op, result int, f func() error) (*ProfileValue, error)

L1Data is used to profile a function and the L1 data cache faults. Use PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func L1Instructions

func L1Instructions(op, result int, f func() error) (*ProfileValue, error)

L1Instructions is used to profile a function for the instruction level L1 cache. Use PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func LLCache

func LLCache(op, result int, f func() error) (*ProfileValue, error)

LLCache is used to profile a function and return the number of emulation PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func MajorPageFaults

func MajorPageFaults(f func() error) (*ProfileValue, error)

MajorPageFaults is used to profile a function and return the number of major page faults. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func MinorPageFaults

func MinorPageFaults(f func() error) (*ProfileValue, error)

MinorPageFaults is used to profile a function and return the number of minor page faults. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func NodeCache

func NodeCache(op, result int, f func() error) (*ProfileValue, error)

NodeCache is used to profile a function for NUMA operations. Use Use PERF_COUNT_HW_CACHE_OP_READ, PERF_COUNT_HW_CACHE_OP_WRITE, or PERF_COUNT_HW_CACHE_OP_PREFETCH for the opt and PERF_COUNT_HW_CACHE_RESULT_ACCESS or PERF_COUNT_HW_CACHE_RESULT_MISS for the result. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func PageFaults

func PageFaults(f func() error) (*ProfileValue, error)

PageFaults is used to profile a function and return the number of page faults. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func StalledBackendCycles

func StalledBackendCycles(f func() error) (*ProfileValue, error)

StalledBackendCycles is used to profile a function and return the number of stalled backend cycles. Note that it will call runtime.LockOSThread to ensure accurate profilng.

func StalledFrontendCycles

func StalledFrontendCycles(f func() error) (*ProfileValue, error)

StalledFrontendCycles is used to profile a function and return the number of stalled frontend cycles. Note that it will call runtime.LockOSThread to ensure accurate profilng.

type Profiler

type Profiler interface {
	Start() error
	Reset() error
	Stop() error
	Close() error
	Profile() (*ProfileValue, error)
}

Profiler is a profiler.

func NewAlignFaultsProfiler

func NewAlignFaultsProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewAlignFaultsProfiler returns a Profiler that profiles the number of alignment faults.

func NewBPUProfiler

func NewBPUProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewBPUProfiler returns a Profiler that profiles the BPU (branch prediction unit).

func NewBranchInstrProfiler

func NewBranchInstrProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewBranchInstrProfiler returns a Profiler that profiles branch instructions.

func NewBranchMissesProfiler

func NewBranchMissesProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewBranchMissesProfiler returns a Profiler that profiles branch misses.

func NewBusCyclesProfiler

func NewBusCyclesProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewBusCyclesProfiler returns a Profiler that profiles bus cycles.

func NewCPUClockProfiler

func NewCPUClockProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewCPUClockProfiler returns a Profiler that profiles CPU clock speed.

func NewCPUCycleProfiler

func NewCPUCycleProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewCPUCycleProfiler returns a Profiler that profiles CPU cycles.

func NewCPUMigrationsProfiler

func NewCPUMigrationsProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewCPUMigrationsProfiler returns a Profiler that profiles the number of times the process has migrated to a new CPU.

func NewCacheMissesProfiler

func NewCacheMissesProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewCacheMissesProfiler returns a Profiler that profiles cache misses.

func NewCacheRefProfiler

func NewCacheRefProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewCacheRefProfiler returns a Profiler that profiles cache references.

func NewCtxSwitchesProfiler

func NewCtxSwitchesProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewCtxSwitchesProfiler returns a Profiler that profiles the number of context switches.

func NewDataTLBProfiler

func NewDataTLBProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewDataTLBProfiler returns a Profiler that profiles the data TLB.

func NewEmulationFaultsProfiler

func NewEmulationFaultsProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewEmulationFaultsProfiler returns a Profiler that profiles the number of alignment faults.

func NewInstrProfiler

func NewInstrProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewInstrProfiler returns a Profiler that profiles CPU instructions.

func NewInstrTLBProfiler

func NewInstrTLBProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewInstrTLBProfiler returns a Profiler that profiles the instruction TLB.

func NewL1DataProfiler

func NewL1DataProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewL1DataProfiler returns a Profiler that profiles L1 cache data.

func NewL1InstrProfiler

func NewL1InstrProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewL1InstrProfiler returns a Profiler that profiles L1 instruction data.

func NewLLCacheProfiler

func NewLLCacheProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewLLCacheProfiler returns a Profiler that profiles last level cache.

func NewMajorFaultsProfiler

func NewMajorFaultsProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewMajorFaultsProfiler returns a Profiler that profiles the number of major page faults.

func NewMinorFaultsProfiler

func NewMinorFaultsProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewMinorFaultsProfiler returns a Profiler that profiles the number of minor page faults.

func NewNodeCacheProfiler

func NewNodeCacheProfiler(pid, cpu, op, result int, opts ...int) (Profiler, error)

NewNodeCacheProfiler returns a Profiler that profiles the node cache accesses.

func NewPageFaultProfiler

func NewPageFaultProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewPageFaultProfiler returns a Profiler that profiles the number of page faults.

func NewProfiler

func NewProfiler(profilerType uint32, config uint64, pid, cpu int, opts ...int) (Profiler, error)

NewProfiler creates a new hardware profiler. It does not support grouping.

func NewRefCPUCyclesProfiler

func NewRefCPUCyclesProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewRefCPUCyclesProfiler returns a Profiler that profiles CPU cycles, it is not affected by frequency scaling.

func NewStalledCyclesBackProfiler

func NewStalledCyclesBackProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewStalledCyclesBackProfiler returns a Profiler that profiles stalled backend cycles.

func NewStalledCyclesFrontProfiler

func NewStalledCyclesFrontProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewStalledCyclesFrontProfiler returns a Profiler that profiles stalled frontend cycles.

func NewTaskClockProfiler

func NewTaskClockProfiler(pid, cpu int, opts ...int) (Profiler, error)

NewTaskClockProfiler returns a Profiler that profiles clock count of the running task.

type SoftwareProfile

type SoftwareProfile struct {
	CPUClock        *uint64 `json:"cpu_clock,omitempty"`
	TaskClock       *uint64 `json:"task_clock,omitempty"`
	PageFaults      *uint64 `json:"page_faults,omitempty"`
	ContextSwitches *uint64 `json:"context_switches,omitempty"`
	CPUMigrations   *uint64 `json:"cpu_migrations,omitempty"`
	MinorPageFaults *uint64 `json:"minor_page_faults,omitempty"`
	MajorPageFaults *uint64 `json:"major_page_faults,omitempty"`
	AlignmentFaults *uint64 `json:"alignment_faults,omitempty"`
	EmulationFaults *uint64 `json:"emulation_faults,omitempty"`
	TimeEnabled     *uint64 `json:"time_enabled,omitempty"`
	TimeRunning     *uint64 `json:"time_running,omitempty"`
}

SoftwareProfile is returned by a SoftwareProfiler.

type SoftwareProfiler

type SoftwareProfiler interface {
	Start() error
	Reset() error
	Stop() error
	Close() error
	Profile() (*SoftwareProfile, error)
}

SoftwareProfiler is a software profiler.

func NewSoftwareProfiler

func NewSoftwareProfiler(pid, cpu int, opts ...int) SoftwareProfiler

NewSoftwareProfiler returns a new software profiler.

Package Files

BUGs

  • this should ideally check mounts for debugfs

  • this should ideally check mounts for debugfs

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier