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

Function get_frameinfo_from_pyframe

imperative/python/src/backtrace.cpp:169–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169FrameInfoPtr get_frameinfo_from_pyframe(PyFrameObject* frame) {
170 auto* cache = FrameInfoCache::get_instance();
171 auto&& [cur_info, key] = FrameInfo::make(frame, cache);
172 auto rst = cur_info;
173 SmallVector<std::pair<PyFrameObject*, FrameInfoPtr>, 100> frames;
174 py::object cur_frame = py::reinterpret_borrow<py::object>((PyObject*)frame);
175 while (key == -1) {
176 if (((PyFrameObject*)cur_frame.ptr())->f_gen == NULL)
177 frames.push_back({(PyFrameObject*)cur_frame.ptr(), cur_info});
178 auto prev_frame = py::getattr(py::handle(cur_frame), "f_back");
179 if (prev_frame.is_none())
180 break;
181 auto&& [prev_info, prev_key] =
182 FrameInfo::make((PyFrameObject*)prev_frame.ptr(), cache);
183 cur_info->prev_frame = prev_info;
184 cur_info = prev_info, key = prev_key;
185 cur_frame = std::move(prev_frame);
186 }
187 if (cache != nullptr)
188 cache->update_cache(key, frames);
189 return rst;
190}
191
192bool set_python_backtrace_enabled(bool enabled) {
193 std::swap(enable_py_bt, enabled);

Callers 3

get_current_frameinfoFunction · 0.85
record_py_backtraceFunction · 0.85
get_py_backtraceFunction · 0.85

Calls 4

update_cacheMethod · 0.80
makeFunction · 0.50
ptrMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected