Skip to content

py/mpprint.h: Add do_printf() macro. #13400

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

Closed
wants to merge 1 commit into from

Conversation

IhorNehrutsa
Copy link
Contributor

@IhorNehrutsa IhorNehrutsa commented Jan 10, 2024

Move do_printf() from drivers/esp-hosted/esp_hosted_hal.h to py/mpprint.h

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bd21820) 98.36% compared to head (4bbb70e) 98.36%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13400   +/-   ##
=======================================
  Coverage   98.36%   98.36%           
=======================================
  Files         159      159           
  Lines       21088    21088           
=======================================
  Hits        20743    20743           
  Misses        345      345           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -37,9 +39,6 @@

#if MICROPY_PY_BLUETOOTH

#define debug_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
#define error_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
Copy link
Contributor

Choose a reason for hiding this comment

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

These debug macros have lost the context of what file the log line is coming from.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See do_print_line()

@projectgus
Copy link
Contributor

projectgus commented Jan 15, 2024

@IhorNehrutsa Could you please explain the reasoning behind this feature?

My understanding is that the API in esp_hosted_hal.h is for integrating an arbitrary program with the ESP Hosted logging functions, so it's designed around ESP Hosted (and ESP-IDF ) logging conventions. Moving that ESP Hosted feature (and design) to become a core part of MicroPython is a big change.

Suggest a good place to start is these two questions from last time:

  • What problem does this solve?
  • Can you please walk step by step through a hypothetical example that explains how a developer would use this to find and debug some MicroPython behaviour? EDIT: an example that isn't possible with the current approach of uncommenting debug_printf in some files(s).

Plus two new questions:

  • Why choose this API for MicroPython logging?
  • What's the plan for documenting this API and ensuring it's adopted, if it's going to be a core part of MP?

Comment on lines 32 to 38
#ifndef ESP_HOSTED_DEBUG
#define ESP_HOSTED_DEBUG (0)
#endif

#if ESP_HOSTED_DEBUG
#define PROTOBUF_C_UNPACK_ERROR(...) error_printf(__VA_ARGS__);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

This block shouldn't be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

@iabdalkader
Copy link
Contributor

iabdalkader commented Jan 16, 2024

My understanding is that the API in esp_hosted_hal.h is for integrating an arbitrary program with the ESP Hosted logging functions, so it's designed around ESP Hosted (and ESP-IDF ) logging conventions

Those macros were actually just meant to be used internally by the esp-hosted driver as a debugging aid, they are also unrelated to ESP-IDF. It was just becoming hard to see useful error output from debugging, warnings etc.. and I wanted some colorful output :) It would be nice if they are standardized in MicroPython, and replace all internal debugging macros/helpers at some point, but they could probably use some work first. Re the context, it can be maintained by using __FILE__ and __LINE__ etc..

Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Jan 16, 2024
@dpgeorge
Copy link
Member

Thanks for the contribution, but we don't need all this additional complexity in MicroPython. I know it's not adding any code size, but it adds lines to the source files and that adds to the complexity for someone reading and trying to understand the code.

The printf-style debugging that we do have in MicroPython is already plenty, and should be done using local-to-the-file DEBUG_printf() macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants