From 7c1a4abc0d28845f8055d1fb5fa15fceedc36dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EB=B3=91=EC=A4=80?= Date: Mon, 5 Aug 2024 01:46:18 +0900 Subject: [PATCH] add: perf measurement --- device/firmware/Core/Src/energymeter_usb.c | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/device/firmware/Core/Src/energymeter_usb.c b/device/firmware/Core/Src/energymeter_usb.c index afd0c26..a29f09e 100644 --- a/device/firmware/Core/Src/energymeter_usb.c +++ b/device/firmware/Core/Src/energymeter_usb.c @@ -370,6 +370,11 @@ void usb_load_one(uint8_t *buf) { uint32_t total_read = 0; uint32_t use_primary = TRUE; + uint32_t spist, spifin, usbfin; + uint32_t arr[300]; + uint32_t i = 0; + + uint32_t start; // it took ~700 ms to send first 100 KB. 140 KB/s // it took ~1900 ms to send next 100 KB. 55 KB/s @@ -380,21 +385,40 @@ void usb_load_one(uint8_t *buf) { // switch buffers to speed up uint8_t *buf = use_primary ? UserTxBufferFS : UserTxBufferFS_2; + spist = HAL_GetTick(); + // f_read took typically 6 ms if (f_read(&fp, buf, APP_TX_DATA_SIZE, (UINT *)&read) != FR_OK) { USB_RESPONSE(RESP_ERROR); return; } + spifin = HAL_GetTick(); + total_read += read; // USB_Transmit normally took 0 ms. // but after first 100 KB sent, once at a fifth, it took avg 130 ms. // so, in avg of total, it took 25 ms USB_Transmit(buf, read); + + usbfin = HAL_GetTick(); + + if (i < 300) { + arr[i] = usbfin - spifin; + } + i++; + use_primary = !use_primary; } + USB_Transmit("dmp", 3); + for (i = 0; i < 300; i++) { + sprintf(UserTxBufferFS + i * 5, "%04d ", arr[i]); + } + USB_Transmit(UserTxBufferFS, 1500); + USB_Transmit("fin", 3); + USB_RESPONSE(RESP_FILE_END); }