基础模块¶
提供用于性能分析的相关基类&函数定义
-
moprofiler.base.
get_callargs
(func, *args, **kwargs)[源代码]¶ 找到层层装饰器下最里层的函数的 callargs
参数: 返回: 调用参数字典
返回类型:
-
moprofiler.base.
is_instance_or_subclass
(self_or_cls, super_cls)[源代码]¶ 判断对象或类是否继承了指定类
参数: - self_or_cls (object) – 对象或类
- super_cls (class) – 父类
返回: 判断结果
返回类型:
-
class
moprofiler.base.
ClassDecoratorBase
(_function=None, fake_method=True)[源代码]¶ 基类:
object
类装饰器初始化
参数: - _function (types.FunctionType or types.MethodType) – 被封装的对象,由解释器自动传入,不需关心
- fake_method (bool) – 是否将被装饰后的类装饰器伪装成方法,默认为是。 注意,伪装后仍然可以正常调用类装饰器中额外定义的对象属性, 此参数仅用于装饰类方法时使用,装饰函数时无效
-
func
¶ 被封装函数的 getter 方法
-
class
moprofiler.base.
ProfilerClassDecorator
(_function=None, print_res=True, force_new_profiler=False, profiler_args=None, profiler_kwargs=None, **kwargs)[源代码]¶ 基类:
moprofiler.base.ClassDecoratorBase
分析器的类装饰器初始化
增加分析器相关的供外部使用的公共属性
参数: - _function (types.FunctionType or types.MethodType) – 被封装的对象,由解释器自动传入,不需关心
- print_res (bool) – 是否在被装饰对象退出后立刻打印分析结果,默认为
True
。 当需要将多次调用结果聚集后输出时,可设为False
,并通过调用被装饰函数/方法 (装饰后将被替换为ProfilerClassDecorator
)的print_stats()
方法进行结果输出 - force_new_profiler (bool) – 是否强制使用新的分析器,默认为
否
- profiler_args (tuple) – 分析器工厂的位置参数列表
- profiler_kwargs (dict) – 分析器工厂的关键字参数字典
-
profiler_factory
¶ 用于生产分析器的工厂
-
profiler
= None¶ 分析器实例对象