2017-05-05 51 views
1

我有一个基类@classmethod,它充当许多后代类中的大量方法的装饰器。Python cProfile - 装饰函数模糊配置文件可视化

class BaseClass(): 
    @classmethod 
    def some_decorator(cls, method): 
     @wraps(method) 
     def inner_method(self, *args, **kwargs): 
      # do stuff 
      return method(self, *args, **kwargs) 
     return inner_method 


class ChildClass(BaseClass): 
    @BaseClass.some_decorator 
    def some_child_method(self): 
     # do other stuff 
     return 

当我资料这个代码,并通过树视图看,我看到数以千计的电话,以some_decorator从数百个不同的地方。

然后我看到some_decorator回拨到数百个刚刚来自的地方。

这很烦人,我还没有找到解决办法,无论是通过更改代码或分析不同的方式。 (使用gprof2dot atm:How can you get the call tree with python profilers?

想法?

+0

由于装饰通常使每个装饰功能的关闭,无法更新(或作出的副本)的代码对象并更改文件和行信息以引用装饰函数上方的一行? –

回答

0

我不完全确定,但我认为snakevizrun snake run可视化工具将完成这项工作并显示正确的树。你有尝试过吗?