Repository navigation
fix: load OOM traces that omit addr during snapshot import #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,9 +87,10 @@ def from_dict(cls, trace_dict: dict, _raw_frames: bool = False): | |
| _validate_raw_frames(frame_dicts) | ||
| trace_entry = cls( | ||
| action=trace_dict["action"], | ||
| addr=int(trace_dict["addr"]), | ||
| size=int(trace_dict["size"]), | ||
| stream=int(trace_dict["stream"]), | ||
| addr=int(trace_dict.get("addr", -1)), | ||
| size=int(trace_dict.get("size", 0)), | ||
| stream=int(trace_dict.get("stream", 0)), | ||
| device_free=int(trace_dict.get("device_free", -1)), | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
本身不算错(补上了之前完全没解析的缺口),但如果后续要做 OOM 分析,值得单独开 issue 跟踪落库 + |
||
| _origin=trace_dict, | ||
| frames=[] if _raw_frames else [Frame.from_dict(frame) for frame in frame_dicts], | ||
| _raw_frames=frame_dicts if _raw_frames else None, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| "free_requested": 5, | ||
| "free_completed": 6, | ||
| "workspace_snapshot": 7, | ||
| "oom": 8, | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 映射表仍缺
建议在本 PR 顺手补一个值;或者更好的做法是给未命中 |
||
| } | ||
|
|
||
| BLOCK_STATE_VALUE_MAP = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,21 @@ def test_from_dict_without_frames(self): | |
| self.assertEqual(trace.size, 2048) | ||
| self.assertEqual(len(trace.frames), 0) | ||
|
|
||
| def test_from_dict_loads_oom_without_addr_or_stream(self): | ||
| trace = TraceEntry.from_dict( | ||
| {"action": "oom", "size": 1024, "device_free": 2048, "frames": []} | ||
| ) | ||
| self.assertEqual(trace.action, "oom") | ||
| self.assertEqual(trace.addr, -1) | ||
| self.assertEqual(trace.size, 1024) | ||
| self.assertEqual(trace.stream, 0) | ||
| self.assertEqual(trace.device_free, 2048) | ||
| self.assertEqual(trace.frames, []) | ||
|
|
||
| def test_from_dict_requires_action(self): | ||
| with self.assertRaises(KeyError): | ||
| TraceEntry.from_dict({"size": 1024, "frames": []}) | ||
|
|
||
| def test_get_callstack(self): | ||
| trace = TraceEntry.from_dict( | ||
| { | ||
|
|
@@ -395,7 +410,6 @@ def test_from_dict(self): | |
| self.assertEqual(snapshot.total_activated, 2048) | ||
| self.assertEqual(snapshot.trace_entries[0].idx, 0) | ||
| self.assertEqual(snapshot.trace_entries[1].idx, 1) | ||
|
|
||
| self.assertTrue( | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:这里删掉了一个与本 PR 无关的空行,建议还原以保持 diff 干净。 |
||
| all( | ||
| isinstance(frame, Frame) | ||
|
|
@@ -404,6 +418,21 @@ def test_from_dict(self): | |
| ) | ||
| ) | ||
|
|
||
| def test_from_dict_loads_oom_trace_without_addr(self): | ||
| snapshot = DeviceSnapshot.from_dict( | ||
| { | ||
| "segments": [], | ||
| "device_traces": [ | ||
| [{"action": "oom", "size": 1024, "device_free": 2048, "frames": []}] | ||
| ], | ||
| }, | ||
| 0, | ||
| ) | ||
| self.assertEqual(len(snapshot.trace_entries), 1) | ||
| self.assertEqual(snapshot.trace_entries[0].action, "oom") | ||
| self.assertEqual(snapshot.trace_entries[0].addr, -1) | ||
| self.assertEqual(snapshot.trace_entries[0].device_free, 2048) | ||
|
|
||
| def test_find_overlapping_segment_returns_idx_and_matches_containing_segment(self): | ||
| snapshot = DeviceSnapshot() | ||
| snapshot.segments = [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size的默认值放宽得过头了。addr/stream缺失是 OOM 的已知特征,放宽合理;但size对所有 action 都是必需字段——OOM 事件里它恰恰是最关键的信息(请求了多少字节却失败了)。改成.get("size", 0)之后,一条畸形的alloc(漏了size)会静默变成 0 字节而不再抛KeyError,掩盖数据损坏。建议只对 OOM 放宽,或至少保留
size为必需键: