misc/common: Add arg to profile macro.

This way it can be called multiple times in the same function.
This commit is contained in:
iabdalkader 2024-08-04 12:55:47 +03:00
parent c99840a39a
commit aad37c9c85
7 changed files with 20 additions and 21 deletions

View File

@ -50,12 +50,11 @@
#if OMV_PROFILE_ENABLE #if OMV_PROFILE_ENABLE
#include <stdio.h> #include <stdio.h>
#include "py/mphal.h" #include "py/mphal.h"
#define OMV_PROFILE_START(F) mp_uint_t F##_ticks_start_ = mp_hal_ticks_us()
#define OMV_PROFILE_START mp_uint_t omv_profile_ticks_start = mp_hal_ticks_us(); #define OMV_PROFILE_END(F) printf("%s %u us\n", #F, mp_hal_ticks_us() - F##_ticks_start_)
#define OMV_PROFILE_END printf("%s %u us\n", __FUNCTION__, mp_hal_ticks_us() - omv_profile_ticks_start);
#else #else
#define OMV_PROFILE_START #define OMV_PROFILE_START(F)
#define OMV_PROFILE_END #define OMV_PROFILE_END(F)
#endif #endif
#endif //__OMV_COMMON_H__ #endif //__OMV_COMMON_H__

View File

@ -2843,7 +2843,7 @@ void imlib_draw_image(image_t *dst_img,
imlib_draw_row_callback_t callback, imlib_draw_row_callback_t callback,
void *callback_arg, void *callback_arg,
void *dst_row_override) { void *dst_row_override) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
int dst_delta_x = 1; // positive direction int dst_delta_x = 1; // positive direction
if (x_scale < 0.f) { if (x_scale < 0.f) {
// flip X // flip X
@ -5518,7 +5518,7 @@ exit_cleanup:
if (&new_src_img == src_img) { if (&new_src_img == src_img) {
fb_free(); fb_free();
} }
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
} }
#ifdef IMLIB_ENABLE_FLOOD_FILL #ifdef IMLIB_ENABLE_FLOOD_FILL

View File

@ -2841,7 +2841,7 @@ static int DecodeJPEG(JPEGIMAGE *pJPEG) {
} }
void jpeg_decompress(image_t *dst, image_t *src) { void jpeg_decompress(image_t *dst, image_t *src) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
JPEGIMAGE jpg; JPEGIMAGE jpg;
// Supports decoding baseline JPEGs only. // Supports decoding baseline JPEGs only.
@ -2882,6 +2882,6 @@ void jpeg_decompress(image_t *dst, image_t *src) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("JPEG decoder failed.")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("JPEG decoder failed."));
} }
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
} }
#endif #endif

View File

@ -1609,7 +1609,7 @@ static void jpeg_write_headers(jpeg_buf_t *jpeg_buf, int w, int h, int bpp, jpeg
} }
bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc, jpeg_subsampling_t subsampling) { bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc, jpeg_subsampling_t subsampling) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
if (!dst->data) { if (!dst->data) {
uint32_t size = 0; uint32_t size = 0;
@ -1941,7 +1941,7 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc, jpeg_s
dst->size = jpeg_buf.idx; dst->size = jpeg_buf.idx;
dst->data = jpeg_buf.buf; dst->data = jpeg_buf.buf;
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
return false; return false;
} }

View File

