@@ -23,6 +23,8 @@ import Data.Maybe
2323import qualified Data.Set as Set
2424import Data.Text (Text)
2525import qualified Data.Text as T
26+import Data.Time (getCurrentTime)
27+import Data.Time.Format (formatTime, defaultTimeLocale)
2628import Data.Traversable (for)
2729import Debug.Trace (trace)
2830import Distribution.Compiler (CompilerFlavor(..))
@@ -100,6 +102,7 @@ run profiled = withProjectRoot "." $ \root -> do
100102 case profiled of
101103 True -> do
102104 putLog Debug "Using profiled build of project."
105+ time <- liftIO $ formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S" <$> getCurrentTime
103106 let exeSource =
104107 unlines $
105108 [ "module Main where"
@@ -111,14 +114,18 @@ run profiled = withProjectRoot "." $ \root -> do
111114 , "main = do"
112115 , " forkIO $ fix $ \\rec -> do"
113116 -- TODO: make this filename customizable
114− , " writeProfilingData \"ob-run.rfprof\""
117+ , " writeProfilingData \"" <> profileBaseName <> ".rprof\""
115118 -- write every .1 seconds.
116119 -- TODO: perhaps it should only write once at the end of ecah run
117120 , " threadDelay 10000"
118121 , " rec"
119122 , " " <> obRunExpr]
120− -- sane flags to enable by default, enable time profiling + closure heap profiling
121− rtsFlags = [ "+RTS", "-p", "-hc", "-RTS" ]
123+ -- Sane flags to enable by default, enable time profiling +
124+ -- closure heap profiling.
125+ rtsFlags = [ "+RTS", "-p", "-po" <> profileBaseName, "-hc", "-RTS" ]
126+ profileDirectory = root </> "profile"
127+ profileBaseName = profileDirectory </> time
128+ liftIO $ createDirectoryIfMissing False profileDirectory
122129 withSystemTempFile "ob-run-profiled.hs" $ \hsFname hsHandle -> withSystemTempFile "ob-run" $ \exeFname exeHandle -> do
123130 liftIO $ hPutStr hsHandle exeSource
124131 liftIO $ hFlush hsHandle