cputime

package
v0.24.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cputime is the single seam through which rule code runs work off its calling thread while retaining per-rule CPU attribution.

Index

Constants

View Source
const Supported = true

Variables

This section is empty.

Functions

func CombinedOutput

func CombinedOutput(m *Meter, cmd *exec.Cmd) ([]byte, error)

CombinedOutput runs cmd and charges the child's user and system CPU whenever it started, including when it returned an *exec.ExitError.

func Go

func Go[T any](m *Meter, fn func() T) <-chan T

Go runs fn on a new goroutine and charges its thread CPU to m before sending fn's result. A nil meter is a programming error.

func Process

func Process() (time.Duration, bool)

Process reads user and system CPU for this process and children it waited for, so waited-for descendants are included exactly once.

func Run added in v0.24.0

func Run(m *Meter, cmd *exec.Cmd) error

Run runs cmd with the streams its caller set and charges the child's user and system CPU as CombinedOutput does: whenever it started, including when it returned an *exec.ExitError.

func Thread

func Thread() (time.Duration, bool)

Thread reads the calling OS thread's user and system CPU. The caller must hold runtime.LockOSThread so the goroutine cannot move threads between reads.

Types

type Meter

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

Meter accumulates user and system CPU consumed by goroutines and child processes started by one rule. Its zero value is ready for concurrent use.

func (*Meter) Add

func (m *Meter) Add(d time.Duration)

Add charges d to the meter.

func (*Meter) OffThreadCPU

func (m *Meter) OffThreadCPU() time.Duration

OffThreadCPU returns CPU charged by metered goroutines and child processes.

Jump to

Keyboard shortcuts

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