def testRun_CheckStats( self, json_mock, unused_urlopen_mock, # pylint: disable=no-self-use unused_compress_mock, run_mock): run_mock.return_value = { 'h': { 'result': 'foobar', 'total': 200 }, 'p': { 'result': 'foobar', 'total': 500 } } func = lambda x, y: x + y runner.run(func, 'hp', args=('foo', 'bar')) json_mock.assert_called_with({ 'h': { 'total': 200 }, 'p': { 'total': 500 } })
def main(): global args parser = argparse.ArgumentParser(description=__description__) parser.add_argument('-t', '--steps', type=int, help='Number of timesteps to simulate.', default=NUM_TIME_STEPS) parser.add_argument('-a', '--agents', type=int, help='Number of agents to create.', default=NUM_AGENTS) parser.add_argument('-b', '--actions', type=int, help='Number of actions per agent.', default=NUM_ACTIONS_PER_AGENT) parser.add_argument('-fa', '--features-agent', type=int, help='Number of features associated with each agent.', default=NUM_FEATURES_PER_AGENT) parser.add_argument('-fb', '--features-action', type=int, help='Number of features used by each action.', default=NUM_FEATURES_ACTION) parser.add_argument('-ph', '--horizon', type=int, help='Planning horizon.', default=HORIZON) parser.add_argument('-s', '--seed', type=int, help='The seed used to initialized the random number generator.', default=SEED) parser.add_argument('-p', '--parallel', help='Whether to use multiple processes to run the simulation.', action='store_true') parser.add_argument('--profiler', help='Whether to run the performance profiler vprof. Note: ' 'run run \'vprof -r\' in command line first to create a listener.', action='store_true') args = parser.parse_args() if args.profiler: # NOTE: run 'vprof -r' in command line first to create a listener # runner.run(run, 'cmhp', host='localhost', port=8000) runner.run(run, 'c', host='localhost', port=8000) else: run()
def testRequest(self): runner.run(self._func, 'm', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen('http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertEqual(stats['m']['objectName'], '_func (function)') self.assertEqual(stats['m']['totalEvents'], 2)
def profiler_handler(uri): """Profiler handler.""" # HTTP method should be GET. if uri == "main": runner.run(show_guestbook, "cmhp") # In this case HTTP method should be POST singe add_entry uses POST elif uri == "add": runner.run(add_entry, "cmhp") return flask.redirect("/")
def profiler_handler(uri): """Profiler handler.""" # HTTP method should be GET. if uri == 'main': runner.run(show_guestbook, 'cmhp') # In this case HTTP method should be POST singe add_entry uses POST elif uri == 'add': runner.run(add_entry, 'cmhp') return flask.redirect('/')
def testRequest(self): runner.run(self._func, "c", ("foo", "bar"), host=_HOST, port=_PORT) response = urllib.request.urlopen("http://%s:%s/profile" % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode("utf-8")) self.assertEqual(stats["c"]["objectName"], "_func (function)") self.assertTrue("sampleInterval" in stats["c"]) self.assertTrue("runTime" in stats["c"]) self.assertTrue("totalSamples" in stats["c"])
def testRequest(self): runner.run( self._func, 'm', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen( 'http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertEqual(stats['m']['objectName'], '_func (function)') self.assertEqual(stats['m']['totalEvents'], 2)
def testRequest(self): runner.run(self._func, 'c', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen('http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertEqual(stats['c']['objectName'], '_func (function)') self.assertEqual(stats['c']['sampleInterval'], flame_graph._SAMPLE_INTERVAL) self.assertTrue('runTime' in stats['c']) self.assertTrue('callStats' in stats['c']) self.assertTrue('totalSamples' in stats['c'])
def testRequest(self): runner.run(self._func, 'p', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen('http://%s:%s/profile' % (_HOST, _PORT)) response_data = gzip.decompress(response.read()) stats = json.loads(response_data.decode('utf-8')) curr_filename = inspect.getabsfile(inspect.currentframe()) self.assertEqual(stats['p']['objectName'], '_func @ %s (function)' % curr_filename) self.assertTrue(len(stats['p']['callStats']) > 0) self.assertTrue(stats['p']['totalTime'] > 0) self.assertTrue(stats['p']['primitiveCalls'] > 0) self.assertTrue(stats['p']['totalCalls'] > 0)
def testRequest(self): runner.run(self._func, 'h', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen('http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertEqual(len(stats), 1) self.assertTrue('function _func' in stats['h'][0]['objectName']) self.assertDictEqual(stats['h'][0]['heatmap'], {'96': 1, '97': 1}) self.assertListEqual(stats['h'][0]['srcCode'], [['line', 95, ' def _func(foo, bar):\n'], ['line', 96, u' baz = foo + bar\n'], ['line', 97, u' return baz\n']])
def testRequest(self): runner.run( self._func, 'c', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen( 'http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertEqual(stats['c']['objectName'], '_func (function)') self.assertEqual( stats['c']['sampleInterval'], flame_graph._SAMPLE_INTERVAL) self.assertTrue('runTime' in stats['c']) self.assertTrue('callStats' in stats['c']) self.assertTrue('totalSamples' in stats['c'])
def testRequest(self): runner.run(self._func, 'm', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen('http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) curr_filename = inspect.getabsfile(inspect.currentframe()) self.assertEqual(stats['m']['objectName'], '_func @ %s (function)' % curr_filename) self.assertEqual(stats['m']['totalEvents'], 2) self.assertEqual(stats['m']['codeEvents'][0][0], 1) self.assertEqual(stats['m']['codeEvents'][0][1], 91) self.assertEqual(stats['m']['codeEvents'][0][3], '_func') self.assertEqual(stats['m']['codeEvents'][1][0], 2) self.assertEqual(stats['m']['codeEvents'][1][1], 92) self.assertEqual(stats['m']['codeEvents'][1][3], '_func')
def testRequest(self): runner.run( self._func, 'h', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen( 'http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertEqual(len(stats), 1) self.assertTrue('function _func' in stats['h'][0]['objectName']) self.assertDictEqual( stats['h'][0]['heatmap'], {'91': 1, '92': 1}) self.assertListEqual( stats['h'][0]['srcCode'], [['line', 90, ' def _func(foo, bar):\n'], ['line', 91, u' baz = foo + bar\n'], ['line', 92, u' return baz\n']])
def testRequest(self): runner.run(self._func, "h", ("foo", "bar"), host=_HOST, port=_PORT) response = urllib.request.urlopen("http://%s:%s/profile" % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode("utf-8")) self.assertEqual(len(stats), 1) self.assertTrue("function _func" in stats["h"][0]["objectName"]) self.assertDictEqual(stats["h"][0]["heatmap"], {"96": 1, "97": 1}) self.assertListEqual( stats["h"][0]["srcCode"], [ ["line", 95, " def _func(foo, bar):\n"], ["line", 96, u" baz = foo + bar\n"], ["line", 97, u" return baz\n"], ], )
def testRequest(self): runner.run(self._func, 'h', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen('http://%s:%s/profile' % (_HOST, _PORT)) response_data = stats_server.decompress_data(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertTrue(stats['h']['runTime'] > 0) heatmaps = stats['h']['heatmaps'] self.assertEqual(len(heatmaps), 1) self.assertTrue('function _func' in heatmaps[0]['name']) self.assertDictEqual(heatmaps[0]['executionCount'], { '102': 1, '103': 1 }) self.assertListEqual(heatmaps[0]['srcCode'], [['line', 101, ' def _func(foo, bar):\n'], ['line', 102, u' baz = foo + bar\n'], ['line', 103, u' return baz\n']])
def testRun_CheckResult(self, unused_urlopen_mock, unused_compress_mock, run_mock): run_mock.return_value = { 'h': {'result': 'foobar', 'total': 200}, 'p': {'result': 'foobar', 'total': 500} } func = lambda x, y: x + y result = runner.run(func, 'hp', args=('foo', 'bar')) self.assertEqual(result, 'foobar')
def testRequest(self): runner.run( self._func, 'h', ('foo', 'bar'), host=_HOST, port=_PORT) response = urllib.request.urlopen( 'http://%s:%s/profile' % (_HOST, _PORT)) response_data = gzip.decompress(response.read()) stats = json.loads(response_data.decode('utf-8')) self.assertTrue(stats['h']['runTime'] > 0) heatmaps = stats['h']['heatmaps'] curr_filename = inspect.getabsfile(inspect.currentframe()) self.assertEqual(stats['h']['objectName'], '_func @ %s (function)' % curr_filename) self.assertEqual(len(heatmaps), 1) self.assertDictEqual( heatmaps[0]['executionCount'], {'101': 1, '102': 1}) self.assertListEqual( heatmaps[0]['srcCode'], [['line', 100, u' def _func(foo, bar):\n'], ['line', 101, u' baz = foo + bar\n'], ['line', 102, u' return baz\n']])
back_a_few_days = (datetime.datetime.now() - datetime.timedelta(days=3)) start_date = back_a_few_days.strftime(ae_consts.COMMON_DATE_FORMAT) ticker = 'SPY' s3_bucket = 'perftests' s3_key = (f'{ticker}_{start_date}') algo_config = (f'./cfg/default_algo.json') history_loc = (f's3://{s3_bucket}/{s3_key}') log.info(f'building {ticker} trade history ' f'start_date={start_date} ' f'config={algo_config} ' f'history_loc={history_loc}') runner = algo_runner.AlgoRunner(ticker=ticker, start_date=start_date, history_loc=history_loc, algo_config=algo_config, verbose_algo=False, verbose_processor=False, verbose_indicators=False) runner.start() # end of start if __name__ == '__main__': perf_runner.run(start, 'cm', args=(), host='0.0.0.0', port=3434)
#warm-up input_transformed = _transform_grid(ref_size_xyz, transfos, min_ref_grid, max_ref_grid) _interpolate(U + 1., input_transformed + 1., min_ref_grid, max_ref_grid, interp_method, padding_mode) tic = time.time() input_transformed = _transform_grid(ref_size_xyz, transfos, min_ref_grid, max_ref_grid) input_transformed = _interpolate(U, input_transformed, min_ref_grid, max_ref_grid, interp_method, padding_mode) output = tf.reshape(input_transformed, tf.stack([tf.shape(U)[0], *ref_size, tf.shape(U)[-1]])) from vprof import runner tmp = _transform_grid(ref_size_xyz, transfos, min_ref_grid, max_ref_grid) runner.run(_interpolate, 'cmhp', args=(U, tmp, min_ref_grid, max_ref_grid, interp_method, padding_mode), host='localhost', port=8001) ElpsTime = time.time() - tic print("*** Total %1.3f s ***"%(ElpsTime)) def save_array_to_sitk(data, name, data_dir): ref_grid = create_ref_grid() sitk_img = utils.get_sitk_from_numpy(data, ref_grid) sitk.WriteImage(sitk_img, os.path.join(data_dir, name + ".nii.gz")) return sitk_img tic=[] ElpsTime=[] for vol in range(output.shape[0]):
from vprof import runner import time from mongoke import main # def hard(): # time.sleep(2) # return 'ok' # def lesshard(): # time.sleep(1) # def main(a, b): # print(hard()) # lesshard() runner.run(main, 'cmhp', args=('confs/testing.yaml', True), host='localhost', port=8000)
from vprof import runner import time from src.main import up # def hard(): # time.sleep(2) # return 'ok' # def lesshard(): # time.sleep(1) # def main(a, b): # print(hard()) # lesshard() runner.run(up, 'cmhp', host='localhost', port=8000)