Version: v0.0.0-...-945046d Latest Latest

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 7 Imported by: 4




This section is empty.


This section is empty.


This section is empty.


type FuncInfo

type FuncInfo struct {
	ID string

	PkgName string

	Filename string

	MaxHeatLevel int

	MaxGlobalHeatLevel int

FuncInfo contains some aggregated function info.

type Index

type Index struct {
	// contains filtered or unexported fields

Index represents a parsed profile that can run heatmap queries efficiently.

func NewIndex

func NewIndex(config IndexConfig) *Index

NewIndex creates an empty heatmap index. Use AddProfile method to populate it.

func (*Index) AddProfile

func (index *Index) AddProfile(p *profile.Profile) error

AddProfile adds samples from the profile to the index. In the simplest use case, index only contains one profile.

Adding samples with different labels/metrics is an error.

This operation can take a long time.

func (*Index) CollectFilenames

func (index *Index) CollectFilenames() []string

func (*Index) Inspect

func (index *Index) Inspect(callback func(LineStats))

Inspect visits all data points using the provided callback.

The data points traversal order is not deterministic, but it's guaranteed to walk func-associated data points in source line sorted order.

func (*Index) QueryLine

func (index *Index) QueryLine(key Key, line int) LineStats

func (*Index) QueryLineRange

func (index *Index) QueryLineRange(key Key, lineFrom, lineTo int, callback func(stats LineStats) bool)

QueryLineRange scans the file data points that are located in [lineFrom, lineTo] range. callback is called for every matching data point. Returning false from the callback causes the iteration to stop early.

type IndexConfig

type IndexConfig struct {
	// Threshold specifies where is the line between the "cold" and "hot" code.
	// Zero value implies 0.5, not 0.
	// The threshould value can be interpreted in this way: what percentage
	// of top sample records we're marking as hot. For 0.5 it's top 50% results.
	// A value of 1.0 would includes all results.
	// Threshould should be in the (0, 1.0] range.
	// After the sample is included into the index, it'll be assigned the
	// "heat level". Values that are very close to the lower bound would get
	// a heat level of 1. The top-1 value always gets the level of 5.
	// Values in between get appropriate levels based on their distance.
	// Samples below the threshold may still end up populating the index,
	// but their heat level is guaranteed to be 0.
	// There could be implementation details for edge cases.
	// For example, for files with a low number of samples we may
	// take all of them.
	Threshold float64

type Key

type Key struct {
	// TypeName is a receiver type name for methods.
	// For functions it should be empty.
	TypeName string

	// FuncName is a Go function name.
	// For methods, TypeName+FuncName compose a full method name.
	FuncName string

	// Filename is a base part of the full file path.
	// For the `/home/go/src/bytes/buffer.go` it would be just `buffer.go`.
	Filename string

	// PkgName is a symbol defining package name.
	PkgName string

type LineStats

type LineStats struct {
	LineNum int

	// Value is the aggregated profile samples value for this line.
	Value int64

	// HeatLevel is a file-local heat score according to the index settings.
	// 0 means "cold": this line either didn't appear in the benchmark,
	// or it was below the specified threshold.
	// Non-cold levels go from 1 to 5 (inclusive) with
	// 5 being the hottest level.
	HeatLevel int

	// GlobalHeatLevel is like HeatLevel, but it shows the score
	// based on global stats, not just file-local stats.
	// For example, some file may have lines with high HeatLevel,
	// but these lines may be irrelevant in the global picture.
	// GlobalHeatLevel is based on the aggregated top among all files.
	GlobalHeatLevel int

	// Func is a containing function info.
	// Note: it will be nil for Query functions.
	Func *FuncInfo

Jump to

Keyboard shortcuts

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