-
Notifications
You must be signed in to change notification settings - Fork 4
增加算子库性能分析去重轨迹 #43
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
base: main
Are you sure you want to change the base?
增加算子库性能分析去重轨迹 #43
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||
| import tempfile | ||||||||||||||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+5
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. |
||||||||||||||||||||||||||||||||||||||||||
| from unittest.mock import patch | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| from mcoplib.profiler import _trace_file_path | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| class ProfilerTracePathTest(unittest.TestCase): | ||||||||||||||||||||||||||||||||||||||||||
| @patch("mcoplib.profiler._timestamp") | ||||||||||||||||||||||||||||||||||||||||||
| def test_trace_file_path_is_unique(self, mock_timestamp): | ||||||||||||||||||||||||||||||||||||||||||
| mock_timestamp.side_effect = ["20260610T120000000001", "20260610T120000000002"] | ||||||||||||||||||||||||||||||||||||||||||
| with tempfile.TemporaryDirectory() as tmp_path: | ||||||||||||||||||||||||||||||||||||||||||
| first = _trace_file_path(tmp_path, "fused_mla", 0) | ||||||||||||||||||||||||||||||||||||||||||
| second = _trace_file_path(tmp_path, "fused_mla", 0) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| self.assertNotEqual(first, second) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertTrue(first.endswith(".json")) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(os.path.dirname(first), tmp_path) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+23
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. 在运行速度非常快的测试环境中,连续两次调用
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def test_trace_file_path_sanitizes_function_name(self): | ||||||||||||||||||||||||||||||||||||||||||
| with tempfile.TemporaryDirectory() as tmp_path: | ||||||||||||||||||||||||||||||||||||||||||
| path = _trace_file_path(tmp_path, "op/name with spaces", 1) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| filename = os.path.basename(path) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertTrue(filename.startswith("op_name_with_spaces_trace_rank_1_")) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertNotIn("/", filename) | ||||||||||||||||||||||||||||||||||||||||||
| self.assertNotIn(" ", filename) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def test_trace_file_path_truncates_long_function_name(self): | ||||||||||||||||||||||||||||||||||||||||||
| with tempfile.TemporaryDirectory() as tmp_path: | ||||||||||||||||||||||||||||||||||||||||||
| path = _trace_file_path(tmp_path, "x" * 300, 0) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| filename = os.path.basename(path) | ||||||||||||||||||||||||||||||||||||||||||
| prefix = filename.split("_trace_rank_", 1)[0] | ||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(len(prefix), 128) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||
| unittest.main() | ||||||||||||||||||||||||||||||||||||||||||
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.
在某些文件系统(如 ext4、NTFS 等)中,文件名长度限制为 255 个字符。如果
func_name非常长(例如在一些经过多层装饰或自动生成的函数中),生成的 trace 文件名可能会超出限制,从而导致OSError: [Errno 36] File name too long异常。建议对safe_name进行截断(例如限制在 128 个字符以内),以提高代码的健壮性。