heap_trace_tohost.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <sdkconfig.h>
  14. #define HEAP_TRACE_SRCFILE /* don't warn on inclusion here */
  15. #include "esp_heap_trace.h"
  16. #undef HEAP_TRACE_SRCFILE
  17. #if CONFIG_SYSVIEW_ENABLE
  18. #include "esp_app_trace.h"
  19. #include "esp_sysview_trace.h"
  20. #endif
  21. #define STACK_DEPTH CONFIG_HEAP_TRACING_STACK_DEPTH
  22. #ifdef CONFIG_HEAP_TRACING_TOHOST
  23. #if !CONFIG_SYSVIEW_ENABLE
  24. #error None of the heap tracing backends is enabled! You must enable SystemView compatible tracing to use this feature.
  25. #endif
  26. static bool s_tracing;
  27. esp_err_t heap_trace_init_tohost(void)
  28. {
  29. if (s_tracing) {
  30. return ESP_ERR_INVALID_STATE;
  31. }
  32. return ESP_OK;
  33. }
  34. esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
  35. {
  36. #if CONFIG_SYSVIEW_ENABLE
  37. esp_err_t ret = esp_sysview_heap_trace_start((uint32_t)-1);
  38. if (ret != ESP_OK) {
  39. return ret;
  40. }
  41. #endif
  42. s_tracing = true;
  43. return ESP_OK;
  44. }
  45. esp_err_t heap_trace_stop(void)
  46. {
  47. esp_err_t ret = ESP_ERR_NOT_SUPPORTED;
  48. #if CONFIG_SYSVIEW_ENABLE
  49. ret = esp_sysview_heap_trace_stop();
  50. #endif
  51. s_tracing = false;
  52. return ret;
  53. }
  54. esp_err_t heap_trace_resume(void)
  55. {
  56. return heap_trace_start(HEAP_TRACE_ALL);
  57. }
  58. size_t heap_trace_get_count(void)
  59. {
  60. return 0;
  61. }
  62. esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
  63. {
  64. return ESP_ERR_NOT_SUPPORTED;
  65. }
  66. void heap_trace_dump(void)
  67. {
  68. return;
  69. }
  70. /* Add a new allocation to the heap trace records */
  71. static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
  72. {
  73. if (!s_tracing) {
  74. return;
  75. }
  76. #if CONFIG_SYSVIEW_ENABLE
  77. esp_sysview_heap_trace_alloc(record->address, record->size, record->alloced_by);
  78. #endif
  79. }
  80. /* record a free event in the heap trace log
  81. For HEAP_TRACE_ALL, this means filling in the freed_by pointer.
  82. For HEAP_TRACE_LEAKS, this means removing the record from the log.
  83. */
  84. static IRAM_ATTR void record_free(void *p, void **callers)
  85. {
  86. if (!s_tracing) {
  87. return;
  88. }
  89. #if CONFIG_SYSVIEW_ENABLE
  90. esp_sysview_heap_trace_free(p, callers);
  91. #endif
  92. }
  93. #include "heap_trace.inc"
  94. #endif /*CONFIG_HEAP_TRACING_TOHOST*/