diff options
author | Michael Pratt <mpratt@google.com> | 2020-08-07 16:28:35 +0000 |
---|---|---|
committer | Michael Pratt <mpratt@google.com> | 2021-04-23 13:48:10 +0000 |
commit | bedfeed54a7a80123c07f83c325a0bcfe5c43398 (patch) | |
tree | e3cd3332028b2bd64350701f5957b5cfbc0beb3d /src/runtime/runtime2.go | |
parent | 105a6e9518a5195950a2798769af6e86b6d87417 (diff) | |
download | go-bedfeed54a7a80123c07f83c325a0bcfe5c43398.tar.gz go-bedfeed54a7a80123c07f83c325a0bcfe5c43398.zip |
runtime,runtime/metrics: add metric to track scheduling latencies
This change adds a metric to track scheduling latencies, defined as the
cumulative amount of time a goroutine spends being runnable before
running again. The metric is an approximations and samples instead of
trying to record every goroutine scheduling latency.
This change was primarily authored by mknyszek@google.com.
Change-Id: Ie0be7e6e7be421572eb2317d3dd8dd6f3d6aa152
Reviewed-on: https://go-review.googlesource.com/c/go/+/308933
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/runtime2.go')
-rw-r--r-- | src/runtime/runtime2.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index f84cb51bad..7fc7174334 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -462,6 +462,10 @@ type g struct { raceignore int8 // ignore race detection events sysblocktraced bool // StartTrace has emitted EvGoInSyscall about this goroutine + tracking bool // whether we're tracking this G for sched latency statistics + trackingSeq uint8 // used to decide whether to track this G + runnableStamp int64 // timestamp of when the G last became runnable, only used when tracking + runnableTime int64 // the amount of time spent runnable, cleared when running, only used when tracking sysexitticks int64 // cputicks when syscall has returned (for tracing) traceseq uint64 // trace event sequencer tracelastp puintptr // last P emitted an event for this goroutine @@ -493,6 +497,10 @@ type g struct { gcAssistBytes int64 } +// gTrackingPeriod is the number of transitions out of _Grunning between +// latency tracking runs. +const gTrackingPeriod = 8 + const ( // tlsSlots is the number of pointer-sized slots reserved for TLS on some platforms, // like Windows. @@ -824,6 +832,15 @@ type schedt struct { // Acquire and hold this mutex to block sysmon from interacting // with the rest of the runtime. sysmonlock mutex + + _ uint32 // ensure timeToRun has 8-byte alignment + + // timeToRun is a distribution of scheduling latencies, defined + // as the sum of time a G spends in the _Grunnable state before + // it transitions to _Grunning. + // + // timeToRun is protected by sched.lock. + timeToRun timeHistogram } // Values for the flags field of a sigTabT. |