Instruments Automation saving options - instruments

I'm new to Instruments Automation. After finishing a script I decided to save my work but see two options 1.) save as 2.) "save as template"
I noticed that when I choose save as it creates a "Trace Document" while save as template saves as "Trace Template"
What is the difference between these?

Save saves your trace data so you can examine it later.
Save as template saves the trace document's instrument list as a template you can choose from when you choose Product > Profile in Xcode or File > New in Instruments.
If you find yourself constantly adding instruments to the trace or removing instruments from the trace, saving as a template frees you from having to add or remove instruments every time you trace. Suppose you're profiling the performance of an OpenGL game and you want to use both the Time Profiler and the OpenGL Driver instruments. You'll notice Apple does not provide a template that combines both of these instruments. You can set up your trace to use both instruments and save as a template so you don't have set up the trace every time you profile your game.

Considering the Instrument named Automation for UI interaction simulation: If you want to save the script itself as a javascript source file, do right click in the script pane, and select Export. Then you can open the file again by tapping the Add button and the choose Import.

Related

Is there a way to launch automation and allocations tracetemplate using Instruments simultaneously?

I am trying to use Automation instruments together with Allocation instruments to profile the memory usage of our iOS app. The idea is to use Automation to drive the use cases, while the Allocation instruments record some memory data in the background. I am wondering if is it possible to launch automation and allocations tracetemplate using Instruments simultaneously? So that I can check the data recorded by Allocations after the automation is done.
Any pointers would be helpful.
Choose the Automation template. Click the Library button in the toolbar to get a list of available instruments. Find the Allocations instrument in the Library and drag it to the instruments list on the left side of the trace document window. You could also reverse this by choosing the Allocations template and dragging the Automation instrument from the Library.
After you add the second instrument from the Library, choose File > Save As Template to save your trace as a template. When you profile your app in Instruments, your template will appear in the list of available templates in the User section. Saving as a template keeps you from having to add a second instrument to the trace every time you profile your app.
#Assassin, I also have to do this for test automation and I ended up writing an AppleScript to export from the command line, as it looks like Apple doesn't provide any other way to do this. My bash script to do this part looks like this:
open file.trace
sleep 10
osascript InstrumentsExport.scpt
And then I have some fancy awk commands to parse the resulting CSV file. My AppleScript to export to CSV looks like this:
tell application "/Applications/Xcode.app/Contents/Applications/Instruments.app"
activate
end tell
delay 3
tell application "System Events" to tell process "Instruments"
set frontmost to true
tell menu bar item "Instrument" of menu bar 1
click
click menu item "Export Track for 'Activity Monitor'..." of menu 1
end tell
delay 3
keystroke return
end tell
For the "Export Track for" text, you'll need to rename that to whatever it's called in your Instruments GUI, complete with "..." at the end.

Memory Warning on the device, not with Instruments

I have a huge synchronization process in which I download and unzip 400-500 XML files and then parse it. With this data Im going to create a lot of core data objects over the RestKit API. At the beginning, I had a memory warning with live bytes of 450mb+ because I did not using autorelease pools and only tried to save core data on the end.
I fixed that, saving now frequently to core data and using #autoreleasepool blocks. When im running my app now with instruments, I can see how the live bytes only being 20mb-30mb, always releasing memory and never going to size up. The process just works. But when I start the app without instruments, after a view files I get a Memory Warning. Later on the app crashs.
What is the differene between running the app with and without the instruments tool? Why does it end in different results?
I'm adding this answer because I'm so happy that I came across this page.
What #borrrden suggested is partially true. You can configure which Build settings it will use when you profile. To configure this, goto Xcode and open the Edit Scheme dialog and select in the left menu Profile XXX.app. You will see you can choose a Build Configuration (either Debug or Release).
What #hooleyhoop commented was more crucial to find the solution. Even if your Profile Build Configuration is set to Debug, there is still a difference between Profiling and a default Run from within Xcode. You can specify Diagnostics in the Run section. Right there, there is an option called Enable Zombie Objects under Memory Management. Make sure that this option is unchecked.
These diagnostic Run settings are not used while profiling. That is the explanation for the behavior you are experiencing. There isn't a Diagnostics tab on the Profile section as well.
The result is that my game (Gump) crashed after 5 minutes of doing nothing in the main menu with Zombie Objects enabled. Once I disabled Zombie Objects, my game runs as far as I know for an infinite amount of time. After 45 minutes, still no Memory Warnings.

Having Instruments always revert to script file on disk (instead of prompting) for iOS UIAutomation testing

Question:
Is there some way to shush up Instruments from warning about changes on disk to the currently loaded script, and have it just use the latest version of the script on disk? I'm always editing it outside of Instruments.
Background:
I'm editing my UIAutomation scripts (JavaScript of course) inside Xcode. I select them in the UIAutomation Instrument for profiling with the Instruments tool. I can hit record and all is good.
As I'm building my testing script, I'll edit it in Xcode and toggle the record button in the Instruments app to restart the test.
Instruments prompts me about a change to the script in an external location. I say "Revert" (to disk version) every time. I'm not keen on editing my scripts inside Instruments because then I keep switching between the 'Script' view and the 'Trace Log' view.
Note: I'm using Xcode 4.4.1 on Mountain Lion 10.8.1 with the iOS5.1 base SDK.
I found a solution:
I use an #import directive in a javascript file to import the file that I'm constantly changing.
I point Instruments to this shell of a javascript file, whose only purpose is to import my actual test file, in active development.
I then modify the file I'm actively developing, in another editor, and Instruments won't complain

iOS: Fetch logs from Instruments in txt format

Is there any way i can fetch the test cases logs that are generated from Instrument in text format. I want it to be passed on to a text file so that i can read them and create a Test Report.
Some (but not all) tools in Instruments support exporting to CSV.
To do so, select the instrument you want and click
Instrument -> Export Data for:

Is it possible to use XCode's Instruments with breakpoints enabled?

I'm trying to optimize the memory usage of an iOS app, and I'd like to see what the app's total memory usage is at specific points in the code. I was thinking I should be able to set breakpoints, profile the app with Activity Monitor, and just look at the memory use when each breakpoint catches. But when I run Instruments, it seems breakpoints no longer stop execution, so it's hard to know exactly when memory usage is changing.
Is it possible to use breakpoints and Instruments at the same time? If not, is there a clever way of writing some code to insert a marker into the Instruments timeline when specific events occur?
I also ran into this issue today, and after a bit of searching I found this solution. Text below is a quote from the post:
Breakpoints Do Not Break. Instruments utilizes debug information from
your debug build, however, it does not stop at break points you set.
This is because while you are loading your application into
Instruments from the menu in XCode, Instruments simply uses the path
of the current executable as its start path and loads it externally
from XCode. The menu in XCode is really there as a convenience
mechanism. This is not a big deal as you can always run again in Debug
mode after your instruments session should you want your application
to break. It’s just something to make a note of.
NSLog Statements Do Not Show In The Debugger Console. If you want to
see your NSLog statements, you will need to load the system Console
application (/Applications/Utilities/Console).
Reference: http://www.cimgf.com/2008/04/02/cocoa-tutorial-fixing-memory-leaks-with-instruments/
Well, you aren't running under control of the debugger.
One approach might be to add alerts at the key points, and take a heapshot then (manually).
Or there may be some dtrace wizardry.

Resources