Skip to content

Instantly share code, notes, and snippets.

@lawrencelomax
Last active July 27, 2016 07:52
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencelomax/03da6538a0cce1b60c47 to your computer and use it in GitHub Desktop.
Save lawrencelomax/03da6538a0cce1b60c47 to your computer and use it in GitHub Desktop.
instruments-without-delay on Xcode 7
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnableTransactions</key>
<true/>
<key>EnvironmentVariables</key>
<dict>
<key>DYLD_INSERT_LIBRARIES</key>
<string>/Users/lawrencelomax/src/instruments-without-delay/build/DTMobileISShim.dylib</string>
<key>LIB_PATH</key>
<string>/Users/lawrencelomax/src/instruments-without-delay/build</string>
</dict>
<key>JetsamProperties</key>
<dict>
<key>JetsamMemoryLimit</key>
<integer>0</integer>
</dict>
<key>Label</key>
<string>com.apple.instruments.deviceservice</string>
<key>MachServices</key>
<dict>
<key>com.apple.instruments.deviceservice.lockdown</key>
<true/>
<key>com.apple.instruments.deviceservice.xpc</key>
<true/>
</dict>
<key>POSIXSpawnType</key>
<string>Adaptive</string>
<key>Program</key>
<string>/Developer/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/DTServiceHub</string>
</dict>
</plist>

instruments-without-delay uses the DYLD_INSERT_LIBRARIES environment variable to shim from the instruments command line all the way down to ScriptAgentShim which is the iOS Simulator service responsible for interfacing UIAutomation JavaScript with the native UIAutomation.framework. It uses a stack of shims, starting at the instruments executable, going through Simulator.app. It is an essential part of ios-driver as it removes a pesky 200ms delay that drastically slows down the process of executing end-to-end tests. This is a fixed cost that would occur on every command.

Other than a few things being moved around and renamed in Xcode 7, there is the new issue of the codesigning of the Simulator app that triggers amfid whenever an unsigned image is loaded. This essentially means that we can't use DYLD_INSERT_LIBRARIES on the Simulator Process with SimShim

It is however, possible to inject these environment variables at the launchdaemon level. There is a plist for DTServiceHub at: /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/LaunchDaemons/com.apple.instruments.deviceservice.plist

It can be modified to inject the DTMobileISShim (see the attached plist). However, this is less than ideal as this requires modifying the Xcode binary.

@alangithubtrader
Copy link

Thank you so much! Going to give this a go.

@salmanchauhan
Copy link

info: [debug] Starting instruments
info: [debug] Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: Launching instruments
info: [debug] Attempting to run app on real device with UDID 0cb62dabcdedfgd5beb534519643a340fa07849
info: On xcode 7.0, instruments-without-delay does not work, skippinginstruments-without-delay

I followed above steps but on my appium server it is saying xcode 7.0, instruments-without-delay does not work.
I am using xcode 7.0.1.

Thanks in advance.

@tarunchauhantft
Copy link

Hi,
I am able to apply this patch and its working fine only with simulators.
Does this work with original devices too?

@lamabaajour
Copy link

I added the iwd as explained above but nothing improved on the performance side please can someone help

@lamabaajour
Copy link

@tarunchauhantft please can you let me know how this worked with you

@lamabaajour
Copy link

@tarunchauhantft I did the following steps:
cd ~
git clone https://github.com/lawrencelomax/instruments-without-delay.git
cd instruments-without-delay/
git checkout xcode7-quirks
./build.sh

Next, you're going to want to edit the plist file at:
/Applications/Xcode-7.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/LaunchDaemons/com.apple.instruments.deviceservice.plist
(I downloaded the library DTMobileISShim.dylib) and then added the path where it is found.
I restarted my MAC and i didn't notice any improvement in the performance.

Please can you give me the exact steps how you used it and noticed the difference in performance.

Thanks in advance

@wujiayi101
Copy link

Hey, I am unable to run the build script with following errors, any ideas?

In file included from :1:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/sys/cdefs.h:707:2: error: Unsupported architecture

error Unsupported architecture

^
While building module 'Darwin' imported from /Users/xx/Documents/git_folder/instruments-without-delay/DTMobileISShim/DTMobileISShim/DTMobileISShim.m:17:
In file included from :3:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/copyfile.h:36:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include/stdint.h:63:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/stdint.h:52:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/sys/_types.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported

error architecture not supported

^
.... more

@bthuan
Copy link

bthuan commented Jan 15, 2016

@ chrisjywu: I had the same issue and here is what I did: Open the build.sh file and add this: -destination 'platform=iOS Simulator,name=iPhone 6' to every xcodebuild command
This seems to be a bug of xcodebuild 7.2 and it is reported

@andreeamatei
Copy link

Does this work for you on xcode 7.2? I added the destination code, ran successfully, plist file has the variables, but it doesn't remove the delay for ios 9.2.

@wujiayi101
Copy link

@bthuan thanks, works for me now

@mmehta-10
Copy link

It speeds up my test on the first run, but on subsequent runs the standard instruments delay seems to be implemented between commands thus slowing down my tests. What could be causing this? A process that may need killing to eliminate the delay second run onwards? Please help..

@krutipandya
Copy link

krutipandya commented Jun 30, 2016

Hi. After successfully running the commands and making changes to the .plist file as mentioned above, if i try to run a test, the instrument crashes.

info: [debug] And launch timeouts (in ms): {"global":90000}
info: [debug] [INST] Waiting for device to boot...
info: [debug] [INSTSERVER] Instruments exited with code 253
info: [debug] Killall instruments
info: [debug] Instruments crashed on startup
info: [debug] Attempting to retry launching instruments, this is retry #3
info: [debug] Killall Simulator

Please assist

@krutipandya
Copy link

It worked! Had to change the folder permissions in order to edit the com.apple.instruments.deviceservice.plist file. Changed it back to Read Only.

@blueice349
Copy link

@krutipandya do you have steps for removing the delay on instruments? I didnt really understand the thre
d here

@zingzheng
Copy link

@tarunchauhantft had you find the way to make IWD working on real device?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment