golang无法跳转函数定义

安装gogetdoc
go get -u -v github.com/zmb3/gogetdoc

1、左下角配置里——>settings
在这里插入图片描述
2、更改配置
2.1
在这里插入图片描述
2.2
在这里插入图片描述

完成~~~~~~~~~~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Golang 中,可以为每个函数定义一个 `expvar` 变量来记录该函数的运行次数、运行时间等性能指标。下面是一个简单的示例: ```go package main import ( "expvar" "fmt" "math/rand" "sync" "time" ) var ( processReqCount = expvar.NewMap("processReqCount") reqDuration = expvar.NewMap("reqDuration") reqDurationMu sync.Mutex ) func main() { rand.Seed(time.Now().UnixNano()) for i := 0; i < 10; i++ { processRequest() time.Sleep(time.Second) } fmt.Println("ProcessReq1 count:", processReqCount.Get("ProcessReq1").String()) fmt.Println("ProcessReq2 count:", processReqCount.Get("ProcessReq2").String()) fmt.Println("ProcessReq3 count:", processReqCount.Get("ProcessReq3").String()) fmt.Println("ProcessReq1 duration:", reqDuration.Get("ProcessReq1").Value()) fmt.Println("ProcessReq2 duration:", reqDuration.Get("ProcessReq2").Value()) fmt.Println("ProcessReq3 duration:", reqDuration.Get("ProcessReq3").Value()) } func processRequest() { start := time.Now() switch rand.Intn(3) { case 0: processReq1() case 1: processReq2() case 2: processReq3() } duration := time.Since(start) reqDurationMu.Lock() reqDuration.Add(getFuncName(2), float64(duration.Nanoseconds())/float64(time.Millisecond)) reqDurationMu.Unlock() } func processReq1() { processReqCount.Add("ProcessReq1", 1) time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) } func processReq2() { processReqCount.Add("ProcessReq2", 1) time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) } func processReq3() { processReqCount.Add("ProcessReq3", 1) time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) } func getFuncName(skip int) string { pc, _, _, ok := runtime.Caller(skip) if !ok { return "unknown" } return runtime.FuncForPC(pc).Name() } ``` 在上面的示例中,我们定义了两个 `expvar` 变量,分别是 `processReqCount` 和 `reqDuration`。在 `processRequest` 函数中,我们根据随机数的值选择调用 `processReq1`、`processReq2` 或 `processReq3` 函数。每个函数都对应一个 `processReqCount` 计数器,用来记录该函数被调用的次数。此外,我们还使用了 `reqDuration` 计数器,来记录每个函数的运行时间。在每个函数结束时,我们调用 `getFuncName` 函数来获取当前函数的名称,并将运行时间累加到对应的 `reqDuration` 变量中。最后,我们在主函数中输出了每个函数的执行次数和运行时间。 需要注意的是,在使用 `processReqCount` 和 `reqDuration` 变量时,我们使用了 `expvar.NewMap` 函数来创建一个 `expvar.Map` 对象。`expvar.Map` 对象可以存储 key-value 类型的数据,可以用来实现多个指标的记录。在示例中,我们使用了 `Get` 函数来获取每个函数对应的 `expvar.Int` 变量,并使用 `Add` 函数来增加计数器的值。在使用 `reqDuration` 变量时,我们使用了 `Get` 函数来获取每个函数对应的 `expvar.Float` 变量,并使用 `Add` 函数将运行时间累加到对应的变量中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值