-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Profiling: sys.settrace implementation. #4265
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
Conversation
|
This looks pretty neat (some commit message will need rewording and more explanation probably), and the example runs fine for the msvc port. I do get a |
|
I think this should depend on #3412 as a vehicle to make this (and many more) feature available in a standard way. |
|
Has unrelated commits:
|
You mean a standard way other than defining features in mpconfigport.h? Otherwise these are just orthogonal issues (or i'm missing some point here) |
|
Let's take sys.atexit() as an example. Not related to profiling per se. Should be in a separate commit, with its own config option, then test - everything as usual. Commit message should explain why that name was chosen, given that it's not compatible with CPython. And likely, submitted as a separate PR for quicker merging (and unloading this PR for noise-free review). |
I mean that one argument against adding more and more features was "this is not useful for intended [production] usage of MicroPython (fitting it where other stuff doesn't fit)" and "this can only lead to fragmentation". So, IMHO, before going to stuff more and more features, answers to those concerns should be given, and #3412 tries to do just that. |
|
Yeah I get that, it's the how I don't see. Like, practically, what does this entail? Just |
|
Sure, nothing magic: pfalcon/pycopy@1752b8a |
|
@malinah : Oh, and otherwise, this is a great feature of course, thanks for posting! |
|
@dpgeorge , You may want to review, and if correct, merge commits "tools/mpy-tools.py: Fix opcode size enumeration and constant definition." and "py/bc.c: Fix opcode size enumeration." ahead of anything else. Then setup suitable tests to avoid that in the future. |
|
@pfalcon I see we are working around the same area (bytecode, vm) - https://github.com/pfalcon/micropython/commits/pfalcon vs https://github.com/trezor/micropython/commits/malinah/profiling. We should sync to avoid redundant work. Where can I reach you? Cheers. |
c044114 to
7732fcd
Compare
|
Hi, I reworked the whole implementation and it should make more sense now. However, I have a problem building the uPy with MICROPY_PERSISTENT_CODE_SAVE enabled. I'm getting some errors in py/persistentcode.c that I'm currently ugly-patching (not in this PR) and I don't know how to fix them properly. Can you give me a feedback please? Cheers and thanks. |
pfalcon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From 1st look, the update spots about the same issues as the original patch had.
|
From a quick look: code itself looks sort of fine and operational, but it's a bit hard to provide constructive feedback on it because the commits look like work in progress built on top of work in progress. I'd suggest to rework this so it's close to it's final state:
|
|
@stinos While I agree with the comments above, it is possible to view squashed changes as one commit here: https://github.com/micropython/micropython/pull/4265/files |
|
@prusnak thanks but I'm aware of that already :) |
|
@malinah thanks a lot for posting this PR, it's a welcome feature for sure, useful for (at least) profiling, debugging, coverage testing. The commits here still need a fair bit of work to be in a state for merging. There are minor things like camel-case variable names and duplicated code (eg But more importantly, from a bigger picture point of view: ideally the commits would be made to add logically independent functionality. Eg first just add bare-bones Anyway, I'm not sure how you'd like to proceed because it will be a lot more work to make it a clean PR in this way. At the very least please remove unused code so there's less to review. I did test this PR on unix and stm32 (with minor changes to get it working on stm32) and it does work very well, and has a very faithful API the same as CPython. So well done there! On unix 64-bit the code size increase is around 11k. On stm32 it's around 8.5k. That's quite acceptable IMO. As for performance, I tested both these ports before and after enabling the profiling feature. Note that with profiling enabled it doesn't actually set For unix 64-bit: For PYBv1.0: Unix sees a loss of 20-40% performance. PYBv1.0 sees a 10-20% loss. They both agree that |
py/profiling.c
Outdated
| } | ||
|
|
||
| // OPCODE | ||
| if (false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A way to implement this would be to support setting frame.f_trace_opcodes=True, a feature added in CPython 3.7.
62a40d2 to
b9d1104
Compare
|
@malinah I see you force-pushed this PR. Please let me know when it's ready for another review. |
b9d1104 to
3d02ebb
Compare
a858696 to
0db9b68
Compare
e11cb83 to
e210bdf
Compare
- Introducing the feature into the vm.c and surrounding runtime. - Introducing the feature into the build system and configuration. - To enable the feature enable MICROPY_PY_SYS_SETTRACE in the mpconfigport.h in the unix port. Other ports are not supported right now.
- tests/misc: Added initial tests for `sys.settrace` feature. - tests/run-tests: register misc/trace_profilin.py as special testcase. - tests/cmdline/cmd_showbc.py had to be updated because of the changes in the compile.c regarding the `sys.settrace` specific line emitters.
e210bdf to
a403df7
Compare
|
@dpgeorge All comments worked in and rebased on the current master. |
|
Superseded by #5026 |
Clear out PIOs and State Machines on RP2040 soft reset
This is a working concept of profiling API related to issue #3864.
Please review this pull-request and comment especially on the overall integration into the Micropython.
So far the main concern of the profiler is runtime instruction tracing used to create detailed code coverage reports. To achieve this the analogue of sys.settrace was implemented and puts Micropython closer to feature a debugger #3009.
Building and Running
So far only the Unix port is concerned.
Enable profiling in
ports/unix/mpconfigport.hlike so:MICROPY_PERSISTENT_CODE_SAVEis required by theMICROPY_PY_SYS_TRACE.Python API
sys.settrace(tracefunc)As defined in original Python3 documentation sys.settrace(tracefunc). The Frame object and Code objects are only partially implemented.