Update parallel processing api (#246)

* Remove m.workers, add run(procs=), update docs

* Update docs
This commit is contained in:
Mark Mossberg
2017-05-10 19:44:55 -04:00
committed by GitHub
parent e4a4916597
commit a10b7bae29
6 changed files with 13 additions and 25 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ def solve(state):
# play with these numbers!
m.verbosity = 0
m.workers = 1
procs = 1
m.run()
m.run(procs)
print m.context['solution']
+2 -2
View File
@@ -33,6 +33,6 @@ def solve(state):
# play with these numbers!
m.verbosity = 0
m.workers = 1
procs = 1
m.run()
m.run(procs)
+1 -2
View File
@@ -17,13 +17,12 @@ if __name__ == '__main__':
sys.exit(2)
m = Manticore(sys.argv[1])
m.workers = 3
m.context['count'] = 0
@m.hook(None)
def explore(state):
m.context['count'] += 1
m.run()
m.run(procs=3)
print "Executed ", m.context['count'], " instructions."
@@ -58,5 +58,4 @@ def hook(state):
# We found the flag, no need to continue execution
m.terminate()
m.workers = 10
m.run()
m.run(procs=10)
+2 -5
View File
@@ -40,7 +40,7 @@ def parse_arguments():
parser.add_argument('--dumpafter', type=int, default=0, help='Dump state after every N instructions; 0 to disable')
parser.add_argument('--maxstorage', type=int, default=0, help='Storage use cap in megabytes.')
parser.add_argument('--maxstates', type=int, default=0, help='Maximun number of states to mantain at the same time')
parser.add_argument('--procs', type=int, default=1, help='Number of parallel workers to spawn')
parser.add_argument('--procs', type=int, default=1, help='Number of parallel processes to spawn')
parser.add_argument('--timeout', type=int, default=0, help='Timeout. Abort exploration aftr TIMEOUT seconds')
parser.add_argument('--replay', type=str, default=None,
help='The trace filename to replay')
@@ -95,9 +95,6 @@ def main():
if args.names is not None:
m.apply_model_hooks(args.names)
if args.procs:
m.workers = args.procs
if args.env:
for entry in args.env:
name, val = entry[0].split('=')
@@ -111,7 +108,7 @@ def main():
logger.info('Loading program: {}'.format(args.programs))
logger.info('Workspace: {}'.format(m.workspace))
m.run(args.timeout)
m.run(args.procs, args.timeout)
m.dump_stats()
+5 -12
View File
@@ -159,7 +159,6 @@ class Manticore(object):
# XXX(yan) '_args' will be removed soon; exists currently to ease porting
self._args = args
self._time_started = 0
self._num_processes = 1
self._begun_trace = False
self._assertions = {}
self._model_hooks = {}
@@ -371,15 +370,6 @@ class Manticore(object):
''' Make working directory '''
return tempfile.mkdtemp(prefix="mcore_", dir='./')
@property
def workers(self):
return self._num_processes
@workers.setter
def workers(self, n):
assert not self._running, "Can't set workers if Manticore is running."
self._num_processes = n
@property
def policy(self):
return self._policy
@@ -518,9 +508,12 @@ class Manticore(object):
self._assertions[pc] = ' '.join(line.split(' ')[1:])
def run(self, timeout=0):
def run(self, procs=1, timeout=0):
'''
Runs analysis.
:param int procs: Number of parallel worker processes
:param timeout: Analysis timeout, in seconds
'''
assert not self._running, "Manticore is already running."
args = self._args
@@ -560,7 +553,7 @@ class Manticore(object):
t = Timer(timeout, self.terminate)
t.start()
try:
self._start_workers(self._num_processes)
self._start_workers(procs)
self._join_workers()
finally: