简体   繁体   中英

Automate profiling for iOS using Xcode 12 xctrace command line tools

I am trying to automate performance testing using Xcode 12 Instruments developer tool and need some help.

I want to parse.trace file into readable format and want to print leaks/CPU usage on console. I am using below xctrace command line to automate leaks/Time Profiling with Xcode 12 Instruments tool:

xcrun xctrace record --device "udid" --template "Leaks" --time-limit 10m --attach "PID" --output "xyz.trace"

xcrun xctrace export --input "xyz.trace" toc --output "xyz.xml"

Is would be really great if someone can help.

Trace file for reference: https://gofile.io/d/EpvOXa

I am not sure if I understood your problem correctly, but if I run your command, I received a an error message. The CLI-tool gave me the following instructions:

usage: xctrace export [<options>] [--toc | --xpath expression]

description:
    Export given .trace using supplied query to the XML file format that can be later read and post-processed

options:
    --input <file>              Export data from the given .trace file
    --output <path>             Command output is written to the given path, if specified
    --toc                       Present entities to export in the table of contents form
    --xpath <expression>        Choose elements to export using specified XPath expression

notes:
    If output path is not specified, the export operation output will be written to the standard output.
    Table of Contents and XPath query are two separate modes and they cannot be specified together.

examples:
    xctrace export --input input.trace --toc
    xctrace export --input input.trace --toc --output table_of_contents.xml
    xctrace export --input input.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="my-table-schema"]'

According to this, the parameter toc is missing the two dashes. I hope that will fix it for you.

Exporting leaks are not supported (yet)..

To quote Kacper from apple on the forums https://developer.apple.com/forums/thread/661295 :

Export feature doesn't support our Leaks and Allocations Instruments yet, as they're build as a different recording technology. We're tracking it internally and will inform when this feature will be available in the release notes.

However you could use the leaks tool in /usr/bin/leaks to do just that!

Execute $ leaks <pid> to get an overview of all blocks of allocated memory that are no longer referenced.

You can also capture 2 memory graphs and compare them.

# Capture memory graph
leaks --outputGraph=before.memgraph <pid>

# Diff current with previous graph
leaks --diffFrom=before.memgraph <pid>

See Finding Leaks: Using the leaks Tool for more information.

leaks: Search through a process for leaked memory.

Usage: leaks [options] pid | partial-process-name | memory-graph-file
       leaks [options] --atExit -- <command-and-arguments>

        -e/--exclude <sym>     exclude leaked blocks whose backtraces include the specified symbol
        -h/--help              show this helpful usage message!
        -q/--quiet             suppress the process description header and footer
        --list                 print the leaks as a list ("classic"-style) rather than as a tree
        --groupByType          in leak trees, group children by type rather than showing individual instances
                                  (for normal leak detection output, and --referenceTree, --dominatorTree, and --autoreleasePools modes)
        --nostacks             do not print backtraces or save them in the memory graph file, even when available
        --fullStacks           print backtraces with one line per frame
        --nosources            do not show sourceFile:lineNumber in backtraces
        --outputGraph=<path>   save a memory graph file into the given directory or file
        --fullContent          print or save full allocation content descriptions
                                  (this is the default for printing output for live processes)
        --readonlyContent      print or save just readonly allocation content descriptions
                                  (this is the default for saving memory graphs)
        --noContent            do not save or print any allocation content descriptions
        --hex                  show the hex content of leaked allocations, if there is no description of content
        --forkCorpse           generate a corpse fork from process and run leaks on it
        --diffFrom=<memgraph>  show only the new leaks since the specified memgraph
        --trace=<address>      print chains of references from process 'roots' (e.g., global data) to the given block
        --traceTree=<address>  print a reverse tree of references, from the given block up to the process roots
        --referenceTree        print a reference tree of allocated memory starting at root nodes
        --autoreleasePools     print contents of autorelease pools, by thread
        --debug=[mode]         enable additional debugging modes; list available modes with --debug=help
        --atExit               launch the specified command and run leaks when that process exits.
                                  This should be the last argument; use '--atExit -- <command-and-arguments>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM