Skip to content

Commit

Permalink
crc32: Enable debug logs of timing *and throughput* in both impls
Browse files Browse the repository at this point in the history
* qCRC is a way to benchmark SWD throughput from inside BMF
* For sufficiently long sections also compute KiB/s
  • Loading branch information
ALTracer committed Jan 3, 2024
1 parent 04b2c0c commit e368eee
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ bool generic_crc32(target_s *const target, uint32_t *const result, const uint32_
for (size_t i = 0; i < read_len; i++)
crc = crc32_calc(crc, bytes[i]);
}
DEBUG_WARN("%" PRIu32 " ms\n", platform_time_ms() - start_time);
#if ENABLE_DEBUG == 1
const uint32_t end_time = platform_time_ms();
if (len > 512U) {
const uint32_t speed = len * 1000U / (end_time - start_time) / 1024U;
DEBUG_INFO("%s: len = %" PRIu32 ": %" PRIu32 " KiB/s,\t", __func__, (uint32_t)len, speed);
}
DEBUG_INFO("%" PRIu32 " ms\n", end_time - start_time);
#endif
*result = crc;
return true;
}
Expand All @@ -149,6 +156,9 @@ bool stm32_crc32(target_s *const target, uint32_t *const result, const uint32_t

CRC_CR |= CRC_CR_RESET;

#if ENABLE_DEBUG == 1
const uint32_t start_time = platform_time_ms();
#endif
uint32_t last_time = platform_time_ms();
const size_t adjusted_len = len & ~3U;
for (size_t offset = 0; offset < adjusted_len; offset += sizeof(bytes)) {
Expand Down Expand Up @@ -185,6 +195,14 @@ bool stm32_crc32(target_s *const target, uint32_t *const result, const uint32_t
}
}
}
#if ENABLE_DEBUG == 1
const uint32_t end_time = platform_time_ms();
if (len > 512U) {
const uint32_t speed = len * 1000U / (end_time - start_time) / 1024U;
DEBUG_INFO("%s: len = %" PRIu32 ": %" PRIu32 " KiB/s,\t", __func__, (uint32_t)len, speed);
}
DEBUG_INFO("%" PRIu32 " ms\n", end_time - start_time);
#endif
*result = crc;
return true;
}
Expand Down

0 comments on commit e368eee

Please sign in to comment.