analysis

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const SortKeyCount = 4

SortKeyCount is the number of available sort keys.

Variables

This section is empty.

Functions

func NormalizeSQL

func NormalizeSQL(query string) string

NormalizeSQL replaces literals in a SQL query with ? placeholders, compresses IN lists, and normalizes whitespace.

func Percentile

func Percentile(sorted []time.Duration, pct float64) time.Duration

Percentile returns the value at the given percentile from a sorted slice of durations using the nearest-rank (ceiling) method. pct must be in [0, 1]. The slice must be sorted in ascending order; passing an unsorted slice yields undefined results.

Types

type EndpointStat

type EndpointStat struct {
	Stats

	Method string
	Path   string
}

EndpointStat holds aggregated statistics for an HTTP endpoint.

func SortEndpoints

func SortEndpoints(stats []EndpointStat, key SortKey) []EndpointStat

SortEndpoints returns a new slice sorted by the given key (descending).

type FuncStat

type FuncStat struct {
	Stats

	Name string
}

FuncStat holds aggregated statistics for a function.

func SortFunctions

func SortFunctions(stats []FuncStat, key SortKey) []FuncStat

SortFunctions returns a new slice sorted by the given key (descending).

type MatchingGroups

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

MatchingGroups groups URIs using regex patterns, like alp's --matching-groups. The first matching pattern's string becomes the group key.

func NewMatchingGroups

func NewMatchingGroups(patterns []string) (*MatchingGroups, error)

NewMatchingGroups compiles pattern strings into a MatchingGroups. Each pattern must be a valid regular expression. Patterns are automatically anchored with ^ and $ if not already present.

func (*MatchingGroups) Match

func (mg *MatchingGroups) Match(uri string) string

Match returns the first matching pattern string for the given URI. If no pattern matches, the original URI is returned unchanged.

type N1Detection

type N1Detection struct {
	Endpoint string
	Query    string
	AvgCount float64
	MaxCount int
}

N1Detection represents a potential N+1 query pattern.

type Report

type Report struct {
	TraceCount int
	Endpoints  []EndpointStat
	SQL        []SQLStat
	Functions  []FuncStat
	N1         []N1Detection
}

Report contains the full analytics result.

func Analyze

func Analyze(roots []tracer.Span, mg *MatchingGroups) Report

Analyze walks trace trees and produces a Report. mg may be nil, in which case URIs are used as-is.

type SQLStat

type SQLStat struct {
	Stats

	Query string
}

SQLStat holds aggregated statistics for a normalized SQL query.

func SortSQL

func SortSQL(stats []SQLStat, key SortKey) []SQLStat

SortSQL returns a new slice sorted by the given key (descending).

type SortKey

type SortKey int

SortKey determines the field used for sorting stat slices.

const (
	SortByTotal SortKey = iota
	SortByAvg
	SortByP95
	SortByCount
)

func (SortKey) String

func (k SortKey) String() string

String returns a human-readable label for the sort key.

type Stats

type Stats struct {
	Count int
	Total time.Duration
	Avg   time.Duration
	P95   time.Duration
	Max   time.Duration
}

Stats holds aggregate timing statistics for a group of spans.

func Compute

func Compute(durations []time.Duration) Stats

Compute calculates Stats from a slice of durations. Returns a zero Stats if the slice is empty.

Jump to

Keyboard shortcuts

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