Two Useful Environment Vars

Today we are sharing usage of two environment variables, which will offer useful information in Xcode when you are debugging, especially focusing on the performance optimization of a app.


The first one is DYLD_PRINT_STATISTICS. Adding it to the project scheme could enable developers to verify the statics of pre-main time cost, as tons of things happen before system executes your app’s main() function and calls app delegate functions like applicationWillFinishLaunching. Here is the screenshot of how to configure it in Xcode:

Then build and run the app, here is the typical output:

For how to optimize the app launch time, you could reference Apple’s WWDC video for detail.


The second environment variable is DYLD_PRINT_LIBRARIES . Adding it to project scheme (similar as DYLD_PRINT_STATISTICS) allows us to check dynamic loader events. Specifically, it could log events when image are loaded.

Build and run the app, it will display info like below:

You can also use DYLD_PRINT_LIBRARIES_POST_LAUNCH . This environment variable will show the subset of the result output by DYLD_PRINT_LIBRARIES— it only logs when images are loaded as a result of a dlopen call, including a dynamic libraries’ dependent libraries. All these loads are happened after app’s main() function is executed.

For details, Apple’s Document here tells about these environment variables.