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

GH-126833: Dumps graphviz representation of executor graph. #126880

Merged
merged 13 commits into from
Dec 13, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Nov 15, 2024

Dumps out the executor graph in graphviz format.
I'm not sure where to the put the function, for now I've named it sys._dump_tracelets()

It definitely shouldn't be part of the public API.

@markshannon markshannon marked this pull request as ready for review December 5, 2024 12:21
Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some PEP 7 nits.

At risk of being pedantic, can the graph arrow be based on the direction of the branch taken? That is, when the branch is false it points left, and when true it goes right. This way we can tell the directionality of the branch without having to refer to the source code.

Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
@markshannon
Copy link
Member Author

can the graph arrow be based on the direction of the branch taken?

There is no direction to the arrow. It is up to the layout tool to decide where to put things.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks okay. I'm not super familiar with graphviz, but otherwise the logic makes sense. There's just two minor comment about the return value of find_line_number(). Other than that, the other comments are essentially just suggestions for comments clarifying what's going on. As a reader, it took me a minute to sort things out, since I don't really know much graphviz, and the suggested comments would have helped.

Also, what are the options for testing this?

Modules/_testinternalcapi.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Comment on lines +1766 to +1767
int line = find_line_number(code, executor);
fprintf(out, ": %d</td></tr>\n", line);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth handling the lno-not-found case?

For example:

Suggested change
int line = find_line_number(code, executor);
fprintf(out, ": %d</td></tr>\n", line);
int line = find_line_number(code, executor);
if (line > 0) { /* lno is 1-based. */
fprintf(out, ": %d", line);
}
fprintf(out, "</td></tr>\n", line);

That said, what you have is probably fine. I doubt it would be confusing.

@bedevere-app
Copy link

bedevere-app bot commented Dec 6, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment on lines +1788 to +1790
fprintf(out, " <tr><td port=\"i%d\" border=\"1\" >%s -- %" PRIu64 "</td></tr>\n", i, opname, inst->execution_count);
#else
fprintf(out, " <tr><td port=\"i%d\" border=\"1\" >%s</td></tr>\n", i, opname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add oparg and operand0 information as well? I've found it incredibly useful to debug polymorphism.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR.
Happy to do so in another PR, or review yours 🙂

@markshannon markshannon merged commit e62e1ca into python:main Dec 13, 2024
58 of 59 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@markshannon markshannon deleted the executor-dump branch January 10, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants