trace.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdint.h>
  2. #include "esp_system.h"
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include "esp_log.h"
  6. #include "freertos/xtensa_api.h"
  7. #include "freertos/FreeRTOSConfig.h"
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/queue.h"
  10. #include "freertos/task.h"
  11. #include "esp_event.h"
  12. #include "tools.h"
  13. #include "trace.h"
  14. static const char TAG[] = "TRACE";
  15. typedef struct mem_usage_trace_for_thread {
  16. TaskHandle_t task;
  17. size_t malloc_int_last;
  18. size_t malloc_spiram_last;
  19. size_t malloc_dma_last;
  20. const char *name;
  21. SLIST_ENTRY(mem_usage_trace_for_thread) next;
  22. } mem_usage_trace_for_thread_t;
  23. static EXT_RAM_ATTR SLIST_HEAD(memtrace, mem_usage_trace_for_thread) s_memtrace;
  24. mem_usage_trace_for_thread_t* memtrace_get_thread_entry(TaskHandle_t task) {
  25. if(!task) {
  26. ESP_LOGE(TAG, "memtrace_get_thread_entry: task is NULL");
  27. return NULL;
  28. }
  29. ESP_LOGD(TAG,"Looking for task %s",STR_OR_ALT(pcTaskGetName(task ), "unknown"));
  30. mem_usage_trace_for_thread_t* it;
  31. SLIST_FOREACH(it, &s_memtrace, next) {
  32. if ( it->task == task ) {
  33. ESP_LOGD(TAG,"Found task %s",STR_OR_ALT(pcTaskGetName(task ), "unknown"));
  34. return it;
  35. }
  36. }
  37. return NULL;
  38. }