當前位置: 首頁>>代碼示例>>Python>>正文


Python pyinstrument.Profiler方法代碼示例

本文整理匯總了Python中pyinstrument.Profiler方法的典型用法代碼示例。如果您正苦於以下問題:Python pyinstrument.Profiler方法的具體用法?Python pyinstrument.Profiler怎麽用?Python pyinstrument.Profiler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyinstrument的用法示例。


在下文中一共展示了pyinstrument.Profiler方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def main():
    p = pyinstrument.Profiler()
    p.start()
    t_lz4 = timeit.timeit(lambda: StoryData.decode(StoryData(
        random_content(), version=StoryData.VERSION_LZ4).encode()), number=10000)
    print(t_lz4)
    p.stop()
    html = p.output_html()
    with open('benchmark_story_data_lz4.html', 'w') as f:
        f.write(html)

    p = pyinstrument.Profiler()
    p.start()
    t_gzip = timeit.timeit(lambda: StoryData.decode(StoryData(
        random_content(), version=StoryData.VERSION_GZIP).encode()), number=10000)
    print(t_gzip)
    p.stop()
    html = p.output_html()
    with open('benchmark_story_data_gzip.html', 'w') as f:
        f.write(html) 
開發者ID:anyant,項目名稱:rssant,代碼行數:22,代碼來源:benchmark_story_data.py

示例2: __call__

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def __call__(self, request: HttpRequest):
        response = self._render_profiler_record(request)
        if response:
            return response
        profiler = None
        try:
            profiler = Profiler()
            profiler.start()
            response = self.get_response(request)
        finally:
            if profiler is not None:
                profiler.stop()
                print(profiler.output_text(unicode=True, color=True))
                link = self._output_html(request, profiler)
                print(f'* Profiler HTML: {link}\n')
        return response 
開發者ID:anyant,項目名稱:rssant,代碼行數:18,代碼來源:profiler.py

示例3: execute_test_code

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def execute_test_code(xml_string, profiler):
    """
    The test code to be executed. If a profiler is defined it is enabled
    just before the test code is executed and disabled just after the
    code is executed.
    """
    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.enable()
        elif isinstance(profiler, Profiler):
            profiler.start()

    # The code to be tested
    tt = _tupletree.xml_to_tupletree_sax(xml_string, "TestData")

    parse_cim(tt)

    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.disable()
        elif isinstance(profiler, Profiler):
            profiler.stop() 
開發者ID:pywbem,項目名稱:pywbem,代碼行數:24,代碼來源:run_response_performance.py

示例4: execute_pyinstrument_tests

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def execute_pyinstrument_tests(self):
        """Execute the parse test for all of the input parameters in args.
        Since this profiler has no enable or disable concept the profiler
        must be enabled for the complete test and the results output
        At the end of the test, the profiler results are printed
        """
        table_rows = []
        profiler = Profiler()

        table_rows = self.execute_raw_tests(profiler)

        _uprint(None, profiler.output_text(unicode=True, color=True))
        if self.logfile:
            _uprint(self.logfile, profiler.output_text(unicode=True,
                                                       color=True))
        return table_rows 
開發者ID:pywbem,項目名稱:pywbem,代碼行數:18,代碼來源:run_response_performance.py

示例5: main

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def main(args):
    """
    Run local training.
    :param args: Dict[str, Any]
    :return:
    """
    args, log_id_dir, initial_step, logger = Init.main(MODE, args)
    R.save_extern_classes(log_id_dir)

    container = Local(args, logger, log_id_dir, initial_step)

    if args.profile:
        try:
            from pyinstrument import Profiler
        except:
            raise ImportError("You must install pyinstrument to use profiling.")
        container.nb_step = 10e3
        profiler = Profiler()
        profiler.start()

    try:
        container.run()
    finally:
        if args.profile:
            profiler.stop()
            print(profiler.output_text(unicode=True, color=True))
        container.close()

    if args.eval:
        from adept.scripts.evaluate import main

        eval_args = {
            "log_id_dir": log_id_dir,
            "gpu_id": 0,
            "nb_episode": 30,
        }
        if args.custom_network:
            eval_args["custom_network"] = args.custom_network
        main(eval_args) 
開發者ID:heronsystems,項目名稱:adeptRL,代碼行數:41,代碼來源:local.py

示例6: start_profiler

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def start_profiler():
    import pyinstrument
    profiler = pyinstrument.Profiler()
    profiler.start()
    return profiler 
開發者ID:team-ocean,項目名稱:veros,代碼行數:7,代碼來源:__init__.py

示例7: process_request

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def process_request(self, request):
        profile_dir = getattr(settings, 'PYINSTRUMENT_PROFILE_DIR', None)
        use_signal = getattr(settings, 'PYINSTRUMENT_USE_SIGNAL', True)

        if getattr(settings, 'PYINSTRUMENT_URL_ARGUMENT', 'profile') in request.GET or profile_dir:
            profiler = Profiler(use_signal=use_signal)
            try:
                profiler.start()
                request.profiler = profiler
            except NotMainThreadError:
                raise NotMainThreadError(not_main_thread_message) 
開發者ID:lrq3000,項目名稱:pyFileFixity,代碼行數:13,代碼來源:middleware.py

示例8: profile_django_context

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def profile_django_context(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        profiler = None
        if CONFIG.profiler_enable:
            profiler = Profiler()
            profiler.start()
        try:
            return f(*args, **kwargs)
        finally:
            if profiler is not None:
                profiler.stop()
                print(profiler.output_text(unicode=True, color=True))
    return wrapper 
開發者ID:anyant,項目名稱:rssant,代碼行數:16,代碼來源:actor_helper.py

示例9: _output_html

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def _output_html(self, request: HttpRequest, profiler: Profiler):
        html = profiler.output_html()
        t = int(time.time() * 1000)
        key = '{}-{}-{}'.format(t, request.method, request.path)
        _PROFILER_RECORDS[key] = html
        while len(_PROFILER_RECORDS) > 20:
            _PROFILER_RECORDS.popitem(False)
        port = request.META['SERVER_PORT']
        link = f'http://localhost:{port}/__profiler__/{key}'
        return link 
開發者ID:anyant,項目名稱:rssant,代碼行數:12,代碼來源:profiler.py

示例10: __enter__

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def __enter__(self):
        if self.profile:
            self.profiler = profiler = Profiler()
            profiler.start() 
開發者ID:anyant,項目名稱:rssant,代碼行數:6,代碼來源:cli.py

示例11: profile_if_necessary

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def profile_if_necessary(profiler_name, file_path):
    if profiler_name == 'pyinstrument':
        profiler = pyinstrument.Profiler(use_signal=False)
        profiler.start()

    try:
        yield
    finally:
        if profiler_name == 'pyinstrument':
            profiler.stop()
            profiler.save(filename=os.path.join(file_path, 'launch-task.trace')) 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:13,代碼來源:local.py

示例12: from_pyinstrument_trace

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def from_pyinstrument_trace(file_ref):
        import pyinstrument
        profiler = pyinstrument.Profiler()
        profiler.add(file_ref)

        root_frame = profiler.root_frame()

        def visit_frame(frame):
            code_pos = frame.code_position_short
            if code_pos is None:
                code_pos = ''

            index = code_pos.find('site-packages')
            if index > 0:
                code_pos = code_pos[index + (len('site-packages') + 1):]

            measurement = Measurement(
                '{function} {code_pos}'.format(
                    function=frame.function or '',
                    code_pos=code_pos
                ),
                self_time=datetime.timedelta(seconds=frame.self_time)
            )

            for child_frame in frame.children:
                measurement.add_child(visit_frame(child_frame))

            return measurement

        return visit_frame(root_frame) 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:32,代碼來源:measure.py

示例13: profile

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def profile(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        profiler = Profiler()
        profiler.start()
        r = func(*args, **kwargs)
        profiler.stop()
        print profiler.output_text(color=True)
        return r
    return wrapper 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:12,代碼來源:debug.py

示例14: attach_pyinstrument_profiler

# 需要導入模塊: import pyinstrument [as 別名]
# 或者: from pyinstrument import Profiler [as 別名]
def attach_pyinstrument_profiler():
    """Run the pyinstrument profiler in the background and dump its output to
    stdout when the process receives SIGTRAP. In general, you probably want to
    use the facilities in inbox.util.profiling instead."""
    profiler = Profiler()
    profiler.start()

    def handle_signal(signum, frame):
        print profiler.output_text(color=True)
        # Work around an arguable bug in pyinstrument in which output gets
        # frozen after the first call to profiler.output_text()
        delattr(profiler, '_root_frame')

    signal.signal(signal.SIGTRAP, handle_signal) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:16,代碼來源:debug.py


注:本文中的pyinstrument.Profiler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。