diff --git a/esphome/espota2.py b/esphome/espota2.py index 61e897f601..adcfde9e2a 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -460,8 +460,14 @@ def perform_ota( (upload_size >> 8) & 0xFF, (upload_size >> 0) & 0xFF, ] + # The device erases flash between receiving the size and acking the + # prepare, so this window shows the erase cost (near zero when the + # device erases lazily during the upload) + prepare_start = time.perf_counter() send_check(sock, upload_size_encoded, "binary size") receive_exactly(sock, 1, "update prepare result", RESPONSE_UPDATE_PREPARE_OK) + prepare_duration = time.perf_counter() - prepare_start + _LOGGER.info("Preparing for upload took %.2f seconds", prepare_duration) upload_md5 = hashlib.md5(upload_contents).hexdigest() _LOGGER.debug("MD5 of upload is %s", upload_md5) @@ -534,6 +540,13 @@ def perform_ota( except OTANetworkError as err: raise _committed_error(err) from err + _LOGGER.info( + "OTA took %.2f seconds total (prepare %.2f, upload %.2f)", + time.perf_counter() - prepare_start, + prepare_duration, + duration, + ) + try: send_check(sock, RESPONSE_OK, "end acknowledgement") except OTANetworkError as err: