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
667 stars 183 forks source link

How to get network usage for an app? #84

Closed khrithik96 closed 1 year ago

khrithik96 commented 1 year ago

Tried network_process. It should give data from the network debug gauge but it is consistently giving same value(sometimes this value is 0) every time.

Trying to use this service com.apple.instruments.server.services.networking using the code https://github.com/YueChen-C/py-ios-device/blob/c50edc5cee9bd0fac84208812a76b10f72748821/ios_device/py_ios_device.py#L304. Steps(Python code):

_rpc_channel = init(device_id)
def _callback(res):
    api_util.network_caller(res, callback)
_rpc_channel.register_channel_callback("com.apple.instruments.server.services.networking", _callback)
with InstrumentsBase(udid=device_id) as rpc:
    pid = rpc.get_pid(bundle_id=bundle_id)
_rpc_channel.call("com.apple.instruments.server.services.networking", "setTargetPID:", pid)
_rpc_channel.call("com.apple.instruments.server.services.networking", "startMonitoring")

Trying to set the target process id here. Ref: https://github.com/YueChen-C/py-ios-device/blob/c50edc5cee9bd0fac84208812a76b10f72748821/ios_device/util/variables.py#L74

The line _rpc_channel.call("com.apple.instruments.server.services.networking", "setTargetPID:", pid) is timing out.

Is there any way we can get an apps network usage?

YueChen-C commented 1 year ago

Try pid string or RawObj(pid)

khrithik96 commented 1 year ago

sending pid as a string fixed the timeout issue _rpc_channel.call("com.apple.instruments.server.services.networking", "setTargetPID:", pid).

But it looks like it is giving the data at the device level.

YueChen-C commented 1 year ago

You can also try to use com.apple.xcode.debug-gauge-data-providers.NetworkStatistics service. Refer to demo netstatPID.py

khrithik96 commented 1 year ago

com.apple.xcode.debug-gauge-data-providers.NetworkStatistics is working fine(In some cases, it gives 0 values).

Thanks.