-
Notifications
You must be signed in to change notification settings - Fork 15
/
Main.lhs
617 lines (568 loc) · 22.6 KB
/
Main.lhs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
\subsubsection{Module header and import directives}
\begin{code}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
#if defined(linux_HOST_OS)
#define LINUX
#endif
{- define the parallel procedures that create messages -}
#define RUN_ProcMessageOutput
#define RUN_ProcObserveIO
#undef RUN_ProcObseverSTM
#undef RUN_ProcObseveDownload
#define RUN_ProcRandom
#define RUN_ProcMonitoring
#define RUN_ProcBufferDump
#define RUN_ProcCounterOutput
module Main
( main )
where
import Control.Concurrent (threadDelay)
import qualified Control.Concurrent.Async as Async
import Control.Monad (forM_, when)
import Data.Aeson (ToJSON (..), Key, Value (..))
import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.HashMap.Strict as HM
import Data.Maybe (isJust)
import Data.Text (Text, pack)
#ifdef ENABLE_OBSERVABLES
#ifdef RUN_ProcObseverSTM
import Control.Monad (forM)
import GHC.Conc.Sync (atomically, STM, TVar, newTVar, readTVar, writeTVar)
#endif
#endif
#ifdef LINUX
#ifdef RUN_ProcObseveDownload
import qualified Data.ByteString.Char8 as BS8
import Network.Download (openURI)
#endif
#endif
import System.Random
import Cardano.BM.Backend.Aggregation
--import Cardano.BM.Backend.Editor
import Cardano.BM.Backend.EKGView
import Cardano.BM.Backend.Monitoring
import Cardano.BM.Backend.Switchboard (Switchboard, readLogBuffer)
import Cardano.BM.Backend.TraceForwarder
#ifdef LINUX
import Cardano.BM.Scribe.Systemd
#endif
import qualified Cardano.BM.Configuration.Model as CM
import Cardano.BM.Counters (readCounters)
import Cardano.BM.Data.Aggregated (Measurable (..))
import Cardano.BM.Data.AggregatedKind
import Cardano.BM.Data.BackendKind
import Cardano.BM.Data.Configuration (Endpoint(..), RemoteAddr(..))
import Cardano.BM.Data.Counter
import Cardano.BM.Data.LogItem
import Cardano.BM.Data.MonitoringEval
import Cardano.BM.Data.Output
import Cardano.BM.Data.Rotation
import Cardano.BM.Data.Severity
import Cardano.BM.Data.SubTrace
import Cardano.BM.Data.Trace
import Cardano.BM.Data.Tracer hiding(mkObject)
#ifdef ENABLE_OBSERVABLES
import Cardano.BM.Configuration
import Cardano.BM.Data.Observable
import Cardano.BM.Observer.Monadic (bracketObserveIO)
#ifdef RUN_ProcObseverSTM
import qualified Cardano.BM.Observer.STM as STM
#endif
#endif
import Cardano.BM.Plugin
import Cardano.BM.Setup
import Cardano.BM.Trace
\end{code}
\subsubsection{Define configuration}
Selected values can be viewed in EKG on \url{http://localhost:12790}.
And, the \emph{Prometheus} interface is accessible at \url{http://localhost:12800/metrics}
\\
The configuration editor listens on \url{http://localhost:13790}.
\begin{code}
prepare_configuration :: IO CM.Configuration
prepare_configuration = do
c <- CM.empty
CM.setMinSeverity c Info
CM.setSetupBackends c [ KatipBK
, AggregationBK
, MonitoringBK
-- , TraceForwarderBK -- testing for pipe
]
CM.setDefaultBackends c [KatipBK]
CM.setSetupScribes c [ ScribeDefinition {
scName = "stdout"
, scKind = StdoutSK
, scFormat = ScText
, scPrivacy = ScPublic
, scMinSev = Notice
, scMaxSev = maxBound
, scRotation = Nothing
}
, ScribeDefinition {
scName = "logs/out.odd.json"
, scKind = FileSK
, scFormat = ScJson
, scPrivacy = ScPublic
, scMinSev = minBound
, scMaxSev = maxBound
, scRotation = Just $ RotationParameters
{ rpLogLimitBytes = 5000 -- 5kB
, rpMaxAgeHours = 24
, rpKeepFilesNum = 3
}
}
, ScribeDefinition {
scName = "logs/out.even.json"
, scKind = FileSK
, scFormat = ScJson
, scPrivacy = ScPublic
, scMinSev = minBound
, scMaxSev = maxBound
, scRotation = Just $ RotationParameters
{ rpLogLimitBytes = 5000 -- 5kB
, rpMaxAgeHours = 24
, rpKeepFilesNum = 3
}
}
, ScribeDefinition {
scName = "logs/downloading.json"
, scKind = FileSK
, scFormat = ScJson
, scPrivacy = ScPublic
, scMinSev = minBound
, scMaxSev = maxBound
, scRotation = Just $ RotationParameters
{ rpLogLimitBytes = 5000 -- 5kB
, rpMaxAgeHours = 24
, rpKeepFilesNum = 3
}
}
, ScribeDefinition {
scName = "logs/out.txt"
, scKind = FileSK
, scFormat = ScText
, scPrivacy = ScPublic
, scMinSev = Info
, scMaxSev = maxBound
, scRotation = Just $ RotationParameters
{ rpLogLimitBytes = 5000 -- 5kB
, rpMaxAgeHours = 24
, rpKeepFilesNum = 3
}
}
, ScribeDefinition {
scName = "logs/info.txt"
, scKind = FileSK
, scFormat = ScText
, scPrivacy = ScPublic
, scMinSev = Debug
, scMaxSev = Info
, scRotation = Just $ RotationParameters
{ rpLogLimitBytes = 5000 -- 5kB
, rpMaxAgeHours = 24
, rpKeepFilesNum = 3
}
}
, ScribeDefinition {
scName = "logs/out.json"
, scKind = FileSK
, scFormat = ScJson
, scPrivacy = ScPublic
, scMinSev = minBound
, scMaxSev = maxBound
, scRotation = Just $ RotationParameters
{ rpLogLimitBytes = 50000000 -- 50 MB
, rpMaxAgeHours = 24
, rpKeepFilesNum = 13
}
}
]
#ifdef LINUX
CM.setDefaultScribes c ["StdoutSK::stdout", "FileSK::logs/out.txt", "FileSK::logs/info.txt", "JournalSK::example-complex"]
#else
CM.setDefaultScribes c ["StdoutSK::stdout"]
#endif
CM.setScribes c "complex.random" (Just ["StdoutSK::stdout", "FileSK::logs/out.txt"])
forM_ [(1::Int)..10] $ \x ->
if odd x
then
CM.setScribes c ("complex.#aggregation.complex.observeSTM." <> pack (show x)) $ Just [ "FileSK::logs/out.odd.json" ]
else
CM.setScribes c ("complex.#aggregation.complex.observeSTM." <> pack (show x)) $ Just [ "FileSK::logs/out.even.json" ]
#ifdef LINUX
#ifdef ENABLE_OBSERVABLES
CM.setSubTrace c "complex.observeDownload" (Just $ ObservableTraceSelf [IOStats,NetStats])
#endif
CM.setBackends c "complex.observeDownload" (Just [KatipBK])
CM.setScribes c "complex.observeDownload" (Just ["FileSK::logs/downloading.json"])
#endif
CM.setSubTrace c "#messagecounters.switchboard" $ Just NoTrace
CM.setSubTrace c "#messagecounters.katip" $ Just NoTrace
CM.setSubTrace c "#messagecounters.aggregation" $ Just NoTrace
CM.setSubTrace c "#messagecounters.ekgview" $ Just Neutral
CM.setBackends c "#messagecounters.switchboard" $ Just [EditorBK, KatipBK]
CM.setSubTrace c "#messagecounters.monitoring" $ Just NoTrace
CM.setSubTrace c "complex.random" (Just $ TeeTrace "ewma")
CM.setSubTrace c "#ekgview"
(Just $ FilterTrace [ (Drop (StartsWith "#ekgview.complex.#aggregation.complex.random"),
Unhide [EndsWith ".count",
EndsWith ".avg",
EndsWith ".mean"]),
(Drop (StartsWith "#ekgview.complex.#aggregation.complex.observeIO"),
Unhide [Contains "diff.RTS.cpuNs.timed."]),
(Drop (StartsWith "#ekgview.complex.#aggregation.complex.observeSTM"),
Unhide [Contains "diff.RTS.gcNum.timed."]),
(Drop (StartsWith "#ekgview.complex.#aggregation.complex.message"),
Unhide [Contains ".timed.m"])
])
#ifdef ENABLE_OBSERVABLES
CM.setSubTrace c "complex.observeIO" (Just $ ObservableTraceSelf [GhcRtsStats,MemoryStats])
forM_ [(1::Int)..10] $ \x ->
CM.setSubTrace
c
("complex.observeSTM." <> (pack $ show x))
(Just $ ObservableTraceSelf [GhcRtsStats,MemoryStats])
#endif
CM.setBackends c "complex.message" (Just [AggregationBK, KatipBK, TraceForwarderBK])
CM.setBackends c "complex.random" (Just [KatipBK, EKGViewBK])
CM.setBackends c "complex.random.ewma" (Just [AggregationBK])
CM.setBackends c "complex.observeIO" (Just [AggregationBK, MonitoringBK])
forM_ [(1::Int)..10] $ \x -> do
CM.setBackends c
("complex.observeSTM." <> pack (show x))
(Just [AggregationBK])
CM.setBackends c
("complex.#aggregation.complex.observeSTM." <> pack (show x))
(Just [KatipBK])
CM.setAggregatedKind c "complex.random.rr" (Just StatsAK)
CM.setAggregatedKind c "complex.random.ewma.rr" (Just (EwmaAK 0.22))
CM.setBackends c "complex.#aggregation.complex.random" (Just [EditorBK])
CM.setBackends c "complex.#aggregation.complex.random.ewma" (Just [EKGViewBK, EditorBK])
CM.setBackends c "complex.#aggregation.complex.message" (Just [EKGViewBK, MonitoringBK])
CM.setBackends c "complex.#aggregation.complex.monitoring" (Just [MonitoringBK])
CM.setBackends c "complex.#aggregation.complex.observeIO" (Just [EKGViewBK])
CM.setScribes c "complex.counters" (Just ["StdoutSK::stdout","FileSK::logs/out.json"])
CM.setEKGBindAddr c $ Just (Endpoint ("localhost", 12790))
CM.setPrometheusBindAddr c $ Just ("localhost", 12800)
CM.setGUIport c 13790
\end{code}
output could also be forwarded using a pipe:
\begin{spec}
CM.setForwardTo c (Just $ RemotePipe "logs/pipe")
CM.setForwardTo c (Just $ RemotePipe "\\\\.\\pipe\\acceptor") -- on Windows
\end{spec}
\begin{code}
CM.setForwardTo c (Just $ RemoteSocket "127.0.0.1" "42999")
CM.setTextOption c "forwarderMinSeverity" "Warning" -- sets min severity filter in forwarder
CM.setTextOption c "prometheusOutput" "json" -- Prometheus' output in JSON-format
CM.setForwardDelay c (Just 1000)
CM.setMonitors c $ HM.fromList
[ ( "complex.monitoring"
, ( Just (Compare "monitMe" (GE, OpMeasurable 10))
, Compare "monitMe" (GE, OpMeasurable 42)
, [CreateMessage Warning "MonitMe is greater than 42!"]
)
)
, ( "complex.#aggregation.complex.monitoring"
, ( Just (Compare "monitMe.fcount" (GE, OpMeasurable 8))
, Compare "monitMe.mean" (GE, OpMeasurable 41)
, [CreateMessage Warning "MonitMe.mean is greater than 41!"]
)
)
, ( "complex.observeIO.close"
, ( Nothing
, Compare "complex.observeIO.close.Mem.size" (GE, OpMeasurable 25)
, [CreateMessage Warning "closing mem size is greater than 25!"]
)
)
]
CM.setBackends c "complex.monitoring" (Just [AggregationBK, KatipBK, MonitoringBK])
return c
\end{code}
\subsubsection{Dump the log buffer periodically}
\begin{code}
dumpBuffer :: Switchboard Text -> Trace IO Text -> IO (Async.Async ())
dumpBuffer sb trace = do
logInfo trace "starting buffer dump"
Async.async (loop trace)
where
loop tr = do
threadDelay 25000000 -- 25 seconds
buf <- readLogBuffer sb
forM_ buf $ \(logname, LogObject _ lometa locontent) -> do
let tr' = modifyName (\n -> "#buffer" <> "." <> n <> "." <> logname) tr
traceNamedObject tr' (lometa, locontent)
loop tr
\end{code}
\subsubsection{Thread that outputs a random number to a |Trace|}
\begin{code}
randomThr :: Trace IO Text -> IO (Async.Async ())
randomThr trace = do
logInfo trace "starting random generator"
let trace' = appendName "random" trace
Async.async (loop trace')
where
loop tr = do
threadDelay 500000 -- 0.5 second
num <- randomRIO (42-42, 42+42) :: IO Double
lo <- (,) <$> mkLOMeta Info Public <*> pure (LogValue "rr" (PureD num))
traceNamedObject tr lo
loop tr
\end{code}
\subsubsection{Thread that outputs a random number to monitoring |Trace|}
\begin{code}
#ifdef RUN_ProcMonitoring
monitoringThr :: Trace IO Text -> IO (Async.Async ())
monitoringThr trace = do
logInfo trace "starting numbers for monitoring..."
let trace' = appendName "monitoring" trace
Async.async (loop trace')
where
loop tr = do
threadDelay 500000 -- 0.5 second
num <- randomRIO (42-42, 42+42) :: IO Double
lo <- (,) <$> mkLOMeta Warning Public <*> pure (LogValue "monitMe" (PureD num))
traceNamedObject tr lo
loop tr
#endif
\end{code}
\subsubsection{Thread that observes an |IO| action}
\begin{code}
#ifdef ENABLE_OBSERVABLES
observeIO :: Configuration -> Trace IO Text -> IO (Async.Async ())
observeIO config trace = do
logInfo trace "starting observer"
proc <- Async.async (loop trace)
return proc
where
loop tr = do
threadDelay 5000000 -- 5 seconds
let tr' = appendName "observeIO" tr
_ <- bracketObserveIO config tr' Warning "complex.observeIO" $ do
num <- randomRIO (100000, 200000) :: IO Int
ls <- return $ reverse $ init $ reverse $ 42 : [1 .. num]
pure $ const ls ()
loop tr
#endif
\end{code}
\subsubsection{Threads that observe |STM| actions on the same TVar}
\begin{code}
#ifdef RUN_ProcObseverSTM
#ifdef ENABLE_OBSERVABLES
observeSTM :: Configuration -> Trace IO Text -> IO [Async.Async ()]
observeSTM config trace = do
logInfo trace "starting STM observer"
tvar <- atomically $ newTVar ([1..1000]::[Int])
-- spawn 10 threads
proc <- forM [(1::Int)..10] $ \x -> Async.async (loop trace tvar (pack $ show x))
return proc
where
loop tr tvarlist trname = do
threadDelay 10000000 -- 10 seconds
STM.bracketObserveIO config tr Warning ("observeSTM." <> trname) (stmAction tvarlist)
loop tr tvarlist trname
stmAction :: TVar [Int] -> STM ()
stmAction tvarlist = do
list <- readTVar tvarlist
writeTVar tvarlist $! (++) [42] $ reverse $ init $ reverse $ list
pure ()
#endif
#endif
\end{code}
\subsubsection{Thread that observes an |IO| action which downloads a text in
order to observe the I/O statistics}
\begin{code}
#ifdef LINUX
#ifdef RUN_ProcObseveDownload
#ifdef ENABLE_OBSERVABLES
observeDownload :: Configuration -> Trace IO Text -> IO (Async.Async ())
observeDownload config trace = do
proc <- Async.async (loop trace)
return proc
where
loop tr = do
threadDelay 1000000 -- 1 second
let tr' = appendName "observeDownload" tr
bracketObserveIO config tr' Warning "complex.observeDownload" $ do
license <- openURI "http://www.gnu.org/licenses/gpl.txt"
case license of
Right bs -> logNotice tr' $ pack $ BS8.unpack bs
Left _ -> return ()
threadDelay 50000 -- .05 second
pure ()
loop tr
#endif
#endif
#endif
\end{code}
\subsubsection{Thread that periodically outputs a message}
\begin{code}
data Pet = Pet { name :: Text, age :: Int}
deriving (Show)
mkObject :: [(Key, v)] -> KeyMap.KeyMap v
mkObject = KeyMap.fromList
instance ToObject Pet where
toObject MinimalVerbosity _ = KeyMap.empty -- do not log
toObject NormalVerbosity (Pet _ _) =
mkObject [ ("kind", String "Pet") ]
toObject MaximalVerbosity (Pet n a) =
mkObject [ ("kind", String "Pet")
, ("name", toJSON n)
, ("age", toJSON a) ]
instance HasTextFormatter Pet where
formatText pet _o = "Pet " <> name pet <> " is " <> pack (show (age pet)) <> " years old."
instance Transformable Text IO Pet where
-- transform to JSON Object
trTransformer MaximalVerbosity tr = trStructuredText MaximalVerbosity tr
trTransformer MinimalVerbosity _tr = nullTracer
-- transform to textual representation using |show|
trTransformer _v tr = Tracer $ \pet -> do
meta <- mkLOMeta Info Public
traceWith tr $ ("pet", LogObject "pet" meta $ (LogMessage . pack . show) pet)
-- default privacy annotation: Public
instance HasPrivacyAnnotation Pet
instance HasSeverityAnnotation Pet where
getSeverityAnnotation _ = Critical
#ifdef RUN_ProcMessageOutput
msgThr :: Trace IO Text -> IO (Async.Async ())
msgThr trace = do
logInfo trace "start messaging .."
let trace' = appendName "message" trace
Async.async (loop trace')
where
loop tr = do
threadDelay 3000000 -- 3 seconds
logNotice tr "N O T I F I C A T I O N ! ! !"
logDebug tr "a detailed debug message."
logError tr "Boooommm .."
traceWith (toLogObject' MaximalVerbosity tr) (Pet "bella" 8)
loop tr
#endif
\end{code}
\subsubsection{Thread that periodically outputs operating system counters}
\begin{code}
#ifdef RUN_ProcCounterOutput
countersThr :: Trace IO Text -> IO (Async.Async ())
countersThr trace = do
let trace' = appendName "counters" trace
Async.async (loop trace')
where
loop tr = do
threadDelay 3000000 -- 3 seconds
let counters = [MemoryStats, ProcessStats, NetStats, IOStats, SysStats]
cts <- readCounters (ObservableTraceSelf counters)
mle <- mkLOMeta Info Confidential
forM_ cts $ \c@(Counter _ct cn cv) ->
traceNamedObject tr (mle, LogValue (nameCounter c <> "." <> cn) cv)
loop tr
#endif
\end{code}
\subsubsection{Main entry point}
\begin{code}
main :: IO ()
main = do
-- create configuration
c <- prepare_configuration
-- create initial top-level Trace
(tr :: Trace IO Text, sb) <- setupTrace_ c "complex"
-- load plugins
{- Cardano.BM.Backend.Editor.plugin c tr sb
>>= loadPlugin sb -}
Cardano.BM.Backend.EKGView.plugin c tr sb
>>= loadPlugin sb
forwardTo <- CM.getForwardTo c
when (isJust forwardTo) $
Cardano.BM.Backend.TraceForwarder.plugin c tr sb "forwarderMinSeverity" (return [])
>>= loadPlugin sb
Cardano.BM.Backend.Aggregation.plugin c tr sb
>>= loadPlugin sb
Cardano.BM.Backend.Monitoring.plugin c tr sb
>>= loadPlugin sb
#ifdef LINUX
-- inspect logs with 'journalctl -t example-complex'
Cardano.BM.Scribe.Systemd.plugin c tr sb "example-complex"
>>= loadPlugin sb
#endif
logNotice tr "starting program; hit CTRL-C to terminate"
-- user can watch the progress only if EKG is enabled.
logInfo tr "watch its progress on http://localhost:12790"
#ifdef RUN_ProcBufferDump
procDump <- dumpBuffer sb tr
#endif
#ifdef RUN_ProcRandom
{- start thread sending unbounded sequence of random numbers
to a trace which aggregates them into a statistics (sent to EKG) -}
procRandom <- randomThr tr
#endif
#ifdef RUN_ProcMonitoring
procMonitoring <- monitoringThr tr
#endif
#ifdef RUN_ProcObserveIO
-- start thread endlessly reversing lists of random length
#ifdef ENABLE_OBSERVABLES
procObsvIO <- observeIO c tr
#endif
#endif
#ifdef RUN_ProcObseverSTM
-- start threads endlessly observing STM actions operating on the same TVar
#ifdef ENABLE_OBSERVABLES
procObsvSTMs <- observeSTM c tr
#endif
#endif
#ifdef LINUX
#ifdef RUN_ProcObseveDownload
-- start thread endlessly which downloads sth in order to check the I/O usage
#ifdef ENABLE_OBSERVABLES
procObsvDownload <- observeDownload c tr
#endif
#endif
#endif
#ifdef RUN_ProcMessageOutput
-- start a thread to output a text messages every n seconds
procMsg <- msgThr tr
#endif
#ifdef RUN_ProcCounterOutput
procCounters <- countersThr tr
#endif
#ifdef RUN_ProcCounterOutput
_ <- Async.waitCatch procCounters
#endif
#ifdef RUN_ProcMessageOutput
-- wait for message thread to finish, ignoring any exception
_ <- Async.waitCatch procMsg
#endif
#ifdef LINUX
#ifdef RUN_ProcObseveDownload
-- wait for download thread to finish, ignoring any exception
#ifdef ENABLE_OBSERVABLES
_ <- Async.waitCatch procObsvDownload
#endif
#endif
#endif
#ifdef RUN_ProcObseverSTM
-- wait for observer thread to finish, ignoring any exception
#ifdef ENABLE_OBSERVABLES
_ <- forM procObsvSTMs Async.waitCatch
#endif
#endif
#ifdef RUN_ProcObserveIO
-- wait for observer thread to finish, ignoring any exception
#ifdef ENABLE_OBSERVABLES
_ <- Async.waitCatch procObsvIO
#endif
#endif
#ifdef RUN_ProcRandom
-- wait for random thread to finish, ignoring any exception
_ <- Async.waitCatch procRandom
#endif
#ifdef RUN_ProcMonitoring
_ <- Async.waitCatch procMonitoring
#endif
#ifdef RUN_ProcBufferDump
_ <- Async.waitCatch procDump
#endif
return ()
\end{code}