How to use the yappi.YFuncStats 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 / test / stats.py View on Github external
foo_child1()
yappi.stop()
fstats1 = yappi.get_func_stats()
fstats1.print_all()
fstats1.save("foo1")
yappi.clear_stats()

#yappi.set_clock_type("waLL")
yappi.start(builtins=True, profile_threads=False)
test1()
yappi.stop()
fstats2 = yappi.get_func_stats()
fstats2.save("foobar1")
yappi.clear_stats()

yfs = yappi.YFuncStats()
yfs.add("foo1").add('foobar1')
yfs.sort(sort_type="totaltime").print_all() 
yfs.save('callgrind.out', 'callgrind')
#foobar_stat = yfs.find_by_name('test1')
#yfs.debug_print()
for stat in yfs:
    fstatin1 = fstats1.find_by_full_name(stat.full_name)
    fstatin2 = fstats2.find_by_full_name(stat.full_name)
    
# test pstats
yfs.save('pstat.out', 'pstat')
import pstats
p = pstats.Stats('pstat.out')
p.strip_dirs().sort_stats("cumulative").print_stats()
from pyprof2calltree import convert
convert('pstat.out', 'callgrind.out2')
github sumerc / yappi / tests / test_functionality.py View on Github external
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")
        fsa = utils.find_stat_by_name(stats, "a")
        fsb = utils.find_stat_by_name(stats, "b")
        fsc = utils.find_stat_by_name(stats, "c")
        self.assertEqual(fsa.ncall, 2)
        self.assertEqual(fsa.ncall, fsb.ncall, fsc.ncall)
github sumerc / yappi / tests / test_functionality.py View on Github external
t.start()
        t.join()
        yappi.get_func_stats().save("tests/ystats1.ys")
        yappi.clear_stats()
        _yappi._set_test_timings(timings)
        self.assertEqual(len(yappi.get_func_stats()), 0)
        self.assertEqual(len(yappi.get_thread_stats()), 1)
        t = threading.Thread(target=a)
        t.start()
        t.join()

        self.assertEqual(_yappi._get_start_flags()["profile_builtins"], 0)
        self.assertEqual(_yappi._get_start_flags()["profile_multithread"], 1)
        yappi.get_func_stats().save("tests/ystats2.ys")

        stats = yappi.YFuncStats([
            "tests/ystats1.ys",
            "tests/ystats2.ys",
        ])
        fsa = utils.find_stat_by_name(stats, "a")
        fsb = utils.find_stat_by_name(stats, "b")
        self.assertEqual(fsa.ncall, 2)
        self.assertEqual(fsb.ncall, 1)
        self.assertEqual(fsa.tsub, fsa.ttot, 4)
        self.assertEqual(fsb.tsub, fsb.ttot, 1)
github sumerc / yappi / tests / merge_stats.py View on Github external
import yappi
stats = yappi.YFuncStats().add("a.1").add("a.2").add("a.3")
stats.sort("tsub", "desc").print_all()
stats.save("a.merged", "pstat")
#stats.save("merged.pstat", "pstat")
#stats.print_all()
#yappi.start()
#yappi.get_func_stats().print_all()
#yappi.get_thread_stats().print_all()
import pstats
#p = pstats.Stats("a.1").add("a.2", "a.3")
p = pstats.Stats("a.merged")
p.strip_dirs().sort_stats(-1).print_stats()
github sumerc / yappi / tests / test_functionality.py View on Github external
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")
        fsa = utils.find_stat_by_name(stats, "a")
        fsb = utils.find_stat_by_name(stats, "b")
        fsc = utils.find_stat_by_name(stats, "c")
        self.assertEqual(fsa.ncall, 2)
        self.assertEqual(fsa.ncall, fsb.ncall, fsc.ncall)
github sumerc / yappi / tests / manual / _test_tag_cbk_performance.py View on Github external
async def dispatch(self, request: Request, call_next) -> Response:
        ctx_id = id(request)
        yappi_request_id.set(ctx_id)
        assert yappi_request_id.get() == ctx_id
        response = await call_next(request)
        tracked_stats: Dict[str, YFuncStats] = {}

        for name, call_to_track in self.calls_to_track.items():
            tracked_stats[name] = yappi.get_func_stats(
                {
                    "name": call_to_track,
                    "tag": ctx_id
                }
            )
        server_timing = []
        for name, stats in tracked_stats.items():
            if not stats.empty():
                server_timing.append(f"{name}={(stats.pop().ttot * 1000):.3f}")
        if server_timing:
            response.headers["Server-Timing"] = ','.join(server_timing)
        #yappi.clear_stats()
        return response
github sumerc / yappi / tests / test_functionality.py View on Github external
os.remove(
                "tests/count_down_rec.profile"
            )  # remove the one from prev test, if available
        except:
            pass

        try:
            count_down_rec(4)
        except:
            pass
        try:
            count_down_rec(3)
        except:
            pass

        stats = yappi.YFuncStats("tests/count_down_rec.profile")
        fsrec = utils.find_stat_by_name(stats, 'count_down_rec')
        self.assertEqual(fsrec.ncall, 9)
        self.assertEqual(fsrec.nactualcall, 2)
github sumerc / yappi / performance_issue.py View on Github external
async def dispatch(self, request: Request, call_next) -> Response:
        ctx_id = id(request)
        yappi_request_id.set(ctx_id)
        assert yappi_request_id.get() == ctx_id
        response = await call_next(request)
        tracked_stats: Dict[str, YFuncStats] = {}

        for name, call_to_track in self.calls_to_track.items():
            tracked_stats[name] = yappi.get_func_stats(
                {
                    "name": call_to_track,
                    "tag": ctx_id
                }
            )
        server_timing = []
        for name, stats in tracked_stats.items():
            if not stats.empty():
                server_timing.append(f"{name}={(stats.pop().ttot * 1000):.3f}")
        if server_timing:
            response.headers["Server-Timing"] = ','.join(server_timing)
        #yappi.clear_stats()
        return response