Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: compilation flags for flamegraph #30

Open
ktmeaton opened this issue Jan 2, 2024 · 0 comments
Open

benchmark: compilation flags for flamegraph #30

ktmeaton opened this issue Jan 2, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@ktmeaton
Copy link
Collaborator

ktmeaton commented Jan 2, 2024

Refer to: c80a888, 967674e

  • Get ready for benchmarking and profiling with flamegraph!
  • Some reminder notes for myself, about what a nightmare it was to install perf for WSL2.

Perf

  1. Check WSL2 kernel version in powershell.

    wsl --version
  2. Download the source code for the matching kernel release: https://github.com/microsoft/WSL2-Linux-Kernel/releases

    Extraction takes a very long time! ☕

    wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-<VER>.tar.gz
    tar -xf linux-msft-wsl-<VER>.tar.gz
  3. Install the compilation dependencies.

    "To actually make sense of the perf record, and get the interactive menu, also install these on top of flex and bison to let perf demangle binaries": @tbarbette Source, + commands from @MondayCha.

    sudo apt update
    sudo apt install flex bison 
    sudo apt install libdwarf-dev libelf-dev libnuma-dev libunwind-dev \
        libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev \
        systemtap-sdt-dev libssl-dev libperl-dev python-dev-is-python3 \
        binutils-dev libiberty-dev libzstd-dev libcap-dev libbabeltrace-dev
  4. Compile and install perf.

    cd WSL2-Linux-Kernel-linux-msft-wsl-<VER>
    cd tools/perf
    make JOBS=1
    
    sudo cp perf /usr/local/bin
  5. Enable perf for unprivileged users.

    "Lower the perf_event_paranoid value in proc to an appropriate level for your environment. The most permissive value is -1 but may not be acceptable for your security needs etc..." Source

    "More information can be found at 'Perf events and tool security' document": https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html

    echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid

Flamegraph

  1. Intall flamegraph.

    cargo install flamegraph
  2. Build for flamegraph.

    cargo build --profile=flamegraph --target x86_64-unknown-linux-musl
  3. Profile.

    perf record target/x86_64-unknown-linux-musl/flamegraph/rebar run --dataset-dir dataset/sars-cov-2/2023-11-30 -- populations "*" --output-dir output/flamegraph
    
    flamegraph -o flamegraph_sars-cov-2.svg --perfdata perf.data

Troubleshooting

  1. Using on a pre-compiled binary doesn't yield informative names on the function names.

    "It seems like you might be stripping away the debug symbols? Do you maybe have strip = true somewhere in Cargo.toml or maybe in some other build script?" @xzaramurd Source

  2. flamegraph hangs after perf record due to an issue collapsing stacks. Might be solved with:

@ktmeaton ktmeaton self-assigned this Jan 2, 2024
@ktmeaton ktmeaton added enhancement New feature or request minor labels Jan 2, 2024
@ktmeaton ktmeaton added this to the v0.3.0 milestone Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant