Measure uasync CPU load and display it in desktop and Android GUIs
Sample thread CPU usage without waking idle loops, expose a one-second moving average, and refresh compact GUI indicators at 3 Hz while visible on Android. Add load and bridge regression coverage, streaming notes, and task list cleanup.
This commit is contained in:
1 parent
bcfe7ca4c1
commit
71d19013c0
25 files changed
+692
-587
No files matched your search
@@ -39,6 +39,22 @@ typedef void (*uasync_post_callback_t)(void* user_arg);
|
||||
|
||||
struct timeout_node; // Forward declaration
|
||||
|
||||
/* CPU одного потока: 100% = одно ядро. При работе цикла/запросе снимок обновляется раз в 100 мс, без пробуждений.
|
||||
* До первого замера valid=0; window_us растёт до секунды. При задержке замера
|
||||
* вклад граничного интервала в среднее оценивается пропорционально времени. */
|
||||
struct uasync_load {
|
||||
double current_percent;
|
||||
double average_percent;
|
||||
uint64_t sample_time_us;
|
||||
uint64_t interval_us;
|
||||
uint64_t window_us;
|
||||
int valid;
|
||||
};
|
||||
|
||||
struct uasync_load_interval {
|
||||
uint64_t start_us, end_us, cpu_ns;
|
||||
};
|
||||
|
||||
struct posted_task {
|
||||
uasync_post_callback_t callback;
|
||||
void* arg;
|
||||
@@ -79,6 +95,11 @@ struct UASYNC {
|
||||
volatile sig_atomic_t stop;
|
||||
volatile sig_atomic_t running; // 0=shutdown mode (API rejected), 1=full init done
|
||||
uint64_t last_poll_exit_us;
|
||||
struct uasync_load load;
|
||||
struct uasync_load_interval load_history[12]; // 10 периодов + граничные интервалы при задержках
|
||||
uint64_t load_previous_us, load_previous_cpu_ns, load_next_us, load_log_us;
|
||||
unsigned int load_head, load_count;
|
||||
int load_state; // 0=не начат, 1=работает, -1=ошибка часов
|
||||
};
|
||||
|
||||
// Type definitions
|
||||
@@ -137,6 +158,9 @@ void uasync_stop(struct UASYNC* ua);
|
||||
// Debug statistics
|
||||
void uasync_get_stats(struct UASYNC* ua, size_t* timer_alloc, size_t* timer_free, size_t* socket_alloc, size_t* socket_free);
|
||||
|
||||
// Актуализирует снимок по сроку 100 мс. Только в потоке uasync; наружу передавать копию через события.
|
||||
err_t uasync_get_load(struct UASYNC* ua, struct uasync_load* load);
|
||||
|
||||
// Handle — кодированный индекс; сохраняется при расширении массива сокетов.
|
||||
int uasync_lookup_socket(struct UASYNC* ua, int fd, void** socket_id);
|
||||
|
||||
|
||||
Reference in new issue
Block a user