From 023e316518c1f0189dd574ef2676053c36cf0567 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Fri, 2 Dec 2022 18:29:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=A3=85=E8=80=97=E6=97=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD,=20=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5=E7=9C=8B?= =?UTF-8?q?=E5=88=B0=E6=AF=8F=E4=B8=AA=E4=BB=BB=E5=8A=A1=E4=B8=8E=E6=AF=8F?= =?UTF-8?q?=E4=B8=AA=E8=AF=B7=E6=B1=82=E7=9A=84=E8=80=97=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pool.go | 4 +++- internal/runner.go | 1 + pkg/baseline.go | 6 ++++-- pkg/statistor.go | 9 ++++++++- pkg/types.go | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/pool.go b/internal/pool.go index 61b8508..4938a14 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -80,7 +80,7 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { logs.Log.Error(err.Error()) return } - + start := time.Now() resp, reqerr := pool.client.Do(pctx, req) if pool.ClientType == ihttp.FAST { defer fasthttp.ReleaseResponse(resp.FastResponse) @@ -117,6 +117,7 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { } } + bl.Spended = time.Since(start).Milliseconds() switch unit.source { case InitRandomSource: pool.base = bl @@ -320,6 +321,7 @@ Loop: } p.wg.Wait() p.Statistor.ReqNumber = p.reqCount + p.Statistor.EndTime = time.Now().Unix() p.Close() } diff --git a/internal/runner.go b/internal/runner.go index cc40cd1..9822392 100644 --- a/internal/runner.go +++ b/internal/runner.go @@ -141,6 +141,7 @@ func (r *Runner) Prepare(ctx context.Context) error { } pool.Run(ctx, r.Offset, r.Limit) + logs.Log.Important(pool.Statistor.String()) logs.Log.Important(pool.Statistor.Detail()) if r.StatFile != nil { diff --git a/pkg/baseline.go b/pkg/baseline.go index 445bb78..152c3ab 100644 --- a/pkg/baseline.go +++ b/pkg/baseline.go @@ -72,7 +72,7 @@ type Baseline struct { RedirectURL string `json:"redirect_url,omitempty"` FrontURL string `json:"front_url,omitempty"` Status int `json:"status"` - Spended int `json:"spended"` // 耗时, 毫秒 + Spended int64 `json:"spend"` // 耗时, 毫秒 Title string `json:"title"` Frameworks Frameworks `json:"frameworks"` Extracteds Extracteds `json:"extracts"` @@ -164,7 +164,7 @@ func (bl *Baseline) Get(key string) string { case "stat", "status": return strconv.Itoa(bl.Status) case "spend": - return strconv.Itoa(bl.Spended) + return strconv.Itoa(int(bl.Spended)) case "extract": return bl.Extracteds.String() case "frame", "framework": @@ -240,6 +240,8 @@ func (bl *Baseline) String() string { line.WriteString(strconv.Itoa(bl.Status)) line.WriteString(" - ") line.WriteString(strconv.Itoa(bl.BodyLength)) + line.WriteString(" - ") + line.WriteString(strconv.Itoa(int(bl.Spended)) + "ms") line.WriteString(bl.Additional("title")) line.WriteString(bl.Frameworks.String()) line.WriteString(bl.Extracteds.String()) diff --git a/pkg/statistor.go b/pkg/statistor.go index 757ace3..61b8a36 100644 --- a/pkg/statistor.go +++ b/pkg/statistor.go @@ -5,12 +5,14 @@ import ( "fmt" "strconv" "strings" + "time" ) var DefaultStatistor Statistor func NewStatistor(url string) *Statistor { stat := DefaultStatistor + stat.StartTime = time.Now().Unix() stat.Counts = make(map[int]int) stat.BaseUrl = url return &stat @@ -29,13 +31,15 @@ type Statistor struct { End int `json:"end"` Offset int `json:"offset"` Total int `json:"total"` + StartTime int64 `json:"start_time"` + EndTime int64 `json:"end_time"` Word string `json:"word"` Dictionaries []string `json:"dictionaries"` } func (stat *Statistor) String() string { var s strings.Builder - s.WriteString(fmt.Sprintf("[stat] %s request total: %d, found: %d, check: %d, failed: %d", stat.BaseUrl, stat.ReqNumber, stat.FoundNumber, stat.CheckNumber, stat.FailedNumber)) + s.WriteString(fmt.Sprintf("[stat] %s took %d s, request total: %d, found: %d, check: %d, failed: %d", stat.BaseUrl, stat.EndTime-stat.StartTime, stat.ReqNumber, stat.FoundNumber, stat.CheckNumber, stat.FailedNumber)) if stat.FuzzyNumber != 0 { s.WriteString(", fuzzy: " + strconv.Itoa(stat.FuzzyNumber)) @@ -54,6 +58,9 @@ func (stat *Statistor) Detail() string { s.WriteString("[stat] ") s.WriteString(stat.BaseUrl) for k, v := range stat.Counts { + if k == 0 { + continue + } s.WriteString(fmt.Sprintf(" %d: %d,", k, v)) } return s.String() diff --git a/pkg/types.go b/pkg/types.go index 4fc87f6..0ae34ee 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -11,7 +11,7 @@ type Frameworks []*parsers.Framework func (fs Frameworks) String() string { frameworkStrs := make([]string, len(fs)) for i, f := range fs { - frameworkStrs[i] = "[" + f.ToString() + "]" + frameworkStrs[i] = " [" + f.ToString() + "]" } return strings.Join(frameworkStrs, " ") + " " }