Skip to content

Instantly share code, notes, and snippets.

@tizoc
Forked from KodrAus/Profile Rust on Linux.md
Created April 29, 2021 02:21
Show Gist options
  • Save tizoc/7f77f32ebf536aed181bcd6a0bc430cb to your computer and use it in GitHub Desktop.
Save tizoc/7f77f32ebf536aed181bcd6a0bc430cb to your computer and use it in GitHub Desktop.

Revisions

  1. @KodrAus KodrAus revised this gist May 26, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Profile Rust on Linux.md
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,8 @@ $ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.sv
    This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph) available in your path. The [`rust-unmangle`](https://github.com/Yamakaky/rust-unmangle/blob/master/rust-unmangle) script is optional but nice.

    Also check out @dlaehnemann's more detailed walkthrough about generating flamegraphs [here](https://gist.github.com/dlaehnemann/df31787c41bd50c0fe223df07cf6eb89).

    # Profiling heap memory

    Using [valgrind (massif)](http://valgrind.org/docs/manual/ms-manual.html) and [massif-visualiser](https://github.com/KDE/massif-visualizer):
  2. @KodrAus KodrAus revised this gist May 26, 2019. 1 changed file with 2 additions and 15 deletions.
    17 changes: 2 additions & 15 deletions Profile Rust on Linux.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@ $ perf record -g binary
    $ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg
    ```

    > NOTE: See [@GabrielMajeri's comments below](https://gist.github.com/KodrAus/97c92c07a90b1fdd6853654357fd557a#gistcomment-2694776) about the `-g` option.
    This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph) available in your path. The [`rust-unmangle`](https://github.com/Yamakaky/rust-unmangle/blob/master/rust-unmangle) script is optional but nice.

    # Profiling heap memory
    @@ -23,21 +25,6 @@ Also check out [heaptrack](https://github.com/KDE/heaptrack), it's similar to `m
    $ heaptrack binary
    ```

    Note that you have to use the system allocator:

    ```rust
    #![feature(alloc_system)]

    extern crate alloc_system;

    use alloc_system::System;

    #[global_allocator]
    static A: System = System;
    ```

    If you don't use it you'll get totally inaccurate results that show no heap usage.

    # Debugging

    ```
  3. @KodrAus KodrAus revised this gist Jun 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Profile Rust on Linux.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ $ heaptrack binary
    Note that you have to use the system allocator:

    ```rust
    #![feature(alloc_system, global_allocator, allocator_api)]
    #![feature(alloc_system)]

    extern crate alloc_system;

  4. @KodrAus KodrAus revised this gist Oct 30, 2017. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion Profile Rust on Linux.md
    Original file line number Diff line number Diff line change
    @@ -26,8 +26,14 @@ $ heaptrack binary
    Note that you have to use the system allocator:

    ```rust
    #![feature(alloc_system)]
    #![feature(alloc_system, global_allocator, allocator_api)]

    extern crate alloc_system;

    use alloc_system::System;

    #[global_allocator]
    static A: System = System;
    ```

    If you don't use it you'll get totally inaccurate results that show no heap usage.
  5. @KodrAus KodrAus revised this gist Jun 9, 2017. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion Profile Rust on Linux.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,28 @@
    # Profiling performance

    Using [perf](https://perf.wiki.kernel.org/index.php/Main_Page):

    ```
    $ perf record -g binary
    $ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg
    ```

    This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph) available in your path. The `rust-unmange` script is optional but nice.
    This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph) available in your path. The [`rust-unmangle`](https://github.com/Yamakaky/rust-unmangle/blob/master/rust-unmangle) script is optional but nice.

    # Profiling heap memory

    Using [valgrind (massif)](http://valgrind.org/docs/manual/ms-manual.html) and [massif-visualiser](https://github.com/KDE/massif-visualizer):

    ```
    $ valgrind --tool=massif binary
    ```

    Also check out [heaptrack](https://github.com/KDE/heaptrack), it's similar to `massif` but more useful out-of-the-box. It also has a nice gui experience:

    ```
    $ heaptrack binary
    ```

    Note that you have to use the system allocator:

    ```rust
  6. @KodrAus KodrAus renamed this gist Mar 2, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md → Profile Rust on Linux.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph)
    $ valgrind --tool=massif binary
    ```

    Note that Rust/valgrind has previously had issues with the `jemalloc` allocator so you'd have to use the system allocator:
    Note that you have to use the system allocator:

    ```rust
    #![feature(alloc_system)]
    @@ -28,7 +28,7 @@ If you don't use it you'll get totally inaccurate results that show no heap usag
    $ rust-gdb binary
    ```

    Namespaces are prefixed by the crate name, which is probably also the name of the binary. Yuo can do stuff like:
    Namespaces are prefixed by the crate name, which is probably also the name of the binary. You can do stuff like:

    - `break` to set breakpoints
    - `print` to print a variable
  7. @KodrAus KodrAus revised this gist Feb 5, 2017. 1 changed file with 15 additions and 2 deletions.
    17 changes: 15 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph)
    # Profiling heap memory

    ```
    $ valgrind --tool=massif
    $ valgrind --tool=massif binary
    ```

    Note that Rust/valgrind has previously had issues with the `jemalloc` allocator so you'd have to use the system allocator:
    @@ -22,9 +22,22 @@ extern crate alloc_system;

    If you don't use it you'll get totally inaccurate results that show no heap usage.

    # Debugging

    ```
    $ rust-gdb binary
    ```

    Namespaces are prefixed by the crate name, which is probably also the name of the binary. Yuo can do stuff like:

    - `break` to set breakpoints
    - `print` to print a variable
    - `step`,`next`,`finish` to step through calls

    # Links

    - http://blog.adamperry.me/rust/2016/07/24/profiling-rust-perf-flamegraph/
    - https://llogiq.github.io/2015/07/15/profiling.html
    - https://www.linux-apps.com/content/show.php?content=122409
    - https://github.com/brendangregg/FlameGraph
    - https://github.com/brendangregg/FlameGraph
    - https://betterexplained.com/articles/debugging-with-gdb/
  8. @KodrAus KodrAus revised this gist Feb 5, 2017. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,11 @@ Note that Rust/valgrind has previously had issues with the `jemalloc` allocator
    extern crate alloc_system;
    ```

    If you don't use it you'll get totally inaccurate results that show no heap usage.
    If you don't use it you'll get totally inaccurate results that show no heap usage.

    # Links

    - http://blog.adamperry.me/rust/2016/07/24/profiling-rust-perf-flamegraph/
    - https://llogiq.github.io/2015/07/15/profiling.html
    - https://www.linux-apps.com/content/show.php?content=122409
    - https://github.com/brendangregg/FlameGraph
  9. @KodrAus KodrAus created this gist Feb 4, 2017.
    23 changes: 23 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Profiling performance

    ```
    $ perf record -g binary
    $ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg
    ```

    This requires you have [flamegraph](https://github.com/brendangregg/FlameGraph) available in your path. The `rust-unmange` script is optional but nice.

    # Profiling heap memory

    ```
    $ valgrind --tool=massif
    ```

    Note that Rust/valgrind has previously had issues with the `jemalloc` allocator so you'd have to use the system allocator:

    ```rust
    #![feature(alloc_system)]
    extern crate alloc_system;
    ```

    If you don't use it you'll get totally inaccurate results that show no heap usage.