heap_trace_tohost.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * SPDX-FileCopyrightText: 2018-2021 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. #if CONFIG_APPTRACE_SV_ENABLE
  11. #include "esp_app_trace.h"
  12. #include "esp_sysview_trace.h"
  13. #endif
  14. #define STACK_DEPTH CONFIG_HEAP_TRACING_STACK_DEPTH
  15. #ifdef CONFIG_HEAP_TRACING_TOHOST
  16. #if !CONFIG_APPTRACE_SV_ENABLE
  17. #error None of the heap tracing backends is enabled! You must enable SystemView compatible tracing to use this feature.
  18. #endif
  19. static bool s_tracing;
  20. esp_err_t heap_trace_init_tohost(void)
  21. {
  22. if (s_tracing) {
  23. return ESP_ERR_INVALID_STATE;
  24. }
  25. return ESP_OK;
  26. }
  27. esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
  28. {
  29. #if CONFIG_APPTRACE_SV_ENABLE
  30. esp_err_t ret = esp_sysview_heap_trace_start((uint32_t)-1);
  31. if (ret != ESP_OK) {
  32. return ret;
  33. }
  34. #endif
  35. s_tracing = true;
  36. return ESP_OK;
  37. }
  38. esp_err_t heap_trace_stop(void)
  39. {
  40. esp_err_t ret = ESP_ERR_NOT_SUPPORTED;
  41. #if CONFIG_APPTRACE_SV_ENABLE
  42. ret = esp_sysview_heap_trace_stop();
  43. #endif
  44. s_tracing = false;
  45. return ret;
  46. }
  47. esp_err_t heap_trace_resume(void)
  48. {
  49. return heap_trace_start(HEAP_TRACE_ALL);
  50. }
  51. size_t heap_trace_get_count(void)
  52. {
  53. return 0;
  54. }
  55. esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
  56. {
  57. return ESP_ERR_NOT_SUPPORTED;
  58. }
  59. void heap_trace_dump(void)
  60. {
  61. return;
  62. }
  63. /* Add a new allocation to the heap trace records */
  64. static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
  65. {
  66. if (!s_tracing) {
  67. return;
  68. }
  69. #if CONFIG_APPTRACE_SV_ENABLE
  70. esp_sysview_heap_trace_alloc(record->address, record->size, record->alloced_by);
  71. #endif
  72. }
  73. /* record a free event in the heap trace log
  74. For HEAP_TRACE_ALL, this means filling in the freed_by pointer.
  75. For HEAP_TRACE_LEAKS, this means removing the record from the log.
  76. */
  77. static IRAM_ATTR void record_free(void *p, void **callers)
  78. {
  79. if (!s_tracing) {
  80. return;
  81. }
  82. #if CONFIG_APPTRACE_SV_ENABLE
  83. esp_sysview_heap_trace_free(p, callers);
  84. #endif
  85. }
  86. #include "heap_trace.inc"
  87. #endif /*CONFIG_HEAP_TRACING_TOHOST*/