Profilieren baut mit Stapel 1.0.0 und neuere
mit einer Profilierung bauen aktiviert:
stack build --profile
Sie müssen möglicherweise stack clean
erste, aber this should be fixed in Stack 1.5.0 laufen.
Zum Profil:
stack exec -- <your program> +RTS <profiling options>
wo für <profiling options>
Sie -p
für Zeit Profilieren oder -h
für Speicherprofilierungs wollen könnte. Für die Zeitprofilerstellung wird das Profil in ./<your program>.prof
angezeigt, und für Profilerstellung wird das Profil in ./<your program>.hp
angezeigt.
Weitere Profilierungsoptionen finden Sie unter GHC profiling documentation.
Profilieren baut mit Stack Versionen vor 1.0.0 (dh von 2015)
mit einer Profilierung bauen aktiviert:
stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts"
zum Profil:
stack exec -- <your program> +RTS <profiling options>
Beispiel für Stapel 1,0. 0 und neuer
Angenommen, Sie haben ein Paket namens test
wi th einer einzigen ausführbaren test
von main
hier definiert:
module Main where
main :: IO()
main = do
print $ foo 0
foo :: Int -> Int
foo x = fooSub (x+1)
where
fooSub x = bar (x+1)
bar :: Int -> Int
bar x = barSub (x+1)
where
barSub x = barSubSub (x+1)
where
barSubSub x = x+1
dann stack build --profile && stack exec -- test +RTS -p
eine Datei ./test.prof
produzieren zu tun, die where
für alle Definitionen, einschließlich lokalen Definitionen in
individual inherited
COST CENTRE MODULE SRC no. entries %time %alloc %time %alloc
[... many lines omitted ...]
main Main src/Main.hs:(4,1)-(5,15) 97 0 0.0 0.0 0.0 0.0
foo Main src/Main.hs:(8,1)-(10,24) 98 1 0.0 0.0 0.0 0.0
foo.fooSub Main src/Main.hs:10:5-24 99 1 0.0 0.0 0.0 0.0
bar Main src/Main.hs:(13,1)-(17,46) 100 1 0.0 0.0 0.0 0.0
bar.barSub Main src/Main.hs:(15,5)-(17,46) 101 1 0.0 0.0 0.0 0.0
bar.barSub.barSubSub Main src/Main.hs:17:9-46 102 1 0.0 0.0 0.0 0.0
main Main src/Main.hs:(4,1)-(5,15) 95 0 0.0 20.5 0.0 20.5
Das heißt, es gibt keine Profilinformationen enthält Klauseln.
Wenn Sie nur Top-Level-Definitionen ein Profil erstellen möchten, können Sie mit die GHC Option aufbauen können -fprof-auto-top
statt: stack build --profile --ghc-options=-fprof-auto-top && stack exec -- test +RTS -p
tun erzeugt ein ./test.prof
die anstelle
individual inherited
COST CENTRE MODULE SRC no. entries %time %alloc %time %alloc
[... many lines omitted ...]
main Main src/Main.hs:(4,1)-(5,15) 97 0 0.0 0.0 0.0 0.0
foo Main src/Main.hs:(8,1)-(10,24) 98 1 0.0 0.0 0.0 0.0
bar Main src/Main.hs:(13,1)-(17,46) 99 1 0.0 0.0 0.0 0.0
main Main src/Main.hs:(4,1)-(5,15) 95 0 0.0 20.5 0.0 20.5
enthält.
Schließlich, beachten Sie, dass stack build --profile
schaltet auch Stack Spuren.Wenn Sie das Programm so, dass barSubSub x = error $ show x
ändern, dann stack build --profile && stack exec test
läuft produziert
test: 4
CallStack (from HasCallStack):
error, called at src/Main.hs:17:23 in main:Main
CallStack (from -prof):
Main.bar.barSub.barSubSub (src/Main.hs:17:9-36)
Main.bar.barSub (src/Main.hs:(15,5)-(17,36))
Main.bar (src/Main.hs:(13,1)-(17,36))
Main.foo.fooSub (src/Main.hs:10:5-24)
Main.foo (src/Main.hs:(8,1)-(10,24))
Main.main (src/Main.hs:(4,1)-(5,15))
Main.CAF:lvl8_r4Fc (<no location info>)
Ziemlich cool!
Dies funktioniert nicht. Die Verwendung von stack exec my-exe + RTS -p zeigt ausführbare Dateien wurde nicht mit -prof kompiliert, und der Versuch, dies zu tun, zeigt, dass ld die profilierten Versionen der Bibliotheken nicht finden kann. –
Das funktionierte für mich: 'stack install --enable-executable-profiling --enable-library-profiling --ghc-options =" - fprof-auto -rtsopts "' – Dfr
Wie führe ich es aus/profile es nach dem Build hat beendet? –