Skip to content
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

absolute include file not working. #574

Open
HernandoR opened this issue Mar 17, 2025 · 3 comments
Open

absolute include file not working. #574

HernandoR opened this issue Mar 17, 2025 · 3 comments

Comments

@HernandoR
Copy link
Contributor

HernandoR commented Mar 17, 2025

I made a custom decorator as follows:

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,
    )

behaviour:

  1. If we pass the relative path only, the viztracer recorded 56092 entries,
  2. If we pass the absolute path only, the viztracer recorded 2 entries, AKA nothing

expected behaviour:

If we pass the absolute path only, the viztracer records 56092 entries align with relative path calling.

debugs

In both experiments, the path was passed to

if include_files is None:
self.include_files = include_files
else:
self.include_files = include_files[:] + [os.path.abspath(f) for f in include_files if not f.startswith("/")]

As to my understanding, this line is to appending abs path to the included files. Which means it should be equal to pass only the abs path.

I could not dig in more, since I didn't find where the self.include_files was used

@gaogaotiantian
Copy link
Owner

It's not equivalent. If you pass in relative path, it's going to be relative path + absolute path. If you pass absolute path, it'll be absolute path only. Normally the code.co_filename of a code object should be abs path so I guess it depends on which code you are tracing. If the code.co_filename of your function is somehow relative then it probably doesn't work (I thought this was always abs path since 3.9).

However, I actually do not suggest using include_files, there are plenty of issues with that option, the major one was performance - it hurts performance if it does not rule out a lot of entries.

@HernandoR
Copy link
Contributor Author

HernandoR commented Mar 19, 2025

I'm tracking the whole throughput, so there would be tons of entries if I did not provide the include_files. To minimize the impact on the production, I wrapped the decorator as above ( I edited the issue to provide highlights and import). In the production environments, there would not be a TRACER environment so it won't hurt anything, and I don't have to remove all the tracing codes.

I debug the code (notice that the decorator here is customized)

@trace_and_save
def main():
    pass

The main function here has code.co_name: '/home/lz/Codes/occ_seg_interpolation/.venv/lib/python3.10/site-packages/viztracer/decorator.py'. and the others have '/home/lz/Codes/occ_seg_interpolation/src/utils/util.py' it kinda explains why it was not picked by absolute path, but did not explain why relative path works.

@gaogaotiantian
Copy link
Owner

Sorry you'll have to give me a minimum reproducible example. Without some code to run, I can't really tell what's happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants