使用 cProfile 在 Python 中分析类的方法? [英] profiling a method of a class in Python using cProfile?

查看:50
本文介绍了使用 cProfile 在 Python 中分析类的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 cProfile 在 Python 中分析一个函数的方法.我尝试了以下方法:

I'd like to profile a method of a function in Python, using cProfile. I tried the following:

import cProfile as profile

# Inside the class method...
profile.run("self.myMethod()", "output_file")

但它不起作用.如何使用run"调用 self.method?

But it does not work. How can I call a self.method with "run"?

推荐答案

使用 profilehooks 装饰器

Use the profilehooks decorator

http://pypi.python.org/pypi/profilehooks

这篇关于使用 cProfile 在 Python 中分析类的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