Diagnosing parallelism – ThreadScope
Next we will look at a program visualization tool, ThreadScope. Install the threadscope
executable with:
stack install threadscope
To extract the eventlog
that ThreadScope uses from a Haskell program, we need to compile with -eventlog
and execute with the -l
Runtime System option. Running the program then generates a program.eventlog
file, which ThreadScope reads. In a convenient single recipe, we lay out these commands:
ghc -O2 -threaded -eventlog -with-rtsopts="-N -l" program.hs ./program threadscope program.eventlog
ThreadScope provides a graphical user interface. The opening view shows processor core utilization. An example view from some eventlog is:
Along with total utilization, we can see the work split on all processors (four in this case). What we also see in this graph, below each core utilization, is that there is GC activity. The program actually pauses quite often just to do GC for a split second. Sometimes such scenarios might require further...