Permalink
Browse files

Added ability to pick table spec from command line

This commit adds a command line flag to specify the table spec to
use for output. In addition, we added a new table that dumps out all
of the stats collected from a ghc stats file.
  • Loading branch information...
1 parent 0aecfef commit 5aa4a144ea35429f9b1a41c1906ab1513e5e45d8 @dmpots committed Feb 21, 2011
@@ -4,13 +4,17 @@ module Fibon.Analyse.CommandLine (
, parseCommandLine
)
where
+import Data.List
import Fibon.Analyse.Output(OutputFormat(..))
+import Fibon.Analyse.Tables(TableSpec, defaultTable, allTables)
+import Fibon.Analyse.ExtraStats(GhcStats)
import System.Console.GetOpt
data Opt = Opt {
optHelpMsg :: Maybe String
, optOutputFormat :: OutputFormat
, optNormalizeBy :: NormalizeBy
+ , optTableSpec :: TableSpec GhcStats
}
type UsageError = String
@@ -22,6 +26,7 @@ defaultOpts = Opt {
optHelpMsg = Nothing
, optOutputFormat = AsciiArt
, optNormalizeBy = ByPercent
+ , optTableSpec = defaultTable
}
parseCommandLine :: [String] -> Either UsageError (Opt, [FilePath])
@@ -65,15 +70,30 @@ options = [
"ratio" -> setNorm ByRatio o
"none" -> setNorm ByNone o
_ -> Left $ "Invalid normalization: "++a)) "NormBy")
- "normalize results by [percent, speedup, none]"
+ "normalize results by [percent, ratio, none]"
+ ,
+ Option ['s'] ["spec"]
+ (ReqArg (\a mbOpt -> process mbOpt (\o ->
+ case lookup a allTables of
+ Just t -> setSpec t o
+ Nothing -> Left $ "Invalid spec: "++a++"\n try: "++validSpecs))
+ "TableSpec")
+ ("table spec [" ++ validSpecs ++ "]")
]
where
setFormat fmt o = Right $ o {optOutputFormat = fmt}
setNorm norm o = Right $ o {optNormalizeBy = norm}
+ setSpec spec o = Right $ o {optTableSpec = spec}
process :: MbOpt -> (Opt -> MbOpt) -> MbOpt
process = flip (either Left)
+validSpecs :: String
+validSpecs = join ", " (map fst allTables)
+
+join :: String -> [String] -> String
+join s = concat . intersperse s
+
usage :: String
usage = usageInfo header options
where header = "Usage: fibon-analyse [OPTION...] [RESULTFILE...]"
@@ -4,7 +4,6 @@ import Fibon.Analyse.Analysis
import Fibon.Analyse.CommandLine
import Fibon.Analyse.Output
import Fibon.Analyse.Result
-import Fibon.Analyse.Tables
import System.Environment
import System.Exit
@@ -16,9 +15,10 @@ main = do
Nothing -> putStrLn "Error Parsing Results"
Just rs -> do
let fmt = optOutputFormat opts
- let norm = getNormFun opts
- putStrLn $ renderSummaryTable rs norm fmt ghcStatsSummaryTable
- putStrLn $ renderTables rs norm fmt ghcStatsSummaryTable
+ norm = getNormFun opts
+ tableSpec = optTableSpec opts
+ putStrLn $ renderSummaryTable rs norm fmt tableSpec
+ putStrLn $ renderTables rs norm fmt tableSpec
getCommandLine :: IO (Opt, [FilePath])
@@ -1,26 +1,32 @@
{-# LANGUAGE ExistentialQuantification #-}
module Fibon.Analyse.Tables (
- basicTable
- , ghcStatsSummaryTable
- , stgTable
+ TableSpec
, ColSpec(..)
- , TableSpec
+ , allTables
+ , defaultTable
)
where
import Fibon.Analyse.ExtraStats
import Fibon.Analyse.Metrics
import Fibon.Analyse.Result
-basicTable :: TableSpec a
-basicTable = [
+-- The default table to use when the user does not specify
+defaultTable :: TableSpec GhcStats
+defaultTable = nofibTable
+
+-- The fibon table only uses stats collected by fibon-run itself
+fibonTable :: TableSpec a
+fibonTable = [
ColSpec "RunTime" (onFibonStats wallTime)
, ColSpec "Size" (onFibonStats binarySize)
, ColSpec "CompileTime" (onFibonStats compileTime)
]
-ghcStatsSummaryTable :: TableSpec GhcStats
-ghcStatsSummaryTable = [
+-- The nofib table mimics the output of nofib-analyse. It uses info from the
+-- extra stats gathered from ghc.
+nofibTable :: TableSpec GhcStats
+nofibTable = [
ColSpec "Size" (onFibonStats binarySize)
, ColSpec "Compile" (onFibonStats compileTime)
, ColSpec "Allocs" (onExtraStats bytesAllocated)
@@ -29,6 +35,7 @@ ghcStatsSummaryTable = [
, ColSpec "TotalMem" (onExtraStats maxBytesUsed)
]
+-- The stg table prints stats related to stg efficiency
stgTable :: TableSpec GhcStats
stgTable = [
ColSpec "StgRuntime" (onExtraStats stgCpuTime)
@@ -39,6 +46,35 @@ stgTable = [
, ColSpec "Elapsed" (onExtraStats ghcWallTime)
]
+-- The ghc table prints all the extra stats collected for ghc executions
+ghcTable :: TableSpec GhcStats
+ghcTable = [
+ ColSpec "BytesAllocated" (onExtraStats bytesAllocated)
+ , ColSpec "NumGCs" (onExtraStats numGCs)
+ , ColSpec "AvgBytesUsed" (onExtraStats averageBytesUsed)
+ , ColSpec "MaxBytes" (onExtraStats maxBytesUsed)
+ , ColSpec "ByteUsageSamples" (onExtraStats numByteUsageSamples)
+ , ColSpec "PeakMBsAllocated" (onExtraStats peakMegabytesAllocated)
+ , ColSpec "InitCPUSeconds" (onExtraStats initCPUSeconds)
+ , ColSpec "InitWallSeconds" (onExtraStats initWallSeconds)
+ , ColSpec "MutatorCPUSeconds" (onExtraStats mutatorCPUSeconds)
+ , ColSpec "MutatorWallSeconds" (onExtraStats mutatorWallSeconds)
+ , ColSpec "GCCPUSeconds" (onExtraStats gcCPUSeconds)
+ , ColSpec "GCWallSeconds" (onExtraStats gcWallSeconds)
+ , ColSpec "TotalCPUTime" (onExtraStats ghcCpuTime)
+ , ColSpec "TotalWallTime" (onExtraStats ghcWallTime)
+ , ColSpec "StgCPUTime" (onExtraStats stgCpuTime)
+ , ColSpec "StgWallTime" (onExtraStats stgWallTime)
+ ]
+
+allTables :: [(String, TableSpec GhcStats)]
+allTables = [
+ ("fibon", fibonTable)
+ , ("nofib", nofibTable)
+ , ("stg", stgTable)
+ , ("ghc", ghcTable)
+ ]
+
-- Idea borrowed graciously from nofib-analyse
data ColSpec a =
forall b . Metric b =>

0 comments on commit 5aa4a14

Please sign in to comment.