This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
options for multiple cores and ast caching
Summary: investigating efficiency options; currently multiple cores and using tmpfs don't seem to make much difference. ast caching saves 40-50% of run time for normal transformations (parsing-isn't-as- expensive / transformations-are-more-expensive than i thought). but i need to look more, and other ppl can too. defaults are still same behavior before this change. Test Plan: running and timing with different settings/environments Revert Plan: ok
- Loading branch information
Daniel Corson
committed
Nov 6, 2009
1 parent
16515bd
commit 873d651
Showing
6 changed files
with
136 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Options where | ||
|
||
import System.Console.GetOpt | ||
|
||
data Options = Options { | ||
optCacheAsts :: Bool, | ||
optNumCores :: Int, | ||
optFiles :: Bool, | ||
optDir :: Maybe String, | ||
optStartAtFile :: Maybe String} | ||
deriving Show | ||
|
||
defaultOptions :: Options | ||
defaultOptions = Options { | ||
optCacheAsts = True, | ||
optNumCores = 1, | ||
optFiles = False, | ||
optDir = Nothing, | ||
optStartAtFile = Nothing} | ||
|
||
options :: [OptDescr (Options -> Options)] | ||
options = [ | ||
Option "a" ["do-not-cache-asts"] | ||
(NoArg (\ opts -> opts {optCacheAsts = False})) | ||
"Do not cache binary dump of ASTs to disk (in .ast/).", | ||
Option "C" ["num-cores"] | ||
(ReqArg (\ n opts -> opts {optNumCores = read n}) "<n>") | ||
"Run n OS threads to optimize for n cores.", | ||
Option "d" ["dir"] | ||
(ReqArg (\ d opts -> opts {optDir = Just d}) "<dir>") | ||
"Top-level directory containing parsable\n\ | ||
\files of interest. Abstract syntax trees\n\ | ||
\will be cached in top-level .ast/\n\ | ||
\directory.", | ||
Option "f" ["files"] | ||
(NoArg (\ opts -> opts {optFiles = True})) | ||
"Pass a specific list of files to stdin\n\ | ||
\(newline-delimited).", | ||
Option "s" ["start-at-file"] | ||
(ReqArg (\ f opts -> opts {optStartAtFile = Just f}) "<file>") | ||
"Start at a particular file instead of the\n\ | ||
\\"beginning\" of the file list, looping back\n\ | ||
\around to get all files."] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module TaskPool where | ||
|
||
import Control.Exception | ||
import Control.Concurrent | ||
import Control.Monad | ||
import Prelude hiding (catch) | ||
|
||
type TaskChan a = Chan (Maybe (IO a)) | ||
|
||
worker :: TaskChan a -> Chan () -> IO () | ||
worker q doneChan = do | ||
taskMb <- readChan q | ||
case taskMb of | ||
Nothing -> writeChan doneChan () | ||
Just task -> errorOnExceptions task >> worker q doneChan | ||
|
||
errorOnExceptions :: IO a -> IO a | ||
errorOnExceptions task = catchAll task (error . show) | ||
|
||
catchAll :: IO a -> (SomeException -> IO a) -> IO a | ||
catchAll = catch | ||
|
||
taskPool :: Int -> [IO ()] -> IO () | ||
taskPool n tasks = do | ||
q <- newChan | ||
doneChan <- newChan | ||
tids <- replicateM n . forkIO $ worker q doneChan | ||
mapM_ (writeChan q) $ map Just tasks ++ replicate n Nothing | ||
replicateM_ n $ readChan doneChan | ||
|
This file was deleted.
Oops, something went wrong.