Skip to content

Commit db9b7f5

Browse files
committed
Disable memory limit for pid
1 parent 0ea513c commit db9b7f5

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

ios/instruments/processcontrol.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func (p *ProcessControl) LaunchApp(bundleID string, my_opts map[string]any) (uin
2323
}
2424
maps.Copy(opts, my_opts)
2525
// Xcode sends all these, no idea if we need them for sth. later.
26-
//"CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0", "CA_DEBUG_TRANSACTIONS": "0", "LLVM_PROFILE_FILE": "/dev/null", "METAL_DEBUG_ERROR_MODE": "0", "METAL_DEVICE_WRAPPER_TYPE": "1",
27-
//"OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"
26+
// "CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0", "CA_DEBUG_TRANSACTIONS": "0", "LLVM_PROFILE_FILE": "/dev/null", "METAL_DEBUG_ERROR_MODE": "0", "METAL_DEVICE_WRAPPER_TYPE": "1",
27+
// "OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"
2828
// NSUnbufferedIO seems to make the app send its logs via instruments using the outputReceived:fromProcess:atTime: selector
2929
// We'll supply per default to get logs
3030
env := map[string]interface{}{"NSUnbufferedIO": "YES"}
@@ -40,8 +40,8 @@ func (p *ProcessControl) LaunchAppWithArgs(bundleID string, my_args []interface{
4040
}
4141
maps.Copy(opts, my_opts)
4242
// Xcode sends all these, no idea if we need them for sth. later.
43-
//"CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0", "CA_DEBUG_TRANSACTIONS": "0", "LLVM_PROFILE_FILE": "/dev/null", "METAL_DEBUG_ERROR_MODE": "0", "METAL_DEVICE_WRAPPER_TYPE": "1",
44-
//"OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"
43+
// "CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0", "CA_DEBUG_TRANSACTIONS": "0", "LLVM_PROFILE_FILE": "/dev/null", "METAL_DEBUG_ERROR_MODE": "0", "METAL_DEVICE_WRAPPER_TYPE": "1",
44+
// "OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"
4545
// NSUnbufferedIO seems to make the app send its logs via instruments using the outputReceived:fromProcess:atTime: selector
4646
// We'll supply per default to get logs
4747
env := map[string]interface{}{"NSUnbufferedIO": "YES"}
@@ -62,6 +62,18 @@ func NewProcessControl(device ios.DeviceEntry) (*ProcessControl, error) {
6262
return &ProcessControl{processControlChannel: processControlChannel, conn: dtxConn}, nil
6363
}
6464

65+
// DisableMemoryLimit disables the memory limit of a process.
66+
func (p ProcessControl) DisableMemoryLimit(pid uint64) (bool, error) {
67+
msg, err := p.processControlChannel.MethodCall("requestDisableMemoryLimitsForPid:", pid)
68+
if err != nil {
69+
return false, err
70+
}
71+
if disabled, ok := msg.Payload[0].(bool); ok {
72+
return disabled, nil
73+
}
74+
return false, fmt.Errorf("expected int 0 or 1 as payload of msg: %v", msg)
75+
}
76+
6577
// KillProcess kills the process on the device.
6678
func (p ProcessControl) KillProcess(pid uint64) error {
6779
_, err := p.processControlChannel.MethodCall("killPid:", pid)

main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Usage:
112112
ios apps [--system] [--all] [--list] [--filesharing] [options]
113113
ios launch <bundleID> [--wait] [--kill-existing] [--arg=<a>]... [--env=<e>]... [options]
114114
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options]
115+
ios memlimitoff (--process=<processName>) [options]
115116
ios runtest [--bundle-id=<bundleid>] [--test-runner-bundle-id=<testrunnerbundleid>] [--xctest-config=<xctestconfig>] [--log-output=<file>] [--xctest] [--test-to-run=<tests>]... [--test-to-skip=<tests>]... [--env=<e>]... [options]
116117
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--log-output=<file>] [--arg=<a>]... [--env=<e>]... [options]
117118
ios ax [--font=<fontSize>] [options]
@@ -226,6 +227,7 @@ The commands work as following:
226227
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.
227228
ios launch <bundleID> [--wait] [--kill-existing] [--arg=<a>]... [--env=<e>]... [options] Launch app with the bundleID on the device. Get your bundle ID from the apps command. --wait keeps the connection open if you want logs.
228229
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options] Kill app with the specified bundleID, process id, or process name on the device.
230+
ios memlimitoff (--process=<processName>) [options] Waives memory limit set by iOS (For instance a Broadcast Extension limit is 50 MB).
229231
ios runtest [--bundle-id=<bundleid>] [--test-runner-bundle-id=<testbundleid>] [--xctest-config=<xctestconfig>] [--log-output=<file>] [--xctest] [--test-to-run=<tests>]... [--test-to-skip=<tests>]... [--env=<e>]... [options] Run a XCUITest. If you provide only bundle-id go-ios will try to dynamically create test-runner-bundle-id and xctest-config.
230232
> If you provide '-' as log output, it prints resuts to stdout.
231233
> To be able to filter for tests to run or skip, use one argument per test selector. Example: runtest --test-to-run=(TestTarget.)TestClass/testMethod --test-to-run=(TestTarget.)TestClass/testMethod (the value for 'TestTarget' is optional)
@@ -841,6 +843,28 @@ The commands work as following:
841843
printSysmontapStats(device)
842844
}
843845

846+
b, _ = arguments.Bool("memlimitoff")
847+
if b {
848+
processName, _ := arguments.String("--process")
849+
850+
pControl, err := instruments.NewProcessControl(device)
851+
exitIfError("processcontrol failed", err)
852+
defer pControl.Close()
853+
854+
svc, err := instruments.NewDeviceInfoService(device)
855+
exitIfError("failed opening deviceInfoService for getting process list", err)
856+
defer svc.Close()
857+
858+
processList, _ := svc.ProcessList()
859+
for _, process := range processList {
860+
if process.Pid > 1 && process.Name == processName {
861+
disabled, err := pControl.DisableMemoryLimit(process.Pid)
862+
exitIfError("DisableMemoryLimit failed", err)
863+
log.WithFields(log.Fields{"process": process.Name, "pid": process.Pid}).Info("memory limit is off: ", disabled)
864+
}
865+
}
866+
}
867+
844868
b, _ = arguments.Bool("kill")
845869
if b {
846870
var response []installationproxy.AppInfo

0 commit comments

Comments
 (0)