⚡️ Removes task manager dependency
This commit is contained in:
@@ -1,111 +1,27 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte'
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores'
|
||||||
import SettingsCard from '$lib/components/SettingsCard.svelte';
|
import SettingsCard from '$lib/components/SettingsCard.svelte'
|
||||||
import { slide } from 'svelte/transition';
|
import { slide } from 'svelte/transition'
|
||||||
import { cubicOut } from 'svelte/easing';
|
import { cubicOut } from 'svelte/easing'
|
||||||
import { Chart, registerables } from 'chart.js';
|
import { Chart, registerables } from 'chart.js'
|
||||||
|
|
||||||
import { daisyColor } from '$lib/utilities';
|
import { daisyColor } from '$lib/utilities'
|
||||||
import { analytics } from '$lib/stores/analytics';
|
import { analytics } from '$lib/stores/analytics'
|
||||||
import { Metrics } from '$lib/components/icons';
|
import { Metrics } from '$lib/components/icons'
|
||||||
|
|
||||||
Chart.register(...registerables);
|
Chart.register(...registerables)
|
||||||
|
|
||||||
let cpuChartElement: HTMLCanvasElement;
|
let heapChartElement: HTMLCanvasElement
|
||||||
let cpuChart: Chart;
|
let heapChart: Chart
|
||||||
|
|
||||||
let heapChartElement: HTMLCanvasElement;
|
let filesystemChartElement: HTMLCanvasElement
|
||||||
let heapChart: Chart;
|
let filesystemChart: Chart
|
||||||
|
|
||||||
let filesystemChartElement: HTMLCanvasElement;
|
let temperatureChartElement: HTMLCanvasElement
|
||||||
let filesystemChart: Chart;
|
let temperatureChart: Chart
|
||||||
|
|
||||||
let temperatureChartElement: HTMLCanvasElement;
|
|
||||||
let temperatureChart: Chart;
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
cpuChart = new Chart(cpuChartElement, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
labels: $analytics.cpu_usage,
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: 'Cpu usage core 0',
|
|
||||||
borderColor: daisyColor('--color-primary'),
|
|
||||||
backgroundColor: daisyColor('--color-primary', 50),
|
|
||||||
borderWidth: 2,
|
|
||||||
data: $analytics.cpu0_usage,
|
|
||||||
yAxisID: 'y',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Cpu usage core 1',
|
|
||||||
borderColor: daisyColor('--color-primary'),
|
|
||||||
backgroundColor: daisyColor('--color-primary', 50),
|
|
||||||
borderWidth: 2,
|
|
||||||
data: $analytics.cpu1_usage,
|
|
||||||
yAxisID: 'y',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Cpu usage total',
|
|
||||||
borderColor: daisyColor('--color-secondary'),
|
|
||||||
backgroundColor: daisyColor('--color-secondary', 50),
|
|
||||||
borderWidth: 2,
|
|
||||||
data: $analytics.cpu_usage,
|
|
||||||
yAxisID: 'y',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
responsive: true,
|
|
||||||
plugins: {
|
|
||||||
legend: {
|
|
||||||
display: true,
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
mode: 'index',
|
|
||||||
intersect: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
elements: {
|
|
||||||
point: {
|
|
||||||
radius: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
scales: {
|
|
||||||
x: {
|
|
||||||
grid: {
|
|
||||||
color: daisyColor('--color-base-content', 10),
|
|
||||||
},
|
|
||||||
ticks: {
|
|
||||||
color: daisyColor('--color-base-content'),
|
|
||||||
},
|
|
||||||
display: false,
|
|
||||||
},
|
|
||||||
y: {
|
|
||||||
type: 'linear',
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'Cpu usage [%]',
|
|
||||||
color: daisyColor('--color-base-content'),
|
|
||||||
font: {
|
|
||||||
size: 16,
|
|
||||||
weight: 'bold',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
position: 'left',
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
grid: { color: daisyColor('--color-base-content', 10) },
|
|
||||||
ticks: {
|
|
||||||
color: daisyColor('--color-base-content'),
|
|
||||||
},
|
|
||||||
border: { color: daisyColor('--color-base-content', 10) },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
heapChart = new Chart(heapChartElement, {
|
heapChart = new Chart(heapChartElement, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
@@ -118,36 +34,36 @@
|
|||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
data: $analytics.used_heap,
|
data: $analytics.used_heap,
|
||||||
fill: true,
|
fill: true,
|
||||||
yAxisID: 'y',
|
yAxisID: 'y'
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
responsive: true,
|
responsive: true,
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: {
|
legend: {
|
||||||
display: true,
|
display: true
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: 'index',
|
mode: 'index',
|
||||||
intersect: false,
|
intersect: false
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
elements: {
|
elements: {
|
||||||
point: {
|
point: {
|
||||||
radius: 0,
|
radius: 0
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
grid: {
|
grid: {
|
||||||
color: daisyColor('--color-base-content', 10),
|
color: daisyColor('--color-base-content', 10)
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content')
|
||||||
},
|
},
|
||||||
display: false,
|
display: false
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
type: 'linear',
|
type: 'linear',
|
||||||
@@ -157,21 +73,21 @@
|
|||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content'),
|
||||||
font: {
|
font: {
|
||||||
size: 16,
|
size: 16,
|
||||||
weight: 'bold',
|
weight: 'bold'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
position: 'left',
|
position: 'left',
|
||||||
min: 0,
|
min: 0,
|
||||||
max: Math.round($analytics.total_heap[0]),
|
max: Math.round($analytics.total_heap[0]),
|
||||||
grid: { color: daisyColor('--color-base-content', 10) },
|
grid: { color: daisyColor('--color-base-content', 10) },
|
||||||
ticks: {
|
ticks: {
|
||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content')
|
||||||
},
|
},
|
||||||
border: { color: daisyColor('--color-base-content', 10) },
|
border: { color: daisyColor('--color-base-content', 10) }
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
})
|
||||||
filesystemChart = new Chart(filesystemChartElement, {
|
filesystemChart = new Chart(filesystemChartElement, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
@@ -184,36 +100,36 @@
|
|||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
data: $analytics.fs_used,
|
data: $analytics.fs_used,
|
||||||
fill: true,
|
fill: true,
|
||||||
yAxisID: 'y',
|
yAxisID: 'y'
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
responsive: true,
|
responsive: true,
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: {
|
legend: {
|
||||||
display: true,
|
display: true
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: 'index',
|
mode: 'index',
|
||||||
intersect: false,
|
intersect: false
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
elements: {
|
elements: {
|
||||||
point: {
|
point: {
|
||||||
radius: 0,
|
radius: 0
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
grid: {
|
grid: {
|
||||||
color: daisyColor('--color-base-content', 10),
|
color: daisyColor('--color-base-content', 10)
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content')
|
||||||
},
|
},
|
||||||
display: false,
|
display: false
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
type: 'linear',
|
type: 'linear',
|
||||||
@@ -223,21 +139,21 @@
|
|||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content'),
|
||||||
font: {
|
font: {
|
||||||
size: 16,
|
size: 16,
|
||||||
weight: 'bold',
|
weight: 'bold'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
position: 'left',
|
position: 'left',
|
||||||
min: 0,
|
min: 0,
|
||||||
max: Math.round($analytics.fs_total[0]),
|
max: Math.round($analytics.fs_total[0]),
|
||||||
grid: { color: daisyColor('--color-base-content', 10) },
|
grid: { color: daisyColor('--color-base-content', 10) },
|
||||||
ticks: {
|
ticks: {
|
||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content')
|
||||||
},
|
},
|
||||||
border: { color: daisyColor('--color-base-content', 10) },
|
border: { color: daisyColor('--color-base-content', 10) }
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
})
|
||||||
temperatureChart = new Chart(temperatureChartElement, {
|
temperatureChart = new Chart(temperatureChartElement, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
@@ -249,36 +165,36 @@
|
|||||||
backgroundColor: daisyColor('--color-primary', 50),
|
backgroundColor: daisyColor('--color-primary', 50),
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
data: $analytics.core_temp,
|
data: $analytics.core_temp,
|
||||||
yAxisID: 'y',
|
yAxisID: 'y'
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
responsive: true,
|
responsive: true,
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: {
|
legend: {
|
||||||
display: true,
|
display: true
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: 'index',
|
mode: 'index',
|
||||||
intersect: false,
|
intersect: false
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
elements: {
|
elements: {
|
||||||
point: {
|
point: {
|
||||||
radius: 0,
|
radius: 0
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
grid: {
|
grid: {
|
||||||
color: daisyColor('--color-base-content', 10),
|
color: daisyColor('--color-base-content', 10)
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content')
|
||||||
},
|
},
|
||||||
display: false,
|
display: false
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
type: 'linear',
|
type: 'linear',
|
||||||
@@ -288,44 +204,38 @@
|
|||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content'),
|
||||||
font: {
|
font: {
|
||||||
size: 16,
|
size: 16,
|
||||||
weight: 'bold',
|
weight: 'bold'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
position: 'left',
|
position: 'left',
|
||||||
suggestedMin: 20,
|
suggestedMin: 20,
|
||||||
suggestedMax: 100,
|
suggestedMax: 100,
|
||||||
grid: { color: daisyColor('--color-base-content', 10) },
|
grid: { color: daisyColor('--color-base-content', 10) },
|
||||||
ticks: {
|
ticks: {
|
||||||
color: daisyColor('--color-base-content'),
|
color: daisyColor('--color-base-content')
|
||||||
},
|
},
|
||||||
border: { color: daisyColor('--color-base-content', 10) },
|
border: { color: daisyColor('--color-base-content', 10) }
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
})
|
||||||
setInterval(updateData, 500);
|
setInterval(updateData, 500)
|
||||||
});
|
})
|
||||||
|
|
||||||
function updateData() {
|
function updateData() {
|
||||||
cpuChart.data.labels = $analytics.cpu_usage;
|
heapChart.data.labels = $analytics.uptime
|
||||||
cpuChart.data.datasets[0].data = $analytics.cpu0_usage;
|
heapChart.data.datasets[0].data = $analytics.used_heap
|
||||||
cpuChart.data.datasets[1].data = $analytics.cpu1_usage;
|
heapChart.options.scales!.y!.max = Math.ceil($analytics.total_heap[0])
|
||||||
cpuChart.data.datasets[2].data = $analytics.cpu_usage;
|
heapChart.update('none')
|
||||||
cpuChart.update('none');
|
|
||||||
|
|
||||||
heapChart.data.labels = $analytics.uptime;
|
filesystemChart.data.labels = $analytics.uptime
|
||||||
heapChart.data.datasets[0].data = $analytics.used_heap;
|
filesystemChart.data.datasets[0].data = $analytics.fs_used
|
||||||
heapChart.options.scales!.y!.max = Math.ceil($analytics.total_heap[0]);
|
heapChart.options.scales!.y!.max = Math.ceil($analytics.fs_total[0])
|
||||||
heapChart.update('none');
|
filesystemChart.update('none')
|
||||||
|
|
||||||
filesystemChart.data.labels = $analytics.uptime;
|
temperatureChart.data.labels = $analytics.uptime
|
||||||
filesystemChart.data.datasets[0].data = $analytics.fs_used;
|
temperatureChart.data.datasets[0].data = $analytics.core_temp
|
||||||
heapChart.options.scales!.y!.max = Math.ceil($analytics.fs_total[0]);
|
temperatureChart.update('none')
|
||||||
filesystemChart.update('none');
|
|
||||||
|
|
||||||
temperatureChart.data.labels = $analytics.uptime;
|
|
||||||
temperatureChart.data.datasets[0].data = $analytics.core_temp;
|
|
||||||
temperatureChart.update('none');
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -337,14 +247,6 @@
|
|||||||
<span>System Metrics</span>
|
<span>System Metrics</span>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
<div class="w-full overflow-x-auto">
|
|
||||||
<div
|
|
||||||
class="flex w-full flex-col space-y-1 h-60"
|
|
||||||
transition:slide|local={{ duration: 300, easing: cubicOut }}>
|
|
||||||
<canvas bind:this={cpuChartElement}></canvas>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="w-full overflow-x-auto">
|
<div class="w-full overflow-x-auto">
|
||||||
<div
|
<div
|
||||||
class="flex w-full flex-col space-y-1 h-60"
|
class="flex w-full flex-col space-y-1 h-60"
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <async_worker.h>
|
#include <async_worker.h>
|
||||||
|
|
||||||
#include <features.h>
|
#include <features.h>
|
||||||
#include <task_manager.h>
|
|
||||||
#include <template/stateful_socket.h>
|
#include <template/stateful_socket.h>
|
||||||
#include <template/stateful_persistence.h>
|
#include <template/stateful_persistence.h>
|
||||||
#include <template/stateful_endpoint.h>
|
#include <template/stateful_endpoint.h>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include <PsychicHttp.h>
|
#include <PsychicHttp.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <task_manager.h>
|
|
||||||
// #include <event_socket.h>
|
// #include <event_socket.h>
|
||||||
#include <filesystem.h>
|
#include <filesystem.h>
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
|
|||||||
@@ -1,184 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <esp_task_wdt.h>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#define IDLE_STACK_SIZE 2048
|
|
||||||
#define DEFAULT_STACK_SIZE 2048 + 512
|
|
||||||
|
|
||||||
#define DELETE_TASK(handle) \
|
|
||||||
if (handle != nullptr) vTaskDelete(handle)
|
|
||||||
|
|
||||||
struct task_t {
|
|
||||||
std::string name;
|
|
||||||
TaskHandle_t handle;
|
|
||||||
uint32_t stackSize;
|
|
||||||
UBaseType_t priority;
|
|
||||||
BaseType_t coreId;
|
|
||||||
bool pinned;
|
|
||||||
bool active; // blocked ('B'), ready ('R'), deleted ('D') or suspended ('S').
|
|
||||||
};
|
|
||||||
|
|
||||||
class IdleTask {
|
|
||||||
private:
|
|
||||||
float idle_ratio = 0.0;
|
|
||||||
unsigned long last_measurement;
|
|
||||||
const int kMillisPerLoop = 1;
|
|
||||||
const int kMillisPerCalc = 1000;
|
|
||||||
unsigned long counter = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
IdleTask() : last_measurement(millis()) {}
|
|
||||||
|
|
||||||
void ProcessIdleTime() {
|
|
||||||
last_measurement = millis();
|
|
||||||
counter = 0;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
unsigned long current_time = millis();
|
|
||||||
unsigned long delta = current_time - last_measurement;
|
|
||||||
if (delta >= kMillisPerCalc) {
|
|
||||||
idle_ratio = static_cast<float>(counter) / delta;
|
|
||||||
last_measurement = current_time;
|
|
||||||
counter = 0;
|
|
||||||
} else {
|
|
||||||
esp_task_wdt_reset();
|
|
||||||
delayMicroseconds(kMillisPerLoop * 1000);
|
|
||||||
counter += kMillisPerLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float GetCPUUsage() const {
|
|
||||||
if (millis() - last_measurement > kMillisPerCalc) return 100.0f;
|
|
||||||
|
|
||||||
return 100.0f - 100 * idle_ratio;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void IdleTaskEntry(void *that) { static_cast<IdleTask *>(that)->ProcessIdleTime(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
class TaskManager {
|
|
||||||
private:
|
|
||||||
std::map<const char *, task_t> _tasks;
|
|
||||||
IdleTask _taskIdle0;
|
|
||||||
IdleTask _taskIdle1;
|
|
||||||
|
|
||||||
TaskHandle_t _hIdle0;
|
|
||||||
TaskHandle_t _hIdle1;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TaskManager() {}
|
|
||||||
|
|
||||||
void begin() {
|
|
||||||
createTask(IdleTask::IdleTaskEntry, "Idle Core 0", IDLE_STACK_SIZE, &_taskIdle0, 1, &_hIdle0, 0);
|
|
||||||
createTask(IdleTask::IdleTaskEntry, "Idle Core 1", IDLE_STACK_SIZE, &_taskIdle1, 1, &_hIdle1, 1);
|
|
||||||
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0));
|
|
||||||
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(1));
|
|
||||||
esp_task_wdt_add(_hIdle0);
|
|
||||||
esp_task_wdt_add(_hIdle1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<task_t> getTasks() {
|
|
||||||
update();
|
|
||||||
std::vector<task_t> tasks;
|
|
||||||
for (auto const &task : _tasks) tasks.push_back(task.second);
|
|
||||||
return tasks;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getTaskCount() const { return _tasks.size(); }
|
|
||||||
|
|
||||||
int getKernelTaskCount() const { return uxTaskGetNumberOfTasks(); }
|
|
||||||
|
|
||||||
void update() {
|
|
||||||
for (auto task = _tasks.begin(); task != _tasks.end();) {
|
|
||||||
eTaskState state = eTaskGetState(task->second.handle);
|
|
||||||
if (state == eDeleted) {
|
|
||||||
task = _tasks.erase(task);
|
|
||||||
} else {
|
|
||||||
_tasks[task->first].priority = uxTaskPriorityGet(task->second.handle);
|
|
||||||
_tasks[task->first].coreId = xTaskGetAffinity(task->second.handle);
|
|
||||||
++task;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float getCpuUsage(int iCore = -1) const {
|
|
||||||
if (iCore == 0)
|
|
||||||
return _taskIdle0.GetCPUUsage();
|
|
||||||
else if (iCore == 1)
|
|
||||||
return _taskIdle1.GetCPUUsage();
|
|
||||||
return (_taskIdle0.GetCPUUsage() + _taskIdle1.GetCPUUsage()) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseType_t createTask(void (*taskFunction)(void *), const char *name, uint32_t stackSize = 2048,
|
|
||||||
void *params = nullptr, UBaseType_t priority = 2, TaskHandle_t *handle = nullptr,
|
|
||||||
BaseType_t coreId = -1) {
|
|
||||||
TaskHandle_t localHandle;
|
|
||||||
if (handle == nullptr) handle = &localHandle;
|
|
||||||
BaseType_t res = coreId == -1
|
|
||||||
? xTaskCreate(taskFunction, name, stackSize, params, tskIDLE_PRIORITY + priority, handle)
|
|
||||||
: xTaskCreatePinnedToCore(taskFunction, name, stackSize, params,
|
|
||||||
tskIDLE_PRIORITY + priority, handle, coreId);
|
|
||||||
task_t task = {name, handle, stackSize, priority, coreId, coreId != -1, true};
|
|
||||||
if (res == pdPASS) _tasks[name] = task;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void suspendTask(const char *name) {
|
|
||||||
if (_tasks.find(name) != _tasks.end()) {
|
|
||||||
vTaskSuspend(_tasks[name].handle);
|
|
||||||
_tasks[name].active = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resumeTask(const char *name) {
|
|
||||||
if (_tasks.find(name) != _tasks.end()) {
|
|
||||||
vTaskResume(_tasks[name].handle);
|
|
||||||
_tasks[name].active = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void notifyTask(const char *name, uint32_t notificationValue, eNotifyAction action = eSetValueWithOverwrite) {
|
|
||||||
if (_tasks.find(name) != _tasks.end()) xTaskNotify(_tasks[name].handle, notificationValue, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteTask(const char *name) {
|
|
||||||
if (_tasks.find(name) != _tasks.end()) {
|
|
||||||
vTaskDelete(_tasks[name].handle);
|
|
||||||
_tasks.erase(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CPUBurnerTask {
|
|
||||||
private:
|
|
||||||
float burn_ratio;
|
|
||||||
const int kMillisPerCalc = 1000;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CPUBurnerTask(float ratio) : burn_ratio(ratio) {}
|
|
||||||
|
|
||||||
void BurnCPUTask() {
|
|
||||||
unsigned long burn_time = burn_ratio * kMillisPerCalc;
|
|
||||||
unsigned long idle_time = kMillisPerCalc - burn_time;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
unsigned long start_time = millis();
|
|
||||||
while ((millis() - start_time) < burn_time) {
|
|
||||||
esp_task_wdt_reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
vTaskDelay(idle_time / portTICK_PERIOD_MS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CPUBurnerTaskEntry(void *instance) { static_cast<CPUBurnerTask *>(instance)->BurnCPUTask(); }
|
|
||||||
|
|
||||||
void StartTask() { xTaskCreate(CPUBurnerTaskEntry, "CPUBurnerTask", 2048, this, tskIDLE_PRIORITY + 2, nullptr); }
|
|
||||||
};
|
|
||||||
|
|
||||||
extern TaskManager g_taskManager;
|
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <event_socket.h>
|
#include <event_socket.h>
|
||||||
#include <features.h>
|
#include <features.h>
|
||||||
#include <motion.h>
|
#include <motion.h>
|
||||||
#include <task_manager.h>
|
|
||||||
#include <wifi_service.h>
|
#include <wifi_service.h>
|
||||||
#include <ap_service.h>
|
#include <ap_service.h>
|
||||||
#include <mdns_service.h>
|
#include <mdns_service.h>
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ void streamTask(void *pv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t CameraService::cameraStream(PsychicRequest *request) {
|
esp_err_t CameraService::cameraStream(PsychicRequest *request) {
|
||||||
g_taskManager.createTask(streamTask, "Stream client task", 4096, request, 4);
|
xTaskCreate(streamTask, "Stream client task", 4096, request, 4, nullptr);
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,17 +120,6 @@ void metrics(JsonObject &root) {
|
|||||||
root["fs_used"] = ESP_FS.usedBytes();
|
root["fs_used"] = ESP_FS.usedBytes();
|
||||||
root["fs_total"] = ESP_FS.totalBytes();
|
root["fs_total"] = ESP_FS.totalBytes();
|
||||||
root["core_temp"] = temperatureRead();
|
root["core_temp"] = temperatureRead();
|
||||||
root["cpu0_usage"] = g_taskManager.getCpuUsage(0);
|
|
||||||
root["cpu1_usage"] = g_taskManager.getCpuUsage(1);
|
|
||||||
root["cpu_usage"] = g_taskManager.getCpuUsage();
|
|
||||||
JsonArray tasks = root["tasks"].to<JsonArray>();
|
|
||||||
for (auto const &task : g_taskManager.getTasks()) {
|
|
||||||
JsonObject nested = tasks.add<JsonObject>();
|
|
||||||
nested["name"] = task.name;
|
|
||||||
nested["stackSize"] = task.stackSize;
|
|
||||||
nested["priority"] = task.priority;
|
|
||||||
nested["coreId"] = task.coreId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitMetrics() {
|
void emitMetrics() {
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
#include <task_manager.h>
|
|
||||||
|
|
||||||
TaskManager g_taskManager;
|
|
||||||
Reference in New Issue
Block a user