Sorry, something went wrong.
There was a problem hiding this comment.
I have no idea if that assembly code does what you say, but I've reviewed the rest.
Definitely an intriguing idea.
Sorry, something went wrong.
|
You can use preprocesor macros if you name the file Objects/asm_trampoline.S or .sx instead of Objects/asm_trampoline.s. The .sx form needs a makefile rule. |
Sorry, something went wrong.
|
You can use preprocesor macros if you name the file Objects/asm_trampoline.S or .sx instead of Objects/asm_trampoline.s. The .sx form needs a makefile rule. Hummm, not sure I follow, could you maybe show me an example of what we can achieve with this? |
Sorry, something went wrong.
|
You can have multiple implementations in the same file: .text
.globl _Py_trampoline_func_start
_Py_trampoline_func_start:
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
mov %rdi,%rax
mov %rsi,%rdi
mov %rdx,%rsi
mov %ecx,%edx
call *%rax
pop %rbp
ret
#endif // __x86_64__
#ifdef __aarch64__
TODO
#endif
.globl _Py_trampoline_func_end
_Py_trampoline_func_end:
|
Sorry, something went wrong.
|
Why did you add a Windows build file? How about we do not define _PyPerfTrampoline_Init unless HAVE_PERF_TRAMPOLINE is defined? |
Sorry, something went wrong.
|
Why did you add a Windows build file? How about we do not define _PyPerfTrampoline_Init unless HAVE_PERF_TRAMPOLINE is defined? Then we need to add more ifdef every place is used but that works as well for sure |
Sorry, something went wrong.
There was a problem hiding this comment.
Two thoughts have been running around in my mind:
(1) We've got the command line flag and sys API, but what about just enabling this system wide or at least task/job wide within a container? An environment variable that turns it on would make that easy without plumbing options through. PYTHONPERFSUPPORT=1 as another equivalent to -Xperf? That's usually done in initconfig.c alongside the -X processing I believe.
Second: multiprocessing spawn start method. If the -Xperf flag was passed to the parent process I assume the "spawn" method should also pass that to its children.
Sorry, something went wrong.
|
Two thoughts have been running around in my mind: (1) We've got the command line flag and sys API, but what about just enabling this system wide or at least task/job wide within a container? An environment variable that turns it on would make that easy without plumbing options through. PYTHONPERFSUPPORT=1 as another equivalent to -Xperf? That's usually done in initconfig.c alongside the -X processing I believe. Second: multiprocessing spawn start method. If the -Xperf flag was passed to the parent process I assume the "spawn" method should also pass that to its children. I think (1) makes sense and is indeed coherent with how we handle some of the other options like tracemalloc so I will add an environment variable alongside the -X option. Regarding (2) I am not that sure. We don't do this for the rest of the flags that we pass around and you can achieve the same with the environment variable if you want. In any case, as that would require some tests I would prefer to do that in a separate PR as this is already gigantic |
Sorry, something went wrong.
|
I implemented the environment variable and solved a bunch of conflicts. Please check it out when you have time. I also had to solve a bunch of conflicts. @gpshead if you are ok with the current status I would like us to land if everything looks good as the size of the PR is already attracting a bunch of merge conflicts in the build system, clinic and other files. |
Sorry, something went wrong.
|
Ah wait, I need to document the environment variable. Will push a commit for that soon. |
Sorry, something went wrong.
|
Ah wait, I need to document the environment variable. Will push a commit for that soon. Done 👍 |
Sorry, something went wrong.
|
@erlend-aasland has mentioned that he was a bunch of docs improvements that he will do in a separate PR. |
Sorry, something went wrong.
There was a problem hiding this comment.
My comments are easy to address things that don't need further review - minor edits or added note/todo comments to our future selves.
Agreed that the docs can use some polishing up but all the important bits are there to seed that future work, thanks for writing them!
Thanks for taking on adding this feature! I expect we'll see how a backport fares internally.
Sorry, something went wrong.
|
Damn, @miss-islington has landed the PR without waiting for the CI to build the last commit I pushed so I created #96433. |
Sorry, something went wrong.
|
Thanks, everyone for the fantastic reviews and for helping to get this feature ready ❤️ You all rock 🤘 |
Sorry, something went wrong.
|
@erlend-aasland You can make the doc improvement PR after #96433 lands. |
Sorry, something went wrong.
|
Thanks for all for pushing for better interoperability with perf(1). I highly appreciate this contribution. 🙏 |
Sorry, something went wrong.
|
Nice feature! There is a typo in sys.deactivate_stack_trampoline() docstring: "Dectivate the perf profiler trampoline": Deactivate. In the doc, python -m sysconfig | grep HAVE_PERF_TRAMPOLINE can be replaced with python -c "import sysconfig; print(bool(sysconfig.get_config_var('PY_HAVE_PERF_TRAMPOLINE')))" to not rely on the external grep command. At least, I suggest to add PY_ to fix the variable name: python -m sysconfig | grep PY_HAVE_PERF_TRAMPOLINE
The second command can be replaced with python -c "import sysconfig; print('no-omit-frame-pointer' in sysconfig.get_config_var('PY_CORE_CFLAGS'))". |
Sorry, something went wrong.
|
There is a typo in sys.deactivate_stack_trampoline() docstring: "Dectivate the perf profiler trampoline": Deactivate. [...] See #96445 :) |
Sorry, something went wrong.
|
Is it possible to port these changes, from python 3.12, without breaking to previous python versions, say 3.11, 3.10, 3.9? Why? |
Sorry, something went wrong.
|
Is it possible to port these changes, from python 3.12, without breaking to previous python versions, say 3.11, 3.10, 3.9? Is possible, but as these versions are only accepting security fixes or bugfixes we cannot backport new features. This means that if you want you can backport them yourself but you need to maintain a fork of the interpreter. |
Sorry, something went wrong.
Automerge-Triggered-By: GH:pablogsal