summaryrefslogtreecommitdiff
path: root/utils/nofib-analyse/CmdLine.hs
blob: 8b606261fc1955d7d29c183520c58d2a59025657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-----------------------------------------------------------------------------
-- CmdLine.hs

-- (c) Simon Marlow 2005
-----------------------------------------------------------------------------

module CmdLine
    (
    flags, other_args, cmdline_errors,
    devs, nodevs, tooquick_threshold, reportTitle,
    CLIFlags(..), usage,
    )
    where

import System.Console.GetOpt
import System.Environment	( getArgs )
import System.IO.Unsafe		( unsafePerformIO )

-----------------------------------------------------------------------------
-- Command line arguments

args :: [String]
args = unsafePerformIO getArgs

flags :: [CLIFlags]
other_args :: [String]
cmdline_errors :: [String]
(flags, other_args, cmdline_errors) = getOpt Permute argInfo args 

default_tooquick_threshold, tooquick_threshold :: Float
default_tooquick_threshold = 0.2 {- secs -}
tooquick_threshold
 = case [ i | OptIgnoreSmallTimes i <- flags ] of
	[] -> default_tooquick_threshold
	(i:_) -> i

devs, nodevs :: Bool
devs   = OptDeviations   `elem` flags
nodevs = OptNoDeviations `elem` flags

default_title, reportTitle :: String
default_title = "NoFib Results"
reportTitle = case [ t | OptTitle t <- flags ] of
        []    -> default_title
        (t:_) -> t

data CLIFlags
  = OptASCIIOutput
  | OptLaTeXOutput (Maybe String)
  | OptHTMLOutput
  | OptIgnoreSmallTimes Float
  | OptDeviations
  | OptNoDeviations
  | OptTitle String
  | OptColumns String
  | OptRows String
  | OptCSV String
  | OptNormalise String
  | OptHelp
  deriving Eq

usageHeader :: String
usageHeader = "usage: nofib-analyse [OPTION...] <logfile1> <logfile2> ..."

usage :: String
usage = usageInfo usageHeader argInfo

argInfo :: [ OptDescr CLIFlags ]
argInfo = 
  [ Option ['?'] ["help"]    (NoArg OptHelp)        
	"Display this message"
  , Option ['a'] ["ascii"]   (NoArg OptASCIIOutput) 
	"Produce ASCII output (default)"
  , Option ['h'] ["html"]    (NoArg OptHTMLOutput)  
	"Produce HTML output"
  , Option ['i'] ["ignore"]  (ReqArg (OptIgnoreSmallTimes . read) "secs")
	"Ignore runtimes smaller than <secs>"
  , Option ['d'] ["deviations"] (NoArg OptDeviations)
	"Display deviations (default)"
  , Option ['l'] ["latex"]    (OptArg OptLaTeXOutput "TABLE")
	"Produce LaTeX output"
  , Option [] ["columns"] (ReqArg OptColumns "COLUMNS")
	"Specify columns for summary table (comma separates)"
  , Option [] ["rows"] (ReqArg OptRows "ROWS")
	"Specify rows for summary table (comma separates)"
  , Option [] ["csv"] (ReqArg OptCSV "TABLE")
	"Output a single table in CSV format"
  , Option [] ["normalise"] (ReqArg OptNormalise "percent|ratio|none")
	"normalise to the baseline"
  , Option ['n'] ["nodeviations"] (NoArg OptNoDeviations)
	"Hide deviations"
  , Option ['t'] ["title"] (ReqArg OptTitle "title")
	"Specify report title"
  ]