diff --git a/dev/README.md b/dev/metrics.md similarity index 100% rename from dev/README.md rename to dev/metrics.md diff --git a/docs/TraceEventIO.md b/docs/TraceEventIO.md deleted file mode 100644 index f1e9293..0000000 --- a/docs/TraceEventIO.md +++ /dev/null @@ -1,24 +0,0 @@ -# WAI Middleware - -``` -import GHC.Conc (labelThread, myThreadId) -import Debug.Trace (traceEventIO) - -withEventLog :: Application -> Application -withEventLog app request respond = do - tid <- myThreadId - labelThread tid "server" - traceEventIO ("START:server") - app request respond1 - - where - - respond1 r = do - res <- respond r - traceEventIO ("END:server") - return res -``` - -``` -runSettings settings $ withEventLog $ app -``` diff --git a/docs/enabling-perf-counters.md b/docs/enabling-perf-counters.md new file mode 100644 index 0000000..b80da3f --- /dev/null +++ b/docs/enabling-perf-counters.md @@ -0,0 +1,19 @@ +## Enable Linux perf counters + +Enable unrestricted use of perf counters: + +``` +# echo -1 > /proc/sys/kernel/perf_event_paranoid +``` + +## Disable CPU scaling + +Set the scaling governer of all your cpus to `performance`: + +``` +echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor +echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor +... +... +echo performance > /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor +``` diff --git a/docs/eventlog-performance-analysis.md b/docs/eventlog-performance-analysis.md index e7a444b..f5b690e 100644 --- a/docs/eventlog-performance-analysis.md +++ b/docs/eventlog-performance-analysis.md @@ -1,12 +1,13 @@ -# GHC Event logging +# Haskell Perf Analysis using Eventlog -Available in GHC 9.2.8 RTS patch. Can be ported to later GHCs. +The GHC RTS instrumentation for accurate and thread-aware event logging +is available in GHC 9.2.8 RTS patch. Can be ported to later GHCs. -Eventlog based Haskell thread aware time and allocation analysis is +Eventlog based Haskell-thread aware time and allocation analysis is possible with stock GHC but there are some limitations and drawbacks which are fixed in the RTS patch described below. The patch adds accurate timing and allocation information and hardware performance @@ -18,53 +19,57 @@ program not just the current thread. TBD: document the exact limitations and differences. --> -## Enable Linux perf counters +## Generating the eventlog -Enable unrestricted use of perf counters: +To generate the event log, we need to enable event log at compile time +(on modern GHCs it is always enabled) and the run the program with +eventlog enabled at run-time, we use the `-l` rts option to do that. -``` -# echo -1 > /proc/sys/kernel/perf_event_paranoid -``` +There are multiple ways of running your program with eventlog enabled at +run-time: -## Disable CPU scaling - -Set the scaling governer of all your cpus to `performance`: +__GHC Command Line__: +Compiling: ``` -echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor -echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor -... -... -echo performance > /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor +ghc Main.hs -rtsopts ``` -## Generating the eventlog - -To generate the event log, we need to compile the program with the eventlog enabled -and run the program setting the `-l` rts option. - -There are multiple ways of doing this. - -__Using plain GHC__: - +Running: ``` -ghc Main.hs -rtsopts -eventlog ./Main +RTS -l -RTS ``` -__Using Cabal__: +You can bake in the rts options during compilation itself: +``` +ghc Main.hs -with-rtsopts=-l +``` -The `.cabal` file should contain the following ghc options +Now you can run without any explicit RTS options: ``` -ghc-options: -eventlog "-with-rtsopts=-l" +./Main ``` -If the `-threaded` option is used while compiling. You may want to use the `-N1` -rts option. +After we run the above program a "Main.eventlog" file will be generated. This +file can be analyzed using the `hperf` executable in this package to +generate an analysis report. To be able to find anything in the report you need +to first instrument your program which is described in the following sections. + +Note 1: For older compilers you need `-eventlog` GHC flag as well when building + +Note 2: If the `-threaded` option is used while compiling. You may want +to use the `-N1` rts option. -## Creating windows +## Measurement instrumentation -Helper function to create windows: +See the example in [examples/traceEventIO.hs](examples/traceEventIO.hs) . + +Use the `traceEventIO` function to log events. Add an event before and +after the code block you want to measure. The event message before the block +should be in the format "START: