iosxcodellvmxcode8pgo

PGO: Why is XCode generating an empty .profdata file?


I'm trying to use profile-guided optimization in XCode 8.

I've followed the instructions here. I made sure to terminate my app using the stop button in XCode, as describe in the document.

I verified that the compile and link commands included the -fprofile-instr-generate argument.

The process successfully generated a .profdata file, but the file is only 1064 bytes, which seems very small considering that my program executed tens, or hundreds of thousands of function calls during the profile generation. Running "xcrun -sdk iphoneos llvm-profdata show <profdata file>" yields this output:

Total functions: 0
Maximum function count: 0
Maximum internal block count: 0

Which seems to indicate that my profdata file is completely empty!

At this point, I'm very stuck and I'm not sure how to generate a valid .profdata file. Can anyone offer guidance?


Solution

  • When generating an optimization profile, it's important to exit your application in a certain way.

    Despite Apple documentation to the contrary, I've observed that exiting the application by pressing the "Stop" button in XCode does not generate a valid profile--instead, it generates a 1064 byte profile with zero functions.

    I've learned that exiting the application by calling exit(0) or by terminating the app through the iOS interface (in iOS 10: double tap the home button, swipe up) does correctly generate a profile. In my case, the correctly generated profile is 34 megabytes.