Golang:什么是etext?

Bil*_*ill 10 linux profiling go pprof

我已经开始介绍我的一些Go1.2代码,而顶级项目总是名为'etext'.我已经四处搜索但除了它可能与Go例程中的调用深度有关外,找不到有关它的更多信息.但是,我没有使用任何Go例程,'etext'仍占用总执行时间的75%或更多.

(pprof) top20 
Total: 171 samples
    128  74.9%  74.9%      128  74.9% etext
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这是什么以及是否有任何方法可以减少影响?

Xip*_*iao 3

我遇到了同样的问题,然后我发现了这个:pprof bad in go 1.2? 。为了验证这确实是一个 1.2 错误,我编写了以下“hello world”程序:

\n\n
package main\n\nimport (\n    "fmt"\n    "testing"\n)\n\nfunc BenchmarkPrintln( t *testing.B ){\n    TestPrintln( nil )\n}\n\nfunc TestPrintln( t *testing.T ){\n    for i := 0; i < 10000; i++ {\n            fmt.Println("hello " + " world!")\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

如您所见,它只调用 fmt.Println。

\n\n

您可以使用 \xe2\x80\x9cgo test \xe2\x80\x93c 进行编译。\xe2\x80\x9d\n使用 \xe2\x80\x9c./test.test -test.bench 运行。-test.cpuprofile=test.prof\xe2\x80\x9d\n用\xe2\x80\x9cgo工具pprof test.test test.prof\xe2\x80\x9d查看结果

\n\n
(pprof) top10\nTotal: 36 samples\n  18  50.0%  50.0%       18  50.0% syscall.Syscall\n   8  22.2%  72.2%        8  22.2% etext\n   4  11.1%  83.3%        4  11.1% runtime.usleep\n   3   8.3%  91.7%        3   8.3% runtime.futex\n   1   2.8%  94.4%        1   2.8% MHeap_AllocLocked\n   1   2.8%  97.2%        1   2.8% fmt.(*fmt).padString\n   1   2.8% 100.0%        1   2.8% os.epipecheck\n   0   0.0% 100.0%        1   2.8% MCentral_Grow\n   0   0.0% 100.0%       33  91.7% System\n   0   0.0% 100.0%        3   8.3% _/home/xxiao/work/test.BenchmarkPrintln\n
Run Code Online (Sandbox Code Playgroud)\n\n

上述结果是使用 go 1.2.1 得到的\n然后我使用 go 1.1.1 做了同样的事情并得到以下结果:

\n\n
(pprof) top10\nTotal: 10 samples\n   2  20.0%  20.0%        2  20.0% scanblock\n   1  10.0%  30.0%        1  10.0% fmt.(*pp).free\n   1  10.0%  40.0%        1  10.0% fmt.(*pp).printField\n   1  10.0%  50.0%        2  20.0% fmt.newPrinter\n   1  10.0%  60.0%        2  20.0% os.(*File).Write\n   1  10.0%  70.0%        1  10.0% runtime.MCache_Alloc\n   1  10.0%  80.0%        1  10.0% runtime.exitsyscall\n   1  10.0%  90.0%        1  10.0% sweepspan\n   1  10.0% 100.0%        1  10.0% sync.(*Mutex).Lock\n   0   0.0% 100.0%        6  60.0% _/home/xxiao/work/test.BenchmarkPrintln\n
Run Code Online (Sandbox Code Playgroud)\n\n

可以看到1.2.1的结果没有多大意义。Syscall 和 etext 占用了大部分时间。1.1.1 结果看起来是正确的。

\n\n

所以我确信这确实是 1.2.1 的一个错误。我在实际项目中改用 go 1.1.1,现在对分析结果很满意。

\n