MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / traceback

Method traceback

imperative/python/src/backtrace.cpp:42–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40};
41
42std::string FrameInfo::traceback() {
43 FrameInfoPtr cur = shared_from_this();
44 std::list<FrameInfo*> frames;
45 while (cur) {
46 frames.push_front(cur.get());
47 cur = cur->prev_frame;
48 }
49 std::string logs;
50 for (auto&& f : frames) {
51 auto code = py::handle((PyObject*)f->code_obj);
52#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10
53 int lineno = PyCode_Addr2Line(f->code_obj, f->lineno);
54#else
55 int lineno = f->lineno;
56#endif
57 if (f->scope != "")
58 logs += "scope: <" + f->scope + ">\n";
59 py::object filename = py::getattr(code, "co_filename");
60 logs += py::str(filename);
61 logs += " , line ";
62 logs += std::to_string(lineno);
63 logs += ", in ";
64 logs += py::str(py::getattr(code, "co_name"));
65 logs += '\n';
66 }
67 return logs;
68}
69
70#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 6
71static Py_tss_t tss_key = Py_tss_NEEDS_INIT;

Callers 2

get_py_backtraceFunction · 0.80
py_tracebackMethod · 0.80

Calls 3

strFunction · 0.85
to_stringFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected