Fix heap tracing function scope issues

- Add extern \C\ linkage to heap tracing functions
- Forward declare the functions in the API server implementation
- Ensures the heap tracing functions are accessible from any namespace
This commit is contained in:
J. Nick Koston 2025-05-08 15:29:11 -05:00
parent 35238c1437
commit 00e128bdd5
No known key found for this signature in database
2 changed files with 12 additions and 3 deletions

View File

@ -221,18 +221,19 @@ async def to_code(config):
) )
) )
# Add helper functions for heap tracing # Add helper functions for heap tracing with extern "C" to make them globally accessible
cg.add_global( cg.add_global(
cg.RawStatement( cg.RawStatement(
""" """
void start_heap_trace() { // Global heap tracing functions that can be called from any context
extern "C" void start_heap_trace() {
heap_trace_init_standalone(trace_record, """ heap_trace_init_standalone(trace_record, """
+ str(num_records) + str(num_records)
+ """); + """);
heap_trace_start(HEAP_TRACE_LEAKS); heap_trace_start(HEAP_TRACE_LEAKS);
} }
void stop_and_dump_heap_trace() { extern "C" void stop_and_dump_heap_trace() {
heap_trace_stop(); heap_trace_stop();
heap_trace_dump(); heap_trace_dump();
} }

View File

@ -14,6 +14,14 @@
#include "esphome/components/logger/logger.h" #include "esphome/components/logger/logger.h"
#endif #endif
#ifdef USE_API_HEAP_TRACE
#include "esp_heap_trace.h"
// Forward declare heap tracing functions that will be used in the API class
extern "C" void start_heap_trace();
extern "C" void stop_and_dump_heap_trace();
#endif
#include <algorithm> #include <algorithm>
namespace esphome { namespace esphome {