gprofile

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSuggestConfigMin = "15%"
	DefaultSuggestConfig    = []*SuggestConfigItem{
		{
			Path: "runtime/internal/syscall.Syscall6",
			Desc: "系统调用占比大,请考虑减少系统调用",
		},
		{
			Path: "runtime.mallocgc",
			Desc: "内存分配占比大,请考虑减少对象分配或者优化内存逃逸",
		},
		{
			Path: "runtime.gcBgMarkWorker",
			Desc: "内存回收占比大,请考虑减少创建和销毁对象的频率",
		},
		{
			Path: "runtime.mcall",
			Desc: "协程调度占比大,请考虑减少直接或者间接触发锁竞争的操作",
		},
		{
			Path: "runtime.memmove",
			Desc: "内存拷贝占比大,请考虑减少变量的复制或者转换,比如:字符串到字节slice,字节slice到字符串的转换等",
		},
		{
			Path: "runtime.newstack",
			Desc: "系统调用占比大,请检查方法里面,可能分配了代码中根本没有调用关系的变量",
		},
		{
			Path: "runtime.futex",
			Desc: "锁竞争时间占比大,请考虑减少锁的使用,减少锁竞争的发生",
		},
	}
)

Functions

func CountToString

func CountToString(metadata *Metadata, count int64) string

func DumpStringSlice

func DumpStringSlice(list []string)

func GetPercent

func GetPercent(total, val int64) float64

func GetPercentString

func GetPercentString(total, val int64) string

func GoGet

func GoGet(pkg []LibraryInfoItem, env map[string]string, retryCount int) (err error)

func IsGoSrcPkg

func IsGoSrcPkg(p string) bool

func Parse

func Parse(f string, opt *ParseOption) (pb *PprofPBFile, singleItems []*SingleInfo, callItems []*CallInfo, err error)

func PercentFloat

func PercentFloat(percent string) float64

func PercentString

func PercentString(percent float64, keepCount int) string

func ReadableCount

func ReadableCount(count int64) string

Types

type Analyser

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

func (*Analyser) BeginnerFuncs

func (s *Analyser) BeginnerFuncs() []string

BeginnerFuncs 获取全部的"起始方法"

func (*Analyser) GetPBF

func (s *Analyser) GetPBF() *PprofPBFile

func (*Analyser) Suggest

func (s *Analyser) Suggest(defaultMin string, configItems ...*SuggestConfigItem) (ret TopItemList)

func (*Analyser) SumVendor

func (s *Analyser) SumVendor(_min interface{}) (ret SumByCheckerResultItemList)

SumVendor 汇总vendor的“转折点方法”占用情况

逻辑:
1.遍历原始数据全部的调用链,把包含“转折点方法”调用,根据“转折点方法”纬度,进行汇总。

func (*Analyser) Top

func (s *Analyser) Top(_min interface{}) TopItemList

Top 用于获取大于等于这个值的“终点方法”调用,结果是排序好的,

minStr 可能的写法:
内存大小:10B, 100KB, 1M, 1G, 1%
数值类型:10, 1000, 1%
时间类型:1ms, 2s, 3m, 4h, 1.5h, 1%

func (*Analyser) TopN

func (s *Analyser) TopN(count int) TopItemList

TopN 用于获取占用靠前的N个“终点方法”调用,结果是排序好的

type AnalyserParser

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

func NewAnalyserParser

func NewAnalyserParser(defaultOpt *ParseOption, opts ...*ParseOption) (s *AnalyserParser, err error)

NewAnalyserParser 可以同时分析cpu,heap(或allocs),mutex(或block),goroutine

func (*AnalyserParser) DumpTop

func (s *AnalyserParser) DumpTop(list TopItemList) string

func (*AnalyserParser) GetAnalyser

func (s *AnalyserParser) GetAnalyser(profileType ProfileType) *Analyser

func (*AnalyserParser) GoPath

func (s *AnalyserParser) GoPath() string

GoPath 遍历内部全部Analyser,返回第一个非空的GoPath

func (*AnalyserParser) GoRoot

func (s *AnalyserParser) GoRoot() string

GoRoot 遍历内部全部Analyser,返回第一个非空的GoRoot

func (*AnalyserParser) ImportPackageList

func (s *AnalyserParser) ImportPackageList() []string

ImportPackageList 用于获取程序import外部的全部类库的“版本路径”列表,可以用于go get等。

func (*AnalyserParser) TopMultiple

