Skip to content

Commit

Permalink
crc32: Buffer up log output to avoid prefix-chunking, fix func
Browse files Browse the repository at this point in the history
* Format the optional output pieces into a stack buffer, then do a single DEBUG_INFO() call
* Restore the name of compiled function implementation in the log output
* Avoid dividing by 0 milliseconds elapsed
  • Loading branch information
ALTracer committed Nov 11, 2024
1 parent 41f86e8 commit ef1c2ab
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,28 @@ bool bmd_crc32(target_s *const target, uint32_t *const result, const uint32_t ba
#if !defined(STM32F0) && !defined(STM32F1) && !defined(STM32F2) && !defined(STM32F3) && !defined(STM32F4) && \
!defined(STM32F7) && !defined(STM32L0) && !defined(STM32L1) && !defined(STM32G0) && !defined(STM32G4)
const bool status = generic_crc32(target, result, base, len);
const char *const func = "generic_crc32";
#else
const bool status = stm32_crc32(target, result, base, len);
const char *const func = "stm32_crc32";
#endif
#ifndef DEBUG_INFO_IS_NOOP
/* "generic_crc32: 08000110+75272 -> 1353ms, 54 KiB/s" */
/* "stm32_crc32: 08000110+75272 -> 237ms, 310 KiB/s" */
/* "generic_crc32: 0x08000110+75272 -> 1353ms, 54 KiB/s" */
/* "stm32_crc32: 0x08000110+75272 -> 237ms, 310 KiB/s" */
const uint32_t end_time = platform_time_ms();
const uint32_t time_elapsed = end_time - start_time;
DEBUG_INFO("%s: 0x%08" PRIx32 "+%" PRIu32 " -> %" PRIu32 "ms", __func__, base, (uint32_t)len, time_elapsed);
if (len >= 512U) {
char logbuf[64] = {0};
const size_t logcap = 64;
size_t loglen = 0;
loglen = snprintf(&logbuf[loglen], logcap, "%s: 0x%08" PRIx32 "+%" PRIu32 " -> %" PRIu32 "ms", func, base,
(uint32_t)len, time_elapsed);
if (len >= 512U && time_elapsed > 0U) {
const uint32_t speed = len * 1000U / time_elapsed / 1024U;
DEBUG_INFO(", %" PRIu32 " KiB/s", speed);
loglen += snprintf(&logbuf[loglen], logcap - loglen, ", %" PRIu32 " KiB/s", speed);
}
DEBUG_INFO("\n");
DEBUG_INFO("%s\n", logbuf);
#else
(void)func;
#endif
return status;
}

0 comments on commit ef1c2ab

Please sign in to comment.