hledger/tools/simplifyprof.hs

34 lines
1007 B
Haskell
Raw Normal View History

2008-05-27 01:19:21 +04:00
#!/usr/bin/env runhaskell
2008-12-05 03:37:47 +03:00
-- simplifyprof.hs somefile.prof
-- filter uninteresting fields from GHC profile output
-- tested with GHC 6.8
-- Simon Michael 2007,2008
2008-05-27 01:19:21 +04:00
import Data.List
2008-12-05 03:37:47 +03:00
import System.Environment
import Text.Printf
main = do
args <- getArgs
let f = head args
s <- readFile f
let ls = lines s
let (firstpart, secondpart) = break ("individual inherited" `isInfixOf`) ls
putStr $ unlines firstpart
let fields = map getfields $ filter (not . null) $ drop 2 $ secondpart
let maxnamelen = maximum $ map (length . head) fields
let fmt = "%-"++(show maxnamelen)++"s %10s %5s %6s %9s %10s"
putStrLn $ showheading fmt
putStr $ unlines $ map (format fmt) fields
getfields s = name:rest
2008-05-27 01:19:21 +04:00
where
2008-12-05 03:37:47 +03:00
space = takeWhile (==' ') s
fields = words s
name = space ++ head fields
rest = drop 3 fields
showheading fmt = format fmt ["cost centre","entries","%time","%alloc","%time-inh","%alloc-inh"]
format fmt (s1:s2:s3:s4:s5:s6:[]) = printf fmt s1 s2 s3 s4 s5 s6