Commit 27920c8d authored by Austin Clements's avatar Austin Clements

internal/trace: flags for what to include in GC utilization

Change-Id: I4ba963b003cb25b39d7575d423f17930d84f3f69
Reviewed-on: https://go-review.googlesource.com/c/60796
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarHyang-Ah Hana Kim <hyangah@gmail.com>
parent 603af813
...@@ -38,7 +38,7 @@ func getMMUCurve() ([]trace.MutatorUtil, *trace.MMUCurve, error) { ...@@ -38,7 +38,7 @@ func getMMUCurve() ([]trace.MutatorUtil, *trace.MMUCurve, error) {
if err != nil { if err != nil {
mmuCache.err = err mmuCache.err = err
} else { } else {
mmuCache.util = tr.MutatorUtilization() mmuCache.util = tr.MutatorUtilization(trace.UtilSTW | trace.UtilBackground | trace.UtilAssist)
mmuCache.mmuCurve = trace.NewMMUCurve(mmuCache.util) mmuCache.mmuCurve = trace.NewMMUCurve(mmuCache.util)
} }
}) })
......
...@@ -22,11 +22,27 @@ type MutatorUtil struct { ...@@ -22,11 +22,27 @@ type MutatorUtil struct {
Util float64 Util float64
} }
// UtilFlags controls the behavior of MutatorUtilization.
type UtilFlags int
const (
// UtilSTW means utilization should account for STW events.
UtilSTW UtilFlags = 1 << iota
// UtilBackground means utilization should account for
// background mark workers.
UtilBackground
// UtilAssist means utilization should account for mark
// assists.
UtilAssist
// UtilSweep means utilization should account for sweeping.
UtilSweep
)
// MutatorUtilization returns the mutator utilization function for the // MutatorUtilization returns the mutator utilization function for the
// given trace. This function will always end with 0 utilization. The // given trace. This function will always end with 0 utilization. The
// bounds of the function are implicit in the first and last event; // bounds of the function are implicit in the first and last event;
// outside of these bounds the function is undefined. // outside of these bounds the function is undefined.
func (p *Parsed) MutatorUtilization() []MutatorUtil { func (p *Parsed) MutatorUtilization(flags UtilFlags) []MutatorUtil {
events := p.Events events := p.Events
if len(events) == 0 { if len(events) == 0 {
return nil return nil
...@@ -42,17 +58,33 @@ func (p *Parsed) MutatorUtilization() []MutatorUtil { ...@@ -42,17 +58,33 @@ func (p *Parsed) MutatorUtilization() []MutatorUtil {
case EvGomaxprocs: case EvGomaxprocs:
gomaxprocs = int(ev.Args[0]) gomaxprocs = int(ev.Args[0])
case EvGCSTWStart: case EvGCSTWStart:
stw++ if flags&UtilSTW != 0 {
stw++
}
case EvGCSTWDone: case EvGCSTWDone:
stw-- if flags&UtilSTW != 0 {
stw--
}
case EvGCMarkAssistStart: case EvGCMarkAssistStart:
gcPs++ if flags&UtilAssist != 0 {
assists[ev.G] = true gcPs++
assists[ev.G] = true
}
case EvGCMarkAssistDone: case EvGCMarkAssistDone:
gcPs-- if flags&UtilAssist != 0 {
delete(assists, ev.G) gcPs--
delete(assists, ev.G)
}
case EvGCSweepStart:
if flags&UtilSweep != 0 {
gcPs++
}
case EvGCSweepDone:
if flags&UtilSweep != 0 {
gcPs--
}
case EvGoStartLabel: case EvGoStartLabel:
if strings.HasPrefix(ev.SArgs[0], "GC ") && ev.SArgs[0] != "GC (idle)" { if flags&UtilBackground != 0 && strings.HasPrefix(ev.SArgs[0], "GC ") && ev.SArgs[0] != "GC (idle)" {
// Background mark worker. // Background mark worker.
bgMark[ev.G] = true bgMark[ev.G] = true
gcPs++ gcPs++
......
...@@ -84,7 +84,7 @@ func TestMMUTrace(t *testing.T) { ...@@ -84,7 +84,7 @@ func TestMMUTrace(t *testing.T) {
if err := p.Parse(0, 1<<62, nil); err != nil { if err := p.Parse(0, 1<<62, nil); err != nil {
t.Fatalf("failed to parse trace: %s", err) t.Fatalf("failed to parse trace: %s", err)
} }
mu := p.MutatorUtilization() mu := p.MutatorUtilization(UtilSTW | UtilBackground | UtilAssist)
mmuCurve := NewMMUCurve(mu) mmuCurve := NewMMUCurve(mu)
// Test the optimized implementation against the "obviously // Test the optimized implementation against the "obviously
...@@ -106,7 +106,7 @@ func BenchmarkMMU(b *testing.B) { ...@@ -106,7 +106,7 @@ func BenchmarkMMU(b *testing.B) {
if err := p.Parse(0, 1<<62, nil); err != nil { if err := p.Parse(0, 1<<62, nil); err != nil {
b.Fatalf("failed to parse trace: %s", err) b.Fatalf("failed to parse trace: %s", err)
} }
mu := p.MutatorUtilization() mu := p.MutatorUtilization(UtilSTW | UtilBackground | UtilAssist | UtilSweep)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment