HpcShowTix.hs 2.21 KB
Newer Older
andy@galois.com's avatar
andy@galois.com committed
1 2 3 4 5 6 7
module HpcShowTix (showtix_plugin) where

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

import HpcFlags

8
import qualified Data.Set as Set
andy@galois.com's avatar
andy@galois.com committed
9

Ian Lynagh's avatar
Ian Lynagh committed
10
showtix_options :: FlagOptSeq
ian@well-typed.com's avatar
ian@well-typed.com committed
11
showtix_options
12 13 14 15
        = excludeOpt
        . includeOpt
        . srcDirOpt
        . hpcDirOpt
16
        . resetHpcDirsOpt
17
        . outputOpt
18
        . verbosityOpt
andy@galois.com's avatar
andy@galois.com committed
19

Ian Lynagh's avatar
Ian Lynagh committed
20
showtix_plugin :: Plugin
andy@galois.com's avatar
andy@galois.com committed
21
showtix_plugin = Plugin { name = "show"
ian@well-typed.com's avatar
ian@well-typed.com committed
22 23 24 25 26 27 28
                       , 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
                       }
andy@galois.com's avatar
andy@galois.com committed
29 30


Ian Lynagh's avatar
Ian Lynagh committed
31
showtix_main :: Flags -> [String] -> IO ()
ian@well-typed.com's avatar
ian@well-typed.com committed
32
showtix_main _     [] = hpcError showtix_plugin $ "no .tix file or executable name specified"
andy@galois.com's avatar
andy@galois.com committed
33
showtix_main flags (prog:modNames) = do
ian@well-typed.com's avatar
ian@well-typed.com committed
34 35 36 37
  let hpcflags1 = flags
                { includeMods = Set.fromList modNames
                                   `Set.union`
                                includeMods flags }
andy@galois.com's avatar
andy@galois.com committed
38 39 40 41 42

  optTixs <- readTix (getTixFileName prog)
  case optTixs of
    Nothing -> hpcError showtix_plugin $ "could not read .tix file : "  ++ prog
    Just (Tix tixs) -> do
43
       tixs_mixs <- sequence
andy@galois.com's avatar
andy@galois.com committed
44
               [ do mix <- readMixWithFlags hpcflags1 (Right tix)
45 46
                    return $ (tix,mix)
               | tix <- tixs
ian@well-typed.com's avatar
ian@well-typed.com committed
47
               , allowModule hpcflags1 (tixModuleName tix)
andy@galois.com's avatar
andy@galois.com committed
48
               ]
ian@well-typed.com's avatar
ian@well-typed.com committed
49 50 51 52

       let rjust n str = take (n - length str) (repeat ' ') ++ str
       let ljust n str = str ++ take (n - length str) (repeat ' ')

andy@galois.com's avatar
andy@galois.com committed
53 54 55
       sequence_ [ sequence_ [ putStrLn (rjust 5 (show ix) ++ " " ++
                                         rjust 10 (show count) ++ " " ++
                                         ljust 20  modName ++ " " ++ rjust 20 (show pos) ++ " " ++ show lab)
Ian Lynagh's avatar
Ian Lynagh committed
56
                             | (count,ix,(pos,lab)) <- zip3 tixs' [(0::Int)..] entries
andy@galois.com's avatar
andy@galois.com committed
57
                             ]
Ian Lynagh's avatar
Ian Lynagh committed
58 59
                 | ( TixModule modName _hash1 _ tixs'
                   , Mix _file _timestamp _hash2 _tab entries
60
                   ) <- tixs_mixs
andy@galois.com's avatar
andy@galois.com committed
61
                 ]
ian@well-typed.com's avatar
ian@well-typed.com committed
62

andy@galois.com's avatar
andy@galois.com committed
63
       return ()
64