...

Package measurement

import "github.com/google/pprof/internal/measurement"
Overview
Index

Overview ▾

Package measurement export utility functions to manipulate/format performance profile sample values.

Variables

UnitTypes holds the definition of units known to pprof.

var UnitTypes = []UnitType{{
    Units: []Unit{
        {"B", []string{"b", "byte"}, 1},
        {"kB", []string{"kb", "kbyte", "kilobyte"}, float64(1 << 10)},
        {"MB", []string{"mb", "mbyte", "megabyte"}, float64(1 << 20)},
        {"GB", []string{"gb", "gbyte", "gigabyte"}, float64(1 << 30)},
        {"TB", []string{"tb", "tbyte", "terabyte"}, float64(1 << 40)},
        {"PB", []string{"pb", "pbyte", "petabyte"}, float64(1 << 50)},
    },
    DefaultUnit: Unit{"B", []string{"b", "byte"}, 1},
}, {
    Units: []Unit{
        {"ns", []string{"ns", "nanosecond"}, float64(time.Nanosecond)},
        {"us", []string{"μs", "us", "microsecond"}, float64(time.Microsecond)},
        {"ms", []string{"ms", "millisecond"}, float64(time.Millisecond)},
        {"s", []string{"s", "sec", "second"}, float64(time.Second)},
        {"hrs", []string{"hour", "hr"}, float64(time.Hour)},
    },
    DefaultUnit: Unit{"s", []string{}, float64(time.Second)},
}, {
    Units: []Unit{
        {"n*GCU", []string{"nanogcu"}, 1e-9},
        {"u*GCU", []string{"microgcu"}, 1e-6},
        {"m*GCU", []string{"milligcu"}, 1e-3},
        {"GCU", []string{"gcu"}, 1},
        {"k*GCU", []string{"kilogcu"}, 1e3},
        {"M*GCU", []string{"megagcu"}, 1e6},
        {"G*GCU", []string{"gigagcu"}, 1e9},
        {"T*GCU", []string{"teragcu"}, 1e12},
        {"P*GCU", []string{"petagcu"}, 1e15},
    },
    DefaultUnit: Unit{"GCU", []string{}, 1.0},
}}

func CommonValueType

func CommonValueType(ts []*profile.ValueType) (*profile.ValueType, error)

CommonValueType returns the finest type from a set of compatible types.

func Label

func Label(value int64, unit string) string

Label returns the label used to describe a certain measurement.

func Percentage

func Percentage(value, total int64) string

Percentage computes the percentage of total of a value, and encodes it as a string. At least two digits of precision are printed.

func Scale

func Scale(value int64, fromUnit, toUnit string) (float64, string)

Scale a measurement from a unit to a different unit and returns the scaled value and the target unit. The returned target unit will be empty if uninteresting (could be skipped).

func ScaleProfiles

func ScaleProfiles(profiles []*profile.Profile) error

ScaleProfiles updates the units in a set of profiles to make them compatible. It scales the profiles to the smallest unit to preserve data.

func ScaledLabel

func ScaledLabel(value int64, fromUnit, toUnit string) string

ScaledLabel scales the passed-in measurement (if necessary) and returns the label used to describe a float measurement.

type Unit

Unit includes a list of aliases representing a specific unit and a factor which one can multiple a value in the specified unit by to get the value in terms of the base unit.

type Unit struct {
    CanonicalName string

    Factor float64
    // contains filtered or unexported fields
}

type UnitType

UnitType includes a list of units that are within the same category (i.e. memory or time units) and a default unit to use for this type of unit.

type UnitType struct {
    DefaultUnit Unit
    Units       []Unit
}