mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:29:48 +08:00
feat: log feed screenshot take/cv elapsed time
This commit is contained in:
@@ -59,7 +59,12 @@ type ScreenResult struct {
|
||||
|
||||
SwipeStartTime int64 `json:"swipe_start_time"` // 滑动开始时间戳
|
||||
SwipeFinishTime int64 `json:"swipe_finish_time"` // 滑动结束时间戳
|
||||
Elapsed int64 `json:"elapsed"` // current_swipe_finish -> next_swipe_start 整体耗时(ms)
|
||||
|
||||
ScreenshotTakeElapsed int64 `json:"screenshot_take_elapsed"` // 设备截图耗时(ms)
|
||||
ScreenshotCVElapsed int64 `json:"screenshot_cv_elapsed"` // CV 识别耗时(ms)
|
||||
|
||||
// 当前 Feed/Live 整体耗时
|
||||
TotalElapsed int64 `json:"total_elapsed"` // current_swipe_finish -> next_swipe_start 整体耗时(ms)
|
||||
}
|
||||
|
||||
type cacheStepData struct {
|
||||
@@ -231,12 +236,14 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
|
||||
"width": screenSize.Width,
|
||||
"height": screenSize.Height,
|
||||
},
|
||||
"video_type": screenResult.VideoType,
|
||||
"feed": screenResult.Feed,
|
||||
"live": screenResult.Live,
|
||||
"swipe_start_time": screenResult.SwipeStartTime,
|
||||
"swipe_finish_time": screenResult.SwipeFinishTime,
|
||||
"elapsed": screenResult.Elapsed,
|
||||
"video_type": screenResult.VideoType,
|
||||
"feed": screenResult.Feed,
|
||||
"live": screenResult.Live,
|
||||
"swipe_start_time": screenResult.SwipeStartTime,
|
||||
"swipe_finish_time": screenResult.SwipeFinishTime,
|
||||
"screenshot_take_elapsed": screenResult.ScreenshotTakeElapsed,
|
||||
"screenshot_cv_elapsed": screenResult.ScreenshotCVElapsed,
|
||||
"total_elapsed": screenResult.TotalElapsed,
|
||||
}
|
||||
|
||||
screenResults[imagePath] = data
|
||||
|
||||
@@ -343,12 +343,14 @@ type IImageService interface {
|
||||
|
||||
// GetScreenResult takes a screenshot, returns the image recognization result
|
||||
func (dExt *DriverExt) GetScreenResult() (screenResult *ScreenResult, err error) {
|
||||
startTime := time.Now()
|
||||
var bufSource *bytes.Buffer
|
||||
var imagePath string
|
||||
if bufSource, imagePath, err = dExt.takeScreenShot(
|
||||
builtin.GenNameWithTimestamp("%d_cv")); err != nil {
|
||||
return
|
||||
}
|
||||
screenshotTakeElapsed := time.Since(startTime).Milliseconds()
|
||||
|
||||
imageResult, err := dExt.ImageService.GetImage(bufSource, actionOptions{"ocr", "upload", "liveType"})
|
||||
if err != nil {
|
||||
@@ -364,8 +366,10 @@ func (dExt *DriverExt) GetScreenResult() (screenResult *ScreenResult, err error)
|
||||
}
|
||||
|
||||
screenResult = &ScreenResult{
|
||||
Texts: imageResult.OCRResult.ToOCRTexts(),
|
||||
Tags: nil,
|
||||
Texts: imageResult.OCRResult.ToOCRTexts(),
|
||||
Tags: nil,
|
||||
ScreenshotTakeElapsed: screenshotTakeElapsed,
|
||||
ScreenshotCVElapsed: time.Since(startTime).Milliseconds() - screenshotTakeElapsed,
|
||||
}
|
||||
if imageResult.LiveType != "" && imageResult.LiveType != "NoLive" {
|
||||
screenResult.Live = &LiveRoom{
|
||||
@@ -374,6 +378,10 @@ func (dExt *DriverExt) GetScreenResult() (screenResult *ScreenResult, err error)
|
||||
}
|
||||
dExt.cacheStepData.screenResults[imagePath] = screenResult
|
||||
|
||||
log.Debug().
|
||||
Int64("ScreenshotTakeElapsed", screenResult.ScreenshotTakeElapsed).
|
||||
Int64("ScreenshotCVElapsed", screenResult.ScreenshotCVElapsed).
|
||||
Msg("get screenshot result success")
|
||||
return screenResult, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error {
|
||||
// log swipe timelines
|
||||
screenResult.SwipeStartTime = swipeStartTime.UnixMilli()
|
||||
screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli()
|
||||
screenResult.Elapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
// log swipe timelines
|
||||
screenResult.SwipeStartTime = swipeStartTime.UnixMilli()
|
||||
screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli()
|
||||
screenResult.Elapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user