Attach Instruments to PacketTunnel earlier than startTunnel

We are trying to reduce the memory footprint of our PacketTunnelProvider so we're using Instruments. The soonest point that we can attach Instruments is in startTunnel, since that's where we can put in a delay to give a developer sufficient time to attach Instruments to the PT process.


However, the memory footprint of our PT is already many MBs in size at that point. We've tried to use the Xcode memory graph but it's extremely difficult to use this approach since there are 1000s of objects created already and no way to associate them to a call tree.


Is there a way to attach Instruments near the initial launch of the PT process, ideally where its memory usage is as close to 0 as possible?

Replies

that's where we can put in a delay to give a developer sufficient time to attach Instruments to the PT process.

Have you tried overriding

-init
and putting the delay there? That should help.

Having said that, there should be a way for Instruments to launch your provider. This works for other types of app extensions. I’m pretty sure we have a bug on file about this already (r. 38024575) but it wouldn’t hurt to file your own.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Overriding -init with a delay for attaching to the PT process unfortunately yields a memory footprint that is virtually identical to attaching within startTunnel (just over 8MB), and the memory graph while in -init is also similar that from startTunnel. Here is a screenshot of the memory graph, since the forum isn't showing the pasted inline image.


It looks like all dependencies are initialized at this point, which is what's using the memory. What we'd like to determine is whether we can excise any of these, to lower our memory footprint, such as any unexpected allocations by these dependencies, perhaps implicitly or inadvertently. This doesn't seem really viable to do with the memory graph but Instruments can easily reveal.


Is there a possibly earlier point or any other suggestions we can try?


Is there a possibly earlier point or any other suggestions we can try?

To start any earlier you’d have to dig into the private parts of the app extension runtime.

You may be able to do better via environment variables; see this thread for details.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"