• Stars
    star
    870
  • Rank 52,440 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 6 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

A sampling CPU profiler for Linux

A sampling CPU profiler for Linux similar to perf

Features

  • Support for AMD64, ARM, AArch64 and MIPS64 architectures (where MIPS64 requires a tiny out-of-tree patch to the kernel to work)
  • Support for offline and online stack trace unwinding
  • Support for profiling of binaries without any debug info (without the .debug_frame section)
    • using .eh_frame based unwinding (this is how normal C++ exception handling unwinds the stack) without requiring .eh_frame_hdr (which, depending on the compiler, may not be emitted)
    • using .ARM.exidx + .ARM.extab based unwinding (which is ARM specific and is used instead of .eh_frame)
  • Support for cross-architectural data analysis
  • Fully architecture-agnostic data format
  • Built-in flamegraph generation

Why should I use this instead of perf?

If perf already works for you - great! Keep on using it.

This project was born out of a few limitations of the original perf which make it non-ideal for CPU profiling in embedded-ish environments. Some of those are as follows:

  • lack of support for MIPS64,
  • the big size of generated CPU profiling data due to offline-only stack unwinding, so if you only have a limited amount of storage space you either need to profile with a very low frequency, or for a very short amount of time;
  • lack of support for cross-architectural analysis - if you run perf record on ARM then you also need to run perf report either on ARM or under QEMU, and running the analysis under QEMU (depending on how you've compiled your binaries and with what flags you've launched perf) can take hours;
  • and poor support for profiling binaries which have limited or no debug info, which is often the case in big, embedded-lite projects where the debug info can't even fit on the target machine, or is not readily available.

Building

  1. Install at least Rust 1.31

  2. Build it:

     $ cd cli
     $ cargo build --release
    
  3. Grab the binary from target/release/.

Cross-compiling

  1. Configure the linker for your target architecture in your ~/.cargo/config, e.g.:
[target.mips64-unknown-linux-gnuabi64]
linker = "/path/to/your/sdk/mips64-octeon2-linux-gnu-gcc"
rustflags = [
  "-C", "link-arg=--sysroot=/path/to/your/sdk/sys-root/mips64-octeon2-linux-gnu"
]

[target.armv7-unknown-linux-gnueabihf]
linker = "/path/to/your/sdk/arm-cortexa15-linux-gnueabihf-gcc"
rustflags = [
  "-C", "link-arg=--sysroot=/path/to/your/sdk/sys-root/arm-cortexa15-linux-gnueabihf"
]
  1. Compile, either for ARM or for MIPS64:

     $ cargo build --release --target=mips64-unknown-linux-gnuabi64
     $ cargo build --release --target=armv7-unknown-linux-gnueabihf
    
  2. Grab the binary from target/mips64-unknown-linux-gnuabi64/ or target/armv7-unknown-linux-gnueabihf/.

Basic usage

Profiling an already running process by its PID:

$ cargo run record -p $PID_OF_YOUR_PROCESS -o datafile

Profiling a process by its name and waiting if it isn't running yet:

$ cargo run record -P cpu-hungry-program -w -o datafile

Generating a CPU flame graph from the gathered data:

$ cargo run flamegraph datafile > flame.svg

Replace cargo run with the path to the executable if you're running the profiler outside of its build directory.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

bytehound

A memory profiler for Linux.
C
4,446
star
2

stdweb

A standard library for the client-side Web
Rust
3,441
star
3

cargo-web

A Cargo subcommand for the client-side Web
Rust
1,106
star
4

pinky

An NES emulator written in Rust
Rust
771
star
5

speedy

A fast binary serialization framework
Rust
373
star
6

polkavm

A fast and secure RISC-V based virtual machine
Rust
239
star
7

schnellru

A fast and flexible LRU map.
Rust
170
star
8

parcel-plugin-cargo-web

JavaScript
48
star
9

libretro-backend

Libretro API bindings for Rust
Rust
46
star
10

sarek

A work-in-progress, experimental neural network library for Rust
Rust
44
star
11

polkadot-starship

Ruby
24
star
12

polkavm-experiment

An experimental RISC-V recompiler
Rust
18
star
13

hooky

A convenient LD_PRELOAD hooker
Rust
12
star
14

rustc-rv32e

Rust toolchain for RV32E
Shell
10
star
15

rwkv_tokenizer

Python
7
star
16

polkadoom

Yet another DOOM port
C++
7
star
17

libretro-sys

Raw FFI bindings to the libretro API
Rust
6
star
18

static_test

Attribute macro for writing tests which check that a given condition ALWAYS holds true or that a given code path is ALWAYS unreachable
Rust
6
star
19

serde-bench

A simple benchmark of various Rust serialization frameworks
Rust
6
star
20

nsctrld

Nintendo Switch Pro Controller userspace driver
Rust
4
star
21

linux-input

Rust
4
star
22

memory-pool

A global, thread-safe memory pool.
Rust
4
star
23

dspr

A DSP plugin server
C++
3
star
24

unsafe_target_feature

A more convenient `#[target_feature]` replacement
Rust
3
star
25

chromium-build

Shell
2
star
26

softfloat

Rust
2
star
27

cargo-shim

A helper library for Cargo subcommands
Rust
2
star
28

mmalloc

A simple mmap-based allocator
Rust
2
star
29

chrf

Rust
2
star
30

koute.github.io

JavaScript
1
star
31

inputd

Rust
1
star
32

linux-elf-loading-bug

Rust
1
star