Skip to content

Commit

Permalink
change: remove GetPerfmon
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Oct 4, 2022
1 parent 8afaf36 commit 40b9b6b
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 528 deletions.
127 changes: 0 additions & 127 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,133 +637,6 @@ func (d *device) MoveCrashReport(hostDir string, opts ...CrashReportMoverOption)
return d.crashReportMover.Move(hostDir, opts...)
}

func (d *device) GetPerfmon(opts *PerfmonOption) (out chan interface{}, outCancel context.CancelFunc, perfErr error) {
if d.lockdown == nil {
if _, err := d.lockdownService(); err != nil {
return nil, nil, err
}
}
if opts == nil {
return nil, nil, fmt.Errorf("parameter is empty")
}
if !opts.OpenChanCPU && !opts.OpenChanMEM && !opts.OpenChanGPU && !opts.OpenChanFPS && !opts.OpenChanNetWork {
opts.OpenChanCPU = true
opts.OpenChanMEM = true
opts.OpenChanGPU = true
opts.OpenChanFPS = true
opts.OpenChanNetWork = true
}

var err error

var instruments Instruments
ctx, cancel := context.WithCancel(context.Background())

chanCPU := make(chan CPUData)
chanMEM := make(chan MemData)
var cancelSysmontap context.CancelFunc

if opts.OpenChanCPU || opts.OpenChanMEM {
instruments, err = d.lockdown.InstrumentsService()
if err != nil {
return nil, cancel, err
}
chanCPU, chanMEM, cancelSysmontap, err = instruments.StartSysmontapServer(opts.PID, ctx)
if err != nil {
cancelSysmontap()
return nil, cancel, err
}
}

chanFPS := make(chan FPSData)
chanGPU := make(chan GPUData)
var cancelOpengl context.CancelFunc

if opts.OpenChanGPU || opts.OpenChanFPS {
instruments, err = d.lockdown.InstrumentsService()
if err != nil {
return nil, cancel, err
}
chanFPS, chanGPU, cancelOpengl, err = instruments.StartOpenglServer(ctx)
if err != nil {
cancelOpengl()
return nil, cancel, err
}
}

chanNetWork := make(chan NetworkData)
var cancelNetWork context.CancelFunc
if opts.OpenChanNetWork {
instruments, err = d.lockdown.InstrumentsService()
if err != nil {
return nil, cancel, err
}
chanNetWork, cancelNetWork, err = instruments.StartNetWorkingServer(ctx)
if err != nil {
cancelNetWork()
return nil, cancel, err
}
}
// 弃用之前的PerfMonData ,统一汇总到interface里,由用户自行决定处理数据
result := make(chan interface{})
go func() {
for {
select {
case v, ok := <-chanCPU:
if opts.OpenChanCPU && ok {
result <- v
}
case v, ok := <-chanMEM:
if opts.OpenChanMEM && ok {
result <- v
}
case v, ok := <-chanFPS:
if opts.OpenChanFPS && ok {
result <- v
}
case v, ok := <-chanGPU:
if opts.OpenChanGPU && ok {
result <- v
}
case v, ok := <-chanNetWork:
if opts.OpenChanNetWork && ok {
result <- v
}
case <-ctx.Done():
err := d.stopPerfmon(opts)
if err != nil {
fmt.Println(err)
}
close(result)
return
}
}
}()
return result, cancel, err
}

func (d *device) stopPerfmon(opts *PerfmonOption) (err error) {
if _, err = d.instrumentsService(); err != nil {
return err
}
if opts.OpenChanCPU || opts.OpenChanMEM {
if err = d.instruments.StopSysmontapServer(); err != nil {
return err
}
}
if opts.OpenChanGPU || opts.OpenChanFPS {
if err = d.instruments.StopOpenglServer(); err != nil {
return err
}
}
if opts.OpenChanNetWork {
if err = d.instruments.StopNetWorkingServer(); err != nil {
return err
}
}
return nil
}

