1 module Spark(sparkGraph,Spark(..))  where
    2 
    3 import StdLib
    4 import GRIP
    5 import PSlib
    6 import Graph
    7 import Parse
    8 
    9 
   10 sparkGraph ordering selectpes statFile = initGraph "Spark Activity Graph" (pes,selectpes)
   11                                          (100*ticks,height) ("Time (ms)", "Sparks")
   12                                          (map f ordering)
   13                                 ++ scale (my_fromInt dimX/my_fromInt 100) 
   14                                                 (my_fromInt dimY/my_fromInt height)
   15                                 ++ concat (map2 plotCurve (map colourSpark order)
   16                                                   (outlinesTrace traces))
   17         where
   18         f a = (colourSpark a,displaySpark a,aggr a aggs)
   19         (pes,ticks,orderedStats) = getParameters stats
   20         height = axisScale h
   21         (traces,(aggs,h,w)) = akkumulate(processSparks (map extractor order)) nullstate
   22                                         (gatherSp (Sp 0 0 0 0 0) (getSp selectpes orderedStats))
   23         order = reverse ordering
   24         stats = parseFile statFile
   25 
   26 processSparks :: [Sparks->Int] -> State -> Sparks -> (Trace,State)
   27 processSparks extractors ((c,u,r,l),graphmax,_) s@(Sp n c' u' r' l')
   28                         = (trace,
   29                                 ((c'+c,u'+u,r'+r,l'+l),max graphmax m,n))
   30                 where
   31                 trace@(T _ (m:_)) = makeTrace extractors n s
   32 
   33 makeTrace fs n s = T n (f fs)
   34         where
   35         f [] = []
   36         f ex@(e:es) = sum (pam ex s):f es
   37 
   38 
   39 type State = ((Int,Int,Int,Int),Int,Int)
   40 nullstate = ((0,0,0,0),0,0)
   41 
   42 data Trace = T Int [Int]
   43 
   44 outlinesTrace :: [Trace] -> [[Point]]
   45 outlinesTrace [T n a] = map (\x->[Pt n x]) a
   46 outlinesTrace (T n a:more) = map2 (:) (map (\x->Pt n x) a) (outlinesTrace more)
   47  
   48 pam [] _ = []
   49 pam (f:fs) a = f a:pam fs a
   50  
   51 gatherSp t [] = [t,(Sp (numberSp t+1) 0 0 0 0)]
   52 gatherSp t l@(a:as) | numberSp t==numberSp a = gatherSp (addSparks t a) as
   53                     | otherwise = t:gatherSp (Sp (n+1) 0 0 0 0) l
   54                                         where      n=numberSp t
   55  
   56 addSparks (Sp n a b c d) (Sp _ e f g h) = Sp n (a+e) (b+f) (c+g) (d+h)
   57 
   58 data Spark = USED | RESUMED | CREATED | LOST deriving (Eq)
   59 
   60 aggr :: Spark -> (Int,Int,Int,Int) -> String
   61 aggr CREATED (i,_,_,_) = show i
   62 aggr USED (_,r,_,_) = show r
   63 aggr RESUMED  (_,_,g,_) = show g
   64 aggr LOST (_,_,_,f) = show f
   65 
   66 extractor LOST = lost
   67 extractor CREATED = created
   68 extractor RESUMED  = resumed
   69 extractor USED  = used
   70 
   71 colourSpark :: Spark -> Int
   72 colourSpark LOST = 8
   73 colourSpark CREATED = 5
   74 colourSpark RESUMED = 2
   75 colourSpark USED = 0
   76 
   77 displaySpark :: Spark -> String
   78 displaySpark LOST = "Sparks Lost"
   79 displaySpark CREATED = "Sparks Created"
   80 displaySpark RESUMED = "Resumed Sparks"
   81 displaySpark USED = "Used Sparks"
   82         
   83 instance Parse Spark where
   84         parseType ('L':string) = (LOST,string)
   85         parseType ('C':string) = (CREATED,string)
   86         parseType ('R':string) = (RESUMED,string)
   87         parseType ('U':string) = (USED,string)
   88         parseType (string) = error ("No such Activity : "++show string++"\n")
   89