sqlstats

package
v0.0.0-...-b529d1d Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package sqlstats implements an SQLite Tracer that collects query stats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryStats

type QueryStats struct {
	Query string

	// Count represents the number of times this query has been
	// executed.
	Count int64

	// Errors represents the number of errors encountered executing
	// this query.
	Errors int64

	// TotalDuration represents the accumulated time spent executing the query.
	TotalDuration time.Duration

	// MeanDuration represents the average time spent executing the query.
	MeanDuration time.Duration
}

QueryStats is a collection of stats for a given Query.

type Tracer

type Tracer struct {
	TxCount        *expvar.Map
	TxCommit       *expvar.Map
	TxCommitError  *expvar.Map
	TxRollback     *expvar.Map
	TxTotalSeconds *expvar.Map
	// contains filtered or unexported fields
}

Tracer implements sqlite.Tracer and collects query stats.

To use, pass the tracer object to sqlite.Connector, then start a debug web server with http.HandlerFunc(sqlTracer.Handle).

func (*Tracer) BeginTx

func (t *Tracer) BeginTx(
	beginCtx context.Context,
	id sqliteh.TraceConnID,
	why string,
	readOnly bool,
	err error,
)

func (*Tracer) Collect

func (t *Tracer) Collect() (rows []*QueryStats)

Collect returns the list of QueryStats pointers from the Tracer.

func (*Tracer) Commit

func (t *Tracer) Commit(id sqliteh.TraceConnID, err error)

func (*Tracer) Handle

func (t *Tracer) Handle(w http.ResponseWriter, r *http.Request)

func (*Tracer) HandleConns

func (t *Tracer) HandleConns(w http.ResponseWriter, r *http.Request)

func (*Tracer) Query

func (t *Tracer) Query(
	prepCtx context.Context,
	id sqliteh.TraceConnID,
	query string,
	duration time.Duration,
	err error,
)

func (*Tracer) Reset

func (t *Tracer) Reset()

Reset resets the state of t to its initial conditions.

func (*Tracer) Rollback

func (t *Tracer) Rollback(id sqliteh.TraceConnID, err error)

Jump to

Keyboard shortcuts

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