1 /* 2 * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef ESP_SYSVIEW_TRACE_H_ 7 #define ESP_SYSVIEW_TRACE_H_ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include <stdarg.h> 14 #include "esp_err.h" 15 #include "SEGGER_RTT.h" // SEGGER_RTT_ESP_Flush 16 #include "esp_app_trace_util.h" // ESP_APPTRACE_TMO_INFINITE 17 18 /** 19 * @brief Flushes remaining data in SystemView trace buffer to host. 20 * 21 * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly. 22 * 23 * @return ESP_OK. 24 */ esp_sysview_flush(uint32_t tmo)25static inline esp_err_t esp_sysview_flush(uint32_t tmo) 26 { 27 SEGGER_RTT_ESP_Flush(0, tmo); 28 return ESP_OK; 29 } 30 31 /** 32 * @brief vprintf-like function to sent log messages to the host. 33 * 34 * @param format Address of format string. 35 * @param args List of arguments. 36 * 37 * @return Number of bytes written. 38 */ 39 int esp_sysview_vprintf(const char * format, va_list args); 40 41 /** 42 * @brief Starts SystemView heap tracing. 43 * 44 * @param tmo Timeout (in us) to wait for the host to be connected. Use -1 to wait forever. 45 * 46 * @return ESP_OK on success, ESP_ERR_TIMEOUT if operation has been timed out. 47 */ 48 esp_err_t esp_sysview_heap_trace_start(uint32_t tmo); 49 50 /** 51 * @brief Stops SystemView heap tracing. 52 * 53 * @return ESP_OK. 54 */ 55 esp_err_t esp_sysview_heap_trace_stop(void); 56 57 /** 58 * @brief Sends heap allocation event to the host. 59 * 60 * @param addr Address of allocated block. 61 * @param size Size of allocated block. 62 * @param callers Pointer to array with callstack addresses. 63 * Array size must be CONFIG_HEAP_TRACING_STACK_DEPTH. 64 */ 65 void esp_sysview_heap_trace_alloc(void *addr, uint32_t size, const void *callers); 66 67 /** 68 * @brief Sends heap de-allocation event to the host. 69 * 70 * @param addr Address of de-allocated block. 71 * @param callers Pointer to array with callstack addresses. 72 * Array size must be CONFIG_HEAP_TRACING_STACK_DEPTH. 73 */ 74 void esp_sysview_heap_trace_free(void *addr, const void *callers); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 #endif //ESP_SYSVIEW_TRACE_H_ 81