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