costwhere

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 11 Imported by: 0

README

costwhere

show where your project cost time

install

工具安装

go install github.com/eaglexiang/costwhere-go/cmd/costwhere

包引用

go get github.com/eaglexiang/costwhere-go
// 或
// go get git.eaglexiang.org/eagle/costwhere

代码引用

import costwhere "github.com/eaglexiang/costwhere-go"
// import costwhere "git.eaglexiang.org/eagle/costwhere"

func main() {
	ctx := context.Background()

	// 初始化并回收 costwhere 采集
	ctx, cw := costwhere.Init(ctx)
	defer func() {
		stacks, err := cw.EndWithJSON() // 以 JSON 格式对采集结果进行输出
		if err != nil {
			log.Printf("%+v", err)
			return
		}

		err = os.WriteFile("costwhere.json", stacks, 0644) // 将采集结果保存到文件(或输出到日志)
		if err != nil {
			log.Printf("%+v", err)
		}
	}()

	F(ctx)
}

func F(ctx context.Context) {
	defer costwhere.Mark(ctx)() // 在任何需要进行耗时统计的地方复制粘贴此代码

	time.Sleep(100 * time.Millisecond)
}

dependency install

yay -S flamegraph # archlinux

FlameGraph

use

costwhere -if="./data.json" -of="./flamegraph.svg"
# output flamegraph.svg

output

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mark added in v0.4.0

func Mark(ctx context.Context) (end func())

Types

type Cost added in v0.4.0

type Cost struct {
	Path        string
	CalledCount int
	Cost        time.Duration
}

type CostWhere

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

func Init

func Init(ctx context.Context, opts ...InitOption) (newCtx context.Context, c *CostWhere)

func (*CostWhere) EndWithJSON added in v0.4.0

func (s *CostWhere) EndWithJSON() (j []byte, err error)

func (*CostWhere) Export added in v0.5.0

func (s *CostWhere) Export() (output Output)

func (*CostWhere) ExportJSON added in v0.4.0

func (s *CostWhere) ExportJSON() (j []byte, err error)

type Costs added in v0.4.0

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

type InitOption added in v0.5.0

type InitOption struct {
	CompressPath *bool // 是否压缩路径,默认为 true
	PathDict     map[string]string
}

type Output added in v0.5.0

type Output struct {
	Stacks []string `json:"stacks"`
}

Directories

Path Synopsis
cmd
tests

Jump to

Keyboard shortcuts

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