on ea77dcf help sign in
elk/profiling/Main.hs
77 lines 1.9 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Main where
4import qualified Data.Attoparsec.Text as Atto
5import qualified Data.IntMap as IntMap
6import qualified Data.Text as Text
7import qualified Data.Text.IO as Text
8import qualified GHC.RTS.TimeAllocProfile as Prof
9import qualified GHC.RTS.TimeAllocProfile.Types as Prof
10import qualified Text.Tabular as Table
11import qualified Text.Tabular.AsciiArt as Table
15main :: IO ()
16main =
17 profToTable "elm-make.prof"
20profToTable :: FilePath -> IO ()
21profToTable filePath =
22 do text <- Text.readFile filePath
23 case Atto.parseOnly Prof.timeAllocProfile text of
24 Left err ->
25 putStrLn $ "Error parsing " ++ filePath ++ ": " ++ err
27 Right profile ->
28 printTable (extractCostCentres profile)
32-- FILTER NAMED COST CENTRES
35extractCostCentres :: Prof.TimeAllocProfile -> [Prof.CostCentre]
36extractCostCentres profile =
37 let
38 nodes =
39 IntMap.elems (Prof.costCentreNodes (Prof.profileCostCentreTree profile))
40 in
41 filter (Text.isPrefixOf "elm_" . Prof.costCentreName) nodes
45-- CREATE A TABLE
48printTable :: [Prof.CostCentre] -> IO ()
49printTable costCentres =
50 let
51 rowHeaders =
52 Table.Group Table.NoLine $
53 map (Table.Header . Text.unpack . Prof.costCentreName) costCentres
55 table =
56 Table.Table rowHeaders colHeaders (map toRow costCentres)
57 in
58 putStrLn (Table.render id id id table)
61colHeaders :: Table.Header String
62colHeaders =
63 Table.Group Table.NoLine
64 [ Table.Header " total time"
65 , Table.Header " local time"
66 , Table.Header " total alloc"
67 , Table.Header " local alloc"
68 ]
71toRow :: Prof.CostCentre -> [String]
72toRow costCentre =
73 [ show $ Prof.costCentreInhTime costCentre
74 , show $ Prof.costCentreIndTime costCentre
75 , show $ Prof.costCentreInhAlloc costCentre
76 , show $ Prof.costCentreIndAlloc costCentre
77 ]