mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
实装耗时功能, 现在可以看到每个任务与每个请求的耗时
This commit is contained in:
parent
a780f002bf
commit
023e316518
@ -80,7 +80,7 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) {
|
|||||||
logs.Log.Error(err.Error())
|
logs.Log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
start := time.Now()
|
||||||
resp, reqerr := pool.client.Do(pctx, req)
|
resp, reqerr := pool.client.Do(pctx, req)
|
||||||
if pool.ClientType == ihttp.FAST {
|
if pool.ClientType == ihttp.FAST {
|
||||||
defer fasthttp.ReleaseResponse(resp.FastResponse)
|
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 {
|
switch unit.source {
|
||||||
case InitRandomSource:
|
case InitRandomSource:
|
||||||
pool.base = bl
|
pool.base = bl
|
||||||
@ -320,6 +321,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
p.wg.Wait()
|
p.wg.Wait()
|
||||||
p.Statistor.ReqNumber = p.reqCount
|
p.Statistor.ReqNumber = p.reqCount
|
||||||
|
p.Statistor.EndTime = time.Now().Unix()
|
||||||
p.Close()
|
p.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +141,7 @@ func (r *Runner) Prepare(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pool.Run(ctx, r.Offset, r.Limit)
|
pool.Run(ctx, r.Offset, r.Limit)
|
||||||
|
|
||||||
logs.Log.Important(pool.Statistor.String())
|
logs.Log.Important(pool.Statistor.String())
|
||||||
logs.Log.Important(pool.Statistor.Detail())
|
logs.Log.Important(pool.Statistor.Detail())
|
||||||
if r.StatFile != nil {
|
if r.StatFile != nil {
|
||||||
|
@ -72,7 +72,7 @@ type Baseline struct {
|
|||||||
RedirectURL string `json:"redirect_url,omitempty"`
|
RedirectURL string `json:"redirect_url,omitempty"`
|
||||||
FrontURL string `json:"front_url,omitempty"`
|
FrontURL string `json:"front_url,omitempty"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
Spended int `json:"spended"` // 耗时, 毫秒
|
Spended int64 `json:"spend"` // 耗时, 毫秒
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Frameworks Frameworks `json:"frameworks"`
|
Frameworks Frameworks `json:"frameworks"`
|
||||||
Extracteds Extracteds `json:"extracts"`
|
Extracteds Extracteds `json:"extracts"`
|
||||||
@ -164,7 +164,7 @@ func (bl *Baseline) Get(key string) string {
|
|||||||
case "stat", "status":
|
case "stat", "status":
|
||||||
return strconv.Itoa(bl.Status)
|
return strconv.Itoa(bl.Status)
|
||||||
case "spend":
|
case "spend":
|
||||||
return strconv.Itoa(bl.Spended)
|
return strconv.Itoa(int(bl.Spended))
|
||||||
case "extract":
|
case "extract":
|
||||||
return bl.Extracteds.String()
|
return bl.Extracteds.String()
|
||||||
case "frame", "framework":
|
case "frame", "framework":
|
||||||
@ -240,6 +240,8 @@ func (bl *Baseline) String() string {
|
|||||||
line.WriteString(strconv.Itoa(bl.Status))
|
line.WriteString(strconv.Itoa(bl.Status))
|
||||||
line.WriteString(" - ")
|
line.WriteString(" - ")
|
||||||
line.WriteString(strconv.Itoa(bl.BodyLength))
|
line.WriteString(strconv.Itoa(bl.BodyLength))
|
||||||
|
line.WriteString(" - ")
|
||||||
|
line.WriteString(strconv.Itoa(int(bl.Spended)) + "ms")
|
||||||
line.WriteString(bl.Additional("title"))
|
line.WriteString(bl.Additional("title"))
|
||||||
line.WriteString(bl.Frameworks.String())
|
line.WriteString(bl.Frameworks.String())
|
||||||
line.WriteString(bl.Extracteds.String())
|
line.WriteString(bl.Extracteds.String())
|
||||||
|
@ -5,12 +5,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultStatistor Statistor
|
var DefaultStatistor Statistor
|
||||||
|
|
||||||
func NewStatistor(url string) *Statistor {
|
func NewStatistor(url string) *Statistor {
|
||||||
stat := DefaultStatistor
|
stat := DefaultStatistor
|
||||||
|
stat.StartTime = time.Now().Unix()
|
||||||
stat.Counts = make(map[int]int)
|
stat.Counts = make(map[int]int)
|
||||||
stat.BaseUrl = url
|
stat.BaseUrl = url
|
||||||
return &stat
|
return &stat
|
||||||
@ -29,13 +31,15 @@ type Statistor struct {
|
|||||||
End int `json:"end"`
|
End int `json:"end"`
|
||||||
Offset int `json:"offset"`
|
Offset int `json:"offset"`
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
|
StartTime int64 `json:"start_time"`
|
||||||
|
EndTime int64 `json:"end_time"`
|
||||||
Word string `json:"word"`
|
Word string `json:"word"`
|
||||||
Dictionaries []string `json:"dictionaries"`
|
Dictionaries []string `json:"dictionaries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (stat *Statistor) String() string {
|
func (stat *Statistor) String() string {
|
||||||
var s strings.Builder
|
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 {
|
if stat.FuzzyNumber != 0 {
|
||||||
s.WriteString(", fuzzy: " + strconv.Itoa(stat.FuzzyNumber))
|
s.WriteString(", fuzzy: " + strconv.Itoa(stat.FuzzyNumber))
|
||||||
@ -54,6 +58,9 @@ func (stat *Statistor) Detail() string {
|
|||||||
s.WriteString("[stat] ")
|
s.WriteString("[stat] ")
|
||||||
s.WriteString(stat.BaseUrl)
|
s.WriteString(stat.BaseUrl)
|
||||||
for k, v := range stat.Counts {
|
for k, v := range stat.Counts {
|
||||||
|
if k == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
s.WriteString(fmt.Sprintf(" %d: %d,", k, v))
|
s.WriteString(fmt.Sprintf(" %d: %d,", k, v))
|
||||||
}
|
}
|
||||||
return s.String()
|
return s.String()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user