From 7c58ef732efd9bf0d0882bb95371ce1909924a75 Mon Sep 17 00:00:00 2001
From: Martin Möhrmann
Date: Mon, 14 Sep 2020 16:55:34 +0200
Subject: runtime: implement GODEBUG=inittrace=1 support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Setting inittrace=1 causes the runtime to emit a single line to standard error for
each package with init work, summarizing the execution time and memory allocation.
The emitted debug information for init functions can be used to find bottlenecks
or regressions in Go startup performance.
Packages with no init function work (user defined or compiler generated) are omitted.
Tracing plugin inits is not supported as they can execute concurrently. This would
make the implementation of tracing more complex while adding support for a very rare
use case. Plugin inits can be traced separately by testing a main package importing
the plugins package imports explicitly.
$ GODEBUG=inittrace=1 go test
init internal/bytealg @0.008 ms, 0 ms clock, 0 bytes, 0 allocs
init runtime @0.059 ms, 0.026 ms clock, 0 bytes, 0 allocs
init math @0.19 ms, 0.001 ms clock, 0 bytes, 0 allocs
init errors @0.22 ms, 0.004 ms clock, 0 bytes, 0 allocs
init strconv @0.24 ms, 0.002 ms clock, 32 bytes, 2 allocs
init sync @0.28 ms, 0.003 ms clock, 16 bytes, 1 allocs
init unicode @0.44 ms, 0.11 ms clock, 23328 bytes, 24 allocs
...
Inspired by stapelberg@google.com who instrumented doInit
in a prototype to measure init times with GDB.
Fixes #41378
Change-Id: Ic37c6a0cfc95488de9e737f5e346b8dbb39174e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/254659
Trust: Martin Möhrmann
Run-TryBot: Martin Möhrmann
TryBot-Result: Go Bot
Reviewed-by: Keith Randall
---
doc/diagnostics.html | 2 ++
1 file changed, 2 insertions(+)
(limited to 'doc/diagnostics.html')
diff --git a/doc/diagnostics.html b/doc/diagnostics.html
index 478611c15c..f9368886c4 100644
--- a/doc/diagnostics.html
+++ b/doc/diagnostics.html
@@ -454,6 +454,8 @@ environmental variable is set accordingly.
GODEBUG=gctrace=1 prints garbage collector events at
each collection, summarizing the amount of memory collected
and the length of the pause.
+GODEBUG=inittrace=1 prints a summary of execution time and memory allocation
+information for completed package initilization work.
GODEBUG=schedtrace=X prints scheduling events every X milliseconds.
--
cgit v1.3
From 3fd491747247e95d00e24feccd1568b9e7eb37b4 Mon Sep 17 00:00:00 2001
From: Hollow Man
Date: Fri, 20 Nov 2020 16:44:15 +0000
Subject: doc: fix misspelling of “initialization” in diagnostics.html
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
initilization -> initialization
Change-Id: Ie5edd30559941f2d044280d8d586c2c2692d5b69
GitHub-Last-Rev: 7495a8c7227bc9c574c93861e5fedc1bada0397c
GitHub-Pull-Request: golang/go#42749
Reviewed-on: https://go-review.googlesource.com/c/go/+/272026
Reviewed-by: Emmanuel Odeke
Trust: Ian Lance Taylor
---
doc/diagnostics.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'doc/diagnostics.html')
diff --git a/doc/diagnostics.html b/doc/diagnostics.html
index f9368886c4..438cdce45f 100644
--- a/doc/diagnostics.html
+++ b/doc/diagnostics.html
@@ -455,7 +455,7 @@ environmental variable is set accordingly.
each collection, summarizing the amount of memory collected
and the length of the pause.
GODEBUG=inittrace=1 prints a summary of execution time and memory allocation
-information for completed package initilization work.
+information for completed package initialization work.
GODEBUG=schedtrace=X prints scheduling events every X milliseconds.
--
cgit v1.3