Skip to content

Commit c9b1357

Browse files
Add "measurement overhead", "lazy evaluation" notes
1 parent 254018a commit c9b1357

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
GHC Patch: https://github.com/composewell/ghc/tree/ghc-8.10.7-eventlog-enhancements
44

5-
## Enable perf counters
5+
## Enable Linux perf counters
66

77
Enable unrestricted use of perf counters:
88

@@ -68,6 +68,55 @@ withTracingFlow tag action = do
6868
We can wrap parts of the flow we want to analyze with `withTracingFlow` using a
6969
tag to help us identify it.
7070

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+
71120
## Labelling Threads
72121

73122
We should label our threads to identify the thread to scrutinize while reading

0 commit comments

Comments
 (0)