Profiling IOS With Unreal Insights

Unreal Insights is a profiling tool provided by UE since 4.23, which allows for an easy view of the flame graphs of various threads during game execution. However, the official documentation only provides connection methods for PC and Android, not directly supporting iOS, which is not very convenient. After some research, it was found that the main issue with iOS is related to network policies. This article provides a solution for real-device profiling and port communication between UE and iOS devices, supporting real-time profiling and cook on the fly, as well as data exchange between iOS devices and PCs.

The essence of UE’s Unreal Insight is to create a TCP listening service on PC with port 1980. When our game program starts, it actively connects to this port to facilitate real-time data transfer for profiling.

In a same LAN environment, iOS devices can directly communicate with machines within the LAN, simply needing to specify the tracehost (Unreal Insight) or filehostip (cook on the fly) to designate the host IP when launching the program.

Thus, to fulfill our requirement, there are two steps:

  1. Enable the iOS device to access PC’s ports or ensure they are on the same LAN.
  2. When starting the game on the device, ensure the correct IP address of the PC is specified to establish a connection.

On Android, it’s possible to connect the device via a data cable and use adb reverse to forward the PC’s port to the device’s port, specifying 127.0.0.1 during game startup. Since the reverse forwarding via adb is implemented, connecting to the local 1980 port on the Android device is essentially connecting to the PC’s 1980 port. It is not as straightforward to achieve this on iOS.

Initially, the idea was to connect the device via USB, seeking a solution similar to adb reverse to map the PC’s port to the iOS device’s port; however, a good implementation was not found. usbmuxd does provide a forward solution to map iOS device ports to the PC, but this does not meet our requirements—implementing it would require creating an additional forwarding service, which is overly tedious.

Thus, we can only take a different approach: keeping the iOS device and PC on the same LAN!

However, this requirement is also limited by certain network policies within some internal networks:

  1. The office public network and Wi-Fi do not belong to the same subnet, resulting in subnet isolation.
  2. Deployment of custom routers is not allowed.

Ultimately, the method thought up is: to enable the iOS device to share a hotspot with the PC via USB, allowing the PC and iOS to be on the same subnet. The configuration method is outlined below.

First, enable Personal Hotspot in the Settings of the iOS device (iOS requires a SIM card to enable Personal Hotspot):

Then connect the PC via USB and open Device Manager on the PC to check if there is an Apple Mobile Devices Ethernet item listed under Network Adapters:

Next, open the Network Connections settings from Control Panel, and you will see two virtual adapters automatically created:

At this point, the PC is already connected to the shared network of the iOS device. You can check the IP address with ipconfig:

172.20.10.2 is the IP address assigned to the PC after connecting to the iOS shared network. You can check the IP address of the iOS device on this LAN using arp -a:

Current network situation:

  1. PC 172.20.10.2
  2. iOS 172.20.10.15

On the same LAN in the same subnet, real-device profiling can now begin!

First, Unreal Insight must be started on the PC, followed by editing a ue4commandline.txt and inserting the following content (modify the project name and PC IP address as necessary):

1
../../../FGame/FGame.uproject -Messaging -tracehost=172.20.10.2 -Trace=CPU 

Using tools like iPhone Assistant or iMazing, place this into the game’s data directory:

Then launch the iOS APP, and data should appear in Unreal Insight on the PC:

Finally, with this method, data communication between UE and debugging devices can be achieved via USB. As long as the iOS device and PC are on the same LAN, profiling or cook on the fly can be realized, which avoids development obstacles caused by network policies.

The article is finished. If you have any questions, please comment and communicate.

Scan the QR code on WeChat and follow me.

Title:Profiling IOS With Unreal Insights
Author:LIPENGZHA
Publish Date:2021/08/19 14:14
Word Count:3.4k Words
Link:https://en.imzlp.com/posts/14154/
License: CC BY-NC-SA 4.0
Reprinting of the full article is prohibited.
Your donation will encourage me to keep creating!