profile

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package profile measures generator work and writes CPU and memory profiles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, work func(context.Context) error, labels ...string) (err error)

Run executes profiled work with alternating pprof label keys and values. Callers invoke Run only while profiling is enabled.

func WithGenerator

func WithGenerator(ctx context.Context, name string) context.Context

WithGenerator records the profiled generator name in ctx.

Types

type BookMetrics

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

BookMetrics collects wall time and inclusive sampled CPU time for named generator operations. Its zero value is ready for concurrent use.

func (*BookMetrics) LoadCPUProfile

func (m *BookMetrics) LoadCPUProfile(filename string) error

LoadCPUProfile attributes sampled CPU time to every active operation, including its nested operations.

func (*BookMetrics) Measure

func (m *BookMetrics) Measure(ctx context.Context, generator, name string, operation func(context.Context) error, labels ...string) (err error)

Measure runs an operation with pprof labels and records its elapsed time and result.

func (*BookMetrics) Print

func (m *BookMetrics) Print()

Print reports named book-pipeline operations ordered by cumulative wall time. Concurrent wall times and nested CPU times overlap, so they cannot be summed.

func (*BookMetrics) Reset

func (m *BookMetrics) Reset()

Reset removes metrics from a previous run.

type Files

type Files struct {
	CPU    string
	Memory string
}

Files names the profiles produced by Capture. Empty paths mean profiling could not start and work ran without profile files.

func Capture

func Capture(name, outputDir string, work func() error) (files Files, err error)

Capture runs work while collecting process CPU and post-GC memory profiles and returns their paths. If another CPU profile is active, Capture logs the conflict and runs work without writing profile files.

type SheetMetricKey

type SheetMetricKey struct {
	Book   string // Book is the source workbook name relative to the input directory.
	Sheet  string // Sheet is the imported worksheet name.
	Detail string // Detail distinguishes operations such as a message or parsing pass.
}

SheetMetricKey identifies one generator operation on an imported sheet.

func (SheetMetricKey) String

func (k SheetMetricKey) String() string

type SheetParserMetrics

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

SheetParserMetrics collects parser time and input metrics by sheet. Its zero value is ready for concurrent use.

func (*SheetParserMetrics) LoadCPUProfile

func (m *SheetParserMetrics) LoadCPUProfile(filename string) (err error)

LoadCPUProfile attributes sampled processor time to sheets through the sheet_key pprof label. Short parser calls may have no samples and remain zero.

func (*SheetParserMetrics) Measure

func (m *SheetParserMetrics) Measure(ctx context.Context, generator string, key SheetMetricKey, sheet *book.Sheet, parse func(context.Context) error) (err error)

Measure runs parse with pprof labels and records its wall time, result, and input metrics. The CPU profile uses sheet_key to attribute processor time without pinning the goroutine to an OS thread.

func (*SheetParserMetrics) Print

func (m *SheetParserMetrics) Print()

Print reports each sheet's sampled CPU time, wall time, and input metrics.

func (*SheetParserMetrics) Reset

func (m *SheetParserMetrics) Reset()

Reset removes metrics collected by the previous generator run.

Jump to

Keyboard shortcuts

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