sys

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Calibrate

func Calibrate()

Calibrate calculates the CPU frequency and measurement overhead.

func CyclesToNano

func CyclesToNano(cycles uint64) uint64

CyclesToNano converts CPU cycles to nanoseconds.

func GetAffinity

func GetAffinity() ([]int, error)

GetAffinity returns the CPU cores that the current thread is allowed to run on.

func LockOSThread

func LockOSThread()

LockOSThread is a wrapper for runtime.LockOSThread but could be optimized with ASM if we need even lower overhead or specific CPU pinning. For now, it serves as a placeholder for the library structure.

func PinToCore

func PinToCore(coreID int) error

PinToCore pins the current goroutine's thread to a specific CPU core. This is critical for cache locality and preventing context switches. This function calls runtime.LockOSThread() internally.

func PreciseDuration

func PreciseDuration(start, end uint64) uint64

PreciseDuration returns the "clean" duration between two TSC readings.

func RDTSC

func RDTSC() uint64

RDTSC reads the current CPU time-stamp counter.

func RDTSCP

func RDTSCP() (tsc uint64, aux uint32)

RDTSCP reads the TSC and processor ID.

func RawSyscall6

func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)

RawSyscall6 is a wrapper for syscall.RawSyscall6 to avoid Go scheduler overhead. Use only for non-blocking syscalls.

Types

type NanoProfiler

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

NanoProfiler is a zero-allocation, fixed-size path recorder.

func NewProfiler

func NewProfiler(maxEntries int) *NanoProfiler

NewProfiler creates a profiler with pre-allocated entries.

func (*NanoProfiler) GetCount

func (p *NanoProfiler) GetCount() uint32

GetCount returns the current number of marks.

func (*NanoProfiler) Mark

func (p *NanoProfiler) Mark(name string)

Mark records a timestamp with a name. This is designed to be extremely fast.

func (*NanoProfiler) Reset

func (p *NanoProfiler) Reset()

Reset clears the profiler.

func (*NanoProfiler) Result

func (p *NanoProfiler) Result()

Result calculates and prints the duration between marks.

type ProfilerEntry

type ProfilerEntry struct {
	Name string
	TSC  uint64
}

ProfilerEntry is a single point of measurement.

Jump to

Keyboard shortcuts

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