refactor(diagnostics): prune unused debug APIs and dedupe cancel counter
This commit is contained in:
@@ -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