X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Fhpc%2FHpcReport.hs;h=d3e3ef07232aba40553fb36ac67688c5f0a0176f;hb=8e4e15d8e837b90190b6b8e7645822772cab2053;hp=8f063f83006887a4d94a40b59fb047887264aab9;hpb=858a055da9f768dd20268cdddb3a3b7c904e83ef;p=ghc-hetmet.git diff --git a/utils/hpc/HpcReport.hs b/utils/hpc/HpcReport.hs index 8f063f8..d3e3ef0 100644 --- a/utils/hpc/HpcReport.hs +++ b/utils/hpc/HpcReport.hs @@ -5,15 +5,13 @@ module HpcReport (report_plugin) where -import System.Exit import Prelude hiding (exp) -import System(getArgs) -import List(sort,intersperse) +import Data.List(sort,intersperse,sortBy) import HpcFlags import Trace.Hpc.Mix import Trace.Hpc.Tix import Control.Monad hiding (guard) -import qualified HpcSet as Set +import qualified Data.Set as Set notExpecting :: String -> a notExpecting s = error ("not expecting "++s) @@ -104,8 +102,8 @@ allBinCounts mi = accumCounts :: [(BoxLabel,Integer)] -> ModInfo -> ModInfo accumCounts [] mi = mi -accumCounts ((bl,btc):etc) mi | single bl = - accumCounts etc mi' +accumCounts ((bl,btc):etc) mi + | single bl = accumCounts etc mi' where mi' = case bl of ExpBox False -> mi{exp = inc (exp mi)} @@ -120,6 +118,7 @@ accumCounts ((bl,btc):etc) mi | single bl = , tixCount = tc + bit (btc>0) } upd dp dps = if btc>0 then dps else dp:dps +accumCounts [_] _ = error "accumCounts: Unhandled case: [_] _" accumCounts ((bl0,btc0):(bl1,btc1):etc) mi = accumCounts etc mi' where @@ -150,17 +149,17 @@ single (TopLevelBox _) = True single (LocalBox _) = True single (BinBox {}) = False -modInfo :: Flags -> Bool -> (String,[Integer]) -> IO ModInfo -modInfo hpcflags qualDecList (moduleName,tickCounts) = do - Mix _ _ _ _ mes <- readMix (hpcDirs hpcflags) moduleName +modInfo :: Flags -> Bool -> TixModule -> IO ModInfo +modInfo hpcflags qualDecList tix@(TixModule moduleName _ _ tickCounts) = do + Mix _ _ _ _ mes <- readMixWithFlags hpcflags (Right tix) return (q (accumCounts (zip (map snd mes) tickCounts) miZero)) where q mi = if qualDecList then mi{decPaths = map (moduleName:) (decPaths mi)} else mi -modReport :: Flags -> (String,[Integer]) -> IO () -modReport hpcflags (moduleName,tickCounts) = do - mi <- modInfo hpcflags False (moduleName,tickCounts) +modReport :: Flags -> TixModule -> IO () +modReport hpcflags tix@(TixModule moduleName _ _ _) = do + mi <- modInfo hpcflags False tix if xmlOutput hpcflags then putStrLn $ " " else putStrLn ("----------") @@ -201,6 +200,7 @@ modDecList hpcflags mi0 = showDecPath dp = putStrLn (" "++ concat (intersperse "." dp)) +report_plugin :: Plugin report_plugin = Plugin { name = "report" , usage = "[OPTION] .. [ [ ..]]" , options = report_options @@ -221,20 +221,21 @@ report_main hpcflags (progName:mods) = do case tix of Just (Tix tickCounts) -> makeReport hpcflags1 progName - [(m,tcs) - | TixModule m _h _ tcs <- tickCounts + $ sortBy (\ mod1 mod2 -> tixModuleName mod1 `compare` tixModuleName mod2) + $ [ tix' + | tix'@(TixModule m _ _ _) <- tickCounts , allowModule hpcflags1 m ] - Nothing -> error $ "unable to find tix file for:" ++ progName - - + Nothing -> hpcError report_plugin $ "unable to find tix file for:" ++ progName +report_main _ [] = + hpcError report_plugin $ "no .tix file or executable name specified" -makeReport :: Flags -> String -> [(String,[Integer])] -> IO () +makeReport :: Flags -> String -> [TixModule] -> IO () makeReport hpcflags progName modTcs | xmlOutput hpcflags = do putStrLn $ "" putStrLn $ "" if perModule hpcflags - then mapM_ (modReport hpcflags) (sort modTcs) + then mapM_ (modReport hpcflags) modTcs else return () mis <- mapM (modInfo hpcflags True) modTcs putStrLn $ " " @@ -243,7 +244,7 @@ makeReport hpcflags progName modTcs | xmlOutput hpcflags = do putStrLn $ "" makeReport hpcflags _ modTcs = if perModule hpcflags then - mapM_ (modReport hpcflags) (sort modTcs) + mapM_ (modReport hpcflags) modTcs else do mis <- mapM (modInfo hpcflags True) modTcs printModInfo hpcflags (foldr miPlus miZero mis) @@ -255,11 +256,22 @@ element tag attrs = putStrLn $ | (x,y) <- attrs ] ++ "/>" +xmlBT :: BoxTixCounts -> [(String, String)] xmlBT (BT b t) = [("boxes",show b),("count",show t)] +xmlBBT :: BinBoxTixCounts -> [(String, String)] xmlBBT (BBT b tt tf bt) = [("boxes",show b),("true",show tt),("false",show tf),("count",show (tt + tf + bt))] ------------------------------------------------------------------------------ -report_options = [perModuleOpt,decListOpt,excludeOpt,includeOpt,hpcDirOpt,xmlOutputOpt] +report_options :: FlagOptSeq +report_options + = perModuleOpt + . decListOpt + . excludeOpt + . includeOpt + . srcDirOpt + . hpcDirOpt + . xmlOutputOpt +