heap_trace_tohost.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <sdkconfig.h>
  7. #define HEAP_TRACE_SRCFILE /* don't warn on inclusion here */
  8. #include "esp_heap_trace.h"
  9. #undef HEAP_TRACE_SRCFILE
  10. #include "esp_heap_caps.h"
  11. #if CONFIG_APPTRACE_SV_ENABLE
  12. #include "esp_app_trace.h"
  13. #include "esp_sysview_trace.h"
  14. #endif
  15. #define STACK_DEPTH CONFIG_HEAP_TRACING_STACK_DEPTH
  16. #ifdef CONFIG_HEAP_TRACING_TOHOST
  17. #if !CONFIG_APPTRACE_SV_ENABLE
  18. #error None of the heap tracing backends is enabled! You must enable SystemView compatible tracing to use this feature.
  19. #endif
  20. static bool s_tracing;
  21. esp_err_t heap_trace_init_tohost(void)
  22. {
  23. if (s_tracing) {
  24. return ESP_ERR_INVALID_STATE;
  25. }
  26. return ESP_OK;
  27. }
  28. esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
  29. {
  30. #if CONFIG_APPTRACE_SV_ENABLE
  31. esp_err_t ret = esp_sysview_heap_trace_start((uint32_t)-1);
  32. if (ret != ESP_OK) {
  33. return ret;
  34. }
  35. #endif
  36. s_tracing = true;
  37. return ESP_OK;
  38. }
  39. esp_err_t heap_trace_stop(void)
  40. {
  41. esp_err_t ret = ESP_ERR_NOT_SUPPORTED;
  42. #if CONFIG_APPTRACE_SV_ENABLE
  43. ret = esp_sysview_heap_trace_stop();
  44. #endif
  45. s_tracing = false;
  46. return ret;
  47. }
  48. esp_err_t heap_trace_resume(void)
  49. {
  50. return heap_trace_start(HEAP_TRACE_ALL);
  51. }
  52. size_t heap_trace_get_count(void)
  53. {
  54. return 0;
  55. }
  56. esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
  57. {
  58. return ESP_ERR_NOT_SUPPORTED;
  59. }
  60. esp_err_t heap_trace_summary(heap_trace_summary_t *summary)
  61. {
  62. return ESP_ERR_NOT_SUPPORTED;
  63. }
  64. void heap_trace_dump(void)
  65. {
  66. return;
  67. }
  68. void heap_trace_dump_caps(__attribute__((unused)) const uint32_t caps)
  69. {
  70. return;
  71. }
  72. /* Add a new allocation to the heap trace records */
  73. static HEAP_IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
  74. {
  75. if (!s_tracing) {
  76. return;
  77. }
  78. #if CONFIG_APPTRACE_SV_ENABLE
  79. esp_sysview_heap_trace_alloc(record->address, record->size, record->alloced_by);
  80. #endif
  81. }
  82. /* record a free event in the heap trace log
  83. For HEAP_TRACE_ALL, this means filling in the freed_by pointer.
  84. For HEAP_TRACE_LEAKS, this means removing the record from the log.
  85. */
  86. static HEAP_IRAM_ATTR void record_free(void *p, void **callers)
  87. {
  88. if (!s_tracing) {
  89. return;
  90. }
  91. #if CONFIG_APPTRACE_SV_ENABLE
  92. esp_sysview_heap_trace_free(p, callers);
  93. #endif
  94. }
  95. #include "heap_trace.inc"
  96. #endif /*CONFIG_HEAP_TRACING_TOHOST*/