func (s *AnalyserParser) TopMultiple(minMap map[ProfileType]interface{}) (ret TopMultipleItemList)

TopMultiple 多维度top汇总。比如cpu和内存都指向的“转折点方法”

逻辑是:
1.Top出终点方法
2.在终点方法的全部调用路径里面筛选出“转折点方法”
3.取“转折点方法”交集
4.结果是“转折点方法”列表,占用情况是“转折点方法”对应的调用链路占用情况汇总,并不是参数里面的大于min。

type ByCount

type ByCount struct {
	Items     []*CallItem
	Ascending bool
}

func (ByCount) Len

func (a ByCount) Len() int

func (ByCount) Less

func (a ByCount) Less(i, j int) bool

func (ByCount) Swap

func (a ByCount) Swap(i, j int)

type ByTotal

type ByTotal struct {
	Items     []*StackItem
	Ascending bool
}

ByTotal 定义排序的结构体

func (ByTotal) Len

func (a ByTotal) Len() int

func (ByTotal) Less

func (a ByTotal) Less(i, j int) bool

func (ByTotal) Swap

func (a ByTotal) Swap(i, j int)

type CallInfo

type CallInfo struct {
	StartFunc  string
	VendorFunc string
	NextFunc   string
	EndFunc    string
	Count      string
	CountVal   int64
	Percent    string
	PercentVal float64
	// contains filtered or unexported fields
}

func (CallInfo) GetPBF

func (s CallInfo) GetPBF() *PprofPBFile

func (CallInfo) String

func (s CallInfo) String() string

type CallItem

type CallItem struct {
	Percent  float64
	Count    int64
	Path     string
	Stack    []string
	Metadata *Metadata
	// contains filtered or unexported fields
}

func (*CallItem) CountPercent

func (s *CallItem) CountPercent() string

func (*CallItem) CountString

func (s *CallItem) CountString() string

func (*CallItem) EndFunc

func (s *CallItem) EndFunc() string

func (*CallItem) MustStartFunc

func (s *CallItem) MustStartFunc() string

func (*CallItem) MustVendorFunc

func (s *CallItem) MustVendorFunc() string

func (*CallItem) NextFunc

func (s *CallItem) NextFunc() string

func (*CallItem) StartFunc

func (s *CallItem) StartFunc() string

func (*CallItem) VendorFunc

func (s *CallItem) VendorFunc() string

type LibraryInfoItem

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

func (LibraryInfoItem) ImportPath

func (s LibraryInfoItem) ImportPath() string

func (LibraryInfoItem) ModFullPath

func (s LibraryInfoItem) ModFullPath() string

func (LibraryInfoItem) ModPath

func (s LibraryInfoItem) ModPath() string

func (LibraryInfoItem) ModVersion

func (s LibraryInfoItem) ModVersion() string

type MathType

type MathType int
const (
	MathTypeEqual MathType = iota + 1
	MathTypePrefix
)

type Metadata

type Metadata struct {
	File         string
	BuildID      string
	Type         string
	Time         time.Time
	Duration     time.Duration
	TotalSamples int64
}

func NewMetadata

func NewMetadata() *Metadata

func (*Metadata) Parse

func (s *Metadata) Parse(header string)

func (*Metadata) TotalString

func (s *Metadata) TotalString() string

type ParseOption

type ParseOption struct {
	//profile pb.gz 格式文件路径(必须参数)
	File string
	//用来判断一个方法路径是go源码的还是项目的,用来定位调用关系(必须参数)
	VendorPkgChecker func(path string) bool
	// profile 文件类型(必须参数)
	ProfileType ProfileType
}

type PprofPBFile

type PprofPBFile struct {
	ProfileFilePath string
	BinFilename     string
	Metadata        *Metadata
	Stacks          map[string]*StackItem
	RawStacks       []*CallItem
	Option          *ParseOption
	ImportPkgList   []string
	GoPath          string
	GoRoot          string
}

func NewPprofPBFile

func NewPprofPBFile(opt *ParseOption, file string) (pf *PprofPBFile, err error)

func (*PprofPBFile) SortStacks

func (p *PprofPBFile) SortStacks(ascending bool) []*StackItem

SortStacks 对 PprofPBFile 的 Stacks 进行排序的方法

type ProfileInfo

type ProfileInfo struct {
	ImportLibraryList []LibraryInfoItem
	GoRoot            string
	GoPath            string
}

func GetProfileInfo

