1 -----------------------------------------------------------------------------
2 -- $Id: Slurp.hs,v 1.2 2000/02/18 10:25:53 simonmar Exp $
4 -- (c) Simon Marlow 1997-1999
5 -----------------------------------------------------------------------------
7 module Slurp (Status(..), Results(..), ResultTable(..), parse_log) where
14 -----------------------------------------------------------------------------
15 -- This is the structure into which we collect our results:
17 type ResultTable = FiniteMap String Results
28 data Results = Results {
29 compile_time :: FiniteMap String Float,
30 module_size :: FiniteMap String Int,
31 binary_size :: Maybe Int,
32 link_time :: Maybe Float,
33 run_time :: Maybe Float,
34 mut_time :: Maybe Float,
35 instrs :: Maybe Integer,
36 mem_reads :: Maybe Integer,
37 mem_writes :: Maybe Integer,
38 gc_work :: Maybe Integer,
39 gc_time :: Maybe Float,
40 allocs :: Maybe Integer,
42 compile_status :: Status
45 emptyResults = Results {
46 compile_time = emptyFM,
47 module_size = emptyFM,
48 binary_size = Nothing,
58 compile_status = NotDone,
62 -----------------------------------------------------------------------------
68 ==nofib== awards: size of QSort.o follows...
69 ==nofib== banner: size of banner follows...
70 ==nofib== awards: time to link awards follows...
71 ==nofib== awards: time to run awards follows...
72 ==nofib== boyer2: time to compile Checker follows...
75 banner_re = mkRegex "^==nofib==[ \t]+([A-Za-z0-9_]+):[ \t]+(size of|time to link|time to run|time to compile)[ \t]+([A-Za-z0-9_]+)(\\.o)?[ \t]+follows"
78 This regexp for the output of "time" works on FreeBSD, other versions
79 of "time" will need different regexps.
82 time_re = mkRegex "^[ \t]*([0-9.]+)[ \t]+real[ \t]+([0-9.]+)[ \t]+user[ \t]+([0-9.]+)[ \t]+sys[ \t]*$"
84 size_re = mkRegex "^[ \t]*([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)"
87 <<ghc: 5820820 bytes, 0 GCs, 0/0 avg/max bytes residency (0 samples), 41087234 bytes GC work, 0.00 INIT (0.05 elapsed), 0.08 MUT (0.18 elapsed), 0.00 GC (0.00 elapsed) :ghc>>
89 = (bytes, gcs, avg_resid, max_resid, samples, gc_work,
90 init, init_elapsed, mut, mut_elapsed, gc, gc_elapsed)
92 ghc1_re = pre GHC 4.02
93 ghc2_re = GHC 4.02 (includes "xxM in use")
94 ghc3_re = GHC 4.03 (includes "xxxx bytes GC work")
97 ghc1_re = mkRegex "^<<ghc:[ \t]+([0-9]+)[ \t]+bytes,[ \t]*([0-9]+)[ \t]+GCs,[ \t]*([0-9]+)/([0-9]+)[ \t]+avg/max bytes residency \\(([0-9]+) samples\\), ([0-9]+) bytes GC work, ([0-9.]+) INIT \\(([0-9.]+) elapsed\\), ([0-9.]+) MUT \\(([0-9.]+) elapsed\\), ([0-9.]+) GC \\(([0-9.]+) elapsed\\) :ghc>>"
99 ghc2_re = mkRegex "^<<ghc:[ \t]+([0-9]+)[ \t]+bytes,[ \t]*([0-9]+)[ \t]+GCs,[ \t]*([0-9]+)/([0-9]+)[ \t]+avg/max bytes residency \\(([0-9]+) samples\\), ([0-9]+)M in use, ([0-9.]+) INIT \\(([0-9.]+) elapsed\\), ([0-9.]+) MUT \\(([0-9.]+) elapsed\\), ([0-9.]+) GC \\(([0-9.]+) elapsed\\) :ghc>>"
101 ghc3_re = mkRegex "^<<ghc:[ \t]+([0-9]+)[ \t]+bytes,[ \t]*([0-9]+)[ \t]+GCs,[ \t]*([0-9]+)/([0-9]+)[ \t]+avg/max bytes residency \\(([0-9]+) samples\\), ([0-9]+) bytes GC work, ([0-9]+)M in use, ([0-9.]+) INIT \\(([0-9.]+) elapsed\\), ([0-9.]+) MUT \\(([0-9.]+) elapsed\\), ([0-9.]+) GC \\(([0-9.]+) elapsed\\) :ghc>>"
103 ghc4_re = mkRegex "^<<ghc-instrs:[ \t]+([0-9]+)[ \t]+bytes,[ \t]*([0-9]+)[ \t]+GCs,[ \t]*([0-9]+)/([0-9]+)[ \t]+avg/max bytes residency \\(([0-9]+) samples\\), ([0-9]+) bytes GC work, ([0-9]+)M in use, ([0-9.]+) INIT \\(([0-9.]+) elapsed\\), ([0-9.]+) MUT \\(([0-9.]+) elapsed\\), ([0-9.]+) GC \\(([0-9.]+) elapsed\\), ([0-9]+) instructions, ([0-9]+) memory reads, ([0-9]+) memory writes :ghc-instrs>>"
105 wrong_exit_status = mkRegex "^\\**[ \t]*expected exit status ([0-9]+) not seen ; got ([0-9]+)"
107 wrong_output = mkRegex "^expected (stdout|stderr) not matched by reality$"
109 out_of_heap = mkRegex "^\\+ Heap exhausted;$"
111 out_of_stack = mkRegex "^\\+ Stack space overflow:"
113 parse_log :: String -> ResultTable
115 = combine_results -- collate information
117 . map process_chunk -- get information from each chunk
118 . tail -- first chunk is junk
119 . chunk_log [] [] -- break at banner lines
122 combine_results :: [(String,Results)] -> FiniteMap String Results
123 combine_results = foldr f emptyFM
125 f (prog,results) fm = addToFM_C comb fm prog results
126 comb Results{ compile_time = ct1, link_time = lt1,
128 run_time = rt1, mut_time = mt1,
129 instrs = is1, mem_reads = mr1, mem_writes = mw1,
130 gc_time = gt1, gc_work = gw1,
131 binary_size = bs1, allocs = al1,
132 run_status = rs1, compile_status = cs1 }
133 Results{ compile_time = ct2, link_time = lt2,
135 run_time = rt2, mut_time = mt2,
136 instrs = is2, mem_reads = mr2, mem_writes = mw2,
137 gc_time = gt2, gc_work = gw2,
138 binary_size = bs2, allocs = al2,
139 run_status = rs2, compile_status = cs2 }
140 = Results{ compile_time = plusFM_C const ct1 ct2,
141 module_size = plusFM_C const ms1 ms2,
142 link_time = combMaybes lt1 lt2,
143 run_time = combMaybes rt1 rt2,
144 mut_time = combMaybes mt1 mt2,
145 instrs = combMaybes is1 is2,
146 mem_reads = combMaybes mr1 mr2,
147 mem_writes = combMaybes mw1 mw2,
148 gc_time = combMaybes gt1 gt2,
149 gc_work = combMaybes gw1 gw2,
150 binary_size = combMaybes bs1 bs2,
151 allocs = combMaybes al1 al2,
152 run_status = combStatus rs1 rs2,
153 compile_status = combStatus cs1 cs2 }
155 combMaybes m1 m2 = case maybeToList m1 ++ maybeToList m2 of
159 combStatus NotDone x = x
160 combStatus x NotDone = x
163 chunk_log :: [String] -> [String] -> [String] -> [([String],[String])]
164 chunk_log header chunk [] = [(header,chunk)]
165 chunk_log header chunk (l:ls) =
166 case matchRegex banner_re l of
167 Nothing -> chunk_log header (l:chunk) ls
168 Just stuff -> (header,chunk) : chunk_log stuff [] ls
170 process_chunk :: ([String],[String]) -> [(String,Results)]
171 process_chunk (prog : what : mod : _, chk) =
173 "time to compile" -> parse_compile_time prog mod chk
174 "time to run" -> parse_run_time prog (reverse chk) NotDone
175 "time to link" -> parse_link_time prog chk
176 "size of" -> parse_size prog mod chk
177 _ -> error ("process_chunk: "++what)
179 parse_compile_time prog mod [] = []
180 parse_compile_time prog mod (l:ls) =
181 case matchRegex time_re l of {
182 Just (real:user:system:_) ->
183 let ct = addToFM emptyFM mod (read user)
185 [(prog,emptyResults{compile_time = ct})];
188 case matchRegex ghc1_re l of {
189 Just (allocs:_:_:_:_:init:_:mut:_:gc:_) ->
193 time = (read init + read_mut + read_gc) :: Float
194 ct = addToFM emptyFM mod time
196 [(prog,emptyResults{compile_time = ct})];
199 case matchRegex ghc2_re l of {
200 Just (allocs:_:_:_:_:_:init:_:mut:_:gc:_) ->
204 time = (read init + read_mut + read_gc) :: Float
205 ct = addToFM emptyFM mod time
207 [(prog,emptyResults{compile_time = ct})];
210 case matchRegex ghc3_re l of {
211 Just (allocs:_:_:_:_:_:_:init:_:mut:_:gc:_) ->
215 time = (read init + read_mut + read_gc) :: Float
216 ct = addToFM emptyFM mod time
218 [(prog,emptyResults{compile_time = ct})];
221 case matchRegex ghc4_re l of {
222 Just (allocs:_:_:_:_:_:_:init:_:mut:_:gc:_:_:_:_) ->
226 time = (read init + read_mut + read_gc) :: Float
227 ct = addToFM emptyFM mod time
229 [(prog,emptyResults{compile_time = ct})];
232 parse_compile_time prog mod ls
235 parse_link_time prog [] = []
236 parse_link_time prog (l:ls) =
237 case matchRegex time_re l of
238 Nothing -> parse_link_time prog ls
239 Just (real:user:system:_) ->
240 [(prog,emptyResults{link_time = Just (read user)})]
242 parse_run_time prog [] NotDone = []
243 parse_run_time prog [] ex =[(prog,emptyResults{run_status=ex})]
244 parse_run_time prog (l:ls) ex =
245 case matchRegex ghc1_re l of {
246 Just (allocs:_:_:_:_:init:_:mut:_:gc:_) ->
250 time = (read init + read_mut + read_gc) :: Float
252 [(prog,emptyResults{run_time = Just time,
253 mut_time = Just read_mut,
254 gc_time = Just read_gc,
255 allocs = Just (read allocs),
256 run_status = Success })];
259 case matchRegex ghc2_re l of {
260 Just (allocs:_:_:_:_:_:init:_:mut:_:gc:_) ->
264 time = (read init + read_mut + read_gc) :: Float
266 [(prog,emptyResults{run_time = Just time,
267 mut_time = Just read_mut,
268 gc_time = Just read_gc,
269 allocs = Just (read allocs),
270 run_status = Success })];
273 case matchRegex ghc3_re l of {
274 Just (allocs:_:_:_:_:gc_work:_:init:_:mut:_:gc:_) ->
278 read_gc_work = read gc_work
279 time = (read init + read_mut + read_gc) :: Float
281 [(prog,emptyResults{run_time = Just time,
282 mut_time = Just read_mut,
283 gc_work = Just read_gc_work,
284 gc_time = Just read_gc,
285 allocs = Just (read allocs),
286 run_status = Success })];
289 case matchRegex ghc4_re l of {
290 Just (allocs:_:_:_:_:gc_work:_:init:_:mut:_:gc:_:is:mem_rs:mem_ws:_) ->
294 read_gc_work = read gc_work
295 time = (read init + read_mut + read_gc) :: Float
297 [(prog,emptyResults{run_time = Just time,
298 mut_time = Just read_mut,
299 gc_work = Just read_gc_work,
300 gc_time = Just read_gc,
301 instrs = Just (read is),
302 mem_writes = Just (read mem_ws),
303 mem_reads = Just (read mem_rs),
304 allocs = Just (read allocs),
305 run_status = Success })];
308 case matchRegex wrong_output l of {
310 parse_run_time prog ls (combineRunResult WrongStdout ex);
312 parse_run_time prog ls (combineRunResult WrongStderr ex);
315 case matchRegex wrong_exit_status l of {
316 Just (wanted:got:_) ->
317 parse_run_time prog ls (combineRunResult (Exit (read got)) ex);
320 case matchRegex out_of_heap l of {
322 parse_run_time prog ls (combineRunResult OutOfHeap ex);
325 case matchRegex out_of_stack l of {
327 parse_run_time prog ls (combineRunResult OutOfStack ex);
329 parse_run_time prog ls ex;
333 combineRunResult OutOfHeap _ = OutOfHeap
334 combineRunResult _ OutOfHeap = OutOfHeap
335 combineRunResult OutOfStack _ = OutOfStack
336 combineRunResult _ OutOfStack = OutOfStack
337 combineRunResult (Exit e) _ = Exit e
338 combineRunResult _ (Exit e) = Exit e
339 combineRunResult exit _ = exit
341 parse_size prog mod [] = []
342 parse_size prog mod (l:ls) =
343 case matchRegex size_re l of
344 Nothing -> parse_size prog mod ls
345 Just (text:datas:bss:_)
347 [(prog,emptyResults{binary_size =
348 Just (read text + read datas),
349 compile_status = Success})]
351 let ms = addToFM emptyFM mod (read text + read datas)
353 [(prog,emptyResults{module_size = ms})]