mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-05 15:59:33 +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)
|
||||
|
||||
Reference in New Issue
Block a user