mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 21:39:41 +08:00
feat: integrage ios performance monitor
This commit is contained in:
@@ -131,8 +131,10 @@ type DriverExt struct {
|
||||
frame *bytes.Buffer
|
||||
doneMjpegStream chan bool
|
||||
scale float64
|
||||
StartTime time.Time // used to associate screenshots name
|
||||
ScreenShots []string // save screenshots path
|
||||
StartTime time.Time // used to associate screenshots name
|
||||
ScreenShots []string // save screenshots path
|
||||
perfStop chan struct{} // stop performance monitor
|
||||
perfData []string // save perf data
|
||||
|
||||
CVArgs
|
||||
}
|
||||
@@ -154,6 +156,14 @@ func extend(driver WebDriver) (dExt *DriverExt, err error) {
|
||||
return dExt, nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) GetPerfData() []string {
|
||||
if dExt.perfStop == nil {
|
||||
return nil
|
||||
}
|
||||
close(dExt.perfStop)
|
||||
return dExt.perfData
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) takeScreenShot() (raw *bytes.Buffer, err error) {
|
||||
// wait for action done
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
@@ -92,6 +92,28 @@ func InitWDAClient(device *IOSDevice) (*DriverExt, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if device.PerfOptions != nil {
|
||||
data, err := iosDevice.d.PerfStart(device.perfOpitons()...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
driverExt.perfStop = make(chan struct{})
|
||||
// start performance monitor
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-driverExt.perfStop:
|
||||
iosDevice.d.PerfStop()
|
||||
return
|
||||
case d := <-data:
|
||||
fmt.Println(string(d))
|
||||
driverExt.perfData = append(driverExt.perfData, string(d))
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
driverExt.UUID = iosDevice.UUID()
|
||||
return driverExt, nil
|
||||
}
|
||||
@@ -122,6 +144,15 @@ func WithLogOn(logOn bool) IOSDeviceOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithPerfOptions(options ...giDevice.PerfOption) IOSDeviceOption {
|
||||
return func(device *IOSDevice) {
|
||||
device.PerfOptions = &giDevice.PerfOptions{}
|
||||
for _, option := range options {
|
||||
option(device.PerfOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func IOSDevices(udid ...string) (devices []giDevice.Device, err error) {
|
||||
var usbmux giDevice.Usbmux
|
||||
if usbmux, err = giDevice.NewUsbmux(); err != nil {
|
||||
@@ -171,11 +202,12 @@ func NewIOSDevice(options ...IOSDeviceOption) (device *IOSDevice, err error) {
|
||||
}
|
||||
|
||||
type IOSDevice struct {
|
||||
d giDevice.Device
|
||||
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
||||
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
d giDevice.Device
|
||||
PerfOptions *giDevice.PerfOptions `json:"perf_options,omitempty" yaml:"perf_options,omitempty"`
|
||||
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
||||
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
}
|
||||
|
||||
func (dev *IOSDevice) UUID() string {
|
||||
@@ -240,6 +272,57 @@ func (dev *IOSDevice) opitons() (deviceOptions []IOSDeviceOption) {
|
||||
return
|
||||
}
|
||||
|
||||
func (dev *IOSDevice) perfOpitons() (perfOptions []giDevice.PerfOption) {
|
||||
if dev.PerfOptions == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// system
|
||||
if dev.PerfOptions.SysCPU {
|
||||
perfOptions = append(perfOptions, giDevice.WithPerfSystemCPU(true))
|
||||
}
|
||||
if dev.PerfOptions.SysMem {
|
||||
perfOptions = append(perfOptions, giDevice.WithPerfSystemMem(true))
|
||||
}
|
||||
if dev.PerfOptions.SysDisk {
|
||||
perfOptions = append(perfOptions, giDevice.WithPerfSystemDisk(true))
|
||||
}
|
||||
if dev.PerfOptions.SysNetwork {
|
||||
perfOptions = append(perfOptions, giDevice.WithPerfSystemNetwork(true))
|
||||
}
|
||||
if dev.PerfOptions.FPS {
|
||||
perfOptions = append(perfOptions, giDevice.WithPerfFPS(true))
|
||||
}
|
||||
if dev.PerfOptions.Network {
|
||||
perfOptions = append(perfOptions, giDevice.WithPerfNetwork(true))
|
||||
}
|
||||
|
||||
// process
|
||||
if dev.PerfOptions.BundleID != "" {
|
||||
perfOptions = append(perfOptions,
|
||||
giDevice.WithPerfBundleID(dev.PerfOptions.BundleID))
|
||||
}
|
||||
if dev.PerfOptions.Pid != 0 {
|
||||
perfOptions = append(perfOptions,
|
||||
giDevice.WithPerfPID(dev.PerfOptions.Pid))
|
||||
}
|
||||
|
||||
// config
|
||||
if dev.PerfOptions.OutputInterval != 0 {
|
||||
perfOptions = append(perfOptions,
|
||||
giDevice.WithPerfOutputInterval(dev.PerfOptions.OutputInterval))
|
||||
}
|
||||
if dev.PerfOptions.SystemAttributes != nil {
|
||||
perfOptions = append(perfOptions,
|
||||
giDevice.WithPerfSystemAttributes(dev.PerfOptions.SystemAttributes...))
|
||||
}
|
||||
if dev.PerfOptions.ProcessAttributes != nil {
|
||||
perfOptions = append(perfOptions,
|
||||
giDevice.WithPerfProcessAttributes(dev.PerfOptions.ProcessAttributes...))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NewHTTPDriver creates new remote HTTP client, this will also start a new session.
|
||||
func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver WebDriver, err error) {
|
||||
localPort, err := getFreePort()
|
||||
|
||||
@@ -55,7 +55,7 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
|
||||
return nil, fmt.Errorf("close body writer error: %v", err)
|
||||
}
|
||||
|
||||
url, _ := base64.StdEncoding.DecodeString("aHR0cHM6Ly9odWJibGUuYnl0ZWRhbmNlLm5ldC92aWRlby9hcGkvdjEvYWxnb3JpdGhtL29jcg==")
|
||||
url, _ := base64.StdEncoding.DecodeString("aHR0cHM6Ly9ndGZ0YXNrLmJ5dGVkYW5jZS5jb20vYXBpL3YxL2FsZ29yaXRobS9vY3I=")
|
||||
req, err := http.NewRequest("POST", string(url), bodyBuf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("construct request error: %v", err)
|
||||
|
||||
@@ -1 +1 @@
|
||||
v4.3.0-beta-10081235
|
||||
v4.3.0-beta-10101409
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -162,8 +161,8 @@ func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
||||
caseSummary.InOut.ExportVars = exportVars
|
||||
caseSummary.InOut.ConfigVars = r.parsedConfig.Variables
|
||||
|
||||
// add WDA/UIA logs to summary
|
||||
for uuid, client := range r.hrpRunner.uiClients {
|
||||
// add WDA/UIA logs to summary
|
||||
log, err := client.Driver.StopCaptureLog()
|
||||
if err != nil {
|
||||
return caseSummary, err
|
||||
@@ -172,6 +171,10 @@ func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
||||
"uuid": uuid,
|
||||
"content": log,
|
||||
}
|
||||
|
||||
// stop performance monitor
|
||||
logs["performance"] = client.GetPerfData()
|
||||
|
||||
caseSummary.Logs = append(caseSummary.Logs, logs)
|
||||
}
|
||||
|
||||
|
||||
21
hrp/step.go
21
hrp/step.go
@@ -1,6 +1,10 @@
|
||||
package hrp
|
||||
|
||||
import "github.com/httprunner/httprunner/v4/hrp/internal/uixt"
|
||||
import (
|
||||
giDevice "github.com/electricbubble/gidevice"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
|
||||
)
|
||||
|
||||
type StepType string
|
||||
|
||||
@@ -24,6 +28,21 @@ var (
|
||||
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
|
||||
)
|
||||
|
||||
var (
|
||||
WithPerfSystemCPU = giDevice.WithPerfSystemCPU
|
||||
WithPerfSystemMem = giDevice.WithPerfSystemMem
|
||||
WithPerfSystemDisk = giDevice.WithPerfSystemDisk
|
||||
WithPerfSystemNetwork = giDevice.WithPerfSystemNetwork
|
||||
WithPerfGPU = giDevice.WithPerfGPU
|
||||
WithPerfFPS = giDevice.WithPerfFPS
|
||||
WithPerfNetwork = giDevice.WithPerfNetwork
|
||||
WithPerfBundleID = giDevice.WithPerfBundleID
|
||||
WithPerfPID = giDevice.WithPerfPID
|
||||
WithPerfOutputInterval = giDevice.WithPerfOutputInterval
|
||||
WithPerfProcessAttributes = giDevice.WithPerfProcessAttributes
|
||||
WithPerfSystemAttributes = giDevice.WithPerfSystemAttributes
|
||||
)
|
||||
|
||||
type StepResult struct {
|
||||
Name string `json:"name" yaml:"name"` // step name
|
||||
StepType StepType `json:"step_type" yaml:"step_type"` // step type, testcase/request/transaction/rendezvous
|
||||
|
||||
@@ -15,6 +15,7 @@ var (
|
||||
WithWDAPort = uixt.WithWDAPort
|
||||
WithWDAMjpegPort = uixt.WithWDAMjpegPort
|
||||
WithLogOn = uixt.WithLogOn
|
||||
WithPerfOptions = uixt.WithPerfOptions
|
||||
)
|
||||
|
||||
type IOSStep struct {
|
||||
|
||||
Reference in New Issue
Block a user