Skip to content

Commit ea2242b

Browse files
committed
asim: don't collect traces when we're not going to record them
This should speed up asim when not using `-rewrite`.
1 parent 8cb5930 commit ea2242b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pkg/kv/kvserver/asim/asim.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ func NewSimulator(
9898
changer := state.NewReplicaChanger()
9999
controllers := make(map[state.StoreID]op.Controller)
100100

101+
var onRecording func(storeID state.StoreID, atDuration time.Duration, rec tracingpb.Recording)
102+
if fn := settings.OnRecording; fn != nil {
103+
onRecording = func(storeID state.StoreID, atDuration time.Duration, rec tracingpb.Recording) {
104+
fn(int64(storeID), atDuration, rec)
105+
}
106+
}
107+
101108
s := &Simulator{
102109
AmbientContext: log.MakeTestingAmbientCtxWithNewTracer(),
103-
onRecording: func(storeID state.StoreID, atDuration time.Duration, rec tracingpb.Recording) {
104-
if fn := settings.OnRecording; fn != nil {
105-
fn(int64(storeID), atDuration, rec)
106-
}
107-
},
110+
// onRecording is intentionally nil if settings.OnRecording is nil, to
111+
// short-circuit trace creation overhead in that case.
112+
onRecording: onRecording,
108113
curr: settings.StartTime,
109114
end: settings.StartTime.Add(duration),
110115
interval: settings.TickInterval,

pkg/kv/kvserver/asim/tests/datadriven_simulation_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,12 @@ func TestDataDriven(t *testing.T) {
577577
seedGen := rand.New(rand.NewSource(seed))
578578
for sample := 0; sample < samples; sample++ {
579579
tr := makeTraceHelper(rewrite, plotDir, testName, sample+1, duration)
580-
settingsGen.Settings.OnRecording = func(storeID int64, atDuration time.Duration, rec tracingpb.Recording) {
581-
tr.OnRecording(t, storeID, atDuration, rec)
580+
if !tr.enabled {
581+
// Only populate OnRecording if we're going to save the results.
582+
// That way, we avoid creating trace spans during normal test runs.
583+
settingsGen.Settings.OnRecording = func(storeID int64, atDuration time.Duration, rec tracingpb.Recording) {
584+
tr.OnRecording(t, storeID, atDuration, rec)
585+
}
582586
}
583587

584588
assertionFailures := []string{}

0 commit comments

Comments
 (0)