metrics

package
v0.0.0-...-9474aff Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package metrics queries metrics collected by Chrome.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearHistogramTransferFile

func ClearHistogramTransferFile() error

ClearHistogramTransferFile clears the histogramTransferFile. The histogramTransferFile is how Histograms get from ChromeOS services into Chrome -- ChromeOS services write their updates to the file, and periodicially, Chrome's chromeos::ExternalMetrics services scrapes the file and adds the Histograms to its own internal list which this package queries.

While this system works well in production, it can be a source of unexpected asynchronous changes in Histograms during tests. Tests intending to watch a Histogram which originates in ChromeOS should clear this file before establishing a "before" Histogram. This will avoid having events from previous tests show up as unexpected diffs in the current test.

func SaveHistogramsMeanValue

func SaveHistogramsMeanValue(ctx context.Context, pv *perf.Values, histograms []*Histogram, metric perf.Metric) error

SaveHistogramsMeanValue saves the mean of each histogram as the performance metrics value. Note that this function does not save data in file.

Types

type Histogram

type Histogram struct {
	// Name of the histogram.
	Name string
	// The sum of the all entries in the histogram.
	Sum int64 `json:"sum"`
	// Buckets contains ranges of reported values.
	// The buckets are disjoint and stored in ascending order.
	Buckets []HistogramBucket `json:"buckets"`
}

Histogram contains data from a single Chrome histogram.

func DiffHistograms

func DiffHistograms(older, newer []*Histogram) ([]*Histogram, error)

DiffHistograms is a convenience function to diff multiple histograms.

func GetHistogram

func GetHistogram(ctx context.Context, tconn *chrome.TestConn, name string) (*Histogram, error)

GetHistogram returns the current state of a Chrome histogram (e.g. "Tabs.TabCountActiveWindow"). If no samples have been reported for the histogram since Chrome was started, the zero value for Histogram is returned.

func GetHistograms

func GetHistograms(ctx context.Context, tconn *chrome.TestConn, histogramNames []string) ([]*Histogram, error)

GetHistograms is a convenience function to get multiple histograms.

func Run

func Run(ctx context.Context, tconn *chrome.TestConn, f func(ctx context.Context) error, names ...string) ([]*Histogram, error)

Run is a helper to calculate histogram diffs before and after running a given function.

func RunAndWaitAll

func RunAndWaitAll(ctx context.Context, tconn *chrome.TestConn,
	timeout time.Duration,
	f func(ctx context.Context) error, names ...string) ([]*Histogram, error)

RunAndWaitAll is a helper to calculate histogram diffs before and after running a given function. It waits for all the histograms before return if there are histograms to wait. Otherwise, it returns immediately like Run.

func RunAndWaitAny

func RunAndWaitAny(ctx context.Context, tconn *chrome.TestConn,
	timeout time.Duration,
	f func(ctx context.Context) error, names ...string) ([]*Histogram, error)

RunAndWaitAny is a helper to calculate histogram diffs before and after running a given function. It waits for any one of the histograms before return if there are histograms to wait. Otherwise, it returns immediately like Run.

func WaitForHistogram

func WaitForHistogram(ctx context.Context, tconn *chrome.TestConn, name string, timeout time.Duration) (*Histogram, error)

WaitForHistogram is a convenience function that calls GetHistogram until the requested histogram is available, ctx's deadline is reached, or timeout (if positive) has elapsed.

func WaitForHistogramUpdate

func WaitForHistogramUpdate(ctx context.Context, tconn *chrome.TestConn, name string,
	old *Histogram, timeout time.Duration) (*Histogram, error)

WaitForHistogramUpdate is a convenience function that calls GetHistogram until the requested histogram contains at least one sample not present in old, an earlier snapshot of the same histogram. A histogram containing the new samples is returned; see Histogram.Diff for details.

func (*Histogram) Diff

func (h *Histogram) Diff(old *Histogram) (*Histogram, error)

Diff returns a histogram containing the additional samples in h that aren't in old, an older version of the same histogram. Buckets that haven't changed are omitted from the returned histogram. old must be an earlier snapshot -- an error is returned if any counts decreased or if old contains buckets not present in h.

func (*Histogram) Mean

func (h *Histogram) Mean() (float64, error)

Mean calculates the estimated mean of the histogram values. It is an error when there are no data points.

func (*Histogram) String

func (h *Histogram) String() string

String contains a human-readable representation of h as "Name: [[0,5):2 [5,10):1 ...]", where each space-separated term is "[<min>,<max>):<count>".

func (*Histogram) TotalCount

func (h *Histogram) TotalCount() int64

TotalCount returns the total number of samples stored across all buckets.

type HistogramBucket

type HistogramBucket struct {
	// Min contains the minimum value that can be stored in this bucket.
	Min int64 `json:"min"`
	// Max contains the exclusive maximum value for this bucket.
	Max int64 `json:"max"`
	// Count contains the number of samples that are stored in this bucket.
	Count int64 `json:"count"`
}

HistogramBucket contains a set of reported samples within a fixed range.

type Recorder

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

Recorder tracks a snapshot to calculate diffs since start or last wait call.

func StartRecorder

func StartRecorder(ctx context.Context, tconn *chrome.TestConn, names ...string) (*Recorder, error)

StartRecorder captures a snapshot to calculate histograms diffs later.

func (*Recorder) Histogram

func (r *Recorder) Histogram(ctx context.Context, tconn *chrome.TestConn) ([]*Histogram, error)

Histogram returns the histogram diffs since the recorder is started.

func (*Recorder) WaitAll

func (r *Recorder) WaitAll(ctx context.Context, tconn *chrome.TestConn, timeout time.Duration) ([]*Histogram, error)

WaitAll waits for update from all of histograms being recorded and returns the diffs since the recorder is started.

func (*Recorder) WaitAny

func (r *Recorder) WaitAny(ctx context.Context, tconn *chrome.TestConn, timeout time.Duration) ([]*Histogram, error)

WaitAny waits for update from any of histograms being recorded and returns the diffs since the recorder is started.

Jump to

Keyboard shortcuts

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