@ -105,7 +105,7 @@ unsigned lodepng_convert_cb(unsigned char *out, const unsigned char *in,
#if defined(IMLIB_ENABLE_PNG_ENCODER) #if defined(IMLIB_ENABLE_PNG_ENCODER)
bool png_compress(image_t *src, image_t *dst) { bool png_compress(image_t *src, image_t *dst) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
if (src->is_compressed) { if (src->is_compressed) {
return true; return true;
@ -177,14 +177,14 @@ bool png_compress(image_t *src, image_t *dst) {
// free fb_alloc() memory used for umm_init_x(). // free fb_alloc() memory used for umm_init_x().
fb_free(); // umm_init_x(); fb_free(); // umm_init_x();
} }
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
return false; return false;
} }
#endif // IMLIB_ENABLE_PNG_ENCODER #endif // IMLIB_ENABLE_PNG_ENCODER
#if defined(IMLIB_ENABLE_PNG_DECODER) #if defined(IMLIB_ENABLE_PNG_DECODER)
void png_decompress(image_t *dst, image_t *src) { void png_decompress(image_t *dst, image_t *src) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
umm_init_x(fb_avail()); umm_init_x(fb_avail());
LodePNGState state; LodePNGState state;
@ -226,7 +226,7 @@ void png_decompress(image_t *dst, image_t *src) {
// free fb_alloc() memory used for umm_init_x(). // free fb_alloc() memory used for umm_init_x().
fb_free(); // umm_init_x(); fb_free(); // umm_init_x();
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
} }
#endif // IMLIB_ENABLE_PNG_DECODER #endif // IMLIB_ENABLE_PNG_DECODER
#endif // IMLIB_ENABLE_PNG_ENCODER || IMLIB_ENABLE_PNG_DECODER #endif // IMLIB_ENABLE_PNG_ENCODER || IMLIB_ENABLE_PNG_DECODER

View File

@ -106,7 +106,7 @@ static void jpeg_compress_data_ready(JPEG_HandleTypeDef *hjpeg, uint8_t *pDataOu
} }
bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc, jpeg_subsampling_t subsampling) { bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc, jpeg_subsampling_t subsampling) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
HAL_JPEG_RegisterGetDataCallback(&JPEG_state.jpeg_descr, jpeg_compress_get_data); HAL_JPEG_RegisterGetDataCallback(&JPEG_state.jpeg_descr, jpeg_compress_get_data);
HAL_JPEG_RegisterDataReadyCallback(&JPEG_state.jpeg_descr, jpeg_compress_data_ready); HAL_JPEG_RegisterDataReadyCallback(&JPEG_state.jpeg_descr, jpeg_compress_data_ready);
@ -365,7 +365,7 @@ exit_cleanup:
fb_free(); // mcu_row_buffer (after DMA is aborted) fb_free(); // mcu_row_buffer (after DMA is aborted)
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
return jpeg_overflow; return jpeg_overflow;
} }
@ -397,7 +397,7 @@ static void jpeg_decompress_data_ready(JPEG_HandleTypeDef *hjpeg, uint8_t *pData
} }
void jpeg_decompress(image_t *dst, image_t *src) { void jpeg_decompress(image_t *dst, image_t *src) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
// Verify the jpeg image is not a non-baseline jpeg image and check that is has // Verify the jpeg image is not a non-baseline jpeg image and check that is has
// valid headers up to the start-of-scan header (which cannot be trivially walked). // valid headers up to the start-of-scan header (which cannot be trivially walked).
@ -752,7 +752,7 @@ exit_cleanup:
fb_free(); // JPEG_state.jpeg_descr.pJpegInBuffPtr (after DMA is aborted) fb_free(); // JPEG_state.jpeg_descr.pJpegInBuffPtr (after DMA is aborted)
} }
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
} }
void imlib_hardware_jpeg_init() { void imlib_hardware_jpeg_init() {

View File

@ -32,7 +32,7 @@ int omv_gpu_draw_image(image_t *src_img,
const uint16_t *color_palette, const uint16_t *color_palette,
const uint8_t *alpha_palette, const uint8_t *alpha_palette,
image_hint_t hint) { image_hint_t hint) {
OMV_PROFILE_START OMV_PROFILE_START(__FUNCTION__);
// DMA2D can only draw on RGB565 buffers and the destination/source buffers must be accessible by DMA. // DMA2D can only draw on RGB565 buffers and the destination/source buffers must be accessible by DMA.
if ((dst_img->pixfmt != PIXFORMAT_RGB565) || (!DMA_BUFFER(dst_img->data)) || (!DMA_BUFFER(src_img->data))) { if ((dst_img->pixfmt != PIXFORMAT_RGB565) || (!DMA_BUFFER(dst_img->data)) || (!DMA_BUFFER(src_img->data))) {
@ -211,7 +211,7 @@ int omv_gpu_draw_image(image_t *src_img,
fb_free(); // clut fb_free(); // clut
} }
OMV_PROFILE_END OMV_PROFILE_END(__FUNCTION__);
return 0; return 0;
} }
#endif // (OMV_GPU_ENABLE == 1) #endif // (OMV_GPU_ENABLE == 1)