How to get "CPU load" and "Memory Usage"
How to get "CPU load" and "Memory Usage"
Hi ESP-IDF,
Is there some API that I can grab to get the CPU usage and Memory Usage, say, like man in the "system monitor" can got?
I'm just planning to build a web-interface for my project. In which a very "nice to have" feature is this one. For me at least.
Cheers
Gfast2
Is there some API that I can grab to get the CPU usage and Memory Usage, say, like man in the "system monitor" can got?
I'm just planning to build a web-interface for my project. In which a very "nice to have" feature is this one. For me at least.
Cheers
Gfast2
Re: How to get "CPU load" and "Memory Usage"
To create a "CPU LOAD" display, you can take advantage of RTOS. Adding a priority 0 task (which indicates when CPU is in IDLE, delay / etc), we can start playing. However it is just a mediocre and basic solution.
There are functions that return the value of free HEAP, such as ESP.getfreeheap () (something similar to this in the Arduino core). If the total is ~ 520kB, we can take the percentage.
There are functions that return the value of free HEAP, such as ESP.getfreeheap () (something similar to this in the Arduino core). If the total is ~ 520kB, we can take the percentage.
Re: How to get "CPU load" and "Memory Usage"
Hi urbanze,urbanze wrote:To create a "CPU LOAD" display, you can take advantage of RTOS. Adding a priority 0 task (which indicates when CPU is in IDLE, delay / etc), we can start playing. However it is just a mediocre and basic solution.
There are functions that return the value of free HEAP, such as ESP.getfreeheap () (something similar to this in the Arduino core). If the total is ~ 520kB, we can take the percentage.
Thanks for your brilient "Idle Task" solusion for CPU load indication! I'll try it out. But if you have a example of its implementation, please do let me know, I believe it will save me a lot time to solve this problem.
About memory:
Because I'm really new in this nearly bare bone level, I did some google about this topic: stack vs heap, but still didn't get the core idea about what you said. Is that means all I got from "free Heap" is all the free memories from the 512KB?
Cheers
Su Gao
Re: How to get "CPU load" and "Memory Usage"
Hi Gfast.
Idle task ideia:
if the cpu is stopped, in 1 second the CTR will be 100. If not, it will be any smaller value. After 1sec, you need to restart ctr.
RAM function: ESP.getFreeHeap();
Here, with blank project (just Serial), has 300k of free heap. (total ~520kB).
Idle task ideia:
Code: Select all
long ctr = 0;
void setup()
{
xTaskCreatePinnedToCore(id, "id", 4096, NULL, 0, NULL, 0);
}
void loop()
{
}
void id(void*z)
{
while (1)
{
ctr++;
delay(10);
}
}
RAM function: ESP.getFreeHeap();
Here, with blank project (just Serial), has 300k of free heap. (total ~520kB).
Re: How to get "CPU load" and "Memory Usage"
You can also loop though all running tasks and get the TaskStatus_t for each task. Which contains usStackHighWaterMark.
if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is defined you can also get vTaskGetRunTimeStats or ulRunTimeCounter from TaskStatus_t, although you might have to do some things to get it working.
if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is defined you can also get vTaskGetRunTimeStats or ulRunTimeCounter from TaskStatus_t, although you might have to do some things to get it working.
Re: How to get "CPU load" and "Memory Usage"
Hi, f.h-f.s.f.h-f.s. wrote:You can also loop though all running tasks and get the TaskStatus_t for each task. Which contains usStackHighWaterMark.
if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is defined you can also get vTaskGetRunTimeStats or ulRunTimeCounter from TaskStatus_t, although you might have to do some things to get it working.
Thanks for your answers. I'll checkout them when I got the chance later.
cheers
gfast2
Re: How to get "CPU load" and "Memory Usage"
Hi urbanze,urbanze wrote:Hi Gfast.
Idle task ideia:Code: Select all
long ctr = 0; void setup() { xTaskCreatePinnedToCore(id, "id", 4096, NULL, 0, NULL, 0); } void loop() { } void id(void*z) { while (1) { ctr++; delay(10); } }
if the cpu is stopped, in 1 second the CTR will be 100. If not, it will be any smaller value. After 1sec, you need to restart ctr.
RAM function: ESP.getFreeHeap();
Here, with blank project (just Serial), has 300k of free heap. (total ~520kB).
I'm using ESP-IDF right now. If I got chance to check out your Arduino Flavor, I will post my results here.
cheers
gfast2
Re: How to get "CPU load" and "Memory Usage"
I thought you used Arduino. You can use this code exactly equals. However, you just don't need to create setup/loop.Gfast2 wrote:Hi urbanze,urbanze wrote:Hi Gfast.
Idle task ideia:Code: Select all
long ctr = 0; void setup() { xTaskCreatePinnedToCore(id, "id", 4096, NULL, 0, NULL, 0); } void loop() { } void id(void*z) { while (1) { ctr++; delay(10); } }
if the cpu is stopped, in 1 second the CTR will be 100. If not, it will be any smaller value. After 1sec, you need to restart ctr.
RAM function: ESP.getFreeHeap();
Here, with blank project (just Serial), has 300k of free heap. (total ~520kB).
I'm using ESP-IDF right now. If I got chance to check out your Arduino Flavor, I will post my results here.
cheers
gfast2
You also need to create another higher-priority task on cpu 0 (for example priority 10), so that every X seconds, it shows the value of the counter on the screen.
You can test that it works, but in an extremely simple way. If you really need this and can not solve it, we can create something together
Re: How to get "CPU load" and "Memory Usage"
Hi urbanze,urbanze wrote:I thought you used Arduino. You can use this code exactly equals. However, you just don't need to create setup/loop.Gfast2 wrote:Hi urbanze,urbanze wrote:Hi Gfast.
Idle task ideia:Code: Select all
long ctr = 0; void setup() { xTaskCreatePinnedToCore(id, "id", 4096, NULL, 0, NULL, 0); } void loop() { } void id(void*z) { while (1) { ctr++; delay(10); } }
if the cpu is stopped, in 1 second the CTR will be 100. If not, it will be any smaller value. After 1sec, you need to restart ctr.
RAM function: ESP.getFreeHeap();
Here, with blank project (just Serial), has 300k of free heap. (total ~520kB).
I'm using ESP-IDF right now. If I got chance to check out your Arduino Flavor, I will post my results here.
cheers
gfast2
You also need to create another higher-priority task on cpu 0 (for example priority 10), so that every X seconds, it shows the value of the counter on the screen.
You can test that it works, but in an extremely simple way. If you really need this and can not solve it, we can create something together
Thanks again for your examples again. It is such a pleasure to have so many support here! I will check this feature very soon.
Cheers
Su
Re: How to get "CPU load" and "Memory Usage"
What you want is built into the RTOS, but sadly ESP has not added it in.
void vTaskGetRunTimeStats( char *pcWriteBuffer );
void vTaskGetRunTimeStats( char *pcWriteBuffer );
Who is online
Users browsing this forum: No registered users and 131 guests