Search code examples
iosjenkinsterminalxcode4.5

Is it Possible using Terminal to run iOS Application in instrument?


I want to run my iPad Application in Instrument for Memory Leak and object Allocation using Terminal.

I have done goggling as well.I know how to open terminal using following command :

open /Developer/Applications/Instruments.app

I have tried the following command as well.

instruments -t "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Resources/templates/Leaks.tracetemplate" -/Users/iOSRider/Downloads/samplecode/build/Release-iphoneos/sample.app 

but I am getting following Error:

`-[NSAlert alertWithError:] called with `nil NSError.

A generic error message will be displayed, but the user deserves better.

Then I have tried

instruments -w "cd73f2aadff0726a923b22bc69fdca4420f08ffb" -t "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Resources/templates/Leaks.tracetemplate" -/Users/iOSRider/Downloads/samplecode/build/Release-iphoneos sample.app

but I am getting Following Error:

Instruments Trace Error : Failed to start trace.

I have tried the following command as well

 instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/iOSRider/Library/Developer/Xcode/DerivedData/sample-ejuawqyrosinegcnvzhyrjhxkyue/Build/Products/Debug-iphonesimulator/sample.app

but I am getting New Error Now

Instruments Trace Error : Failed to start trace.
iOSTeam:~ iOSRider$ 
iOSTeam:~ iOSRider$ instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/iOSRider/Library/Developer/Xcode/DerivedData/sample-ejuawqyrosinegcnvzhyrjhxkyue/Build/Products/Debug-iphonesimulator/sample.app
2013-06-27 17:02:44.103 instruments[15986:1603] -[NSAlert alertWithError:] called with nil NSError. A generic error message will be displayed, but the user deserves better.


2013-06-27 17:09:03.530 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.processcontrol"; channel canceled <DTXChannel: 0x7fde6dbc2390>
2013-06-27 17:09:03.530 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.capabilities"; channel canceled <DTXChannel: 0x7fde6db89130>
2013-06-27 17:09:03.530 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.processcontrol.posixspawn"; channel canceled <DTXChannel: 0x7fde6dbc2a50>
2013-06-27 17:09:03.531 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.filebrowser"; channel canceled <DTXChannel: 0x7fde6dbb8da0>
2013-06-27 17:09:03.531 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.deviceinfo"; channel canceled <DTXChannel: 0x7fde6db8ead0>
2013-06-27 17:09:03.531 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.launchdaemon"; channel canceled <DTXChannel: 0x7fde6dbc3740>
2013-06-27 17:09:03.532 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.wireless"; channel canceled <DTXChannel: 0x7fde6dbbcfb0>
2013-06-27 17:09:03.532 instruments[15986:7877] Connection peer refused channel request for "com.apple.instruments.server.services.mobilenotifications"; channel canceled <DTXChannel: 0x7fde6dbbe050>

I want to run Instruments from Jenkins, that's why I am testing in Terminal.

I am using an iPad 2 with iOS 6.1.3. I am okay if it works in Simulator as well.

Please guide me on this if I am making any mistake.


Solution

  • Looks like you're missing a specific device ID ([-w device]). Although the template might have it, I think you need to specify it anyways at a command line.

    I did a bit of googling around and found this article.

    Here's a paired down script based on that article that you could use to run Instruments from a command line.

    runTests.sh

    XCODE_PATH=`xcode-select -print-path`
    TRACETEMPLATE="$XCODE_PATH/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
    APP_LOCATION=$2
    DEVICE_ID=$3
    
    if [ ! $# -gt 1 ]; then
        echo "You must specify the app location and the test file."
        echo "\t (optionally supply unique device ID of physical iOS device)"
        echo "\t eg. ./build.sh suite.js <xcodeproject directory>/build/Debug-iphonesimulator/myapp.app <device-udid>"
        exit -1
    fi
    
    # If running on device, only need name of app, full path not important
    if [ ! "$DEVICE_ID" = "" ]; then
      RUN_ON_SPECIFIC_DEVICE_OPTION="-w $DEVICE_ID"
      APP_LOCATION=`basename $APP_LOCATION`
    fi
    
    # Kick off the instruments build
    instruments \
    $RUN_ON_SPECIFIC_DEVICE_OPTION \
    -t $TRACETEMPLATE \
    $APP_LOCATION \
    -e UIARESULTSPATH /var/tmp
    

    Source: here