Build and deploy Docs site to GitHub Pages / github-pages (push) Canceled after 0s
PR Build Check / build (Heltec_v3_companion_radio_ble) (push) Canceled after 0s
PR Build Check / build (Heltec_v3_repeater) (push) Canceled after 0s
PR Build Check / build (Heltec_v3_room_server) (push) Canceled after 0s
PR Build Check / build (LilyGo_Tlora_C6_repeater_) (push) Canceled after 0s
PR Build Check / build (PicoW_repeater) (push) Canceled after 0s
PR Build Check / build (RAK_4631_companion_radio_ble) (push) Canceled after 0s
PR Build Check / build (RAK_4631_companion_radio_ethernet) (push) Canceled after 0s
PR Build Check / build (RAK_4631_repeater) (push) Canceled after 0s
PR Build Check / build (RAK_4631_repeater_ethernet) (push) Canceled after 0s
PR Build Check / build (RAK_4631_room_server) (push) Canceled after 0s
PR Build Check / build (RAK_4631_room_server_ethernet) (push) Canceled after 0s
PR Build Check / build (Tbeam_SX1276_repeater) (push) Canceled after 0s
PR Build Check / build (wio-e5-mini_repeater) (push) Canceled after 0s
PR Build Check / build (wio_wm1110_repeater) (push) Canceled after 0s
Run Unit Tests / test (push) Canceled after 0s
41 lines
819 B
C++
41 lines
819 B
C++
#pragma once
|
|
#ifdef ESP32
|
|
|
|
#include <stdint.h>
|
|
#include "esp_attr.h"
|
|
#include "esp_timer.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
class CPUUsageTracker {
|
|
public:
|
|
void begin();
|
|
|
|
float getCore0Util() const {
|
|
return (float)_sma_sum * (1.0f / (SMA_WINDOW * 255.0f));
|
|
}
|
|
|
|
private:
|
|
static constexpr uint8_t SMA_WINDOW = 64; // power of 2 — enables & mask
|
|
|
|
static volatile uint32_t s_ticks[2]; // [0] = idle ticks, [1] = busy ticks
|
|
static TaskHandle_t s_idle_handle;
|
|
|
|
static void IRAM_ATTR s_tick_hook();
|
|
static void s_sample_cb(void* arg);
|
|
|
|
uint32_t _last_idle = 0;
|
|
uint32_t _last_busy = 0;
|
|
|
|
uint8_t _sma_buf[SMA_WINDOW] = {};
|
|
uint8_t _sma_idx = 0;
|
|
|
|
volatile uint16_t _sma_sum = 0;
|
|
|
|
esp_timer_handle_t _timer = nullptr;
|
|
|
|
void _onSample();
|
|
};
|
|
|
|
#endif
|