refactor(diagnostics): prune unused debug APIs and dedupe cancel counter
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -16,17 +14,8 @@ typedef enum {
|
||||
CONTROL_PLANE_LIFECYCLE_STATE_STOPPING,
|
||||
} control_plane_lifecycle_state_t;
|
||||
|
||||
typedef struct {
|
||||
control_plane_lifecycle_state_t state;
|
||||
esp_err_t last_error;
|
||||
uint32_t start_attempt;
|
||||
int64_t last_transition_ms;
|
||||
char last_stage[32];
|
||||
} control_plane_lifecycle_status_t;
|
||||
|
||||
esp_err_t control_plane_lifecycle_start(void);
|
||||
esp_err_t control_plane_lifecycle_stop(void);
|
||||
void control_plane_lifecycle_get_status(control_plane_lifecycle_status_t *out_status);
|
||||
const char *control_plane_lifecycle_state_str(control_plane_lifecycle_state_t state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -11,7 +11,15 @@
|
||||
|
||||
static const char *TAG = "control_plane_lifecycle";
|
||||
static SemaphoreHandle_t s_lock;
|
||||
static control_plane_lifecycle_status_t s_status = {
|
||||
typedef struct {
|
||||
control_plane_lifecycle_state_t state;
|
||||
esp_err_t last_error;
|
||||
uint32_t start_attempt;
|
||||
int64_t last_transition_ms;
|
||||
char last_stage[32];
|
||||
} lifecycle_status_t;
|
||||
|
||||
static lifecycle_status_t s_status = {
|
||||
.state = CONTROL_PLANE_LIFECYCLE_STATE_STOPPED,
|
||||
.last_error = ESP_OK,
|
||||
.start_attempt = 0,
|
||||
@@ -268,18 +276,3 @@ esp_err_t control_plane_lifecycle_stop(void) {
|
||||
|
||||
return first_err;
|
||||
}
|
||||
|
||||
void control_plane_lifecycle_get_status(control_plane_lifecycle_status_t *out_status) {
|
||||
if (out_status == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
memset(out_status, 0, sizeof(*out_status));
|
||||
|
||||
if (!lifecycle_lock_take(200)) {
|
||||
return;
|
||||
}
|
||||
|
||||
*out_status = s_status;
|
||||
xSemaphoreGive(s_lock);
|
||||
}
|
||||
|
||||
@@ -63,21 +63,9 @@ typedef enum {
|
||||
DOMAIN_DIAG_GAUGE_MAX,
|
||||
} domain_diag_gauge_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t counters[DOMAIN_DIAG_COUNTER_MAX];
|
||||
int32_t gauges[DOMAIN_DIAG_GAUGE_MAX];
|
||||
int64_t last_error_ms;
|
||||
esp_err_t last_error_code;
|
||||
char last_error_source[32];
|
||||
char last_error_message[96];
|
||||
} domain_diag_snapshot_t;
|
||||
|
||||
void domain_diag_counter_add(domain_diag_counter_t counter, uint32_t delta);
|
||||
void domain_diag_set_gauge(domain_diag_gauge_t gauge, int32_t value);
|
||||
void domain_diag_record_error(const char *source, esp_err_t code, const char *message);
|
||||
void domain_diag_get_snapshot(domain_diag_snapshot_t *out_snapshot);
|
||||
const char *domain_diag_counter_name(domain_diag_counter_t counter);
|
||||
const char *domain_diag_gauge_name(domain_diag_gauge_t gauge);
|
||||
|
||||
// ---------- raster_tools ----------
|
||||
esp_err_t raster_tools_render_text_384(const char *text,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "domain.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
static runtime_diag_counter_t to_platform_counter(domain_diag_counter_t counter) {
|
||||
@@ -119,43 +117,3 @@ void domain_diag_set_gauge(domain_diag_gauge_t gauge, int32_t value) {
|
||||
void domain_diag_record_error(const char *source, esp_err_t code, const char *message) {
|
||||
runtime_diag_record_error(source, code, message);
|
||||
}
|
||||
|
||||
void domain_diag_get_snapshot(domain_diag_snapshot_t *out_snapshot) {
|
||||
if (out_snapshot == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
runtime_diag_snapshot_t platform_snapshot = {0};
|
||||
runtime_diag_get_snapshot(&platform_snapshot);
|
||||
|
||||
for (int i = 0; i < DOMAIN_DIAG_COUNTER_MAX && i < RUNTIME_DIAG_COUNTER_MAX; ++i) {
|
||||
out_snapshot->counters[i] = platform_snapshot.counters[i];
|
||||
}
|
||||
for (int i = 0; i < DOMAIN_DIAG_GAUGE_MAX && i < RUNTIME_DIAG_GAUGE_MAX; ++i) {
|
||||
out_snapshot->gauges[i] = platform_snapshot.gauges[i];
|
||||
}
|
||||
out_snapshot->last_error_ms = platform_snapshot.last_error_ms;
|
||||
out_snapshot->last_error_code = platform_snapshot.last_error_code;
|
||||
strlcpy(out_snapshot->last_error_source,
|
||||
platform_snapshot.last_error_source,
|
||||
sizeof(out_snapshot->last_error_source));
|
||||
strlcpy(out_snapshot->last_error_message,
|
||||
platform_snapshot.last_error_message,
|
||||
sizeof(out_snapshot->last_error_message));
|
||||
}
|
||||
|
||||
const char *domain_diag_counter_name(domain_diag_counter_t counter) {
|
||||
runtime_diag_counter_t mapped = to_platform_counter(counter);
|
||||
if (mapped >= RUNTIME_DIAG_COUNTER_MAX) {
|
||||
return "unknown";
|
||||
}
|
||||
return runtime_diag_counter_name(mapped);
|
||||
}
|
||||
|
||||
const char *domain_diag_gauge_name(domain_diag_gauge_t gauge) {
|
||||
runtime_diag_gauge_t mapped = to_platform_gauge(gauge);
|
||||
if (mapped >= RUNTIME_DIAG_GAUGE_MAX) {
|
||||
return "unknown";
|
||||
}
|
||||
return runtime_diag_gauge_name(mapped);
|
||||
}
|
||||
|
||||
@@ -272,6 +272,8 @@ esp_err_t printer_protocol_list_jobs(print_job_info_t *out_jobs, size_t max_jobs
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_cancel_job(uint32_t job_id, char *err, size_t err_len) {
|
||||
bool canceled_finalized = false;
|
||||
|
||||
if (job_id == 0) {
|
||||
if (err != NULL && err_len > 0) {
|
||||
snprintf(err, err_len, "invalid job id");
|
||||
@@ -311,12 +313,15 @@ esp_err_t printer_protocol_cancel_job(uint32_t job_id, char *err, size_t err_len
|
||||
strlcpy(s_jobs[idx].error, "job canceled", sizeof(s_jobs[idx].error));
|
||||
free(s_jobs[idx].data);
|
||||
s_jobs[idx].data = NULL;
|
||||
canceled_finalized = true;
|
||||
} else if (s_jobs[idx].state == PRINT_JOB_STATE_RUNNING) {
|
||||
strlcpy(s_jobs[idx].error, "cancel requested", sizeof(s_jobs[idx].error));
|
||||
}
|
||||
|
||||
xSemaphoreGive(s_mutex);
|
||||
if (canceled_finalized) {
|
||||
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_PRINTER_JOB_CANCELED, 1);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,6 @@ void printer_protocol_worker_task(void *arg) {
|
||||
s_jobs[idx].finished_ms = esp_timer_get_time() / 1000;
|
||||
}
|
||||
xSemaphoreGive(s_mutex);
|
||||
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_PRINTER_JOB_CANCELED, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,22 +180,9 @@ typedef enum {
|
||||
RUNTIME_DIAG_GAUGE_MAX,
|
||||
} runtime_diag_gauge_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t counters[RUNTIME_DIAG_COUNTER_MAX];
|
||||
int32_t gauges[RUNTIME_DIAG_GAUGE_MAX];
|
||||
int64_t last_error_ms;
|
||||
esp_err_t last_error_code;
|
||||
char last_error_source[32];
|
||||
char last_error_message[96];
|
||||
} runtime_diag_snapshot_t;
|
||||
|
||||
void runtime_diag_counter_add(runtime_diag_counter_t counter, uint32_t delta);
|
||||
void runtime_diag_set_gauge(runtime_diag_gauge_t gauge, int32_t value);
|
||||
void runtime_diag_record_error(const char *source, esp_err_t code, const char *message);
|
||||
void runtime_diag_get_snapshot(runtime_diag_snapshot_t *out_snapshot);
|
||||
|
||||
const char *runtime_diag_counter_name(runtime_diag_counter_t counter);
|
||||
const char *runtime_diag_gauge_name(runtime_diag_gauge_t gauge);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_timer.h"
|
||||
@@ -8,34 +7,16 @@
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
static SemaphoreHandle_t s_lock;
|
||||
static runtime_diag_snapshot_t s_snapshot;
|
||||
typedef struct {
|
||||
uint64_t counters[RUNTIME_DIAG_COUNTER_MAX];
|
||||
int32_t gauges[RUNTIME_DIAG_GAUGE_MAX];
|
||||
int64_t last_error_ms;
|
||||
esp_err_t last_error_code;
|
||||
char last_error_source[32];
|
||||
char last_error_message[96];
|
||||
} runtime_diag_state_t;
|
||||
|
||||
static const char *const s_counter_names[RUNTIME_DIAG_COUNTER_MAX] = {
|
||||
"lifecycle_start_attempt",
|
||||
"lifecycle_start_success",
|
||||
"lifecycle_start_failed",
|
||||
"lifecycle_start_retry",
|
||||
"lifecycle_stop_attempt",
|
||||
"lifecycle_stop_success",
|
||||
"lifecycle_stop_failed",
|
||||
"wifi_connect_success",
|
||||
"wifi_connect_failed",
|
||||
"wifi_connect_timeout",
|
||||
"printer_job_submitted",
|
||||
"printer_job_success",
|
||||
"printer_job_failed",
|
||||
"printer_job_canceled",
|
||||
"image_generate_attempt",
|
||||
"image_generate_success",
|
||||
"image_generate_failed",
|
||||
"image_generate_timeout",
|
||||
};
|
||||
|
||||
static const char *const s_gauge_names[RUNTIME_DIAG_GAUGE_MAX] = {
|
||||
"lifecycle_state",
|
||||
"status_poll_pause_depth",
|
||||
"printer_queue_depth",
|
||||
};
|
||||
static runtime_diag_state_t s_snapshot;
|
||||
|
||||
static void runtime_diag_ensure_lock(void) {
|
||||
if (s_lock == NULL) {
|
||||
@@ -98,37 +79,3 @@ void runtime_diag_record_error(const char *source, esp_err_t code, const char *m
|
||||
|
||||
xSemaphoreGive(s_lock);
|
||||
}
|
||||
|
||||
void runtime_diag_get_snapshot(runtime_diag_snapshot_t *out_snapshot) {
|
||||
if (out_snapshot == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
memset(out_snapshot, 0, sizeof(*out_snapshot));
|
||||
|
||||
runtime_diag_ensure_lock();
|
||||
if (s_lock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_lock, pdMS_TO_TICKS(100)) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
*out_snapshot = s_snapshot;
|
||||
xSemaphoreGive(s_lock);
|
||||
}
|
||||
|
||||
const char *runtime_diag_counter_name(runtime_diag_counter_t counter) {
|
||||
if (counter < 0 || counter >= RUNTIME_DIAG_COUNTER_MAX) {
|
||||
return "unknown";
|
||||
}
|
||||
return s_counter_names[counter];
|
||||
}
|
||||
|
||||
const char *runtime_diag_gauge_name(runtime_diag_gauge_t gauge) {
|
||||
if (gauge < 0 || gauge >= RUNTIME_DIAG_GAUGE_MAX) {
|
||||
return "unknown";
|
||||
}
|
||||
return s_gauge_names[gauge];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user