Adding draft and show to hpc
[ghc-hetmet.git] / utils / hpc / HpcShowTix.hs
1 module HpcShowTix (showtix_plugin) where
2
3 import Trace.Hpc.Mix
4 import Trace.Hpc.Tix
5 import Trace.Hpc.Util
6
7 import HpcFlags
8
9 import qualified Data.Set as Set
10
11 showtix_options = 
12   [ excludeOpt,includeOpt,hpcDirOpt
13   , outputOpt
14   ]
15
16 showtix_plugin = Plugin { name = "show"
17                        , usage = "[OPTION] .. <TIX_FILE> [<MODULE> [<MODULE> ..]]" 
18                        , options = showtix_options 
19                        , summary = "Show .tix file in readable, verbose format"
20                        , implementation = showtix_main
21                        , init_flags = default_flags
22                        , final_flags = default_final_flags
23                        }
24
25
26
27 showtix_main flags [] = hpcError showtix_plugin $ "no .tix file or executable name specified" 
28 showtix_main flags (prog:modNames) = do
29   let hpcflags1 = flags 
30                 { includeMods = Set.fromList modNames
31                                    `Set.union` 
32                                 includeMods flags }
33
34   optTixs <- readTix (getTixFileName prog)
35   case optTixs of
36     Nothing -> hpcError showtix_plugin $ "could not read .tix file : "  ++ prog
37     Just (Tix tixs) -> do
38        let modules = map tixModuleName tixs       
39
40        mixs <- sequence
41                [ readMix (hpcDirs hpcflags1) modName            -- hard wired to .hpc for now
42                | modName <- modules
43                , allowModule hpcflags1 modName
44                ]
45      
46        let rjust n str = take (n - length str) (repeat ' ') ++ str 
47        let ljust n str = str ++ take (n - length str) (repeat ' ') 
48      
49        sequence_ [ sequence_ [ putStrLn (rjust 5 (show ix) ++ " " ++
50                                          rjust 10 (show count) ++ " " ++
51                                          ljust 20  modName ++ " " ++ rjust 20 (show pos) ++ " " ++ show lab)
52                              | (count,ix,(pos,lab)) <- zip3 tixs [(0::Int)..] entries
53                              ]
54                  | ( TixModule modName hash _ tixs
55                    , Mix _file _timestamp _hash _tab entries
56                    ) <- zip tixs mixs
57                  ]
58        
59        return ()
60