For #15490.
Change-Id: Ic587dda1f42d613ea131a6b53ce6ba6e6cadf4c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/690398
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
out.scalar = uint64(in.schedStats.gWaiting)
},
},
+ "/sched/goroutines-created:goroutines": {
+ deps: makeStatDepSet(schedStatsDep),
+ compute: func(in *statAggregate, out *metricValue) {
+ out.kind = metricKindUint64
+ out.scalar = uint64(in.schedStats.gCreated)
+ },
+ },
"/sched/latencies:seconds": {
compute: func(_ *statAggregate, out *metricValue) {
sched.timeToRun.write(out)
gRunnable uint64
gNonGo uint64
gWaiting uint64
+ gCreated uint64
}
// compute populates the schedStatsAggregate with values from the runtime.
lock(&sched.lock)
// Collect running/runnable from per-P run queues.
+ a.gCreated += sched.goroutinesCreated.Load()
for _, p := range allp {
if p == nil || p.status == _Pdead {
break
}
+ a.gCreated += p.goroutinesCreated
switch p.status {
case _Prunning:
a.gRunning++
Description: "The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously.",
Kind: KindUint64,
},
+ {
+ Name: "/sched/goroutines-created:goroutines",
+ Description: "Count of goroutines created since program start.",
+ Cumulative: true,
+ Kind: KindUint64,
+ },
{
Name: "/sched/goroutines/not-in-go:goroutines",
Description: "Approximate count of goroutines running or blocked in a system call or cgo call. Not guaranteed to add up to /sched/goroutines:goroutines with other goroutine metrics.",
operating system threads that can execute user-level Go code
simultaneously.
+ /sched/goroutines-created:goroutines
+ Count of goroutines created since program start.
+
/sched/goroutines/not-in-go:goroutines
Approximate count of goroutines running or blocked in
a system call or cgo call. Not guaranteed to add up to
runnable
running
waiting
+ created
)
- var s [4]metrics.Sample
- s[0].Name = "/sched/goroutines/not-in-go:goroutines"
- s[1].Name = "/sched/goroutines/runnable:goroutines"
- s[2].Name = "/sched/goroutines/running:goroutines"
- s[3].Name = "/sched/goroutines/waiting:goroutines"
+ var s [5]metrics.Sample
+ s[notInGo].Name = "/sched/goroutines/not-in-go:goroutines"
+ s[runnable].Name = "/sched/goroutines/runnable:goroutines"
+ s[running].Name = "/sched/goroutines/running:goroutines"
+ s[waiting].Name = "/sched/goroutines/waiting:goroutines"
+ s[created].Name = "/sched/goroutines-created:goroutines"
logMetrics := func(t *testing.T, s []metrics.Sample) {
for i := range s {
check(t, &s[waiting], 0, waitingSlack)
})
+ metrics.Read(s[:])
+ createdAfterBase := s[created].Value.Uint64()
+
// Force Running count to be high. We'll use these goroutines
// for Runnable, too.
const count = 10
// of runnable goroutines all spinning. We cannot write anything
// out.
if testenv.HasParallelism() {
+ t.Run("created", func(t *testing.T) {
+ metrics.Read(s[:])
+ logMetrics(t, s[:])
+ checkEq(t, &s[created], createdAfterBase+count)
+ })
t.Run("running", func(t *testing.T) {
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(count + 4))
// It can take a little bit for the scheduler to
exit.Store(1)
// Now we can check our invariants.
+ t.Run("created", func(t *testing.T) {
+ // Look for count-1 goroutines because we read metrics
+ // *before* t.Run goroutine was created for this sub-test.
+ checkEq(t, &s[created], createdAfterBase+count-1)
+ })
t.Run("running", func(t *testing.T) {
logMetrics(t, s[:])
checkEq(t, &s[running], 1)
racereleasemergeg(newg, unsafe.Pointer(&labelSync))
}
}
+ pp.goroutinesCreated++
releasem(mp)
return newg
pp.gcAssistTime = 0
gcCleanups.queued += pp.cleanupsQueued
pp.cleanupsQueued = 0
+ sched.goroutinesCreated.Add(int64(pp.goroutinesCreated))
+ pp.goroutinesCreated = 0
pp.xRegs.free()
pp.status = _Pdead
}
// gcStopTime is the nanotime timestamp that this P last entered _Pgcstop.
gcStopTime int64
+ // goroutinesCreated is the total count of goroutines created by this P.
+ goroutinesCreated uint64
+
// xRegs is the per-P extended register state used by asynchronous
// preemption. This is an empty struct on platforms that don't use extended
// register state.
// M, but waiting for locks within the runtime. This field stores the value
// for Ms that have exited.
totalRuntimeLockWaitTime atomic.Int64
+
+ // goroutinesCreated (plus the value of goroutinesCreated on each P in allp)
+ // is the sum of all goroutines created by the program.
+ goroutinesCreated atomic.Uint64
}
// Values for the flags field of a sigTabT.