From 322478d9a238cee3292131840bfd5e7cdd617f41 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 26 Apr 2021 09:35:31 +0200 Subject: [PATCH] ls: document flamegraph --- src/uu/ls/BENCHMARKING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/uu/ls/BENCHMARKING.md b/src/uu/ls/BENCHMARKING.md index 84a0c3d84..c6568f879 100644 --- a/src/uu/ls/BENCHMARKING.md +++ b/src/uu/ls/BENCHMARKING.md @@ -32,3 +32,19 @@ This can also be used to compare with version of ls built before your changes to - Another thing to look at would be system calls count using strace (on linux) or equivalent on other operating systems. - Example: `strace -c target/release/coreutils ls -al -R tree` + +## Cargo Flamegraph + +With Cargo Flamegraph you can easily make a flamegraph of `ls`: +```bash +cargo flamegraph --cmd coreutils -- ls [additional parameters] +``` + +However, if the `-R` option is given, the output becomes pretty much useless due to recursion. We can fix this by merging all the direct recursive calls with `uniq`, below is a `bash` script that does this. +```bash +#!/bin/bash + +cargo build --release --no-default-features --features ls +perf record target/release/coreutils ls "$@" +perf script | uniq | inferno-collapse-perf | inferno-flamegraph > flamegraph.svg +``` \ No newline at end of file