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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/DebugProf/profile/profile.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/DebugProf/profile/profile.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 903 - (view) (download)

1 : blume 903 (* profile.sml
2 :     *
3 :     * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     structure Profile : sig
8 :    
9 :     val reset : unit -> unit (* reset profiling counts to zero *)
10 :    
11 :     val report : TextIO.outstream -> unit
12 :     (* print profiling report to stream *)
13 :     val reportAll : TextIO.outstream -> unit
14 :     (* print profiling report to stream; DON'T suppress zero entries*)
15 :     val reportData: unit -> {name: string, count: int, time: Time.time} list
16 :     (* Return the unformatted data for a report *)
17 :    
18 :     val runTimeIndex : int
19 :     val minorGCIndex : int
20 :     val majorGCIndex : int
21 :     val otherIndex : int
22 :     val compileIndex : int
23 :     val numPredefIndices : int
24 :    
25 :     end = struct
26 :    
27 :     structure A = Array
28 :     structure PC = SMLofNJ.Internals.ProfControl
29 :    
30 :     val runTimeIndex = PC.runTimeIndex
31 :     val minorGCIndex = PC.minorGCIndex
32 :     val majorGCIndex = PC.majorGCIndex
33 :     val otherIndex = PC.otherIndex
34 :     val compileIndex = PC.compileIndex
35 :     val numPredefIndices = PC.numPredefIndices
36 :    
37 :     val reset = PC.reset
38 :    
39 :     datatype entry = ENTRY of {name: string, count: int, time: int}
40 :    
41 :     val splitlines = String.tokens (fn #"\n" => true | _ => false)
42 :    
43 :     fun join (entries, base, _, counts, times, nil) = entries
44 :     | join (entries, base, n, counts, times, line::lines) =
45 :     join (ENTRY{
46 :     name = line, count= A.sub(counts, n), time = A.sub(times, base+n)
47 :     }::entries, base, n+1, counts, times, lines)
48 :    
49 :     fun batch (PC.UNIT{base,size,counts,names}) =
50 :     join(nil, base, 0, counts, PC.getTimeArray(), splitlines names)
51 :    
52 :     fun log10 0 = 0
53 :     | log10 i = 1 + log10(i div 10)
54 :    
55 :     fun field (st, w) = StringCvt.padLeft #" " w st
56 :    
57 :     (* take a string of digits and a number of decimal places, and return the
58 :     * digits with the decimal point added in the right place.
59 :     *)
60 :     fun decimal (st, w) = let
61 :     val len = size st
62 :     in
63 :     if (len <= w)
64 :     then String.concat [".", StringCvt.padLeft #"0" w st]
65 :     else String.concat [
66 :     substring(st, 0, len-w), ".", substring(st, len-w, w)
67 :     ]
68 :     end
69 :    
70 :     fun muldiv(i,j,k) =
71 :     (i*j div k)
72 :     handle Overflow => muldiv(i,j div 2, k div 2)
73 :    
74 :     (* This convolution is required because the PPC cannot distinguish
75 :     * between div-by-zero and overflow -- Lal.
76 :     *)
77 :     fun muldiv(i, j, 0) = raise General.Div
78 :     | muldiv(i, j, k) =
79 :     (i * j div k) handle Overflow => muldiv(i, j div 2, k div 2)
80 :    
81 :     fun decfield(n,j,k,w1,w2) =
82 :     field(decimal(Int.toString (muldiv(n,j,k)),w1)
83 :     handle Div => "",w2)
84 :    
85 :     fun getBigList() = let
86 :     val biglist = List.concat (List.map batch (! PC.units))
87 :     fun compare (
88 :     ENTRY{time=a,count=ca,name=na,...},
89 :     ENTRY{time=b,count=cb,name=nb,...}
90 :     ) = a<b orelse a=b andalso (ca<cb orelse ca=cb andalso na>nb)
91 :     in
92 :     ListMergeSort.sort compare biglist
93 :     end
94 :    
95 :     fun reportData() = let
96 :     val usPerSample = Int.toLarge(PC.getQuantum())
97 :     fun f (ENTRY{name,count,time}) = {
98 :     name=name, count=count,
99 :     time=Time.fromMicroseconds(Int.toLarge time * usPerSample)
100 :     }
101 :     in
102 :     map f (getBigList ())
103 :     end
104 :    
105 :     fun reportx suppress outstream = let
106 :     val biglist' = getBigList()
107 :     val tot = List.foldr (fn (ENTRY{time=a,...},b)=> a+b) 0 biglist'
108 :     val maxc = List.foldr (fn (ENTRY{count=a,...},b)=> Int.max(a,b)) 0 biglist'
109 :     val digits_cum = log10 tot
110 :     val digits_cnt = Int.max(6,1+log10 maxc)
111 :     fun pr s = TextIO.output(outstream, s)
112 :     fun printlines (ENTRY{time,name,count}::rest, cum) =
113 :     if suppress andalso count=0 andalso time=0 then ()
114 :     else (
115 :     pr(decfield(time,10000,tot,2,6));
116 :     if (digits_cum > 4)
117 :     then pr(field(Int.toString(cum+time+50 div 100),7))
118 :     else pr(decfield(cum+time,1,1,2,7));
119 :     pr(field(Int.toString count,digits_cnt));
120 :     (* pr(decfield(time,50000,count,4,10)); *)
121 :     pr " "; pr name; pr "\n";
122 :     printlines(rest,cum+time))
123 :     | printlines (nil, _) = ()
124 :    
125 :     in pr(field("%time",6));
126 :     pr(field("cumsec",7));
127 :     pr(field("#call",digits_cnt));
128 :     (* pr(field("ms/call",10)); *)
129 :     pr(" name\n");
130 :     printlines(biglist',0);
131 :     TextIO.flushOut outstream
132 :     end
133 :    
134 :     val report = reportx true
135 :     val reportAll = reportx false
136 :    
137 :     end;
138 :    

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