绝对包含文件无法正常工作。
作者: HernandoR创建于 2025年3月17日更新于 2025年5月9日
标签need repro
我做了一个自定义装饰器如下:
from viztracer import trace_and_save as _trace_and_save
def trace_and_save(func=None):
if os.environ.get("TRACER", None) is None:
return func
project_root = rootutils.autosetup()
include_files=None
# include_files = list(map(str, project_root.glob("src/**/*.py")))
include_files =["src/"]
# BUG: stops working when using absolute path
include_files=[os.path.abspath(f) for f in include_files if not f.startswith("/")]
output_dir = os.path.join(project_root, "output/profiles", func.__module__)
if not Path(output_dir).exists():
Path(output_dir).mkdir(parents=True)
# return decorator with trace_and_save(output_dir=output_dir, include_files=include_files)
return _trace_and_save(
func,
output_dir=output_dir,
include_files=include_files,
tracer_entries=2_000_000,
)
## 行为:
1. 如果只传递相对路径, viztracer 记录了 56092 条记录,
2. 如果只传递绝对路径, viztracer 记录了 2 条记录, 即没有记录任何内容
## 预期行为:
如果只传递绝对路径, viztracer 记录的记录数与相对路径调用时相同。
## 调试
在两次实验中, 都将路径传递给 https://GitHub.com/gaogaotiantian/viztracer/blob/86775df01cb9b4ce57a8bf79b1598e806427949b/src/viztracer/viztracer.py#L71-L74
根据我的理解, 这行是将绝对路径添加到包含文件中。这意味着它应该等于仅传递绝对路径。
我无法进一步调试, 因为我找不到 `self.include_files` 被使用的地方。内容来源: gaogaotiantian/viztracer