Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/compiler/MiscUtil/util/stats.sml
ViewVC logotype

Diff of /sml/trunk/src/compiler/MiscUtil/util/stats.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 188, Thu Nov 12 00:24:58 1998 UTC revision 189, Sun Nov 15 22:29:42 1998 UTC
# Line 6  Line 6 
6  signature STATS =  signature STATS =
7    sig    sig
8      type stat      type stat
9        type counter
10    
11        (* The counters (argument) will be add'd whenever the new counter is *)
12        val newCounter : counter list -> counter
13        val getCounter : counter -> int
14        val addCounter : counter -> int -> unit
15    
16        (* A stat contains the sum of the argument counters. *)
17        val newStat : string * counter list -> stat
18        val getStat : stat -> int
19        (* Add the stat to the summary *)
20        val registerStat : stat -> unit
21    
22        (* old interface, deprecated. *)
23      val makeStat : string -> stat      val makeStat : string -> stat
24      val addStat : stat -> int -> unit      val addStat : stat -> int -> unit
25    
# Line 28  Line 42 
42    
43      val timeToStr = T.fmt 2      val timeToStr = T.fmt 2
44    
45      datatype stat = STAT of {name:string, tot: int ref}      datatype counter = C of {c:int ref, cs:counter list}
46    
47        datatype stat = STAT of {name:string, tot: counter list}
48      val allStats = ref (nil : stat list)      val allStats = ref (nil : stat list)
49    
50      fun lookSt(name,nil) = NONE      fun lookSt(name,nil) = NONE
# Line 39  Line 55 
55            if pn<qn then p::q::rest else q::insert(p,rest)            if pn<qn then p::q::rest else q::insert(p,rest)
56        | insert(p,nil) = p::nil        | insert(p,nil) = p::nil
57    
58        fun newCounter cs = C{c=ref 0, cs=cs}
59        fun addCounter (C{c,cs}) n = (c := !c + n; app (fn c => addCounter c n) cs)
60        fun getCounter (C{c=ref c,...}) = c
61    
62        fun newStat (name,cs) = STAT{name=name,tot=cs}
63        fun registerStat (p as STAT{name,tot}) =
64            (case lookSt (name,!allStats)
65              of SOME p => ()
66               | NONE => allStats := insert(p,!allStats))
67    
68      fun makeStat name = (case lookSt (name,!allStats)      fun makeStat name = (case lookSt (name,!allStats)
69             of SOME p => p             of SOME p => p
70              | NONE => let              | NONE => let
71                  val p = STAT{name=name, tot=ref 0}                  val p = newStat(name, [newCounter[]])
72                  in                  in
73                    allStats := insert(p,!allStats); p                    allStats := insert(p,!allStats); p
74                  end                  end
75            (* end case *))            (* end case *))
76        fun addStat(STAT{tot=[c],...}) n = addCounter c n
     fun addStat(STAT{tot,...}) n = tot := !tot + n  
77    
78      val say = Control.Print.say      val say = Control.Print.say
79      val flush = Control.Print.flush      val flush = Control.Print.flush
# Line 105  Line 130 
130            last := gettime();            last := gettime();
131            app (fn PHASE{this,accum,...} => (this := zeros; accum := zeros))            app (fn PHASE{this,accum,...} => (this := zeros; accum := zeros))
132              (!allPhases);              (!allPhases);
133            app (fn STAT{tot,...} => tot:=0) (!allStats))            app (fn STAT{tot,...} => app (fn C{c,...} => c:=0) tot) (!allStats))
134    
135      structure CU = SMLofNJ.Internals.CleanUp      structure CU = SMLofNJ.Internals.CleanUp
136      val _ = CU.addCleaner (      val _ = CU.addCleaner (
# Line 166  Line 191 
191                before finish()                before finish()
192            end            end
193    
194      fun showStat(STAT{name,tot}) = (      fun getStat (STAT{tot,...}) = foldl (fn (c,s) => getCounter c + s) 0 tot
195        fun showStat(s as STAT{name,tot}) = (
196            sayfield(40, name);            sayfield(40, name);
197            say(Int.toString(!tot));            say(Int.toString(getStat s));
198            say "\n")            say "\n")
199    
200      fun showPhase(PHASE{name,this,accum}) = let      fun showPhase(PHASE{name,this,accum}) = let

Legend:
Removed from v.188  
changed lines
  Added in v.189

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0