0a303e15aead7812dc6c0adcae51ec271d0cb8ed
[ghc-hetmet.git] / utils / nofib-analyse / CmdLine.hs
1 -----------------------------------------------------------------------------
2 -- CmdLine.hs
3
4 -- (c) Simon Marlow 2005
5 -----------------------------------------------------------------------------
6
7 module CmdLine
8     (
9     flags, other_args, cmdline_errors,
10     devs, nodevs, tooquick_threshold, reportTitle,
11     CLIFlags(..), usage,
12     )
13     where
14
15 import System.Console.GetOpt
16 import System.Environment       ( getArgs )
17 import System.IO.Unsafe         ( unsafePerformIO )
18
19 -----------------------------------------------------------------------------
20 -- Command line arguments
21
22 args :: [String]
23 args = unsafePerformIO getArgs
24
25 flags :: [CLIFlags]
26 other_args :: [String]
27 cmdline_errors :: [String]
28 (flags, other_args, cmdline_errors) = getOpt Permute argInfo args 
29
30 default_tooquick_threshold, tooquick_threshold :: Float
31 default_tooquick_threshold = 0.2 {- secs -}
32 tooquick_threshold
33  = case [ i | OptIgnoreSmallTimes i <- flags ] of
34         [] -> default_tooquick_threshold
35         (i:_) -> i
36
37 devs, nodevs :: Bool
38 devs   = OptDeviations   `elem` flags
39 nodevs = OptNoDeviations `elem` flags
40
41 default_title, reportTitle :: String
42 default_title = "NoFib Results"
43 reportTitle = case [ t | OptTitle t <- flags ] of
44         []    -> default_title
45         (t:_) -> t
46
47 data CLIFlags
48   = OptASCIIOutput
49   | OptLaTeXOutput
50   | OptHTMLOutput
51   | OptIgnoreSmallTimes Float
52   | OptDeviations
53   | OptNoDeviations
54   | OptTitle String
55   | OptColumns String
56   | OptRows String
57   | OptCSV String
58   | OptNoNormalise
59   | OptHelp
60   deriving Eq
61
62 usageHeader :: String
63 usageHeader = "usage: nofib-analyse [OPTION...] <logfile1> <logfile2> ..."
64
65 usage :: String
66 usage = usageInfo usageHeader argInfo
67
68 argInfo :: [ OptDescr CLIFlags ]
69 argInfo = 
70   [ Option ['?'] ["help"]    (NoArg OptHelp)        
71         "Display this message"
72   , Option ['a'] ["ascii"]   (NoArg OptASCIIOutput) 
73         "Produce ASCII output (default)"
74   , Option ['h'] ["html"]    (NoArg OptHTMLOutput)  
75         "Produce HTML output"
76   , Option ['i'] ["ignore"]  (ReqArg (OptIgnoreSmallTimes . read) "secs")
77         "Ignore runtimes smaller than <secs>"
78   , Option ['d'] ["deviations"] (NoArg OptDeviations)
79         "Display deviations (default)"
80   , Option ['l'] ["latex"]    (NoArg OptLaTeXOutput)  
81         "Produce LaTeX output"
82   , Option [] ["columns"] (ReqArg OptColumns "COLUMNS")
83         "Specify columns for summary table (comma separates)"
84   , Option [] ["rows"] (ReqArg OptRows "ROWS")
85         "Specify rows for summary table (comma separates)"
86   , Option [] ["csv"] (ReqArg OptCSV "TABLE")
87         "Output a single table in CSV format"
88   , Option [] ["no-normalise"] (NoArg OptNoNormalise)
89         "Do not normalise to the baseline"
90   , Option ['n'] ["nodeviations"] (NoArg OptNoDeviations)
91         "Hide deviations"
92   , Option ['t'] ["title"] (ReqArg OptTitle "title")
93         "Specify report title"
94   ]
95