当前位置: 首页>>代码示例>>Python>>正文


Python yappi.clear_stats函数代码示例

本文整理汇总了Python中yappi.clear_stats函数的典型用法代码示例。如果您正苦于以下问题:Python clear_stats函数的具体用法?Python clear_stats怎么用?Python clear_stats使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了clear_stats函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_profile_single_context

    def test_profile_single_context(self):
        
        def id_callback():
            return self.callback_count
        def a():
            pass

        self.callback_count = 1
        yappi.set_context_id_callback(id_callback)
        yappi.start(profile_threads=False)
        a() # context-id:1
        self.callback_count = 2
        a() # context-id:2
        stats = yappi.get_func_stats()
        fsa = utils.find_stat_by_name(stats, "a")
        self.assertEqual(fsa.ncall, 1)
        yappi.stop()
        yappi.clear_stats()
        
        self.callback_count = 1
        yappi.start() # profile_threads=True
        a() # context-id:1
        self.callback_count = 2
        a() # context-id:2
        stats = yappi.get_func_stats()
        fsa = utils.find_stat_by_name(stats, "a")
        self.assertEqual(fsa.ncall, 2)
开发者ID:sumerc,项目名称:yappi,代码行数:27,代码来源:test_hooks.py

示例2: test_merge_multithreaded_stats

 def test_merge_multithreaded_stats(self):
     import threading
     import _yappi
     timings = {"a_1":2, "b_1":1}
     _yappi._set_test_timings(timings)
     def a(): pass
     def b(): pass
     yappi.start()
     t = threading.Thread(target=a)
     t.start()
     t.join()
     t = threading.Thread(target=b)
     t.start()
     t.join()
     yappi.get_func_stats().save("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("ystats2.ys")
    
     stats = yappi.YFuncStats(["ystats1.ys", "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)
开发者ID:pombredanne,项目名称:yappi,代码行数:34,代码来源:test_functionality.py

示例3: test_merge_load_different_clock_types

 def test_merge_load_different_clock_types(self):
     import threading
     yappi.start(builtins=True)
     def a(): b()
     def b(): c()
     def c(): pass
     t = threading.Thread(target=a)
     t.start()
     t.join()
     yappi.get_func_stats().sort("name", "asc").save("ystats1.ys")
     yappi.stop()
     yappi.clear_stats()
     yappi.start(builtins=False)
     t = threading.Thread(target=a)
     t.start()
     t.join()
     yappi.get_func_stats().save("ystats2.ys")
     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("ystats3.ys")
     self.assertRaises(yappi.YappiError, yappi.YFuncStats().add("ystats1.ys").add, "ystats3.ys")
     stats = yappi.YFuncStats(["ystats1.ys", "ystats2.ys"]).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)
开发者ID:pombredanne,项目名称:yappi,代码行数:33,代码来源:test_functionality.py

示例4: setUp

 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)
开发者ID:smeder,项目名称:GreenletProfiler,代码行数:7,代码来源:utils.py

示例5: stop_profiler

    def stop_profiler(self):
        """
        Stop yappi and write the stats to the output directory.
        Return the path of the yappi statistics file.
        """
        if not self.profiler_running:
            raise RuntimeError("Profiler is not running")

        if not HAS_YAPPI:
            raise RuntimeError("Yappi cannot be found. Plase install the yappi library using your preferred package "
                               "manager and restart Tribler afterwards.")

        yappi.stop()

        yappi_stats = yappi.get_func_stats()
        yappi_stats.sort("tsub")

        log_dir = os.path.join(self.session.config.get_state_dir(), 'logs')
        file_path = os.path.join(log_dir, 'yappi_%s.stats' % self.profiler_start_time)
        # Make the log directory if it does not exist
        if not os.path.exists(log_dir):
            os.makedirs(log_dir)

        yappi_stats.save(file_path, type='callgrind')
        yappi.clear_stats()
        self.profiler_running = False
        return file_path
开发者ID:Tribler,项目名称:tribler,代码行数:27,代码来源:resource_monitor.py

示例6: _stop_profiling

def _stop_profiling(filename, format):
    logging.debug("Stopping CPU profiling")
    with _lock:
        if yappi.is_running():
            yappi.stop()
            stats = yappi.get_func_stats()
            stats.save(filename, format)
            yappi.clear_stats()
开发者ID:andrewlukoshko,项目名称:vdsm,代码行数:8,代码来源:cpu.py

示例7: stop

    def stop(self):
        if not yappi.is_running():
            raise UsageError("CPU profiler is not running")

        logging.info("Stopping CPU profiling")
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(self.filename, self.format)
        yappi.clear_stats()
开发者ID:EdDev,项目名称:vdsm,代码行数:9,代码来源:cpu.py

示例8: test_clear_stats_while_running

 def test_clear_stats_while_running(self):
     def a():            
         pass
     yappi.start()
     a()
     yappi.clear_stats()
     a()
     stats = yappi.get_func_stats()
     fsa = utils.find_stat_by_name(stats, 'a')
     self.assertEqual(fsa.ncall, 1)
开发者ID:pombredanne,项目名称:yappi,代码行数:10,代码来源:test_functionality.py

示例9: do_action

 def do_action(self):
     action = self.cleaned_data['action']
     if action == 'start':
         yappi.start()
     elif action == 'start_with_builtins':
         yappi.start(builtins=True)
     elif action == 'stop':
         yappi.stop()
     elif action == 'reset':
         yappi.clear_stats()
     return action
开发者ID:shtalinberg,项目名称:django-profiling-dashboard,代码行数:11,代码来源:forms.py

示例10: _stop_profiling

    def _stop_profiling(self):
        with lock:
            if not yappi.is_running():
                raise http.Error(http.BAD_REQUEST, "profile is not running")

            log.info("Stopping profiling, writing profile to %r",
                     self.config.profile.filename)
            yappi.stop()
            stats = yappi.get_func_stats()
            stats.save(self.config.profile.filename, type="pstat")
            yappi.clear_stats()
开发者ID:oVirt,项目名称:ovirt-imageio,代码行数:11,代码来源:profile.py

示例11: test_subsequent_profile

 def test_subsequent_profile(self):
     import threading
     WORKER_COUNT = 5
     def a(): pass
     def b(): pass
     def c(): pass
     
     _timings = {"a_1":3,"b_1":2,"c_1":1,}
     
     yappi.start()
     def g(): pass
     g()
     yappi.stop()
     yappi.clear_stats()
     _yappi._set_test_timings(_timings)
     yappi.start()
     
     _dummy = []
     for i in range(WORKER_COUNT):
         t = threading.Thread(target=a)
         t.start()
         t.join()
     for i in range(WORKER_COUNT):
         t = threading.Thread(target=b)
         t.start()
         _dummy.append(t)
         t.join()
     for i in range(WORKER_COUNT):
         t = threading.Thread(target=a)
         t.start()
         t.join()
     for i in range(WORKER_COUNT):
         t = threading.Thread(target=c)
         t.start()
         t.join()    
     yappi.stop()    
     yappi.start()
     def f():
         pass
     f() 
     stats = yappi.get_func_stats()
     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, 10)
     self.assertEqual(fsb.ncall, 5)
     self.assertEqual(fsc.ncall, 5)
     self.assertEqual(fsa.ttot, fsa.tsub, 30)
     self.assertEqual(fsb.ttot, fsb.tsub, 10)
     self.assertEqual(fsc.ttot, fsc.tsub, 5)
     
     # MACOSx optimizes by only creating one worker thread
     self.assertTrue(len(yappi.get_thread_stats()) >= 2) 
开发者ID:pombredanne,项目名称:yappi,代码行数:53,代码来源:test_functionality.py

示例12: profile_cpu_bound_program

def profile_cpu_bound_program():
    real_dog = DogStatsApi()
    real_dog.reporter = NullReporter()
    fake_dog = NullDogStatsApi()
    for type_, dog in [('real', real_dog), ('fake', fake_dog)]:
        print('\n\n\nTESTING %s\n\n' % type_)
        dog.start()
        program = CPUBoundProgram(dog)
        yappi.start()
        program.run()
        yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB, sort_order=yappi.SORTORDER_DESC)
        yappi.stop()
        yappi.clear_stats()
开发者ID:DataDog,项目名称:dogapi,代码行数:13,代码来源:test_stats_api_performance.py

示例13: test_no_stats_different_clock_type_load

 def test_no_stats_different_clock_type_load(self):
     def a(): pass
     yappi.start()
     a()
     yappi.stop()
     yappi.get_func_stats().save("ystats1.ys")
     yappi.clear_stats()
     yappi.set_clock_type("WALL")
     yappi.start()
     yappi.stop()
     stats = yappi.get_func_stats().add("ystats1.ys")
     fsa = utils.find_stat_by_name(stats, 'a')
     self.assertTrue(fsa is not None)
开发者ID:pombredanne,项目名称:yappi,代码行数:13,代码来源:test_functionality.py

示例14: test_run

    def test_run(self):

        def profiled():
            pass

        yappi.clear_stats()
        try:
            with yappi.run():
                profiled()
            stats = yappi.get_func_stats()
        finally:
            yappi.clear_stats()

        self.assertIsNotNone(utils.find_stat_by_name(stats, 'profiled'))
开发者ID:sumerc,项目名称:yappi,代码行数:14,代码来源:test_functionality.py

示例15: profile_yappi

def profile_yappi(label):
    import yappi

    timestamp = datetime.now()
    yappi.start()
    _start = time.time()

    try:
        yield
    finally:
        _elapsed = time.time() - _start
        func_stats = yappi.get_func_stats()
        file_prefix = '/tmp/profile-yappi-%s-%s' % (label, timestamp.isoformat('T'))
        with open(file_prefix + '-summary.txt', 'w') as f:
            func_stats.print_all(out=f, columns={0:("name",140), 1:("ncall", 8), 2:("tsub", 8), 3:("ttot", 8), 4:("tavg",8)})
        func_stats.save(file_prefix + '.kgrind', 'CALLGRIND')
        yappi.stop()
        yappi.clear_stats()
        profiling_results.append((label, _elapsed))
开发者ID:thorgate,项目名称:CodeClub,代码行数:19,代码来源:profiling.py


注:本文中的yappi.clear_stats函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。