-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Here's an example.
x_test.go:
package p
import (
"sync"
"testing"
)
func BenchmarkBlocking(b *testing.B) {
var mu sync.Mutex
b.RunParallel(func(pb *testing.PB) {
var x int
for pb.Next() {
for i := 0; i < 10000; i++ {
x *= 2
x /= 2
}
mu.Lock()
for i := 0; i < 1000; i++ {
x *= 2
x /= 2
}
mu.Unlock()
}
})
}Do this:
$ go test -bench=. -trace=trace.out
BenchmarkBlocking-8 500000 3401 ns/op
$ go tool trace p.test trace.outThen click on View trace.
Result: Browser tab crashes.
@egonelbre did an initial analysis on a related trace that came from real code (thanks, Egon!):
Preliminary analysis seems to indicate that the trace-viewer is blowing some sort of internal memory limit in Chrome. i.e. the trace json file is 133MB and chrome dies after allocating 800MB of RAM.
Found somewhat related issue google/trace-viewer#298I did some experimenting and was able to load 1.07 million events, but not 1.08M. It seems that trace-viewer can load around ~1M events. The whole dataset is ~1.5M events.
From DOM/JavaScript perspective it is quite impressive that it can handle that much and the tool stays quite responsive.
I think it might be better to do this at the go trace tool level, enforce the limit that you cannot look over 1M events. And then from the selection part you can select the range you wish to see.Note that there is also a possibility of removing some particular counters from the trace.json they make up over half of the events.
Alternatively we can reduce counters using some similarity: https://play.golang.org/p/GnJIyzmsA5
Given how easy it is to create giant (and thus unusable) traces, I think we should handle them gracefully, since the trace-viewer can't.
One option (perhaps not great): 'go tool trace' could allow you to specify a time window to display, and refuse to send windows that are too large to the trace viewer.
/cc @dvyukov @egonelbre