Difference between revisions of "ThreadScope Tour/Run"

From HaskellWiki
Jump to navigation Jump to search
m (→‎Steps: add -l RTS flag to generate trace)
 
Line 29: Line 29:
 
<pre> ghc -O2 -rtsopts -eventlog -threaded hellofib</pre></li>
 
<pre> ghc -O2 -rtsopts -eventlog -threaded hellofib</pre></li>
 
<li><p>Run hellofib</p>
 
<li><p>Run hellofib</p>
<pre> ./hellofib +RTS -N2</pre></li>
+
<pre> ./hellofib +RTS -N2 -l</pre></li>
 
<li><p>View its trace</p>
 
<li><p>View its trace</p>
 
<pre>threadscope hellofib.eventlog # on Windows, may be hellofib.exe.eventlog</pre></li></ol>
 
<pre>threadscope hellofib.eventlog # on Windows, may be hellofib.exe.eventlog</pre></li></ol>

Latest revision as of 17:36, 7 December 2011

Objective

Run ThreadScope on a sample program and get a trace.

ThreadScope hellofib

Steps

  1. Copy the following parallel code to hellofib.hs

     import Control.Parallel.Strategies
     import System.Environment
    
     fib 0 = 1
     fib 1 = 1
     fib n = runEval $ do
       x <- rpar (fib (n-1))
       y <- rseq (fib (n-2))
       return (x + y + 1)
    
     main = do
       args <- getArgs
       n <- case args of
             []    -> return 20 
             [x]   -> return (read x)
             _     -> fail ("Usage: hellofib [n]")
       print (fib n)
  2. Build hellofib.hs

     ghc -O2 -rtsopts -eventlog -threaded hellofib
  3. Run hellofib

     ./hellofib +RTS -N2 -l
  4. View its trace

    threadscope hellofib.eventlog # on Windows, may be hellofib.exe.eventlog