Thursday, January 5, 2017

Profiling Xcode tests from the command line

Leave a Comment

I've written unit tests in Xcode, using XCTest, and they are running great from Xcode. Besides the GUI environment, I also have a makefile that automates some processes from the command line. These include building, testing, cleaning, analyzing, and so on. The rationale for this is including the scripts in a build pipeline, mostly for nightly builds. With that we get builds, performance reports, memory leaks, and so on, fresh in the morning.

I'd also like to profile from the command line, using Instruments. Here's how I'm doing it:

instruments -t "Allocations" -D build/hul.trace hul.xcodeproj 

I get the following output:

Instruments Trace Error : Target failed to run: Unable to find actual binary to posix_spawn for path: hul.xcodeproj 

Is this related with the project being a static library? I'd like the tool to write the results to a file, so that I can consult in the next day, or even automate some processing, such as using pattern matching. Has anyone done something like this before using Instruments?

Edit: This seems to be doing something:

sudo instruments -v -t "Time Profiler" "build/Build/Products/Debug-iphonesimulator/hulTests.xctest/" -w "iPhone SE" 

However, then I get the following dialog:

enter image description here

I just don't know what the appropriate action is...

Edit: One thing was wrong. According to the docs:

 -w [hardware device, or simulator name]           The name or identifier of the hardware device or simulator to target. Should be specified first 

So the previous line changes to:

instruments  -w "iPhone SE" -v -t "Time Profiler" "build/Build/Products/Debug-iphonesimulator/hulTests.xctest/" 

Also, besides "iPhone SE" I'm using an actual device identifier, and I read somewhere that you're not supposed to use sudo. Indeed this helped! I noticed that the results for instruments -s devices and sudo instruments -s devices is actually different. So now I'm getting a different error:

Instruments : Instruments Accepted Command Instruments : Preparing To Start Trace Instruments : Starting Instrument(s) Instruments : Stopping Instrument(s) Instruments Trace Error : Target failed to run: Permission to debug com.hypelabs.test was denied. make: *** [profile] Error 253 

I googled around and this seems to indicate signing errors, but does that make sense if I'm running unit tests? That is, I'm writing a static library, so there's not even a .app file to sign.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment