You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
runtime,runtime/metrics: track on-cpu time per goroutine
Fixesgolang#41554.
This commit introduces a /sched/goroutine/running:nanoseconds metric,
defined as the total time spent by a goroutine in the running state.
This measurement is useful for systems that would benefit from
fine-grained CPU attribution.
An alternative to scheduler-backed CPU attribution would be the use of
profiler labels. Given it's common to spawn multiple goroutines for the
same task, goroutine-backed statistics can easily become misleading.
Profiler labels instead let you measure CPU performance across a set of
cooperating goroutines. That said, it comes with overhead that makes it
unfeasible to always enable. For high-performance systems that care
about fine-grained CPU attribution (databases for e.g. that want to
measure total CPU time spent processing each request), profiler labels
are too cost-prohibitive, especially given the Go runtime has a much
cheaper view of the data needed.
It's worth noting that we already export /sched/latencies:seconds to
track scheduling latencies, i.e. time spent by a goroutine in the
runnable state (go-review.googlesource.com/c/go/+/308933). This commit
does effectively the same except for the running state. Users are free
to use this metric to power histograms or tracking on-CPU time across a
set of goroutines.
Change-Id: Ie78336a3ddeca0521ae29cce57bc7a5ea67da297
Copy file name to clipboardExpand all lines: src/runtime/metrics/description.go
+5
Original file line number
Diff line number
Diff line change
@@ -214,6 +214,11 @@ var allDesc = []Description{
214
214
Description: "All memory mapped by the Go runtime into the current process as read-write. Note that this does not include memory mapped by code called via cgo or via the syscall package. Sum of all metrics in /memory/classes.",
215
215
Kind: KindUint64,
216
216
},
217
+
{
218
+
Name: "/sched/goroutine/running:nanoseconds",
219
+
Description: "Time spent by the current goroutine in the running state.",
0 commit comments