Search code examples
cxcodeinstruments

Can Instruments be used using the command line?


Can Instruments be used as a replacement for

valgrind

If one wants to check for memory leaks using instruments can it be used from the terminal?


Solution

  • Instruments used to have a command line interface:

    $ instruments -h
    

    Example usage:

    $ instruments -t mytemplate -a myapp.app
    

    For leaks, try the Leaks.tracetemplate. To see all available templates, use -s.

    There is another executable, just called leaks. You can inspect any running application by giving leaks its PID:

    $ echo $$
    620
    
    $ leaks 620
    leaks Report Version:  2.0 
    Process:         bash [620]
    Path:            /bin/bash
    Load Address:    0x100000000
    ...
    Process 620: 37983 nodes malloced for 1123 KB
    Process 620: 0 leaks for 0 total leaked bytes.
    

    Read more about leaks in the Apple developer reference library.