Skip to content

Commit

Permalink
WIP: try to get sysmon stats
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sauce committed Sep 10, 2024
1 parent 4120842 commit 7391a7a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ios/instruments/instruments_deviceinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ type ProcessInfo struct {
StartDate time.Time
}

// SystemAttributes returns the attributes list which can be used for monitoring
func (d DeviceInfoService) SystemAttributes() ([]interface{}, error) {
resp, err := d.channel.MethodCall("sysmonSystemAttributes")
if err != nil {
return nil, err
}
return resp.Payload[0].([]interface{}), nil
}

// ProcessList returns a []ProcessInfo, one for each process running on the iOS device
func (d DeviceInfoService) ProcessList() ([]ProcessInfo, error) {
resp, err := d.channel.MethodCall("runningProcesses")
Expand Down
58 changes: 58 additions & 0 deletions ios/instruments/instruments_sysmontap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package instruments

import (
"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
log "github.com/sirupsen/logrus"
)

const sysmontapName = "com.apple.instruments.server.services.sysmontap"

type SysmontapService struct {
channel *dtx.Channel
conn *dtx.Connection
}

func NewSysmontapService(device ios.DeviceEntry) (*SysmontapService, error) {
dtxConn, err := connectInstruments(device)
if err != nil {
return nil, err
}
processControlChannel := dtxConn.RequestChannelIdentifier(sysmontapName, loggingDispatcher{dtxConn})
return &SysmontapService{channel: processControlChannel, conn: dtxConn}, nil
}

// Close closes up the DTX connection
func (d *SysmontapService) Close() {
d.conn.Close()
}

func (s SysmontapService) Start() ([]interface{}, error) {
fetchDataNow, err := s.channel.MethodCall("start")

if err != nil {
return nil, err
}

log.Info(fetchDataNow)

return nil, nil
}

func (s SysmontapService) SetConfig(sysAttrs []interface{}) error {
config := make(map[string]interface{})
config["ur"] = 1000
config["bm"] = 0
config["cpuUsage"] = true
config["physFootprint"] = true
config["sampleInterval"] = 1000 * 1000000
config["sysAttrs"] = sysAttrs

_, err := s.channel.MethodCall("setConfig:", config)

if err != nil {
return err
}

return nil
}
44 changes: 42 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Usage:
ios forward [options] <hostPort> <targetPort>
ios dproxy [--binary] [--mode=<all(default)|usbmuxd|utun>] [--iface=<iface>] [options]
ios readpair [options]
ios sysmontap [options]
ios pcap [options] [--pid=<processID>] [--process=<processName>]
ios install --path=<ipaOrAppFolder> [options]
ios uninstall <bundleID> [options]
Expand Down Expand Up @@ -218,6 +219,7 @@ The commands work as following:
> to stop usbmuxd and load to start it again should the proxy mess up things.
> The --binary flag will dump everything in raw binary without any decoding.
ios readpair Dump detailed information about the pairrecord for a device.
ios sysmontap Get system stats like MEM, CPU
ios install --path=<ipaOrAppFolder> [options] Specify a .app folder or an installable ipa file that will be installed.
ios pcap [options] [--pid=<processID>] [--process=<processName>] Starts a pcap dump of network traffic, use --pid or --process to filter specific processes.
ios apps [--system] [--all] [--list] [--filesharing] Retrieves a list of installed applications. --system prints out preinstalled system apps. --all prints all apps, including system, user, and hidden apps. --list only prints bundle ID, bundle name and version number. --filesharing only prints apps which enable documents sharing.
Expand Down Expand Up @@ -828,6 +830,44 @@ The commands work as following:
}
}

b, _ = arguments.Bool("sysmontap")
if b {
deviceInfoService, err := instruments.NewDeviceInfoService(device)
if err != nil {
log.Error("NewDeviceInfoService error")
log.Error(err)
}
defer deviceInfoService.Close()

sysAttrs, err := deviceInfoService.SystemAttributes()
if err != nil {
log.Error("SystemAttributes error")
log.Error(err)
}
log.Info(sysAttrs)

sysmontapService, err := instruments.NewSysmontapService(device)
if err != nil {
log.Error("NewSysmontapService error")
log.Error(err)
}
defer sysmontapService.Close()

err = sysmontapService.SetConfig(sysAttrs)
if err != nil {
log.Error("SetConfig error")
log.Error(err)
}

res, err := sysmontapService.Start()
if err != nil {
log.Error("Start error")
log.Error(err)
}

log.Info(res)
}

b, _ = arguments.Bool("kill")
if b {
var response []installationproxy.AppInfo
Expand Down Expand Up @@ -1622,8 +1662,8 @@ func startAx(device ios.DeviceEntry, arguments docopt.Opts) {
/* conn.GetElement()
time.Sleep(time.Second)
conn.TurnOff()*/
//conn.GetElement()
//conn.GetElement()
// conn.GetElement()
// conn.GetElement()

exitIfError("ax failed", err)
}()
Expand Down

0 comments on commit 7391a7a

Please sign in to comment.