support --no-stat flag

This commit is contained in:
M09Ic 2024-07-14 04:16:12 +08:00
parent 3f4094d89e
commit f942c9c1b3
3 changed files with 18 additions and 8 deletions

View File

@ -93,6 +93,7 @@ type OutputOptions struct {
Quiet bool `short:"q" long:"quiet" description:"Bool, Quiet" config:"quiet"`
NoColor bool `long:"no-color" description:"Bool, no color" config:"no-color"`
NoBar bool `long:"no-bar" description:"Bool, No progress bar" config:"no-bar"`
NoStat bool `long:"no-stat" description:"Bool, No stat file output" config:"no-stat"`
}
type RequestOptions struct {
@ -719,11 +720,14 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
if err != nil {
return nil, err
}
if !opt.NoStat {
r.StatFile.Mod = os.O_WRONLY | os.O_CREATE
err = r.StatFile.Init()
if err != nil {
return nil, err
}
}
return r, nil
}

View File

@ -154,7 +154,9 @@ func (r *Runner) Prepare(ctx context.Context) error {
r.Pools, err = ants.NewPoolWithFunc(r.PoolSize, func(i interface{}) {
t := i.(*Task)
if t.origin != nil && t.origin.End == t.origin.Total {
if r.StatFile != nil {
r.StatFile.SafeWrite(t.origin.Json())
}
r.Done()
return
}
@ -231,10 +233,14 @@ Loop:
if len(r.taskCh) > 0 {
for t := range r.taskCh {
stat := pkg.NewStatistor(t.baseUrl)
if r.StatFile != nil {
r.StatFile.SafeWrite(stat.Json())
}
}
}
if r.StatFile != nil {
logs.Log.Importantf("already save all stat to %s", r.StatFile.Filename)
}
break Loop
case t, ok := <-r.taskCh:
if !ok {

@ -1 +1 @@
Subproject commit f1150d00253e0c888976dbfe55cf2669c51f0b58
Subproject commit ebc4dc165fccdf3be5745410da7e266fe2135916