aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/export_debuglog_test.go
AgeCommit message (Collapse)Author
2024-07-30runtime: make TestDebugLogInterleaving much more robustAustin Clements
The current test often doesn't actually generate enough interleaving to result in multiple log shards. This CL rewrites this test to forcibly create at least 10 log shards with interleaved log messages. It also tests dlog's robustness to being held across M and P switches. Change-Id: Ia913b17c0392384ff679832047f359945669bb15 Reviewed-on: https://go-review.googlesource.com/c/go/+/600699 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Austin Clements <austin@google.com>
2024-07-30runtime: run debuglog tests when debuglog tag is *not* setAustin Clements
Currently, the debuglog tests only run when the debuglog build tag is set because, until the last few CLs, all of debuglog was compiled away without that build tag. This causes two annoying problems: 1. The tests basically never run, because we don't regularly test this configuration. 2. If you do turn on the debuglog build tag, it's probably because you're adding debuglogs into the runtime, which are very likely to mess up these tests, so you wind up disabling the tests and they, again, don't get coverage. Now we've set things up so the debuglog implementation is always accessible, if you ask nicely enough. So we can switch these tests to run when the tag is *not* set, and turn off when the tag *is* set (and you're probably adding actual log statements). Change-Id: Ib68d7a5022d4f5db96e9c7c8010cbef21d11fe11 Reviewed-on: https://go-review.googlesource.com/c/go/+/600697 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2024-07-30runtime: switch debuglog from const-toggled to type-toggledAustin Clements
Currently, the debuglog build tag controls the dlogEnabled const, and all methods of dlogger first check this const and immediately return if dlog is not enabled. With constant folding and inlining, this makes the whole dlog implementation compile away if it's not enabled. However, we want to be able to test debuglog even when the build tag isn't set. For that to work, we need a different mechanism. This CL changes this mechanism so the debuglog build tag instead controls the type alias for dlogger to be either dloggerImpl or dloggerFake. These two types have the same method set, but one is just stubs. This way, the methods of dloggerImpl don't need to be conditional dlogEnabled, which sets us up to use the now fully-functional dloggerImpl type in the test. I confirmed that this change has no effect on the final size of the cmd/go binary. It does increase the size of the runtime.a file by 0.9% and make the runtime take ever so slightly longer to compile because the compiler can no longer simply eliminate the bodies of the all of dlogger during early deadcode. However, this all gets eliminated by the linker. I consider this worth it to always get build and test coverage of debuglog. Change-Id: I81759e9e1411b7d369a23383a18b022ab7451421 Reviewed-on: https://go-review.googlesource.com/c/go/+/600696 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-30runtime: rename dlogger to dloggerImplAustin Clements
This is a mechanical change, other than adding the type alias for dlogger. This is a step in preparing us to make debuglog testable without the debuglog build tag. Change-Id: Ief12f0eaf5db98a8b006c759fd325dabcc9a52d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/600695 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-15runtime/metrics: add STW stopping and total time metricsMichael Pratt
This CL adds four new time histogram metrics: /sched/pauses/stopping/gc:seconds /sched/pauses/stopping/other:seconds /sched/pauses/total/gc:seconds /sched/pauses/total/other:seconds The "stopping" metrics measure the time taken to start a stop-the-world pause. i.e., how long it takes stopTheWorldWithSema to stop all Ps. This can be used to detect STW struggling to preempt Ps. The "total" metrics measure the total duration of a stop-the-world pause, from starting to stop-the-world until the world is started again. This includes the time spent in the "start" phase. The "gc" metrics are used for GC-related STW pauses. The "other" metrics are used for all other STW pauses. All of these metrics start timing in stopTheWorldWithSema only after successfully acquiring sched.lock, thus excluding lock contention on sched.lock. The reasoning behind this is that while waiting on sched.lock the world is not stopped at all (all other Ps can run), so the impact of this contention is primarily limited to the goroutine attempting to stop-the-world. Additionally, we already have some visibility into sched.lock contention via contention profiles (#57071). /sched/pauses/total/gc:seconds is conceptually equivalent to /gc/pauses:seconds, so the latter is marked as deprecated and returns the same histogram as the former. In the implementation, there are a few minor differences: * For both mark and sweep termination stops, /gc/pauses:seconds started timing prior to calling startTheWorldWithSema, thus including lock contention. These details are minor enough, that I do not believe the slight change in reporting will matter. For mark termination stops, moving timing stop into startTheWorldWithSema does have the side effect of requiring moving other GC metric calculations outside of the STW, as they depend on the same end time. Fixes #63340 Change-Id: Iacd0bab11bedab85d3dcfb982361413a7d9c0d05 Reviewed-on: https://go-review.googlesource.com/c/go/+/534161 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-05-19runtime: emit STW events for all pauses, not just those for the GCMichael Anthony Knyszek
Currently STW events are only emitted for GC STWs. There's little reason why the trace can't contain events for every STW: they're rare so don't take up much space in the trace, yet being able to see when the world was stopped is often critical to debugging certain latency issues, especially when they stem from user-level APIs. This change adds new "kinds" to the EvGCSTWStart event, renames the GCSTW events to just "STW," and lets the parser deal with unknown STW kinds for future backwards compatibility. But, this change must break trace compatibility, so it bumps the trace version to Go 1.21. This change also includes a small cleanup in the trace command, which previously checked for STW events when deciding whether user tasks overlapped with a GC. Looking at the source, I don't see a way for STW events to ever enter the stream that that code looks at, so that condition has been deleted. Change-Id: I9a5dc144092c53e92eb6950e9a5504a790ac00cf Reviewed-on: https://go-review.googlesource.com/c/go/+/494495 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Knyszek <mknyszek@google.com>
2022-08-02runtime: trivial replacements of g in remaining filesMichael Pratt
Rename g variables to gp for consistency. Change-Id: I09ecdc7e8439637bc0e32f9c5f96f515e6436362 Reviewed-on: https://go-review.googlesource.com/c/go/+/418591 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2019-04-04runtime: ring buffer for binary debug loggingAustin Clements
This adds an internal runtime debug log. It uses per-M time-stamped ring buffers of binary log records. On panic, these buffers are collected, interleaved, and printed. The entry-point to the debug log is a new "dlog" function. dlog is designed so it can be used even from very constrained corners of the runtime such as signal handlers or inside the write barrier. The facility is only enabled if the debuglog build tag is set. Otherwise, it compiles away to a no-op implementation. The debug log format is also designed so it would be reasonable to decode from a core dump, though this hasn't been implemented. Change-Id: I6e2737c286358e97a0d8091826498070b95b66a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/157997 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>