Skip to content

Commit 4808cee

Browse files
committed
Disable profile by default
1 parent 2d1eddb commit 4808cee

9 files changed

+92
-82
lines changed

book.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type book struct {
3737
grpcRunners map[string]*grpcRunner
3838
cdpRunners map[string]*cdpRunner
3939
sshRunners map[string]*sshRunner
40-
disableProfile bool
40+
profile bool
4141
intervalStr string
4242
interval time.Duration
4343
loop *Loop

cmd/loadt.go

-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ var loadtCmd = &cobra.Command{
4747
if err != nil {
4848
return err
4949
}
50-
opts = append(opts, runn.DisableProfile(true))
51-
5250
// setup cache dir
5351
if err := runn.SetCacheDir(flgs.CacheDir); err != nil {
5452
return err

cmd/run.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var runCmd = &cobra.Command{
7676
}
7777
}
7878

79-
if !flgs.DisableProfile {
79+
if flgs.Profile {
8080
p, err := os.Create(filepath.Clean(flgs.ProfileOut))
8181
if err != nil {
8282
return err
@@ -124,7 +124,7 @@ func init() {
124124
runCmd.Flags().IntVarP(&flgs.ShardN, "shard-n", "", 0, flgs.Usage("ShardN"))
125125
runCmd.Flags().IntVarP(&flgs.Random, "random", "", 0, flgs.Usage("Random"))
126126
runCmd.Flags().StringVarP(&flgs.Format, "format", "", "", flgs.Usage("Format"))
127-
runCmd.Flags().BoolVarP(&flgs.DisableProfile, "disable-profile", "", false, flgs.Usage("DisableProfile"))
127+
runCmd.Flags().BoolVarP(&flgs.Profile, "profile", "", false, flgs.Usage("Profile"))
128128
runCmd.Flags().StringVarP(&flgs.ProfileOut, "profile-out", "", "runn.prof", flgs.Usage("ProfileOut"))
129129
runCmd.Flags().StringVarP(&flgs.CacheDir, "cache-dir", "", "", flgs.Usage("CacheDir"))
130130
runCmd.Flags().BoolVarP(&flgs.RetainCacheDir, "retain-cache-dir", "", false, flgs.Usage("RetainCacheDir"))

flags/flags.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Flags struct {
5555
LoadTWarmUp string `usage:"warn-up time for load test"`
5656
LoadTThreshold string `usage:"if this threshold condition is not met, loadt command returns exit status 1 (EXIT_FAILURE)"`
5757
LoadTMaxRPS int `usage:"max RunN per second for load test. 0 means unlimited"`
58-
DisableProfile bool `usage:"disable profile runs of runbooks"`
58+
Profile bool `usage:"profile runs of runbooks"`
5959
ProfileOut string `usage:"profile output path"`
6060
ProfileDepth int `usage:"depth of profile"`
6161
ProfileUnit string `usage:"-"`
@@ -81,7 +81,7 @@ func (f *Flags) ToOpts() ([]runn.Option, error) {
8181
runn.GRPCNoTLS(f.GRPCNoTLS),
8282
runn.GRPCProtos(f.GRPCProtos),
8383
runn.GRPCImportPaths(f.GRPCImportPaths),
84-
runn.DisableProfile(f.DisableProfile),
84+
runn.Profile(f.Profile),
8585
runn.Scopes(f.Scopes...),
8686
runn.RunLabel(f.RunLabels...),
8787
}

include.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (o *operator) newNestedOperator(parent *step, opts ...Option) (*operator, e
135135
}
136136

137137
popts = append(popts, Debug(o.debug))
138-
popts = append(popts, DisableProfile(o.disableProfile))
138+
popts = append(popts, Profile(o.profile))
139139
popts = append(popts, SkipTest(o.skipTest))
140140
popts = append(popts, Force(o.force))
141141
popts = append(popts, Trace(o.trace))

operator.go

+68-68
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ var errStepSkiped = errors.New("step skipped")
3030
var _ otchkiss.Requester = (*operators)(nil)
3131

3232
type operator struct {
33-
id string
34-
httpRunners map[string]*httpRunner
35-
dbRunners map[string]*dbRunner
36-
grpcRunners map[string]*grpcRunner
37-
cdpRunners map[string]*cdpRunner
38-
sshRunners map[string]*sshRunner
39-
steps []*step
40-
store store
41-
desc string
42-
labels []string
43-
useMap bool // Use map syntax in `steps:`.
44-
debug bool
45-
disableProfile bool
46-
interval time.Duration
47-
loop *Loop
33+
id string
34+
httpRunners map[string]*httpRunner
35+
dbRunners map[string]*dbRunner
36+
grpcRunners map[string]*grpcRunner
37+
cdpRunners map[string]*cdpRunner
38+
sshRunners map[string]*sshRunner
39+
steps []*step
40+
store store
41+
desc string
42+
labels []string
43+
useMap bool // Use map syntax in `steps:`.
44+
debug bool
45+
profile bool
46+
interval time.Duration
47+
loop *Loop
4848
// loopIndex - Index of the loop is dynamically recorded at runtime
4949
loopIndex *int
5050
concurrency string
@@ -419,31 +419,31 @@ func New(opts ...Option) (*operator, error) {
419419
bindVars: map[string]any{},
420420
useMap: bk.useMap,
421421
},
422-
useMap: bk.useMap,
423-
desc: bk.desc,
424-
labels: bk.labels,
425-
debug: bk.debug,
426-
disableProfile: bk.disableProfile,
427-
interval: bk.interval,
428-
loop: bk.loop,
429-
concurrency: bk.concurrency,
430-
t: bk.t,
431-
thisT: bk.t,
432-
force: bk.force,
433-
trace: bk.trace,
434-
failFast: bk.failFast,
435-
included: bk.included,
436-
ifCond: bk.ifCond,
437-
skipTest: bk.skipTest,
438-
stdout: bk.stdout,
439-
stderr: bk.stderr,
440-
newOnly: bk.loadOnly,
441-
bookPath: bk.path,
442-
beforeFuncs: bk.beforeFuncs,
443-
afterFuncs: bk.afterFuncs,
444-
sw: stopw.New(),
445-
capturers: bk.capturers,
446-
runResult: newRunResult(bk.desc, bk.labels, bk.path),
422+
useMap: bk.useMap,
423+
desc: bk.desc,
424+
labels: bk.labels,
425+
debug: bk.debug,
426+
profile: bk.profile,
427+
interval: bk.interval,
428+
loop: bk.loop,
429+
concurrency: bk.concurrency,
430+
t: bk.t,
431+
thisT: bk.t,
432+
force: bk.force,
433+
trace: bk.trace,
434+
failFast: bk.failFast,
435+
included: bk.included,
436+
ifCond: bk.ifCond,
437+
skipTest: bk.skipTest,
438+
stdout: bk.stdout,
439+
stderr: bk.stderr,
440+
newOnly: bk.loadOnly,
441+
bookPath: bk.path,
442+
beforeFuncs: bk.beforeFuncs,
443+
afterFuncs: bk.afterFuncs,
444+
sw: stopw.New(),
445+
capturers: bk.capturers,
446+
runResult: newRunResult(bk.desc, bk.labels, bk.path),
447447
}
448448

449449
if o.debug {
@@ -737,7 +737,7 @@ func (o *operator) Run(ctx context.Context) error {
737737
if o.t != nil {
738738
o.t.Helper()
739739
}
740-
if o.disableProfile {
740+
if !o.profile {
741741
o.sw.Disable()
742742
}
743743
defer o.sw.Start().Stop()
@@ -1133,21 +1133,21 @@ func (o *operator) StepResults() []*StepResult {
11331133
}
11341134

11351135
type operators struct {
1136-
ops []*operator
1137-
t *testing.T
1138-
sw *stopw.Span
1139-
disableProfile bool
1140-
shuffle bool
1141-
shuffleSeed int64
1142-
shardN int
1143-
shardIndex int
1144-
sample int
1145-
random int
1146-
concmax int
1147-
opts []Option
1148-
results []*runNResult
1149-
runCount int64
1150-
mu sync.Mutex
1136+
ops []*operator
1137+
t *testing.T
1138+
sw *stopw.Span
1139+
profile bool
1140+
shuffle bool
1141+
shuffleSeed int64
1142+
shardN int
1143+
shardIndex int
1144+
sample int
1145+
random int
1146+
concmax int
1147+
opts []Option
1148+
results []*runNResult
1149+
runCount int64
1150+
mu sync.Mutex
11511151
}
11521152

11531153
func Load(pathp string, opts ...Option) (*operators, error) {
@@ -1165,17 +1165,17 @@ func Load(pathp string, opts ...Option) (*operators, error) {
11651165

11661166
sw := stopw.New()
11671167
ops := &operators{
1168-
t: bk.t,
1169-
sw: sw,
1170-
disableProfile: bk.disableProfile,
1171-
shuffle: bk.runShuffle,
1172-
shuffleSeed: bk.runShuffleSeed,
1173-
shardN: bk.runShardN,
1174-
shardIndex: bk.runShardIndex,
1175-
sample: bk.runSample,
1176-
random: bk.runRandom,
1177-
concmax: 1,
1178-
opts: opts,
1168+
t: bk.t,
1169+
sw: sw,
1170+
profile: bk.profile,
1171+
shuffle: bk.runShuffle,
1172+
shuffleSeed: bk.runShuffleSeed,
1173+
shardN: bk.runShardN,
1174+
shardIndex: bk.runShardIndex,
1175+
sample: bk.runSample,
1176+
random: bk.runRandom,
1177+
concmax: 1,
1178+
opts: opts,
11791179
}
11801180
if bk.runConcurrent {
11811181
ops.concmax = bk.runConcurrentMax
@@ -1404,7 +1404,7 @@ func (ops *operators) runN(ctx context.Context) (*runNResult, error) {
14041404
if ops.t != nil {
14051405
ops.t.Helper()
14061406
}
1407-
if ops.disableProfile {
1407+
if !ops.profile {
14081408
ops.sw.Disable()
14091409
}
14101410
defer ops.sw.Start().Stop()

option.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,14 @@ func Debug(debug bool) Option {
648648
}
649649
}
650650

651-
// DisableProfile - Disable profile.
652-
func DisableProfile(disable bool) Option {
651+
// Profile - Enable profile.
652+
func Profile(enable bool) Option {
653653
return func(bk *book) error {
654654
if bk == nil {
655655
return ErrNilBook
656656
}
657-
if !bk.disableProfile {
658-
bk.disableProfile = disable
657+
if !bk.profile {
658+
bk.profile = enable
659659
}
660660
return nil
661661
}

profile_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestProfile(t *testing.T) {
3737
opts := []Option{
3838
T(t),
3939
Book(tt.book),
40-
DisableProfile(!tt.profile),
40+
Profile(tt.profile),
4141
Runner("db", fmt.Sprintf("sqlite://%s", db.Name())),
4242
Scopes(ScopeAllowRunExec),
4343
}

result_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func TestResultElasped(t *testing.T) {
232232
for _, tt := range tests {
233233
tt := tt
234234
t.Run(tt.book, func(t *testing.T) {
235-
o, err := New(Book(tt.book))
235+
o, err := New(Book(tt.book), Profile(true))
236236
if err != nil {
237237
t.Fatal(err)
238238
}
@@ -242,5 +242,17 @@ func TestResultElasped(t *testing.T) {
242242
t.Error("cannot measure elapsed time")
243243
}
244244
})
245+
246+
t.Run(tt.book, func(t *testing.T) {
247+
o, err := New(Book(tt.book))
248+
if err != nil {
249+
t.Fatal(err)
250+
}
251+
_ = o.Run(ctx)
252+
result := o.Result()
253+
if result.Elapsed != 0 {
254+
t.Error("elapsed time should be zero")
255+
}
256+
})
245257
}
246258
}

0 commit comments

Comments
 (0)