HpcShowTix.hs 1.93 KB
Newer Older
andy@galois.com's avatar
andy@galois.com committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module HpcShowTix (showtix_plugin) where

import Trace.Hpc.Mix
import Trace.Hpc.Tix

import HpcFlags

import qualified Data.Set as Set

showtix_options = 
  [ excludeOpt,includeOpt,hpcDirOpt
  , outputOpt
  ]

showtix_plugin = Plugin { name = "show"
	      	       , usage = "[OPTION] .. <TIX_FILE> [<MODULE> [<MODULE> ..]]" 
		       , options = showtix_options 
		       , summary = "Show .tix file in readable, verbose format"
		       , implementation = showtix_main
		       , init_flags = default_flags
		       , final_flags = default_final_flags
		       }



showtix_main flags [] = hpcError showtix_plugin $ "no .tix file or executable name specified" 
showtix_main flags (prog:modNames) = do
  let hpcflags1 = flags 
      		{ includeMods = Set.fromList modNames
  	      	     	 	   `Set.union` 
				includeMods flags }

  optTixs <- readTix (getTixFileName prog)
  case optTixs of
    Nothing -> hpcError showtix_plugin $ "could not read .tix file : "  ++ prog
    Just (Tix tixs) -> do
       let modules = map tixModuleName tixs       

       mixs <- sequence
               [ readMix (hpcDirs hpcflags1) modName            -- hard wired to .hpc for now
               | modName <- modules
	       , allowModule hpcflags1 modName
               ]
     
       let rjust n str = take (n - length str) (repeat ' ') ++ str 
       let ljust n str = str ++ take (n - length str) (repeat ' ') 
     
       sequence_ [ sequence_ [ putStrLn (rjust 5 (show ix) ++ " " ++
                                         rjust 10 (show count) ++ " " ++
                                         ljust 20  modName ++ " " ++ rjust 20 (show pos) ++ " " ++ show lab)
                             | (count,ix,(pos,lab)) <- zip3 tixs [(0::Int)..] entries
                             ]
                 | ( TixModule modName hash _ tixs
                   , Mix _file _timestamp _hash _tab entries
                   ) <- zip tixs mixs
                 ]
       
       return ()