Using instruments with a Packet Tunnel Provider

I cannot get Instruments to work. I'm trying to inspect allocations in my packet tunnel provider (NEPacketTunnelProvider).

I've tried several methods:
  1. Attaching the debugger to the tunnel provider process and transferring the debug session to Instruments using the Memory Report panel

  2. Attaching the debugger to the tunnel provider process and handing over the session to Instruments using the Memory Report panel while choosing restart

  3. Profiling directly from instruments by selecting the running tunnel provider process

  4. Profiling directly from instruments by selecting the running tunnel provider process while attached to debugger in XCode

  5. Profile directly from XCode (command-I) running the packet tunnel scheme

Neither of these options have resulted in successfully instrumenting the tunnel provider. This was not an issue in the past, and I remember that option 4 used to do the trick.

Any advice, and are there people still able to achieve this?

You're on the right track, but this can be difficult to say the least. If this is on iOS this can be a dance to make sure the PacketTunnel extension is in the running state and not just being selected from the App Extension list.

Try this:

1) Start you host app that has a Packet Tunnel. Install the configuration and connect the VPN. Make sure the VPN starts up successfully.

2) Navigate to Settings screen in your iOS device and make sure that your Packet Tunnel stays connected. If you were running your iOS project from Xcode and stopped, you may run the risk of your tunnel disconnecting here, so reconnect the tunnel if this happens. This will start the PacketTunnel (or whatever your Network Extension's name is) process.

3) From Xcode, launch Instruments by doing Product -> Profile with your desired device tethered to your macOS machine.

4) After you select Allocations in Instruments make sure to set your tethered device and then select the Network Extension name from the Running Applications list. Make sure your extension has a PID next to it's name and then start recording the allocations. In my experience selecting just the Network Extension from the App Extensions list has never worked as expected. The Network Extension needs to be profiled from the Running Applications list.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Matt, thanks for your elaborate answer.

It turned out I was actually able to attach briefly, but a crash appeared that took me a while to understand. After paying close attention to the logs in the Console, I found out that the following message appeared just before the crash:

This copy of libswiftCore.dylib requires an OS version prior to 12.2.0

After reading about it online, I resolved this issue by adding
Code Block
/usr/lib/swift
as the first item in my Runtime Search Paths for the tunnel provider target.

After adding this item Instruments works as expected again. I'm not at all sure if it's at all related to Instruments at this point, but I hope that future readers find this useful.
Using instruments with a Packet Tunnel Provider
 
 
Q