• Stars
    star
    419
  • Rank 100,062 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cargo subcommand to profile binaries

cargo-profiler

Build Status Crates.io license

Cargo subcommand to profile binaries

To install

NOTE: This subcommand can only be used on Linux machines.

First install valgrind:

$ sudo apt-get install valgrind

Then you can install cargo-profiler via cargo install.

$ cargo install cargo-profiler

Alternatively, you can clone this repo and build the binary from the source.

$ cargo build --release

Now, copy the built binary to the same directory as cargo.

$ sudo cp ./target/release/cargo-profiler $(dirname $(which cargo))/

To run

Cargo profiler currently supports callgrind and cachegrind.

You can call cargo profiler anywhere in a rust project directory with a Cargo.toml.

$ cargo profiler callgrind
$ cargo profiler cachegrind --release

You can also specify a binary directly:

$ cargo profiler callgrind --bin $PATH_TO_BINARY

To specify command line arguments to the executable being profiled, append them after a --:

$ cargo profiler callgrind --bin $PATH_TO_BINARY -- -a 3 --like this

You can chose to keep the callgrind/cachegrind output files using the --keep option

$ cargo profiler callgrind --keep

You can limit the number of functions you'd like to look at:

$ cargo profiler callgrind --bin ./target/debug/rsmat -n 10

Profiling rsmat with callgrind...

Total Instructions...198,466,456

78,346,775 (39.5%) dgemm_kernel.rs:matrixmultiply::gemm::masked_kernel
-----------------------------------------------------------------------
23,528,320 (11.9%) iter.rs:_..std..ops..Range..A....as..std..iter..Iterator..::next
-----------------------------------------------------------------------
16,824,925 (8.5%) loopmacros.rs:matrixmultiply::gemm::masked_kernel
-----------------------------------------------------------------------
10,236,864 (5.2%) mem.rs:core::mem::swap
-----------------------------------------------------------------------
7,712,846 (3.9%) memset.S:memset
-----------------------------------------------------------------------
7,197,344 (3.6%) ???:core::cmp::impls::_..impl..cmp..PartialOrd..for..usize..::lt
-----------------------------------------------------------------------
6,979,680 (3.5%) ops.rs:_..usize..as..ops..Add..::add
-----------------------------------------------------------------------

With cachegrind, you can also sort the data by a particular metric column:

$ cargo profiler cachegrind --bin ./target/debug/rsmat -n 10 --sort dr

Profiling rsmat with cachegrind...

Total Memory Accesses...320,385,356

Total L1 I-Cache Misses...371 (0%)
Total LL I-Cache Misses...308 (0%)
Total L1 D-Cache Misses...58,549 (0%)
Total LL D-Cache Misses...8,451 (0%)

 Ir  I1mr ILmr  Dr  D1mr DLmr  Dw  D1mw DLmw
0.40 0.18 0.21 0.35 0.93 1.00 0.38 0.00 0.00 dgemm_kernel.rs:matrixmultiply::gemm::masked_kernel
-----------------------------------------------------------------------
0.08 0.04 0.05 0.12 0.00 0.00 0.02 0.00 0.00 loopmacros.rs:matrixmultiply::gemm::masked_kernel
-----------------------------------------------------------------------
0.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
-----------------------------------------------------------------------
0.05 0.01 0.01 0.07 0.00 0.00 0.08 0.00 0.00 mem.rs:core::mem::swap
-----------------------------------------------------------------------
0.03 0.00 0.00 0.05 0.00 0.00 0.00 0.00 0.00 ???:core::cmp::impls::_implcmp..PartialOrdforusize::lt
-----------------------------------------------------------------------
0.03 0.01 0.01 0.04 0.00 0.00 0.03 0.00 0.00 ops.rs:_busizeasops..Addausize::add
-----------------------------------------------------------------------
0.04 0.01 0.01 0.04 0.00 0.00 0.03 0.00 0.00 ptr.rs:core::ptr::_implconstT::offset
-----------------------------------------------------------------------
0.02 0.01 0.00 0.03 0.00 0.00 0.01 0.00 0.00 ???:_usizeasops..Add::add
-----------------------------------------------------------------------
0.01 0.01 0.01 0.02 0.00 0.00 0.01 0.00 0.00 mem.rs:core::mem::uninitialized
-----------------------------------------------------------------------
0.02 0.01 0.01 0.02 0.00 0.00 0.04 0.00 0.00 wrapping.rs:_XorShiftRngasRng::next_u32
-----------------------------------------------------------------------


What are the cachegrind metrics?

  • Ir -> Total Instructions
  • I1mr -> Level 1 I-Cache misses
  • ILmr -> Last Level I-Cache misses
  • Dr -> Total Memory Reads
  • D1mr -> Level 1 D-Cache read misses
  • DLmr -> Last Level D-cache read misses
  • Dw -> Total Memory Writes
  • D1mw -> Level 1 D-Cache write misses
  • DLmw -> Last Level D-cache write misses

TODO

  • cmp subcommand - compare binary profiles
  • profiler macros
  • better context around expensive functions
  • support for more profiling tools

More Repositories

1

genact

πŸŒ€ A nonsense activity generator
Rust
7,449
star
2

miniserve

🌟 For when you really just want to serve some files over HTTP right now!
Rust
4,653
star
3

rofi-calc

πŸ–© Do live calculations in rofi!
C
756
star
4

upload-release-action

Upload files to a GitHub release
TypeScript
429
star
5

rust-web-boilerplate

Rust web template for modern web backend applications
Rust
286
star
6

