src.nth.io/

summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-19 19:07:55 -0500
committerLuke Hoersten <[email protected]>2026-06-19 19:07:55 -0500
commit846e4dbfed188154332fa01058e13df8336f0476 (patch)
tree1f956c62334aef09f6422e04726fcf3598a2b2e5 /main
parent4cf36e2569a85f63aa0726cd0318dce0aa9e71bd (diff)
unified end-to-end per-frame instrumentation + version stamps
Cross-side timing was opaque: script saw "req=70ms" but couldn't split TCP/dispatch overhead from firmware decode time, and firmware serial logs and Scrypted console logs couldn't be correlated. Firmware /frame handler now emits Server-Timing on every response with per-stage breakdown: Server-Timing: recv;dur=X, dec;dur=Y, paint;dur=Z, post;dur=W, handle;dur=total Script parses it, joins by X-Frame-Seq implicitly (one POST per seq), derives net_up = req − fw_total, and logs a multi-line p50/p95 breakdown every 10 fetches: fetch "kitchen" #10 (jpeg=137KB) wall p50=65ms p95=140ms emit→post p50=0ms p95=2ms (queue wait) req p50=62ms p95=135ms (fetch → Response headers) net_up p50=43ms p95=110ms (TCP + body wire + dispatch) fw_recv p50=12ms p95=18ms (body off the wire) fw_dec p50=6ms p95=8ms (hardware JPEG) fw_paint p50=0.1ms p95=0.2ms (backbuffer flip) fw_post p50=0.4ms p95=0.6ms body-read p50=1ms (drain — empty body) inflight d0=8 d1=2 d2=0 stale-drops=0 Plus version stamps on both sides for the "is the user on the right code" question: - CMakeLists: PROJECT_VER = git short hash + -dirty marker if dirty. esp_app_get_description()->version exposes it at runtime. Boot log: "Scrypted Viewport boot (v0.1.0 build=4cf36e2-dirty)". - TS: SCRIPT_VERSION const at the top, bumped per commit, logged at script-eval: "Scrypted Viewport up (script=4cf36e2). Callback ..."
Diffstat (limited to 'main')
-rw-r--r--main/app_main.c8
-rw-r--r--main/http_api.c16
2 files changed, 23 insertions, 1 deletions
diff --git a/main/app_main.c b/main/app_main.c
index a60496d..00a77bb 100644
--- a/main/app_main.c
+++ b/main/app_main.c
@@ -10,6 +10,7 @@
#include "touch.h"
#include "viewport_state.h"
+#include "esp_app_desc.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
@@ -39,7 +40,12 @@ void app_main(void)
viewport_state_init();
nvs_config_load(); // apply persisted config over defaults (best-effort)
- ESP_LOGI(TAG, "Scrypted Viewport boot (v%s)", VIEWPORT_VERSION);
+ // PROJECT_VER comes from CMakeLists.txt — git short hash + dirty
+ // marker. Logged in the very first line so any captured boot log
+ // tells us exactly which build is running.
+ const esp_app_desc_t *desc = esp_app_get_description();
+ ESP_LOGI(TAG, "Scrypted Viewport boot (v%s build=%s)",
+ VIEWPORT_VERSION, desc ? desc->version : "?");
// ------------------------------------------------------------------
// Networking. Driver starts even with no cable plugged in; we just
diff --git a/main/http_api.c b/main/http_api.c
index c490a85..69e555e 100644
--- a/main/http_api.c
+++ b/main/http_api.c
@@ -499,6 +499,22 @@ static esp_err_t frame_post_handler(httpd_req_t *req)
state_machine_frame_painted(); // reset idle timer
+ // Server-Timing per-stage breakdown so the Scrypted side can build
+ // a unified end-to-end trace per frame (joined by X-Frame-Seq).
+ // Units are ms with 0.1ms precision — paint is sub-millisecond
+ // so the decimal matters there. Scrypted subtracts the sum from
+ // its own (fetch_start → Response_headers) measurement to derive
+ // the network up + handler-dispatch overhead it can't see directly.
+ char st_hdr[160];
+ snprintf(st_hdr, sizeof(st_hdr),
+ "recv;dur=%.1f, dec;dur=%.1f, paint;dur=%.1f, post;dur=%.1f, handle;dur=%.1f",
+ (t_recv - t_first_byte) / 1000.0,
+ (t_decode - t_recv) / 1000.0,
+ (t_paint - t_decode) / 1000.0,
+ (t_post - t_paint) / 1000.0,
+ (t_post - t_entry) / 1000.0);
+ httpd_resp_set_hdr(req, "Server-Timing", st_hdr);
+
httpd_resp_set_status(req, "204 No Content");
return httpd_resp_send(req, NULL, 0);
}