How to use the yappi.set_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
t.start()
        t.join()
        yappi.get_func_stats().sort("name", "asc").save(
            "tests/ystats1-%s.ys" % (sys.version)
        )
        yappi.stop()
        yappi.clear_stats()
        yappi.start(builtins=False)
        t = threading.Thread(target=a)
        t.start()
        t.join()
        yappi.get_func_stats().save("tests/ystats2-%s.ys" % ((sys.version)))
        yappi.stop()
        self.assertRaises(_yappi.error, yappi.set_clock_type, "wall")
        yappi.clear_stats()
        yappi.set_clock_type("wall")
        yappi.start()
        t = threading.Thread(target=a)
        t.start()
        t.join()
        yappi.get_func_stats().save("tests/ystats3-%s.ys" % (sys.version))
        self.assertRaises(
            yappi.YappiError,
            yappi.YFuncStats().add("tests/ystats1-%s.ys" % (sys.version)).add,
            "tests/ystats3-%s.ys" % (sys.version)
        )
        stats = yappi.YFuncStats(
            [
                "tests/ystats1-%s.ys" % (sys.version),
                "tests/ystats2-%s.ys" % (sys.version)
            ]
        ).sort("name")
github sumerc / yappi / tests / test_functionality.py View on Github external
def test_filter_callback(self):

        def a():
            time.sleep(0.1)

        def b():
            a()

        def c():
            pass

        def d():
            pass

        yappi.set_clock_type("wall")
        yappi.start(builtins=True)
        a()
        b()
        c()
        d()
        stats = yappi.get_func_stats(
            filter_callback=lambda x: yappi.func_matches(x, [a, b])
        )
        #stats.print_all()
        r1 = '''
        tests/test_functionality.py:98 a      2      0.000000  0.200350  0.100175
        tests/test_functionality.py:101 b     1      0.000000  0.120000  0.100197
        '''
        self.assert_traces_almost_equal(r1, stats)
        self.assertEqual(len(stats), 2)
        stats = yappi.get_func_stats(
github sumerc / yappi / tests / test_functionality.py View on Github external
def test_singlethread_profiling(self):
        yappi.set_clock_type('wall')

        def a():
            time.sleep(0.2)

        class Worker1(threading.Thread):

            def a(self):
                time.sleep(0.3)

            def run(self):
                self.a()

        yappi.start(profile_threads=False)

        c = Worker1()
        c.start()
github sumerc / yappi / tests / utils.py View on Github external
def setUp(self):
        # reset everything back to default
        yappi.stop()
        yappi.clear_stats()
        yappi.set_clock_type('cpu')  # reset to default clock type
        yappi.set_context_id_callback(None)
        yappi.set_context_name_callback(None)
        yappi.set_tag_callback(None)
github abenassi / xlseries / tests / profiling.py View on Github external
def single_analysis_with_yappi(ini, end=None):
    """Perform profiling analysis for each test case, separately.

    Args:
        ini (int): First test case number analyzed.
        end (int): Last test case number analyzed.
        config (Config): Configuration object for PyCallGraph.
    """
    import yappi
    end = end or ini

    for num in xrange(ini, end + 1):

        print "Running test case number", num, "in a single analysis."
        yappi.set_clock_type('cpu')
        yappi.start(builtins=True)

        _run_test_case(num)

        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save('yappi.callgrind', type='callgrind')
github sumerc / yappi / tests / manual / _test_tag_cbk_performance.py View on Github external
async def main():
    start = time.time()
    yappi.set_clock_type("wall")
    yappi.start()  # If you don't start yappi, stats.empty() will always be true
    client = AsyncClient(app=app, )
    async with client:
        tasks = [
            client.get("http://www.example.org/")
            for _ in range(int(sys.argv[1]))
        ]
        resps = await asyncio.gather(*tasks)
        for resp in resps:
            print(f"Request ID: {resp.json()[0]}")
            print(f"Actual timing: {resp.json()[1]* 1000:>8.3f}")
            print(f"Server Timing: {resp.headers.get('server-timing')}")
            print("-----")
    end = time.time()
    print(f"TOTAL:{end-start:>8.3f}")
github mitmproxy / mitmproxy / test / helper_tools / benchtool.py View on Github external
def main(profiler, clock_type, concurrency):

    outfile = "callgrind.mitmdump-{}-c{}".format(clock_type, concurrency)
    a = ApacheBenchThread(concurrency)
    a.start()

    if profiler == "yappi":
        yappi.set_clock_type(clock_type)
        yappi.start(addons=True)

    print("Start mitmdump...")
    mitmdump(["-k", "-q", "-S", "1024example"])
    print("mitmdump stopped.")

    print("Save profile information...")
    if profiler == "yappi":
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(outfile, type='callgrind')
    print("Done.")
github wolfmanstout / dragonfly-commands / _repeat.py View on Github external
def start_wall_profiling():
    yappi.set_clock_type("wall")
    yappi.start()
github oVirt / vdsm / lib / vdsm / profiling / cpu.py View on Github external
def start(self):
        # Lazy import so we do not effect runtime environment if profiling is
        # not used.
        global yappi
        import yappi  # pylint: disable=import-error

        # yappi start semantics are a bit too liberal, returning success if
        # yappi is already started, happily having two different code paths
        # that thinks they own the single process profiler.
        if yappi.is_running():
            raise UsageError('CPU profiler is already running')

        logging.info("Starting CPU profiling")
        yappi.set_clock_type(self.clock)
        yappi.start(builtins=self.builtins, profile_threads=self.threads)