### Install via Nix Source: https://github.com/cmyr/cargo-instruments/blob/main/README.md Use nix-shell to provide dependencies and build from source. ```sh $ nix-shell --command 'cargo install cargo-instruments' --pure -p \ darwin.apple_sdk.frameworks.SystemConfiguration \ darwin.apple_sdk.frameworks.CoreServices \ rustc cargo sccache libgit2 pkg-config libiconv \ llvmPackages_13.libclang openssl ``` -------------------------------- ### Install via Homebrew Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/README.md Installs the cargo-instruments binary using the Homebrew package manager. ```bash brew install cargo-instruments ``` -------------------------------- ### Install cargo-instruments via Cargo Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/project-overview.md Standard installation method using the Rust package manager. ```bash cargo install cargo-instruments ``` ```bash cargo install --features vendored-openssl cargo-instruments ``` -------------------------------- ### Trace File Example Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/configuration.md A concrete example of a generated trace file name. ```text myapp_Time-Profiler_2024-01-15_143025-123.trace ``` -------------------------------- ### Install via Cargo Source: https://github.com/cmyr/cargo-instruments/blob/main/README.md Install from source using Cargo. Use the vendored-openssl feature if OpenSSL is missing or installation fails. ```sh $ cargo install cargo-instruments ``` ```sh $ cargo install --features vendored-openssl cargo-instruments ``` -------------------------------- ### Profile workspace package example Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/README.md Targets a specific package and example within a workspace using the allocation profiler. ```bash cargo instruments -p mypackage --example myexample -t alloc ``` -------------------------------- ### Install via Homebrew Source: https://github.com/cmyr/cargo-instruments/blob/main/README.md Use Homebrew to install the package on macOS. ```sh $ brew install cargo-instruments ``` -------------------------------- ### Execute Profiling Command Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-instruments.md Example of constructing and executing a profiling command for a binary. ```rust let xcode = XcodeInstruments::detect()?; let mut cmd = xcode.profiling_command("Time Profiler", Path::new("trace.trace"), Some(30000))?; cmd.arg("/path/to/binary").arg("binary_arg"); let output = cmd.output()?; ``` -------------------------------- ### Install with vendored OpenSSL Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/configuration.md Use this command to install cargo-instruments with a vendored copy of OpenSSL when the system version is unavailable. ```bash cargo install --features vendored-openssl cargo-instruments ``` -------------------------------- ### Combined Profiling Example Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-opt.md A complex command demonstrating multiple flags used in conjunction. ```bash # Complex example: workspace package, custom features, release mode, time limit, custom output $ cargo instruments -p foo --bin bar -t time \ --release \ --features "feature1 feature2" \ --time-limit 30000 \ -o ~/profiling/my_trace.trace \ -- arg1 arg2 arg3 ``` -------------------------------- ### Verify Xcode Instruments Installation Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/errors.md Commands to verify the installation of Xcode Instruments based on the macOS version. ```bash xctrace --version # For macOS 10.15+ instruments -h # For macOS 10.13-10.14 ``` -------------------------------- ### List available templates Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/configuration.md Displays all available Instruments templates and exits without starting a profiling session. ```bash cargo instruments --list-templates ``` -------------------------------- ### Verify Xcode Templates Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/errors.md Commands to manually list available Xcode templates to verify the installation is functional. ```bash xcrun xctrace list templates # macOS 10.15+ instruments -s templates # macOS 10.13-10.14 ``` -------------------------------- ### Profile Binaries with Cargo Instruments Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/project-overview.md Examples of profiling different targets using various templates and time limits. ```bash # Profile main binary with Time Profiler cargo instruments -t time # Profile example binary cargo instruments -t alloc --example my_example --time-limit 10000 # Profile from specific workspace package cargo instruments -p foo --bin bar -t sys ``` -------------------------------- ### Get Package from AppConfig Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-opt.md Retrieves the package configuration based on CLI input. ```rust fn get_package(&self) -> Package ``` -------------------------------- ### Demangled symbol example Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-demangle.md Example of the same symbol after being processed by the demangle module. ```text as alloc::vec::spec_extend::SpecExtend>::spec_extend ``` -------------------------------- ### Mangled symbol example Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-demangle.md Example of a mangled Rust symbol as it appears before processing. ```text _$LT$alloc..vec..Vec$LT$T$C$A$GT$$u20$as$u20$alloc..vec..spec_extend..SpecExtend$LT$T$C$I$GT$$GT$::spec_extend::hb9d6b49df4cfa5e3 ``` -------------------------------- ### Target Selection Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-opt.md Commands for profiling specific project targets like examples, binaries, or benchmarks. ```bash # Profile a specific example $ cargo instruments -t alloc --example my_example # Profile a specific binary $ cargo instruments -t time --bin my_binary # Profile a benchmark $ cargo instruments -t sys --bench my_bench ``` -------------------------------- ### Retrieve Available Profiling Templates Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-instruments.md Queries the installed Instruments for a list of available profiling templates. ```rust let xcode = XcodeInstruments::detect()?; let catalog = xcode.available_templates()?; println!("{}", render_template_catalog(&catalog)); ``` -------------------------------- ### Workspace package profiling Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/configuration.md Profiles a specific example within a workspace package using the System Trace template. ```bash cargo instruments -p mypackage --example myexample -t sys ``` -------------------------------- ### Get Target from AppConfig Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-opt.md Determines the build target based on CLI flags with specific priority order. ```rust fn get_target(&self) -> Target ``` -------------------------------- ### Get macOS Version Signature Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-instruments.md Signature for the function that retrieves and parses the current macOS version. ```rust fn get_macos_version() -> Result ``` -------------------------------- ### Detect Xcode Instruments Version Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/api-reference-instruments.md Detects the installed version of Xcode Instruments by validating system binaries. ```rust let xcode = XcodeInstruments::detect()?; println!("Using: {}", xcode); ``` -------------------------------- ### Xcode-select reset command Source: https://github.com/cmyr/cargo-instruments/blob/main/_autodocs/errors.md Command used to reset Xcode developer directory paths when Xcode or CLT installations are problematic. ```bash xcode-select --reset ``` -------------------------------- ### View help documentation Source: https://github.com/cmyr/cargo-instruments/blob/main/README.md Displays the command-line help and usage information. ```text Profile a binary with Xcode Instruments. By default, cargo-instruments will build your main binary. Usage: cargo instruments [OPTIONS] [ARGS]... Arguments: [ARGS]... Arguments passed to the target binary. To pass flags, precede child args with `--`, e.g. `cargo instruments -- -t test1.txt --slow-mode`. Options: -l, --list-templates List available templates -t, --template