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

Function test_backtrace

imperative/python/test/unit/utils/test_profiler.py:105–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103
104
105def test_backtrace():
106 bts = []
107 cur_frame = sys._getframe(0)
108 start_lineno = cur_frame.f_lineno
109 cur_frame.f_trace = lambda *_: 1
110
111 def gen():
112 for i in range(10):
113 bts.append(_mge_backtrace())
114 yield i
115
116 ge = gen()
117 next(ge)
118 next(ge)
119
120 def func():
121 return next(ge)
122
123 func()
124 bt_lines = []
125 for bt in bts:
126 lines = []
127 for path in bt.split("\n")[-3:-1]:
128 lines.append(int(path.split(",")[1].split()[1]))
129 bt_lines.append([i - start_lineno for i in lines])
130 # test if backtrace line numbers are correct
131 assert cur_frame.f_trace(0, 0, 0) == 1
132 assert bt_lines == [[9, 5], [10, 5], [13, 5]]
133 cache_id = []
134
135 def get_cache_id():
136 cache_id.append(_get_frame_cache_id())
137
138 threads = [threading.Thread(target=get_cache_id) for i in range(10)]
139 for t in threads:
140 t.start()
141 t.join()
142 assert len(set(cache_id)) == 10

Callers

nothing calls this directly

Calls 6

nextFunction · 0.85
joinMethod · 0.80
genFunction · 0.70
funcFunction · 0.70
appendMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected