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

Create a tracing tool that can extract all of the OCP calls (with parameters) from buid123d code #750

Open
gumyr opened this issue Oct 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@gumyr
Copy link
Owner

gumyr commented Oct 24, 2024

To aid with debugging of OCCT issues, a tool that could extract the OCP calls (with parameter values) either statically or dynamically from build123d code would enable rapid creation of OCCT test cases.

Potentially something like this:

import sys
from build123d import Box

def trace_func(frame, event, arg):
    # We're only interested in call events
    if event != "call":
        return

    try:
        # Get the name of the module where the function is defined
        module_name = frame.f_globals.get("__name__")

        # Filter for build123d calls
        if module_name and module_name.startswith("build123d"):
            func_name = frame.f_code.co_name
            func_file = frame.f_code.co_filename
            func_line = frame.f_lineno
            print(f"Calling {func_name} in {module_name} at {func_file}:{func_line}")

            # Only print arguments that are safe to inspect
            try:
                print(f"Arguments: {frame.f_locals}")
            except AttributeError:
                print(f"Could not inspect locals for {func_name}")

    except AttributeError as e:
        print(f"AttributeError caught in {func_name}: {e}")

    return trace_func

# Set the trace
sys.settrace(trace_func)

# This will trace any build123d calls, including those calling into OCP
b = Box(1, 1, 1)

# Turn off tracing
sys.settrace(None)

where the filtering was improved to only include OCP calls.

@gumyr gumyr added the enhancement New feature or request label Oct 24, 2024
@gumyr gumyr added this to the Not Gating Release 1.0.0 milestone Oct 24, 2024
@jdegenstein
Copy link
Collaborator

This is a fantastic idea!

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

No branches or pull requests

2 participants