author Jorge Acereda <jacereda@gmail.com> 1588965308 +0200
committer Jorge Acereda <jacereda@gmail.com> 1589305057 +0200

Flamegraph script
This commit is contained in:
Jorge Acereda 2020-05-08 21:15:08 +02:00
parent 9ba6a26ff1
commit 0749af832b
2 changed files with 34 additions and 3 deletions

View File

@ -4,6 +4,9 @@ let
inherit (nixpkgs) pkgs;
optionals = nixpkgs.stdenv.lib.optionals;
linuxOnly = optionals nixpkgs.stdenv.isLinux;
f = { mkDerivation, ansi-terminal, base, blaze-html, blaze-markup
, cmark, cmdargs, containers, directory, edit-distance, filepath
, haskeline, HUnit, mtl, parsec, process, split, stdenv, text
@ -29,12 +32,12 @@ let
];
pkgconfigDepends =
[ glfw3 SDL2 SDL2_image SDL2_gfx SDL2_mixer SDL2_ttf ]
++ stdenv.lib.optionals stdenv.isLinux [ libXext libXcursor libXinerama libXi libXrandr libXScrnSaver libXxf86vm libpthreadstubs libXdmcp libGL];
++ linuxOnly [ libXext libXcursor libXinerama libXi libXrandr libXScrnSaver libXxf86vm libpthreadstubs libXdmcp libGL];
executableHaskellDepends = [
base cmdargs containers directory haskeline parsec process
clang
];
executableFrameworkDepends = with darwin.apple_sdk.frameworks; stdenv.lib.optionals stdenv.isDarwin [
executableFrameworkDepends = with darwin.apple_sdk.frameworks; optionals stdenv.isDarwin [
Carbon Cocoa IOKit CoreFoundation CoreVideo IOKit ForceFeedback
];
buildDepends = [ makeWrapper ];
@ -64,6 +67,7 @@ in
if pkgs.lib.inNixShell
then drv.env.overrideAttrs (o: {
buildInputs = o.buildInputs ++ [ haskellPackages.cabal-install pkgs.clang ];
buildInputs = with pkgs; o.buildInputs ++ [ haskellPackages.cabal-install clang gdb ]
++ linuxOnly [ flamegraph linuxPackages.perf ];
})
else drv

27
flamegraph.sh Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# To enable the required permissions, execute the following sequence as root:
# $ chown root:wheel /proc/modules
# $ chown root:wheel /proc/kallsyms
# $ echo 0 > /proc/sys/kernel/kptr_restrict
# $ echo -1 > /proc/sys/kernel/perf_event_paranoid
#
# Usage:
#
# Profile an executable
# ./flamegraph.sh <executable>
#
# To change the frequency:
# HZ=100 ./flamegraph.sh <executable>
#
# To use the maximum frequency
# HZ=max ./flamegraph.sh <executable>
#
# This can be useful to see how much time is spent in carp vs clang
# ./flamegraph.sh ./carp.sh -b <file.carp>
HZ=${HZ:-1000}
prg=`basename $1`
svg=flamegraph.svg
perf record -F $HZ -a -g -- $*
perf script | stackcollapse-perf.pl | flamegraph.pl > $svg
xdg-open $svg