func GetProfileInfo(files []string) (info *ProfileInfo, err error)

type ProfileType

type ProfileType int
const (
	ProfileTypeCPU ProfileType = iota + 1
	ProfileTypeHeapInuseSpace
	ProfileTypeHeapInuseObjects
	ProfileTypeHeapAllocSpace
	ProfileTypeHeapAllocObjects
	ProfileTypeAllocs
	ProfileTypeBlock
	ProfileTypeMutex
	ProfileTypeGoroutine
)

func (ProfileType) String

func (s ProfileType) String() string

可能档值是:inuse_space, inuse_objects, alloc_space, alloc_objects

type SingleInfo

type SingleInfo struct {
	Path       string
	Count      string
	CountVal   int64
	Percent    string
	PercentVal float64
}

func (SingleInfo) String

func (s SingleInfo) String() string

type SortSumItem

type SortSumItem struct {
	Items     []*SumByCheckerResultItem
	Ascending bool
}

func (SortSumItem) Len

func (a SortSumItem) Len() int

func (SortSumItem) Less

func (a SortSumItem) Less(i, j int) bool

func (SortSumItem) Swap

func (a SortSumItem) Swap(i, j int)

type SortTopMultipleItem

type SortTopMultipleItem struct {
	Items     []*TopMultipleItem
	Ascending bool
}

func (SortTopMultipleItem) Len

func (a SortTopMultipleItem) Len() int

func (SortTopMultipleItem) Less

func (a SortTopMultipleItem) Less(i, j int) bool

func (SortTopMultipleItem) Swap

func (a SortTopMultipleItem) Swap(i, j int)

type StackItem

type StackItem struct {
	Total    int64
	Path     string
	CallInfo []*CallItem
	Metadata *Metadata
}

func (*StackItem) TotalPercent

func (s *StackItem) TotalPercent() string

func (*StackItem) TotalString

func (s *StackItem) TotalString() string

type SuggestConfigItem

type SuggestConfigItem struct {
	Path     string
	Desc     string
	Min      interface{}
	MathType MathType
}

func (*SuggestConfigItem) Match

func (s *SuggestConfigItem) Match(str string) bool

type SumByCheckerResultItem

type SumByCheckerResultItem struct {
	Total      string
	VendorPath string
	TotalVal   int64

	//下面四个值只有Diff返回的时候才有
	RawTotalVal  int64
	DiffTotalVal int64
	RawTotal     string
	DiffTotal    string
	// contains filtered or unexported fields
}

func (SumByCheckerResultItem) GetPBF

func (s SumByCheckerResultItem) GetPBF() *PprofPBFile

func (SumByCheckerResultItem) Percent

func (s SumByCheckerResultItem) Percent() string

type SumByCheckerResultItemList

type SumByCheckerResultItemList []*SumByCheckerResultItem

func (SumByCheckerResultItemList) Diff

Diff 遍历自身列表,减去参数list里面对应的元素方法的占用值。通常用来计算alloc内存和inuse内存差值情况。结果是排序好的。

func (SumByCheckerResultItemList) Dump

func (s SumByCheckerResultItemList) Dump()

func (SumByCheckerResultItemList) String

func (SumByCheckerResultItemList) ToMap

func (s SumByCheckerResultItemList) ToMap() *gmap.Map

func (SumByCheckerResultItemList) TopN

TopN 返回排名前N个。结果是排序好的。

type TopItem

type TopItem struct {
	//只有调用了Suggest方法,此变量才有值
	SuggestConfig *SuggestConfigItem

	Info   *SingleInfo
	Stacks []*CallInfo
	// contains filtered or unexported fields
}

type TopItemList

type TopItemList []*TopItem

func (TopItemList) Dump

func (s TopItemList) Dump()

func (TopItemList) String

func (s TopItemList) String() string

type TopMultipleItem

type TopMultipleItem struct {
	List               []*CallInfo
	Path               string
	TotalMap           map[ProfileType]string
	TotalPercentMap    map[ProfileType]string
	TotalValMap        map[ProfileType]int64
	TotalPercentValMap map[ProfileType]float64
	//对TotalPercentValMap全部值求和,用于排序
	OrderTotalPercent float64
}

type TopMultipleItemList

type TopMultipleItemList []*TopMultipleItem

func (TopMultipleItemList) Dump

func (s TopMultipleItemList) Dump()

func (TopMultipleItemList) String

func (s TopMultipleItemList) String() string

Jump to

Keyboard shortcuts

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