{"id":13503135,"url":"https://github.com/svenstaro/cargo-profiler","last_synced_at":"2025-04-05T13:08:16.517Z","repository":{"id":8493721,"uuid":"57214129","full_name":"svenstaro/cargo-profiler","owner":"svenstaro","description":"Cargo subcommand to profile binaries ","archived":false,"fork":false,"pushed_at":"2023-03-09T05:00:26.000Z","size":46661,"stargazers_count":436,"open_issues_count":36,"forks_count":16,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T12:08:18.180Z","etag":null,"topics":["cachegrind","cargo","cargo-profiler","cargo-subcommand","rust","valgrind"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svenstaro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-04-27T13:07:52.000Z","updated_at":"2025-03-01T00:40:29.000Z","dependencies_parsed_at":"2023-07-14T08:53:35.689Z","dependency_job_id":"c8d75937-b36f-4987-a116-2f395b00f69e","html_url":"https://github.com/svenstaro/cargo-profiler","commit_stats":null,"previous_names":["pegasos1/cargo-profiler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenstaro%2Fcargo-profiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenstaro%2Fcargo-profiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenstaro%2Fcargo-profiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenstaro%2Fcargo-profiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svenstaro","download_url":"https://codeload.github.com/svenstaro/cargo-profiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339158,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cachegrind","cargo","cargo-profiler","cargo-subcommand","rust","valgrind"],"created_at":"2024-07-31T22:02:38.385Z","updated_at":"2025-04-05T13:08:16.500Z","avatar_url":"https://github.com/svenstaro.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# cargo-profiler\n\n[![Build Status](https://travis-ci.org/svenstaro/cargo-profiler.svg?branch=master)](https://travis-ci.org/svenstaro/cargo-profiler)\n[![Crates.io](https://img.shields.io/crates/v/cargo-profiler.svg)](https://crates.io/crates/cargo-profiler)\n[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/svenstaro/cargo-profiler/blob/master/LICENSE)\n\n**Cargo subcommand to profile binaries**\n\n## To install\n\nNOTE: This subcommand can only be used on Linux machines.\n\nFirst install valgrind:\n\n```\n$ sudo apt-get install valgrind\n```\n\nThen you can install `cargo-profiler` via `cargo install`.\n```\n$ cargo install cargo-profiler\n```\n\nAlternatively, you can clone this repo and build the binary from the source.\n\n```\n$ cargo build --release\n```\n\nNow, copy the built binary to the same directory as cargo.\n\n```\n$ sudo cp ./target/release/cargo-profiler $(dirname $(which cargo))/\n```\n\n## To run\n\nCargo profiler currently supports callgrind and cachegrind.\n\nYou can call cargo profiler anywhere in a rust project directory with a `Cargo.toml`.\n\n```\n$ cargo profiler callgrind\n$ cargo profiler cachegrind --release\n```\n\nYou can also specify a binary directly:\n\n```\n$ cargo profiler callgrind --bin $PATH_TO_BINARY\n```\n\nTo specify command line arguments to the executable being profiled, append them\nafter a `--`:\n\n```\n$ cargo profiler callgrind --bin $PATH_TO_BINARY -- -a 3 --like this\n```\n\nYou can chose to keep the callgrind/cachegrind output files using the `--keep` option\n\n```\n$ cargo profiler callgrind --keep\n```\n\nYou can limit the number of functions you'd like to look at:\n\n```\n$ cargo profiler callgrind --bin ./target/debug/rsmat -n 10\n\nProfiling rsmat with callgrind...\n\nTotal Instructions...198,466,456\n\n78,346,775 (39.5%) dgemm_kernel.rs:matrixmultiply::gemm::masked_kernel\n-----------------------------------------------------------------------\n23,528,320 (11.9%) iter.rs:_..std..ops..Range..A....as..std..iter..Iterator..::next\n-----------------------------------------------------------------------\n16,824,925 (8.5%) loopmacros.rs:matrixmultiply::gemm::masked_kernel\n-----------------------------------------------------------------------\n10,236,864 (5.2%) mem.rs:core::mem::swap\n-----------------------------------------------------------------------\n7,712,846 (3.9%) memset.S:memset\n-----------------------------------------------------------------------\n7,197,344 (3.6%) ???:core::cmp::impls::_..impl..cmp..PartialOrd..for..usize..::lt\n-----------------------------------------------------------------------\n6,979,680 (3.5%) ops.rs:_..usize..as..ops..Add..::add\n-----------------------------------------------------------------------\n\n```\n\nWith cachegrind, you can also sort the data by a particular metric column:\n\n```\n$ cargo profiler cachegrind --bin ./target/debug/rsmat -n 10 --sort dr\n\nProfiling rsmat with cachegrind...\n\nTotal Memory Accesses...320,385,356\n\nTotal L1 I-Cache Misses...371 (0%)\nTotal LL I-Cache Misses...308 (0%)\nTotal L1 D-Cache Misses...58,549 (0%)\nTotal LL D-Cache Misses...8,451 (0%)\n\n Ir  I1mr ILmr  Dr  D1mr DLmr  Dw  D1mw DLmw\n0.40 0.18 0.21 0.35 0.93 1.00 0.38 0.00 0.00 dgemm_kernel.rs:matrixmultiply::gemm::masked_kernel\n-----------------------------------------------------------------------\n0.08 0.04 0.05 0.12 0.00 0.00 0.02 0.00 0.00 loopmacros.rs:matrixmultiply::gemm::masked_kernel\n-----------------------------------------------------------------------\n0.12 0.02 0.02 0.10 0.00 0.00 0.15 0.00 0.00 iter.rs:_std..ops..RangeAasstd..iter..Iterator::next\n-----------------------------------------------------------------------\n0.05 0.01 0.01 0.07 0.00 0.00 0.08 0.00 0.00 mem.rs:core::mem::swap\n-----------------------------------------------------------------------\n0.03 0.00 0.00 0.05 0.00 0.00 0.00 0.00 0.00 ???:core::cmp::impls::_implcmp..PartialOrdforusize::lt\n-----------------------------------------------------------------------\n0.03 0.01 0.01 0.04 0.00 0.00 0.03 0.00 0.00 ops.rs:_busizeasops..Addausize::add\n-----------------------------------------------------------------------\n0.04 0.01 0.01 0.04 0.00 0.00 0.03 0.00 0.00 ptr.rs:core::ptr::_implconstT::offset\n-----------------------------------------------------------------------\n0.02 0.01 0.00 0.03 0.00 0.00 0.01 0.00 0.00 ???:_usizeasops..Add::add\n-----------------------------------------------------------------------\n0.01 0.01 0.01 0.02 0.00 0.00 0.01 0.00 0.00 mem.rs:core::mem::uninitialized\n-----------------------------------------------------------------------\n0.02 0.01 0.01 0.02 0.00 0.00 0.04 0.00 0.00 wrapping.rs:_XorShiftRngasRng::next_u32\n-----------------------------------------------------------------------\n\n\n```\n\n## What are the cachegrind metrics?\n\n* Ir -\u003e Total Instructions\n* I1mr -\u003e Level 1 I-Cache misses\n* ILmr -\u003e Last Level I-Cache misses\n* Dr -\u003e Total Memory Reads\n* D1mr -\u003e Level 1 D-Cache read misses\n* DLmr -\u003e Last Level D-cache read misses\n* Dw -\u003e Total Memory Writes\n* D1mw -\u003e Level 1 D-Cache write misses\n* DLmw -\u003e Last Level D-cache write misses\n\n## TODO\n\n* cmp subcommand - compare binary profiles\n* profiler macros\n* better context around expensive functions\n* support for more profiling tools\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenstaro%2Fcargo-profiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvenstaro%2Fcargo-profiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenstaro%2Fcargo-profiler/lists"}