diff --git a/default.nix b/default.nix index e166d79e..ec8b5a33 100644 --- a/default.nix +++ b/default.nix @@ -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 diff --git a/flamegraph.sh b/flamegraph.sh new file mode 100755 index 00000000..28cbef1f --- /dev/null +++ b/flamegraph.sh @@ -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 +# +# To change the frequency: +# HZ=100 ./flamegraph.sh +# +# To use the maximum frequency +# HZ=max ./flamegraph.sh +# +# This can be useful to see how much time is spent in carp vs clang +# ./flamegraph.sh ./carp.sh -b + +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