stats

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package stats provides Stats

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Progress

type Progress struct {
	Done bool // Done indicates if the viewer is currently done

	Stage          Stage
	Current, Total int
}

type Stage

type Stage string

Stage represents a stage used for statistics

const (
	StageInitial         Stage = ""
	StageImportIndex     Stage = "import"
	StageExportIndex     Stage = "export"
	StageExportSQL       Stage = "export/sql"
	StageExportJSON      Stage = "export/json"
	StageReadPathbuilder Stage = "pathbuilder"
	StageScanSameAs      Stage = "index/sameas"
	StageScanInverse     Stage = "index/inverse"
	StageScanTriples     Stage = "index/triples"
	StageExtractSameAs   Stage = "sameas"
	StageExtractBundles  Stage = "bundles"
	StageExtractCache    Stage = "cache"
	StageHandler         Stage = "handler"
)

type StageStats

type StageStats struct {
	Stage Stage

	Start perf.Snapshot // At the start of the stage
	End   perf.Snapshot // At the end of the stage

	Current int
	Total   int
}

StageStats holds the stats for a specific stage

func (StageStats) Diff

func (ss StageStats) Diff() perf.Diff

Diff returns a diff of the given stage

func (StageStats) Progress

func (ss StageStats) Progress() string

Progress returns a string holding progress information on the current stage

type Stats

type Stats struct {

	// OnUpdate is called every time this stats updates.
	// OnUpdate may be nil.
	OnUpdate func(*Stats)
	// contains filtered or unexported fields
}

Stats holds statistical information about the current stage of the previous. Updating the status writes out detailed information to an underlying io.Writer.

Stats is safe to access concurrently, however the caller is responsible for only logging to one stage at a time.

A nil Stats is valid, and discards any information written to it.

func NewStats

func NewStats(w io.Writer) *Stats

NewStats creates a new stats object that writes statistics to the given output.

func (*Stats) All

func (st *Stats) All() []StageStats

Current returns a copy of the current StageStats

func (*Stats) Close

func (st *Stats) Close()

Close marks this status as done. Future edits will have no effect.

func (*Stats) Current

func (st *Stats) Current() StageStats

Current returns a copy of the current StageStats

func (*Stats) Diff

func (st *Stats) Diff() perf.Diff

Diff returns a performance diff starting at the first, and ending at the last stage. If status is nil, a nil diff is returned.

func (*Stats) DoStage

func (st *Stats) DoStage(stage Stage, f func() error) error

DoStage is a convenience wrapper to start a new stage, call f, and log the resulting error if any.

If st is nil, immediately invokes f.

func (*Stats) Done

func (st *Stats) Done() bool

Done checks if further edits made to this status have any effect.

func (*Stats) End

func (st *Stats) End() (prev StageStats)

End ends the current stage if any. Any changes are flushed to the underlying writer.

If st is nil, this function has no effect.

func (*Stats) IndexStats

func (st *Stats) IndexStats() igraph.Stats

IndexStats returns the current stats for the index

func (*Stats) Log

func (st *Stats) Log(message string, fields ...any)

Log logs an informational message with the provided key, value field pairs.

When status or the associated logger are nil, no logging occurs.

func (*Stats) LogDebug

func (st *Stats) LogDebug(message string, fields ...any)

Log logs a debug message with the provided key, value field pairs.

When status or the associated logger are nil, no logging occurs.

func (*Stats) LogError

func (st *Stats) LogError(message string, err error, fields ...any)

LogError logs an error message containing the provided error and the provided key, value field pairs.

When status or the associated logger are nil, no logging occurs.

func (*Stats) LogFatal

func (st *Stats) LogFatal(message string, err error)

LogFatal is like LogError followed by os.Exit(1). When the associated logger are nil, os.Exit(1) is called immediately.

func (*Stats) Progress

func (st *Stats) Progress() (progress Progress)

Progress returns information about the current stage

func (*Stats) Rewritable

func (st *Stats) Rewritable() *progress.Rewritable

Rewritable returns the rewritable associated with this status. It is automatically closed at the end of each stage

func (*Stats) SetCT

func (st *Stats) SetCT(current, total int)

SetCT sets the current and total for the given stage. It the status is nil, or the status is done, has no effect.

func (*Stats) Start

func (st *Stats) Start(stage Stage)

Start starts a new stage, updating the current property. Any changes are written to the underlying writer.

If st is done or nil, this function has no effect.

func (*Stats) StoreIndexStats

func (st *Stats) StoreIndexStats(stats igraph.Stats)

StoreIndexStats optionally stores index statistics. If st is nil or done, this call has no effect

Jump to

Keyboard shortcuts

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