def __init__(self): ''' Constructor ''' framenode = frame(time_step=200, instrument=True) framenode.attach_app(NodeSimulation(framenode)) frametest = frame(time_step=200, instrument=True) frametest.attach_app(NodeTestSimulation(frametest)) si.setup_instruments(frame.framelist) framenode.run_async() frametest.run_async() frame.loop()
def Controller(settings): """ Controller is the main entry point for driving the simulation. Arguments: settings -- nested dictionary with variables for configuring the connectors """ laysettings = LayoutSettings.LayoutSettings(settings) # laysettings = None # load the world infofile = settings["General"].get("WorldInfoFile", "info.js") logger.info('loading world data from %s', infofile) world = WorldInfo.WorldInfo.LoadFromFile(infofile) # world = None cnames = settings["General"].get("Connectors", ['sumo', 'opensim', 'social', 'stats']) instrument = settings["General"].get("Instrument", False) profiling = settings["General"].get("Profiling", False) store_type = settings["General"].get("Store", "SimpleStore") process = settings["General"].get("MultiProcessing", False) timer = settings["General"].get("Timer", None) autostart = settings["General"].get("AutoStart", False) if timer: seconds = 0 minutes = 0 hours = 0 if "Seconds" in timer: seconds = timer["Seconds"] if "Minutes" in timer: minutes = timer["Minutes"] if "Hours" in timer: hours = timer["Hours"] timer = datetime.timedelta(seconds=seconds, minutes=minutes, hours=hours) connectors = [] for cname in cnames: if cname not in _SimulationControllers: logger.warn('skipping unknown simulation connector; %s' % (cname)) continue cframe = frame(time_step=200, instrument=instrument, profiling=profiling) connector = _SimulationControllers[cname](settings, world, laysettings, cname, cframe) cframe.attach_app(connector) connectors.append(cframe) if instrument: si.setup_instruments(connectors) for f in connectors: f.run_async() frame.loop() print "closing down controller" sys.exit(0)
def run(self): testcases = [] args = self.args dir_path = self.dir_path if args.mode and args.mode in MODES: self.mode = args.mode else: if args.mode: print "# WARNING #: COULD NOT FIND MODE %s, DEFAULTING TO FULL" % args.mode self.mode = "FULL" if args.testfile: filename = os.path.basename(args.testfile.split('.')[0]) with open(args.testfile) as f: for line in f.readlines(): if not line.strip().startswith('#'): test_suite, test_name, instances, steps = line.split( ' ') module = importlib.import_module( "benchmark.%s.%s" % (test_suite, test_name)) testcases.append( TestCase(module, test_suite, test_name, int(instances), int(steps), args.testsims)) else: module = importlib.import_module("benchmark.%s" % args.test) testcases.append( TestCase(module, args.test.split('.')[0], args.test.split('.')[1], args.instances, args.steps, args.testsims)) filename = '' for testcase in testcases: # Replace for argument based choice #import benchmark.subset.subset_01 as test_case reload(testcase.test_module) bs = importlib.import_module("benchmark.benchmark") reload(bs) if hasattr(testcase.test_module, "TIMESTEP"): ts = testcase.test_module.TIMESTEP else: ts = args.timestep framebench = BenchmarkFrame(address=args.address, time_step=ts, instrument=True, profiling=True, wire_format="json") if self.mode: framebench.set_benchmode(self.mode) framebench.attach_app( bs.BenchmarkSimulation(framebench, testcase.instances, testcase.steps, testcase.test_module.initialize, testcase.test_module.update)) test_options = "%sn %si %ss" % (testcase.test_name, testcase.instances, testcase.steps) filenames = [ os.path.join( dir_path, "%s %s %s.csv" % (filename, "producer", test_options)) ] si.setup_instruments( [framebench], filenames=filenames, options={ 'instances': testcase.instances, 'steps': testcase.steps, 'type': '%s.%s' % (testcase.test_suite, testcase.test_name), 'sims': testcase.testsims, 'mode': self.mode }) # Synchronize to start together self.event.set() framebench.run() # Test is over self.event.set() time.sleep(15) self.event.set()
def __run(self): self.__clear() if not self.__app: raise NotImplementedError("App has not been attached") success = self.__register_app(self.__app) if success: try: if self.__profiling: try: from cProfile import Profile # @UnresolvedImport if not os.path.exists('stats'): os.mkdir('stats') self.__profile = Profile() self.__profile.enable() self.logger.info("starting profiler for %s", self.__appname) except: self.logger.error( "Could not import cProfile (not supported in Jython)." ) self.__profile = None self.__profiling = None self.__pull() self.__app.initialize() self.__push() while not self.__app.done: st_time = time.time() self.__pull() self.__app.update() self.__push() end_time = time.time() timespent = end_time - st_time self.__curstep += 1 self.__curtime = time.time() # time spent on execution loop if timespent < self.__time_step: time.sleep(float(self.__time_step - timespent)) else: self.logger.info("loop exceeded maximum time: %s ms", timespent) # Writes down total time spent in spacetime methods if self.__instrumented: si.record_instruments(timespent, self) # One last time, because _shutdown may delete objects from the store self.__pull() self._shutdown() self.__push() self.__unregister_app() except ConnectionError as cerr: self.logger.error("A connection error occurred: %s", cerr.message) except HTTPError as herr: self.logger.error( "A fatal error has occurred while communicating with the server: %s", herr.message) except: self.logger.exception("An unknown error occurred.") raise finally: if self.__profiling: self.__profile.disable() self.__profile.create_stats() self.__profile.dump_stats( os.path.join( 'stats', "%s_stats_%s.ps" % (self.__start_time, self.__appname))) else: self.logger.info("Could not register, exiting run loop...")
def run(self): testcases = [] args = self.args dir_path = self.dir_path if args.mode and args.mode in MODES: self.mode = args.mode else: if args.mode: print "# WARNING #: COULD NOT FIND MODE %s, DEFAULTING TO FULL" % args.mode self.mode = "FULL" if args.testfile: filename = os.path.basename(args.testfile.split('.')[0]) with open(args.testfile) as f: for line in f.readlines(): if not line.strip().startswith('#'): test_suite, test_name, instances, steps = line.split( ' ') module = importlib.import_module( "benchmark.%s.%s" % (test_suite, test_name)) testcases.append( TestCase(module, test_suite, test_name, int(instances), int(steps), args.testsims)) else: module = importlib.import_module("benchmark.%s" % args.test) testcases.append( TestCase(module, args.test.split('.')[0], args.test.split('.')[1], args.instances, args.steps, args.testsims)) filename = '' for testcase in testcases: reload(testcase.test_module) bt = importlib.import_module("benchmark.benchtest") reload(bt) if hasattr(testcase.test_module, "TIMESTEP"): ts = testcase.test_module.TIMESTEP else: ts = args.timestep test_options = "%sn %si %ss" % (testcase.test_name, testcase.instances, testcase.steps) frametest = BenchmarkFrame(address=args.address, time_step=ts, instrument=True, profiling=True, wire_format="json") if self.mode: frametest.set_benchmode(self.mode) frametest.attach_app( bt.BenchmarkTestSimulation( frametest, self.event, testcase.test_module.initialize_test, testcase.test_module.update_test)) filenames = [ os.path.join( dir_path, "%s %s %s.csv" % (filename, "consumer", test_options)) ] si.setup_instruments( [frametest], filenames=filenames, options={ 'instances': testcase.instances, 'steps': testcase.steps, 'type': '%s.%s' % (testcase.test_suite, testcase.test_name), 'sims': testcase.testsims, 'mode': self.mode }) # Wait for BenchSimulation to give the go self.event.wait() # Clear event, so update loop can wait for event to signal end self.event.clear() frametest.run() # Wait until benchmark is ready self.event.wait()