Skip to content

Commit ad8aab2

Browse files
committed
Render the graph from previous results
1 parent 218d83f commit ad8aab2

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

bench/Command.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Graph = String
4444
data ListOption = Benchs | Libs
4545
deriving (Show, Eq)
4646

47-
data Command = List ListOption | Run (Maybe Option) (Maybe [String]) Output (Maybe [Lib]) Bool Bool [(Graph,Int)]
47+
data Command = List ListOption | Run (Maybe Option) (Maybe [String]) Output (Maybe [Lib]) Bool Bool [(Graph,Int)] | Render String ChartOutput
4848
deriving (Show, Eq)
4949

5050
newtype CommandDataSize = RunD [(Graph,Int)]
@@ -81,14 +81,17 @@ saveOpt = strOption $ long "saveRawResults" <> short 'r' <> help "Write the raw
8181

8282
figFlag :: Parser (Maybe ChartOutput)
8383
#ifdef CHART
84-
figFlag = optional $ ChartOutput <$> outfile <*> outtype
85-
where
86-
outfile = strOption $ long "chartfile" <> short 'f' <> metavar "FILENAME" <> help "Output file WITHOUT extension" <> value "result"
87-
outtype = option auto $ long "chart" <> short 'c' <> metavar "OUTTYPE" <> help "Output type: Png or Svg"
84+
figFlag = optional figSFlag
8885
#else
8986
figFlag = pure Nothing
9087
#endif
9188

89+
figSFlag :: Parser ChartOutput
90+
figSFlag = ChartOutput <$> outfile <*> outtype
91+
where
92+
outfile = strOption $ long "chartfile" <> short 'f' <> metavar "FILENAME" <> help "Output file WITHOUT extension" <> value "result"
93+
outtype = option auto $ long "chart" <> short 'c' <> metavar "OUTTYPE" <> help "Output type: Png or Svg"
94+
9295
benchWithCreation :: Parser Bool
9396
benchWithCreation = flag False True $ long "bench-with-creation" <> short 'b' <> help "When set, will benchmark also the graph-creation function. See README (IGNORED FOR SPACE BENCHMARKS)"
9497

@@ -110,10 +113,17 @@ listOpt = flag' Benchs (long "benchs") <|> flag' Libs (long "libs")
110113
listCom :: Parser Command
111114
listCom = List <$> listOpt
112115

116+
renderGOpt :: Parser String
117+
renderGOpt = strArgument $ help "the file to load raw datas. Likely something exported with \" run -r \"" <> metavar "INFILE"
118+
119+
renderGCom :: Parser Command
120+
renderGCom = Render <$> renderGOpt <*> figSFlag
121+
113122
command' :: Parser Command
114123
command' = subparser
115124
( command "list" list
116125
<> command "run" run
126+
<> command "renderG" renderG
117127
)
118128
where
119129
run = info (runCom <**> helper)
@@ -124,6 +134,10 @@ command' = subparser
124134
( fullDesc
125135
<> progDesc "List benchmarks"
126136
<> header "Help" )
137+
renderG = info (renderGCom <**> helper)
138+
( fullDesc
139+
<> progDesc "Render data into a graph"
140+
<> header "Help" )
127141

128142
commandP :: ParserInfo Command
129143
commandP = info (semiOptional <**> helper)

bench/Space.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ useResults flg notDef todo = do
6969
putStrLn "Note: results are in bytes"
7070
results <- mapM mapped $ nubBy (liftExtract2 eqG) namedBenchs
7171
maybe (return ()) (\x -> writeFile x $ show results) $ saveToFile flg
72-
#ifdef CHART
73-
maybe (return ()) (\x -> mkChart "time" defaultGr show x $ Left $ catMaybes results) $ figOut flg
74-
#endif
75-
return ()
72+
case figOut flg of
73+
Nothing -> return ()
74+
(Just x) -> renderG x results
7675
where
7776
namedBenchs = concatMap sequence $ mapMaybe groupedToNamed todo
7877
mapped e = do
@@ -92,6 +91,13 @@ useResults flg notDef todo = do
9291
printAbstract "lighter" onlyLargeBenchs
9392
return $ Just (showGrouped $ snd e, onlyLargeBenchs)
9493

94+
renderG :: T.ChartOutput -> [Maybe (Named (T.Grouped [Named Double]))] -> IO ()
95+
#ifdef CHART
96+
renderG x results = mkChart "Space results" defaultGr show x $ Left $ catMaybes results
97+
#else
98+
renderG _ _ = return ()
99+
#endif
100+
95101
-- | Print a report from the lists of benchmarks
96102
printReport :: Int -- ^ The number of # to write, must start with 2
97103
-> StaOut -- ^ Output infos
@@ -169,6 +175,7 @@ main' :: Command -> IO ()
169175
main' (List opt) = case opt of
170176
Benchs -> putStr $ unlines $ benchsNames Nothing Nothing
171177
Libs -> putStr $ unlines $ nub $ map fst listOfSuites
178+
main' (Render fp opt) = readFile fp >>= renderG opt . read
172179
main' (Run only notonly flg libs _ _ _) = do
173180
printHeader defaultGr bN
174181
mainWeigh benchs (useResults flg (mapMaybe (\(n,Shadow s) -> either (\x -> Just (n,x)) (const Nothing) s ) filteredArr))
@@ -180,7 +187,7 @@ main' (Run only notonly flg libs _ _ _) = do
180187
filteredArr = filter (`isNameIn` bN) listOfSuites
181188

182189
benchsNames :: Maybe Option -> Maybe [String] -> [String]
183-
benchsNames only notonly = useNotOnly $ useOnly extractedNames
190+
benchsNames only notonly = nub $ useNotOnly $ useOnly extractedNames
184191
where
185192
extractedNames = "creation" : map (\(_,Shadow s) -> either fst name s) listOfSuites
186193
useOnly = case only of

bench/Time.hs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ genReport gr flg arr = do
8080
oth = head $ tail libNames
8181
in unwords ["\nComparing",comp,"to",oth,". It means that the displayed number will be k such that", comp,"= k *", oth ]
8282
results <- mapM mapped $ nubBy (liftExtract2 (==)) refinedarr
83-
maybe (return ()) (\x -> writeFile x $ show results) $ saveToFile flg
84-
#ifdef CHART
85-
maybe (return ()) (\x -> mkChart "Time results" gr secs x $ Right $ catMaybes results) $ figOut flg
86-
#endif
87-
return ()
83+
maybe (return ()) (\x -> writeFile x $ unlines [show gr,show results]) $ saveToFile flg
84+
case figOut flg of
85+
Nothing -> return ()
86+
(Just x) -> renderG gr x results
8887
where
8988
mapped e = do
9089
let bname = showBenchName $ snd e
@@ -111,6 +110,13 @@ genReport gr flg arr = do
111110
notquickComp = staOut flg /= QuickComparison
112111
(noimpl,refinedarr) = partitionEithers $ map stripOutEither arr
113112

113+
renderG :: [(String,Int)] -> ChartOutput -> [Maybe (Name, Grouped [(Name, (Double, Double))])] -> IO ()
114+
#ifdef CHART
115+
renderG gr x results = mkChart "Time results" gr secs x $ Right $ catMaybes results
116+
#else
117+
renderG _ _ _ = return ()
118+
#endif
119+
114120
toPrint :: Int -- ^ Will start with 2
115121
-> StaOut -> [Named Benchmark] -> Benchmark -> IO (Maybe (Grouped [Named Report]))
116122
toPrint lev flg arr breport = case lev of
@@ -202,6 +208,9 @@ main' opts
202208
List listOpt -> case listOpt of
203209
Benchs -> putStr $ unlines grNames
204210
Libs -> putStr $ unlines $ nub $ map fst listOfSuites ++ map fst (listOfCreation False [])
211+
Render filep dg -> do
212+
(gr,res) <- span (/='\n') <$> readFile filep
213+
renderG (read gr) dg (read res)
205214
Run opt nottodo' flg libs benchWithCreation dontBenchLittleOnes gr' -> do
206215
let modifyL = case libs of
207216
Nothing -> id

src/BenchGraph/Render/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515

1616
-- | The Bool is here to tell if we get it into the benchs
1717
-- The string is the type of graphs used
18-
data Grouped a = Simple Bool String a | Group [Grouped a] deriving (Show)
18+
data Grouped a = Simple Bool String a | Group [Grouped a] deriving (Show, Read)
1919

2020
instance Functor Grouped where
2121
fmap f (Simple b n a) = Simple b n $ f a

0 commit comments

Comments
 (0)