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

python support #95

Merged
merged 15 commits into from
Jul 12, 2023
Merged

python support #95

merged 15 commits into from
Jul 12, 2023

Conversation

pelletier
Copy link
Contributor

@pelletier pelletier commented Jul 7, 2023

Draft changes to support stack walking and symbolization for Python guests to provide meaningful profiles for python scripts.

Limitations: only support CPython3.11 (testing against https://github.com/stealthrocket/timecraft/tree/main/python), which is built with debug symbols.

Refs #64

TODO

  • Detection of Python.
  • Detect and constraint version of Python.
  • Basic python stack walking.
  • Find the right functions to instrument (_PyEvalFramePushAndInit triggers twice).
  • Add module information.
  • Memory allocations.
  • Tests.
  • Update README.

Stretch


image

image

@pelletier pelletier added enhancement New feature or request python Issue related to Python labels Jul 7, 2023
@pelletier pelletier marked this pull request as ready for review July 11, 2023 21:39
@pelletier pelletier changed the title wip: python support python support Jul 11, 2023
@pelletier pelletier linked an issue Jul 11, 2023 that may be closed by this pull request
wzprof.go Show resolved Hide resolved
wzprof.go Outdated Show resolved Hide resolved
python.go Outdated Show resolved Hide resolved
python.go Outdated Show resolved Hide resolved
python.go Outdated Show resolved Hide resolved
@@ -36,20 +56,37 @@ type vmem interface {
func deref[T any](r vmem, p ptr) T {
Copy link
Contributor

@achille-roussel achille-roussel Jul 11, 2023

Choose a reason for hiding this comment

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

Could we add a stricter constraint to the type parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a constraint like:

type dereferenceable interface {
  ~ptr32 | ~ptr64 | // etc...
}

I imagine there are types that would not be valid to pass (e.g. things containing inner pointers), so the compiler could help us validate that if we are more strict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use deref on struct types. Is there a way to express a type constraint of structs only made of dereferenceable types?

otherwise the full type set is

type derefable interface {
	~int32 | ~int64 | ~uint32 | ~uint64 | ~byte | findfuncbucket | moduledata | functab | textsect | inlinedCall
}

@pelletier
Copy link
Contributor Author

I will put the stretch action items into separate GitHub issues to open them up for contributions.

@achille-roussel since deref was already in the code I don't think missing a type constraint for it is a blocker for this change. That said I'd love to learn how to add it, so let's continue the discussion in this thread and will open a new pull request when we figure out a good way forward.

@pelletier pelletier merged commit ba3fa22 into main Jul 12, 2023
@pelletier pelletier deleted the python branch July 12, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Issue related to Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbolization not working with python.wasm
3 participants