我试图在我的程序中使用pprof,但是,我的文章与我读过的文章略有不同(链接如下).在我的结果中,我得到了这样的表:
(pprof) top10
1.65s of 1.72s total (95.93%)
Showing top 10 nodes out of 114 (cum >= 0.01s)
flat flat% sum% cum cum%
1.19s 69.19% 69.19% 1.20s 69.77% syscall.Syscall
0.16s 9.30% 78.49% 0.16s 9.30% runtime._ExternalCode
Run Code Online (Sandbox Code Playgroud)
这列是什么:flat flat% sum% cum cum%
?
我正在阅读的文章:https : //software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs http://blog.golang.org/profiling-走的程序
我正在运行 GO (1.9.2) 程序,并且我的代码类似于:
startTime := time.Now()
...
...
fmt.Printf("%v (1) %v \n", user.uid, int64(time.Since(startTime)))
fmt.Printf("%v (F) %v \n", user.uid, int64(time.Since(startTime)))
Run Code Online (Sandbox Code Playgroud)
(两个fmt语句在连续行上)
我预计打印输出的时间相似,但以下是打印的一些结果:
921 (1) 2000100
921 (F) 3040173800
Run Code Online (Sandbox Code Playgroud)
(3秒)
360 (1) 2000100
360 (F) 1063060800
Run Code Online (Sandbox Code Playgroud)
(1秒)
447 (1) 4000200
447 (F) 2564146700
Run Code Online (Sandbox Code Playgroud)
(2.5 秒)
两次打印输出之间的时间差始终很大。
这种现象的解释是什么?
额外信息:根据 pprof 的说法,打印时大约有 15000 个 goroutine 正在运行,但大多数都在等待套接字上的传入数据。
我运行了代码,GODEBUG=gctrace=1
但没有太多 GC 打印输出,几乎没有我的代码的打印输出数量那么多。
编辑: 似乎按照@Verran的建议将 time.Since() 的结果存储到变量中解决了这个问题。
更改为fmt
没有log
帮助,但打印不再同步。
fmt
看来“问题”是在高负载环境中处理的方式。我希望有人能够阐明这里发生的事情。
我正在使用"net/http/pprof"在远程服务器上运行我的golang应用程序的远程分析.
我为go工具设置了PPROF_BINARY_PATH env变量,以便能够在我的机器上找到我的本地二进制文件.
当我在go工具pprof cli中使用"list"关键字时 - 当go工具查找.go源文件时,我得到一个"没有这样的文件或目录".
Error: open /go/src/github.com/foo/bar/baz.go: no such file or directory
Run Code Online (Sandbox Code Playgroud)
看起来它正在寻找远程机器的GOPATH中的源文件,它是"/ go /",而在我的个人机器上它是在我的主目录中,因此文件在.
/Users/myuser/go/src/github.com/foo/bar/baz.go
Run Code Online (Sandbox Code Playgroud)
当我将所需的源代码文件复制到我的GOPATH之外并转到go工具正在搜索的目录时 - "list"关键字按预期工作,但这当然不是最佳的.
我正在优化 Go 程序的性能。在查看互斥锁分析时,我得到了
> go tool pprof -seconds 30 -ignore .*Shopify.* http://HOST/debug/pprof/mutex
(pprof) top 20
Active filters:
ignore=.*Shopify.*
Showing nodes accounting for 3.08mins, 91.03% of 3.39mins total
Dropped 82 nodes (cum <= 0.02mins)
flat flat% sum% cum cum%
3.08mins 91.03% 91.03% 3.08mins 91.03% sync.(*Mutex).Unlock
0 0% 91.03% 0.06mins 1.75% ....func2
0 0% 91.03% 0.06mins 1.75% ....func3
Run Code Online (Sandbox Code Playgroud)
代码片段是
. . 502: w.mu.Lock()
. . ... some calculation
. 5.02mins 510: w.mu.Unlock()
. . 511:
. . 512: return nil
. . …
Run Code Online (Sandbox Code Playgroud) 我有一个小程序,使用go例程并行执行大部分代码.我开始进行CPU分析,如博客中描述的分析程序,但是当我查看数据时,我只看到3-5个样本(程序的实际运行时间为几秒).有没有办法提高采样率?尝试谷歌搜索但找不到东西......
如何获得点击数:
(pprof) top
Total: 2525 samples
298 11.8% 11.8% 345 13.7% runtime.mapaccess1_fast64
268 10.6% 22.4% 2124 84.1% main.FindLoops
Run Code Online (Sandbox Code Playgroud)
不,持续时间如:
(pprof) top
2220ms of 3080ms total (72.08%)
Dropped 72 nodes (cum <= 15.40ms)
Showing top 10 nodes out of 111 (cum >= 60ms)
flat flat% sum% cum cum%
1340ms 43.51% 43.51% 1410ms 45.78% runtime.cgocall_errno
Run Code Online (Sandbox Code Playgroud)
环境:我使用golang1.4,添加以下代码.
defer pprof.StopCPUProfile()
f, err := os.Create("innercpu.pprof")
if err != nil {
fmt.Println("Error: ", err)
}
pprof.StartCPUProfile(f)
Run Code Online (Sandbox Code Playgroud) 我正在使用 Go 的 pprof 工具来调查我的服务的内存使用情况。几乎所有内存使用都来自设置多个有界队列通道的单个函数。我对 pprof 在这里告诉我的内容有些困惑:
$ go tool pprof ~/pprof/pprof.server.alloc_objects.alloc_space.inuse_objects.inuse_space.007.pb.gz
File: server
Type: inuse_space
Time: Dec 21, 2020 at 10:46am (PST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) list foo
Total: 102.73MB
ROUTINE ======================== github.com/******/foo in ***.go
79.10MB 79.10MB (flat, cum) 77.00% of Total
. . 135:
. . 136:func foo() {
. . 137:
14.04MB 14.04MB 138: chanA := make(chan chanAEntry, bufferSize)
. . 139: defer close(chanA)
. . 140:
. . 141: …
Run Code Online (Sandbox Code Playgroud) 我一直在尝试分析用 cobra 构建的 cli 工具的堆使用情况。该pprof
工具显示如下,
Flat Flat% Sum% Cum Cum% Name Inlined?
1.58GB 49.98% 49.98% 1.58GB 49.98% os.ReadFile
1.58GB 49.98% 99.95% 1.58GB 50.02% github.com/bytedance/sonic.(*frozenConfig).Unmarshal
0 0.00% 99.95% 3.16GB 100.00% runtime.main
0 0.00% 99.95% 3.16GB 100.00% main.main
0 0.00% 99.95% 3.16GB 100.00% github.com/spf13/cobra.(*Command).execute
0 0.00% 99.95% 3.16GB 100.00% github.com/spf13/cobra.(*Command).ExecuteC
0 0.00% 99.95% 3.16GB 100.00% github.com/spf13/cobra.(*Command).Execute (inline)
0 0.00% 99.95% 3.16GB 100.00% github.com/mirantis/broker/misc.ParseUcpNodesInspect
0 0.00% 99.95% 3.16GB 100.00% github.com/mirantis/broker/cmd.glob..func3
0 0.00% 99.95% 3.16GB 100.00% github.com/mirantis/broker/cmd.getInfos
0 0.00% 99.95% 3.16GB 100.00% …
Run Code Online (Sandbox Code Playgroud) 我最近切换到 go 模块,但似乎无法识别pprof
源文件。也许这里有人知道怎么做?
我尝试使用-source_path
和-trim_path
选项,但我不知道如何使其工作。
有趣的是,o
在 的交互模式下键入pprof
会显示该trim_path
选项,但不会显示source_path
。
只是为了确定:pprof
是否可以使用本地模块并在堆栈跟踪中显示它们的源代码,对吧?
问题
我有一个 go 包,带有测试套件。
当我运行此包的测试套件时,总运行时间约为 7 秒:
$ go test ./mydbpackage/ -count 1
ok mymodule/mydbpackage 7.253s
Run Code Online (Sandbox Code Playgroud)
但是,当我添加-cpuprofile=cpu.out
选项时,采样不会覆盖整个运行:
$ go test ./mydbpackage/ -count 1 -cpuprofile=cpu.out
ok mymodule/mydbpackage 7.029s
$ go tool pprof -text -cum cpu.out
File: mydbpackage.test
Type: cpu
Time: Aug 6, 2020 at 9:42am (CEST)
Duration: 5.22s, Total samples = 780ms (14.95%) # <--- depending on the runs, I get 400ms to 1s
Showing nodes accounting for 780ms, 100% of 780ms total
flat flat% sum% cum cum%
0 …
Run Code Online (Sandbox Code Playgroud)