YueChen-C / py-ios-device

IOS Professional Performance Testing Tool . You can get CPU, GPU, Memory , Lifecycle and other metrics from real iOS devices . IOS 专业性能测试工具
GNU General Public License v3.0
634 stars 179 forks source link

Question: App in compiled using DEBUG mode #45

Closed fbaptista closed 2 years ago

fbaptista commented 2 years ago

Hello there! We are writing a routine to get Startup Time calculation using TimeProfiler over instruments. It will be nice to create a PR to this repo to add those capabilities.

Is there any way to check in advance if a certain APP is in debug mode ? This will be the pre-requisite to make this routine work properly.

Thanks !

YueChen-C commented 2 years ago
    print(rpc.call('com.apple.instruments.server.services.processcontrol', 'launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:',
                   '',
                   'com.alipay.iphoneclient',
                   {'OS_ACTIVITY_DT_MODE': '1', 'HIPreventRefEncoding': '1', 'DYLD_PRINT_TO_STDERR': '1'},
                   [],
                   {'StartSuspendedKey': True, 'iODestinationKey': 0}).selector)

When "StartSuspendedKey" is True and the pid is returned successfully, the app is in debug mode

fbaptista commented 2 years ago

Hello Yue Chen, thanks a lot for sharing your approach. I found two issues taking this mechanism:

Do you think there is a way to get this information without having those issues?

Update: Even using this mechanism with an unlocked device, if the app is on debug mode, the device got stuck. To reproduce you can try running the code first with a debug app, and then with a release one.

Example:

pid_1 = _rpc_channel.call(
        'com.apple.instruments.server.services.processcontrol',
        'launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:',
        '',
        'com.mydebug-app',
       {'OS_ACTIVITY_DT_MODE': '1', 'HIPreventRefEncoding': '1', 'DYLD_PRINT_TO_STDERR': '1'},[],
       {'StartSuspendedKey': True}).selector

pid_2 = _rpc_channel.call(
        'com.apple.instruments.server.services.processcontrol',
        'launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:',
        '',
        'com.any-app',
       {'OS_ACTIVITY_DT_MODE': '1', 'HIPreventRefEncoding': '1', 'DYLD_PRINT_TO_STDERR': '1'},[],
       {'StartSuspendedKey': True}).selector

After running the first launch, device got stuck until you manually kill the starting app. It is like the instrument server is expecting another command 🤷🏽‍♂️

YueChen-C commented 2 years ago
if HouseArrestService().send_command('com.xxxx'):

You can try using house_arrest. I don't know any other way

fbaptista commented 2 years ago

This definitively works fast and without issues! You rock !