|
2 | 2 |
|
3 | 3 | GHC Patch: https://github.com/composewell/ghc/tree/ghc-8.10.7-eventlog-enhancements |
4 | 4 |
|
5 | | -## Enable perf counters |
| 5 | +## Enable Linux perf counters |
6 | 6 |
|
7 | 7 | Enable unrestricted use of perf counters: |
8 | 8 |
|
@@ -68,6 +68,55 @@ withTracingFlow tag action = do |
68 | 68 | We can wrap parts of the flow we want to analyze with `withTracingFlow` using a |
69 | 69 | tag to help us identify it. |
70 | 70 |
|
| 71 | +## End of Window |
| 72 | + |
| 73 | +You can put the END of the window in different paths but ensure that all paths |
| 74 | +are covered: |
| 75 | + |
| 76 | +``` |
| 77 | + r <- f x |
| 78 | + case r of |
| 79 | + Just val -> do |
| 80 | + -- _ <- L.runIO $ traceEventIO $ "END:" ++ "window" |
| 81 | + -- Some processing |
| 82 | + Nothing -> do |
| 83 | + -- _ <- L.runIO $ traceEventIO $ "END:" ++ "window" |
| 84 | + -- Some processing |
| 85 | +``` |
| 86 | + |
| 87 | +## Measurement Overhead |
| 88 | + |
| 89 | +Even when you are measuring an empty block of code there will be some minimum |
| 90 | +timing and allocations reported because of the measurement overhead. |
| 91 | + |
| 92 | +``` |
| 93 | + _ <- traceEventIO $ "START:emptyWindow" |
| 94 | + _ <- traceEventIO $ "END:emptyWindow" |
| 95 | +``` |
| 96 | + |
| 97 | +The timing is due to the time measurement system call itself. The allocations |
| 98 | +are due to the traceEventIO haskell code execution. TODO: fix the allocations. |
| 99 | + |
| 100 | +## Measurement with Lazy Evaluation |
| 101 | + |
| 102 | +If we want to measure the cost of the lookup in the code below we need |
| 103 | +to evaluate it right there: |
| 104 | + |
| 105 | +``` |
| 106 | + m <- readIORef _configCache |
| 107 | + return . snd $ SimpleLRU.lookup k m |
| 108 | +``` |
| 109 | + |
| 110 | +For correct measurement use the following code: |
| 111 | + |
| 112 | +``` |
| 113 | + m <- readIORef _configCache |
| 114 | + _ <- traceEventIO $ "START:" ++ "mapLookup" |
| 115 | + let !v = HM.lookup k m |
| 116 | + _ <- traceEventIO $ "END:" ++ "mapLookup" |
| 117 | + return v |
| 118 | +``` |
| 119 | + |
71 | 120 | ## Labelling Threads |
72 | 121 |
|
73 | 122 | We should label our threads to identify the thread to scrutinize while reading |
|
0 commit comments