5be7d324b0f1eab3feb165f6ee680675ad81dd59
[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 = unsafePerformIO getArgs
23 (flags, other_args, cmdline_errors) = getOpt Permute argInfo args 
24
25 default_tooquick_threshold = 0.2 {- secs -} :: Float
26 tooquick_threshold
27  = case [ i | OptIgnoreSmallTimes i <- flags ] of
28         [] -> default_tooquick_threshold
29         (i:_) -> i
30
31 devs   = OptDeviations   `elem` flags
32 nodevs = OptNoDeviations `elem` flags
33
34 default_title = "NoFib Results"
35 reportTitle = case [ t | OptTitle t <- flags ] of
36         []    -> default_title
37         (t:_) -> t
38
39 data CLIFlags
40   = OptASCIIOutput
41   | OptLaTeXOutput
42   | OptHTMLOutput
43   | OptIgnoreSmallTimes Float
44   | OptDeviations
45   | OptNoDeviations
46   | OptTitle String
47   | OptColumns String
48   | OptRows String
49   | OptHelp
50   deriving Eq
51
52 usageHeader :: String
53 usageHeader = "usage: nofib-analyse [OPTION...] <logfile1> <logfile2> ..."
54
55 usage :: String
56 usage = usageInfo usageHeader argInfo
57
58 argInfo :: [ OptDescr CLIFlags ]
59 argInfo = 
60   [ Option ['?'] ["help"]    (NoArg OptHelp)        
61         "Display this message"
62   , Option ['a'] ["ascii"]   (NoArg OptASCIIOutput) 
63         "Produce ASCII output (default)"
64   , Option ['h'] ["html"]    (NoArg OptHTMLOutput)  
65         "Produce HTML output"
66   , Option ['i'] ["ignore"]  (ReqArg (OptIgnoreSmallTimes . read) "secs")
67         "Ignore runtimes smaller than <secs>"
68   , Option ['d'] ["deviations"] (NoArg OptDeviations)
69         "Display deviations (default)"
70   , Option ['l'] ["latex"]    (NoArg OptLaTeXOutput)  
71         "Produce LaTeX output"
72   , Option [] ["columns"] (ReqArg OptColumns "COLUMNS")
73         "Specify columns for summary table (comma separates)"
74   , Option [] ["rows"] (ReqArg OptRows "ROWS")
75         "Specify rows for summary table (comma separates)"
76   , Option ['n'] ["nodeviations"] (NoArg OptNoDeviations)
77         "Hide deviations"
78   , Option ['t'] ["title"] (ReqArg OptTitle "title")
79         "Specify report title"
80   ]
81