bvh

A fast BVH using SAH in rust
Rust
220
star
7

wmfocus

Visually focus windows by label
Rust
195
star
8

flamejam

A generic game jam application with ratings and comments using Flask
HTML
141
star
9

memefs

Mount your memes using FUSE
Rust
131
star
10

glsl-language-server

Language server implementation for GLSL
C++
104
star
11

proxyboi

A super simple reverse proxy with TLS support
Rust
81
star
12

dwarf_fortress_unfuck

Unfucking Dwarf Fortress
C++
80
star
13

dummyhttp

Super simple HTTP server that replies a fixed body with a fixed response code
Rust
56
star
14

pseudoform

Pseudoform is a community-driven collaboration project that aims to create an involving and brain-melting first-person puzzle-solving game.
C++
38
star
15

trac0r

A fast real time physically based renderer
C++
28
star
16

upx-action

Strips and runs upx on binaries
JavaScript
25
star
17

mt940-rs

A MT940 parser in Rust
Rust
22
star
18

python-web-boilerplate

Python web template for modern web backend applications
Python
21
star
19

keycloak-http-webhook-provider

A Keycloak provider that posts events to a URL via HTTP POST as JSON
Java
20
star
20

derp

The derp game engine in D
D
20
star
21

gamejam

This is a gamejam project for all kinds of jams.
Lua
19
star
22

wiresmith

Auto-config WireGuard clients into a mesh
Rust
17
star
23

lglive

live.linuX-gamers live gaming distro
Shell
15
star
24

site24x7_exporter

A Prometheus compatible exporter for site24x7.com
Rust
13
star
25

crabcluster

A simple integrated container orchestration solution
Rust
12
star
26

pytest-colordots

Colorizes the progress indicators
Python
12
star
27

dotfiles

Various dotfiles from my machines
Vim Script
12
star
28

minimal-examples

A bunch of small standalone programs
C++
11
star
29

proby

πŸ“‘ Check whether hosts are reachable on certain ports and return result on HTTP
Rust
10
star
30

playgrounds

Just some playing around with physics.
C++
9
star
31

Spacescape

A space skybox tool using Ogre3D
C++
8
star
32

fints-institute-db

A library and CLI tool to access FinTS access information for many German banks
Rust
6
star
33

talks

Talks for conferences and such
HTML
5
star
34

fints-rs

A compliant FinTS implementation
Rust
5
star
35

vulkanology

Test Vulkan compute shaders using Rust
Rust
5
star
36

qponies

Desktop ponies using qml
C++
5
star
37

NoisyHunter

Implementation of http://www.squidi.net/three/entry.php?id=85
C++
5
star
38

Pseudoform-2

C++
4
star
39

piplayer

Receive a command, play a song
Rust
4
star
40

bankthing

πŸ’° A thing that does stuff with banks
Python
3
star
41

instacheer

Instant cheer for your desktop!
C++
3
star
42

benchy

FOSS cross-platform desktop benchmarking tool
C++
3
star
43

MegaGong

School gong for my class
C++
2
star
44

ilswlol

Wer weiss?
Python
2
star
45

arkenon

Stuff with spaceships
C++
2
star
46

pong4p

4-player multiplayer pong
Python
2
star
47

minitraderoute

A Mini Metro-inspired space trading game
Rust
2
star
48

txt2vid

A text to video renderer
2
star
49

windowcrap

Experimental crap for your desktop!
C++
2
star
50

esp32-toys

Just playing around with ESP32
Python
2
star
51

ssl-proxy-docker

Dockerized version of https://github.com/suyashkumar/ssl-proxy
Dockerfile
2
star
52

rust-web-experiments

Various experiments with rust in the web
Rust
2
star
53

overpower

CLI tool to benchmark web servers with nice output
Rust
2
star
54

rust-timescale-sqlx-rocket

A little integration test of Rust, TimescaleDB, sqlx, and Rocket
Rust
2
star
55

lolpi

A simple implementation of Bellard's formula for calculating PI.
C++
2
star
56

uefi-playground

Experiments with UEFI
Makefile
2
star
57

innojam13

IGJam #13
Rust
1
star
58

cargo-sweb

Simple and convenient cargo subcommand to develop web applications
1
star
59

gameservers

Instant game servers for various games
Shell
1
star
60

pink-fluffy-unicorns

Interactive Visual Computing using POVRay
TeX
1
star
61

taxi-simulation

Schizl
Rust
1
star
62

innojam8

InnoGames Game Jam 8
JavaScript
1
star
63

infinerator

Image generator to generate every possible combination of a given resolution and color depth
C++
1
star
64

qemu-espressif-docker

A container image containing espressif-qemu
Dockerfile
1
star
65

caca

Copy And Convert Audio
Python
1
star
66

svenstaro

My GitHub profile page
1
star
67

fredjam2018

Rust
1
star
68

gamedev-starter-packs

Starter packs for various languages
Lua
1
star
69

epaper-frame

A color e-ink-based picture frame driven by an ESP32
Rust
1
star
70

docker-phoronix-test-suite

A Docker image featuring a ready-to-run installation of the Phoronix Test Suite
Dockerfile
1
star
71

uni-projekt

Projekt Mikrocomputer
Python
1
star
72

docker-archlinux-bootstrap

Arch Linux Docker base image that is generated from the official bootstrap
Shell
1
star
73

rust-python-experiment

Experiments involving Rust + Python
Rust
1
star
74

strapon

Modern C++14 helpers for game stuff
C++
1
star