1 module Activity (activityGraph,Activity(..))  where
    2 
    3 import GRIP
    4 import StdLib
    5 import PSlib
    6 import Graph
    7 import Parse
    8 
    9 
   10 activityGraph ordering selectpes statFile = 
   11                                 --show (pes,ticks) ++
   12                                 --show "DEBUG " ++ show (aggs) ++
   13                                 initGraph "Processor Activity Graph"
   14                                  (pes,selectpes) (ticks*100,100) ("Time (ms)","% Activity") 
   15                                                 (map f ordering)
   16                                 
   17                                 ++ scale (my_fromInt dimX/my_fromInt 100) 
   18                                                 (my_fromInt dimY/my_fromInt (maxticks))
   19                                 ++ concat (map2 plotCurve (map colour order)
   20                                                   (outlinesTrace traces))
   21         where
   22         f a = (colour a,display a,aggr a aggs)
   23         active = if selectpes==[] then length pes-1 else length selectpes
   24         maxticks = active*ticks
   25         (pes,ticks,orderedStats) = getParameters stats
   26         (traces,aggs) = (akkumulate (processAct (map extractor order)) nullstate.
   27                                         gatherAct (Act 0 0 0 0 0 0).
   28                                         map (scaleAct ticks).
   29                                         getAct selectpes) orderedStats
   30         order = reverse ordering
   31         stats = parseFile statFile
   32 
   33 processAct :: [Activities->Int] -> State -> Activities -> (Trace,State)
   34 processAct extractors (i,r,g,f,t) a@(Act n i' r' g' f' t') 
   35                         = (trace, (i'+i,r'+r,g'+g,f'+f,t+t'))
   36                 where
   37                 trace@(T _ (m:_)) = makeTrace extractors n a
   38 
   39 makeTrace fs n s = T n (f fs)
   40         where
   41         f [] = []
   42         f ex@(e:es) = sum (pam ex s):f es
   43 
   44 
   45 type State = (Int,Int,Int,Int,Int)
   46 nullstate = (0,0,0,0,0)
   47 
   48 data Trace = T Int [Int]
   49 
   50 outlinesTrace :: [Trace] -> [[Point]]
   51 outlinesTrace [T n a] = map (\x->[Pt n x]) a
   52 outlinesTrace (T n a:more) = map2 (:) (map (\x->Pt n x) a) (outlinesTrace more)
   53  
   54 aggr IDLE (i,_,_,_,t) = printFloat (percentage i t) ++ "%"
   55 aggr REDN (_,r,_,_,t) = printFloat (percentage r t) ++ "%"
   56 aggr GC  (_,_,g,_,t) = printFloat (percentage g t) ++ "%"
   57 aggr FLUSH (_,_,_,f,t) = printFloat (percentage f t) ++ "%"
   58 
   59 percentage x y = my_fromInt x * 100 / my_fromInt y
   60  
   61 gatherAct :: Activities -> [Activities] -> [Activities]
   62 gatherAct t [] = [t,(Act (numberAct t+1) 0 0 0 0 0)]
   63 gatherAct t l@(a:as) | numberAct t==numberAct a = gatherAct (addAct t a) as
   64                      | otherwise = t:gatherAct (Act (n+1) 0 0 0 0 0) l
   65                                         where      n=numberAct t
   66  
   67 
   68 pam [] _ = []
   69 pam (f:fs) a = f a:pam fs a
   70  
   71 
   72 data Activity = REDN | IDLE | FLUSH | GC deriving (Eq)
   73 
   74 extractor REDN = reduction
   75 extractor IDLE = idle
   76 extractor GC = gc
   77 extractor FLUSH = flush
   78 
   79 colour REDN = 0
   80 colour IDLE = 8
   81 colour FLUSH = 5
   82 colour GC = 2
   83 
   84 instance Parse Activity where
   85         parseType ('R':string) = (REDN,string)
   86         parseType ('G':string) = (GC,string)
   87         parseType ('F':string) = (FLUSH,string)
   88         parseType ('I':string) = (IDLE,string)
   89         parseType (string) = error ("No such Activity : "++show string++"\n")
   90 
   91 display REDN = "Reduction"
   92 display GC = "Garbage Collection"
   93 display FLUSH = "Flush Read/Write"
   94 display IDLE = "Idle"
   95         
   96 addAct (Act _ a b c d t1) (Act n e f g h t2) = Act n (a+e) (b+f) (c+g) (d+h) (t1+t2)