examiner.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:py_gpumap 作者: ipachev 项目源码 文件源码
def trace(self, frame, event, arg):
        name = frame.f_code.co_name
        is_method = "self" in frame.f_locals
        curr_obj = None
        if is_method:
            curr_obj = frame.f_locals["self"]
            cls = type(curr_obj)
        else:
            cls = None

        if event == "call":
            if (cls, name) not in self.prev_call:
                if is_method:
                    func = getattr(curr_obj, name)
                else:
                    try:
                        func = frame.f_globals[name]
                    except:
                        # hack to make spark work
                        func = self.top_level_func

                if not isinstance(func, BuiltinFunctionType):
                    arg_names = list(frame.f_code.co_varnames[:frame.f_code.co_argcount])
                    types = []
                    for var_name in arg_names:
                        var = frame.f_locals[var_name]
                        if isinstance(var, list):
                            types.append((list, type(var[0])))
                        else:
                            types.append(type(var))
                    print("found {}".format(func))
                    call = FunctionCall(cls, name, arg_names, types, func)
                    self.results.append(call)
                    self.prev_call[(cls, name)] = call
                else:
                    print("found builtin function {}".format(func))
        elif event == "return":
            if (cls, name) in self.prev_call:
                prev_call = self.prev_call[(cls, name)]
                if not prev_call.return_type:
                    prev_call.set_return_type(type(arg))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号