Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_clock(self):
yappi.set_clock_type('cpu')
self.assertEqual('cpu', yappi.get_clock_type())
clock_info = yappi.get_clock_info()
self.assertTrue('api' in clock_info)
self.assertTrue('resolution' in clock_info)
yappi.set_clock_type('wall')
self.assertEqual('wall', yappi.get_clock_type())
t0 = yappi.get_clock_time()
time.sleep(0.1)
duration = yappi.get_clock_time() - t0
self.assertTrue(0.05 < duration < 0.2)
socks5_port = None
if args.yappi == 'wall':
profile = "wall"
elif args.yappi == 'cpu':
profile = "cpu"
else:
profile = None
if args.socks5:
socks5_port = int(args.socks5)
if profile:
yappi.set_clock_type(profile)
yappi.start(builtins=True)
print "Profiling using %s time" % yappi.get_clock_type()['type']
crawl = True if args.crawl else False
proxy_settings = ProxySettings()
# Set extend strategy
if args.extend_strategy == 'delegate':
logger.error("EXTEND STRATEGY DELEGATE: We delegate the selection of "
"hops to the rest of the circuit")
proxy_settings.extend_strategy = TrustThyNeighbour
elif args.extend_strategy == 'subset':
logger.error("SUBSET STRATEGY DELEGATE: We delegate the selection of "
"hops to the rest of the circuit")
proxy_settings.extend_strategy = NeighbourSubset
else:
raise ValueError("extend_strategy must be either random or delegate")
def run_tribler_with_yappi(run_function=None):
t1 = time()
# Start yappi
yappi.start()
# Do we have a custom run function?
if run_function:
run_function()
else: # Default to the normal run function
run()
# Stop yappi and get the results
yappi.stop()
logger.info("YAPPI: %s tribler has run for %s seconds", yappi.get_clock_type(), time() - t1)
yappi_stats = yappi.get_func_stats()
yappi_stats.sort("tsub")
# If a yappi output dir is specified, save the output in callgrind format.
if "YAPPI_OUTPUT_DIR" in os.environ:
output_dir = os.environ["YAPPI_OUTPUT_DIR"]
fname = os.path.join(output_dir, 'yappi.callgrind')
yappi_stats.save(fname, type='callgrind')
# Log the 50 most time consuming functions.
count = 0
for func_stat in yappi_stats:
logger.info("YAPPI: %10dx %10.3fs %s", func_stat.ncall, func_stat.tsub, func_stat.name)
count += 1
if count >= 50:
break