Hello everyone,
I'm working on a project where I have three tasks that need to be executed in a specific order. I want to optimize the performance of my code . One way to do this is to measure the execution time of each task.
My question is: how can I get the execution time of each task in my terminal? Is there a built-in function or library that can help me with this?
I'm working with freeRTOS and ESP32, but any general advice or specific solutions are welcome.
/* Include FreeRTOS APIs and defines */
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#define LED1_PIN 2
#define LED2_PIN 4
#define LED3_PIN 5
void task1(void *pvParameters) {
while (1) {
digitalWrite(LED1_PIN, HIGH);
vTaskDelay(2000 / portTICK_PERIOD_MS);
digitalWrite(LED1_PIN, LOW);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
void task2(void *pvParameters) {
while (1) {
digitalWrite(LED2_PIN, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(LED2_PIN, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void task3(void *pvParameters) {
while (1) {
digitalWrite(LED3_PIN, HIGH);
vTaskDelay(250 / portTICK_PERIOD_MS);
digitalWrite(LED3_PIN, LOW);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}
void setup() {
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(LED3_PIN, OUTPUT);
xTaskCreate(task1, "Task 1", 1000, NULL, 1, NULL);
xTaskCreate(task2, "Task 2", 1000, NULL, 1, NULL);
xTaskCreate(task3, "Task 3", 1000, NULL, 1, NULL);
// vTaskStartScheduler();
}
void loop() {
// Do nothing here.
}
Thank you in advance for your help!