func (d *device) XCTest(bundleID string, opts ...XCTestOption) (out <-chan string, cancel context.CancelFunc, err error) {
xcTestOpt := defaultXCTestOption()
for _, fn := range opts {
Expand Down
48 changes: 1 addition & 47 deletions device_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package giDevice

import (
"encoding/json"
"fmt"
"os"
"os/signal"
Expand Down Expand Up @@ -69,7 +68,7 @@ func Test_device_SavePairRecord(t *testing.T) {
func Test_device_XCTest(t *testing.T) {
setupLockdownSrv(t)

bundleID = "com.DataMesh.CheckList"
bundleID = "com.leixipaopao.WebDriverAgentRunner.xctrunner"
out, cancel, err := dev.XCTest(bundleID)
// out, cancel, err := dev.XCTest(bundleID, WithXCTestEnv(map[string]interface{}{"USE_PORT": 8222, "MJPEG_SERVER_PORT": 8333}))
if err != nil {
Expand Down Expand Up @@ -155,51 +154,6 @@ func Test_device_Shutdown(t *testing.T) {
dev.Shutdown()
}

func Test_device_Perf(t *testing.T) {
//setupDevice(t)
//SetDebug(true,true)
setupLockdownSrv(t)

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, os.Kill)

var opts = &PerfmonOption{
//PID: "0",
OpenChanNetWork: true,
// OpenChanFPS: true,
// OpenChanMEM: true,
//OpenChanCPU: true,
//OpenChanGPU: true,
}

outData, cannel, err := dev.GetPerfmon(opts)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
var timeLast = time.Now().Unix()
for {
select {
case <-c:
if cannel != nil {
cannel()
}
default:
data, ok := <-outData
if !ok {
fmt.Println("end get perfmon data")
return
}
result, _ := json.MarshalIndent(data, "", "\t")
fmt.Println(string(result))
if time.Now().Unix()-timeLast > 60 {
cannel()
}
}
}

}

func Test_device_InstallationProxyBrowse(t *testing.T) {
setupDevice(t)

Expand Down
24 changes: 0 additions & 24 deletions idevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ type Device interface {
GetIconPNGData(bundleId string) (raw *bytes.Buffer, err error)
GetInterfaceOrientation() (orientation OrientationState, err error)

GetPerfmon(opts *PerfmonOption) (out chan interface{}, outCancel context.CancelFunc, perfErr error)

PerfStart(opts ...PerfOption) (data <-chan []byte, err error)
PerfStop()
}
Expand Down Expand Up @@ -157,19 +155,6 @@ type Instruments interface {
// SysMonStart(cfg ...interface{}) (_ interface{}, err error)

registerCallback(obj string, cb func(m libimobiledevice.DTXMessageResult))

StartOpenglServer(ctx context.Context) (chanFPS chan FPSData, chanGPU chan GPUData, cancel context.CancelFunc, err error)

StopOpenglServer() (err error)

StartSysmontapServer(pid string, ctx context.Context) (chanCPU chan CPUData, chanMem chan MemData, cancel context.CancelFunc, err error)

StopSysmontapServer() (err error)
//ProcessNetwork(pid int) (out <-chan interface{}, cancel context.CancelFunc, err error)

StartNetWorkingServer(ctx context.Context) (chanNetWorking chan NetworkData, cancel context.CancelFunc, err error)

StopNetWorkingServer() (err error)
}

type Testmanagerd interface {
Expand Down Expand Up @@ -379,15 +364,6 @@ func WithUpdateToken(updateToken string) AppListOption {
}
}

type PerfmonOption struct {
PID string
OpenChanGPU bool
OpenChanFPS bool
OpenChanCPU bool
OpenChanMEM bool
OpenChanNetWork bool
}

type Process struct {
IsApplication bool `json:"isApplication"`
Name string `json:"name"`
Expand Down
Loading

0 comments on commit 40b9b6b

Please sign in to comment.