Description
The faketime mechanism used for The Go Playground doesn't cover the timers used in the block and mutex profiles. That makes the playground unhelpful for demonstrating behaviors of those profiles.
It does seem to work with the execution tracer!
It's easiest to see the problem with the block profile, run with "Go 1.24": https://go.dev/play/p/gczXjd0_kT1
I'd expect delays attributable to lines 14, 15, and 16. I'd expect line 15 to have 2x the delay of line 14, and for line 16 to have 3x delay. I'd expect the delays, when divided by the "cycles/second" figure, to correspond with 100, 200, and 300ms.
Instead, line 16 has the shortest reported delay of the three and is reported as 193328/197107886 = 980 µs.
package main
import (
"log"
"os"
"runtime"
"runtime/pprof"
"time"
)
func main() {
runtime.SetBlockProfileRate(1)
<-time.After(100 * time.Millisecond)
<-time.After(200 * time.Millisecond)
<-time.After(300 * time.Millisecond)
if err := pprof.Lookup("block").WriteTo(os.Stdout, 1); err != nil {
log.Fatal(err)
}
}
--- contention:
cycles/second=197107886
14356016 1 @ 0x40beb2 0x4d1bb0 0x43cc3d 0x472781
# 0x40beb1 runtime.chanrecv1+0x11 /usr/local/go-faketime/src/runtime/chan.go:506
# 0x4d1baf main.main+0x2f /tmp/sandbox2369965660/prog.go:14
# 0x43cc3c runtime.main+0x27c /usr/local/go-faketime/src/runtime/proc.go:283
572950 1 @ 0x40beb2 0x4d1bc5 0x43cc3d 0x472781
# 0x40beb1 runtime.chanrecv1+0x11 /usr/local/go-faketime/src/runtime/chan.go:506
# 0x4d1bc4 main.main+0x44 /tmp/sandbox2369965660/prog.go:15
# 0x43cc3c runtime.main+0x27c /usr/local/go-faketime/src/runtime/proc.go:283
193328 1 @ 0x40beb2 0x4d1bd9 0x43cc3d 0x472781
# 0x40beb1 runtime.chanrecv1+0x11 /usr/local/go-faketime/src/runtime/chan.go:506
# 0x4d1bd8 main.main+0x58 /tmp/sandbox2369965660/prog.go:16
# 0x43cc3c runtime.main+0x27c /usr/local/go-faketime/src/runtime/proc.go:283
Here's the execution tracer working: https://go.dev/play/p/ZOMrkPAUbWM
Which after base64-decoding and viewing with "go tool trace" shows a task log of:
When Elapsed Goroutine Events
0.000001215s 49.99904ms Task 1 (goroutine view) (complete)
0.000001215 . 1215 1 task "task" (D 1, parent 18446744073709551615) begin
0.010000255 . 9999040 1 log "10ms"
0.020000191 . 9999936 1 log "20ms"
0.030000191 . 10000000 1 log "30ms"
0.040000191 . 10000000 1 log "40ms"
0.050000191 . 10000000 1 log "50ms"
0.050000255 . 64 1 task end
Metadata
Metadata
Assignees
Labels
Type
Projects
Status