mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
feat: add performance monitor for iOS, including CLI hrp ios perf
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Release History
|
# Release History
|
||||||
|
|
||||||
## v4.3.1 (2022-12-15)
|
## v4.3.1 (2022-12-16)
|
||||||
|
|
||||||
**go version**
|
**go version**
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
- feat: run step with specified loop times
|
- feat: run step with specified loop times
|
||||||
- feat: add options for FindTexts
|
- feat: add options for FindTexts
|
||||||
- feat: capture pcap file for iOS, including CLI `hrp ios pcap` and option `uixt.WithIOSPcapOn(true)`
|
- feat: capture pcap file for iOS, including CLI `hrp ios pcap` and option `uixt.WithIOSPcapOn(true)`
|
||||||
|
- feat: add performance monitor for iOS, including CLI `hrp ios perf` and options `uixt.WithIOSPerfOptions(...)`
|
||||||
- refactor: move all UI APIs to uixt pkg
|
- refactor: move all UI APIs to uixt pkg
|
||||||
- docs: add examples for UI APIs
|
- docs: add examples for UI APIs
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var pcapCmd = &cobra.Command{
|
var pcapCmd = &cobra.Command{
|
||||||
|
|||||||
87
hrp/cmd/ios/perf.go
Normal file
87
hrp/cmd/ios/perf.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package ios
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var perfCmd = &cobra.Command{
|
||||||
|
Use: "perf",
|
||||||
|
Short: "capture ios performance data (cpu,mem,disk,net,fps,etc.)",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
perfOptions := []uixt.IOSPerfOption{}
|
||||||
|
for _, p := range indicators {
|
||||||
|
switch p {
|
||||||
|
case "sys_cpu":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemCPU(true))
|
||||||
|
case "sys_mem":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemMem(true))
|
||||||
|
case "sys_net":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemNetwork(true))
|
||||||
|
case "sys_disk":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemDisk(true))
|
||||||
|
case "network":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfNetwork(true))
|
||||||
|
case "fps":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfFPS(true))
|
||||||
|
case "gpu":
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfGPU(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
perfOptions = append(perfOptions, uixt.WithIOSPerfOutputInterval(interval*1000))
|
||||||
|
|
||||||
|
device, err := uixt.NewIOSDevice(
|
||||||
|
uixt.WithUDID(udid),
|
||||||
|
uixt.WithIOSPerfOptions(perfOptions...),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("failed to init ios device")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = builtin.EnsureFolderExists(env.ResultsPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = device.StartPerf(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer device.StopPerf()
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
|
||||||
|
timer := time.NewTimer(time.Duration(timeDuration) * time.Second)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-timer.C:
|
||||||
|
return nil
|
||||||
|
case <-c:
|
||||||
|
log.Warn().Msg("received signal, stop perf")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
interval int
|
||||||
|
indicators []string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
perfCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||||
|
perfCmd.Flags().StringSliceVarP(&indicators, "indicators", "p", []string{"sys_cpu", "sys_mem"},
|
||||||
|
"specify performance monitor, e.g. sys_cpu,sys_mem,sys_net,sys_disk,fps,network,gpu")
|
||||||
|
perfCmd.Flags().IntVarP(&timeDuration, "duration", "t", 10, "specify time duraion in seconds")
|
||||||
|
perfCmd.Flags().IntVarP(&interval, "interval", "i", 3, "set interval in seconds")
|
||||||
|
iosRootCmd.AddCommand(perfCmd)
|
||||||
|
}
|
||||||
@@ -344,13 +344,13 @@ func (dev *IOSDevice) NewDriver(capabilities Capabilities) (driverExt *DriverExt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *IOSDevice) StartPerf() error {
|
func (dev *IOSDevice) StartPerf() error {
|
||||||
|
log.Info().Msg("start performance monitor")
|
||||||
data, err := dev.d.PerfStart(dev.perfOpitons()...)
|
data, err := dev.d.PerfStart(dev.perfOpitons()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dev.perfFile = filepath.Join(env.ResultsPath, "perf.data")
|
dev.perfFile = filepath.Join(env.ResultsPath, "perf.data")
|
||||||
log.Info().Str("perfFile", dev.perfFile).Msg("create perf file")
|
|
||||||
file, err := os.OpenFile(dev.perfFile,
|
file, err := os.OpenFile(dev.perfFile,
|
||||||
os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o755)
|
os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -384,6 +384,7 @@ func (dev *IOSDevice) StopPerf() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
close(dev.perfStop)
|
close(dev.perfStop)
|
||||||
|
log.Info().Str("perfFile", dev.perfFile).Msg("stop performance monitor")
|
||||||
return dev.perfFile
|
return dev.perfFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user