From 63ceff95fa7cc93dd848b503dedcef53b918cdc3 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Wed, 31 Aug 2022 21:34:23 +0000 Subject: runtime/metrics: add /sync/mutex/wait/total:seconds metric This change adds a metric to the runtime/metrics package which tracks total mutex wait time for sync.Mutex and sync.RWMutex. The purpose of this metric is to be able to quickly get an idea of the total mutex wait time. The implementation of this metric piggybacks off of the existing G runnable tracking infrastructure, as well as the wait reason set on a G when it goes into _Gwaiting. Fixes #49881. Change-Id: I4691abf64ac3574bec69b4d7d4428b1573130517 Reviewed-on: https://go-review.googlesource.com/c/go/+/427618 Reviewed-by: Michael Pratt Auto-Submit: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Gopher Robot --- src/runtime/export_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/runtime/export_test.go') diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 93cae48211..4aabf90fe7 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -525,6 +525,12 @@ func Getg() *G { return getg() } +func GIsWaitingOnMutex(gp *G) bool { + return readgstatus(gp) == _Gwaiting && gp.waitreason.isMutexWait() +} + +var CasGStatusAlwaysTrack = &casgstatusAlwaysTrack + //go:noinline func PanicForTesting(b []byte, i int) byte { return unexportedPanicForTesting(b, i) @@ -1617,3 +1623,5 @@ func (s *ScavengeIndex) Mark(base, limit uintptr) { func (s *ScavengeIndex) Clear(ci ChunkIdx) { s.i.clear(chunkIdx(ci)) } + +const GTrackingPeriod = gTrackingPeriod -- cgit v1.3-5-g9baa