How to use the yappi.get_clock_type function in yappi

To help you get started, we’ve selected a few yappi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sumerc / yappi / tests / test_functionality.py View on Github external
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)
github Tribler / tribler / Tribler / community / anontunnel / Main.py View on Github external
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")
github Tribler / tribler / Tribler / Main / tribler_profiler.py View on Github external
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