mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 09:25:54 +08:00
添加智能灯固件代码
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(sysview_tracing_heap_log)
|
||||
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := sysview_tracing_heap_log
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
# SystemView Heap and Log Tracing Example
|
||||
|
||||
Heap memory leaking is quite widespread software bug. IDF provides [heap tracing feature](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/heap_debug.html#heap-tracing) which allows to collect information related to heap operations (allocations/deallocations) and detect potential memory leaks. This feature can be used in two modes: standalone and host-based. In standalone mode collected data are kept on-board, so this mode is limited by avaialable memory in the system. Host-based mode does not have such limitation because collected data are sent to the host and can be analysed there using special tools. One of such tool is SEGGER SystemView. For description of [SystemView tracing feature](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/app_trace.html#system-behaviour-analysis-with-segger-systemview) please refer to **ESP32 Programming Guide**, section **Application Level Tracing library**. SystemView is also can be useful to show log message sent from the target.
|
||||
This example shows how to use this tool and IDF's scripts for host-based heap and log tracing analysis.
|
||||
|
||||
Consider the following situation. User program have two tasks. One task allocates memory and puts obtained addresses into the queue. Another task waits on that queue, reads sent pointers and frees memory. The first task queues only part of the pointers so some of the allocated blocks are not freed and become leaked. Both tasks uses IDF's logging API to report their actions. This example uses IDF's heap tracing module to record allocations and deallocations to detect memory leaks. Both heap tracing records and log mesages are redirected to the host.
|
||||
|
||||
## How to use example
|
||||
|
||||
### Hardware and tools required
|
||||
|
||||
This example does not require any special hardware, and can be run on any common development board.
|
||||
This example requires the following tools:
|
||||
1. [OpenOCD](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html#run-openocd).
|
||||
NOTE: In order to run this example you need OpenOCD version `v0.10.0-esp32-20190313` or later.
|
||||
|
||||
2. [GDB](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#setup-toolchain) can be used to start and/or stop tracing automatically. To do this you need to prepare special GDB command file. Having provided with `gdbinit` file from the example project directory GDB will connect to the target, reset it, start and stop tracing automatically.
|
||||
when program hits breakpoint at `heap_trace_start`. Trace data will be saved to `/tmp/hesp_log.svdat`. Tracing will be stopped when program hits breakpoint at `heap_trace_stop`.
|
||||
|
||||
3. [SEGGER SystemView tool](https://www.segger.com/products/development-tools/systemview/). By default SystemView shows only numeric values of IDs and parameters for IDF's heap messages in `Events` view. To make them pretty-looking you need to copy `SYSVIEW_FreeRTOS.txt` from the project's root directory to SystemView installation one.
|
||||
|
||||
### Build and flash
|
||||
|
||||
```
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(Replace PORT with serial port name.)
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
### Collect And View Trace Data
|
||||
|
||||
To run the example and collect trace data:
|
||||
|
||||
1. Run GDB using the following command from the project root directory:
|
||||
|
||||
```
|
||||
xtensa-esp32-elf-gdb -x gdbinit build/sysview_tracing_heap_log.elf
|
||||
```
|
||||
|
||||
2. When program stops at `heap_trace_stop` quit GDB.
|
||||
|
||||
3. Open trace data file in SystemView tool.
|
||||
|
||||
4. Now you can inspect all collected events. Log messages are shown in `Terminal` view.
|
||||
|
||||
5. You can filter out API related and heap events by right-clicking on any item in `Events` view and select `Show APIs only`.
|
||||
|
||||
### Auto-detect Heap Leaks
|
||||
|
||||
Since SystemView tool is mostly intended for OS level analysis. It allows just to inspect custom events' timestamps and parameters. So it can require some efforts to analyse heap operations flow. IDF provides special script to make the life a bit more easy. This script parses SystemView trace file sand reports detected memory leaks. The script also prints found log messages. To run it type the following from the project root directory:
|
||||
|
||||
```
|
||||
$IDF_PATH/tools/esp_app_trace/sysviewtrace_proc.py -p -b build/sysview_tracing_heap_log.elf /tmp/heap_log.svdat
|
||||
```
|
||||
|
||||
Below is the sample scripts output.
|
||||
|
||||
```
|
||||
[0.002272225] HEAP: Allocated 8 bytes @ 0x3ffaff6c from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:85
|
||||
/home/user/projects/esp/esp-idf/components/esp32/cpu_start.c:570
|
||||
|
||||
[0.002307300] HEAP: Allocated 2500 bytes @ 0x3ffb580c from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:804
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:84 (discriminator 2)
|
||||
|
||||
[0.002323775] HEAP: Allocated 356 bytes @ 0x3ffb61d4 from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:809
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:84 (discriminator 2)
|
||||
|
||||
[0.002427700] HEAP: Allocated 120 bytes @ 0x3ffaff78 from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/queue.c:391
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:46
|
||||
|
||||
[0.002471225] HEAP: Allocated 2500 bytes @ 0x3ffb633c from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:804
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:55
|
||||
|
||||
[0.002487725] HEAP: Allocated 356 bytes @ 0x3ffb6d04 from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:809
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:55
|
||||
|
||||
[0.002569725] HEAP: Allocated 2 bytes @ 0x3ffafff4 from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:59
|
||||
/home/user/projects/esp/esp-idf/components/freertos/port.c:145
|
||||
|
||||
[0.002835275] LOG: I (298) example: Task[0x3ffb61d4]: allocated 2 bytes @ 0x3ffafff4
|
||||
[0.002974600] LOG: I (299) example: Task[0x3ffb6d04]: free memory @ 0x3ffafff4
|
||||
|
||||
....
|
||||
|
||||
[2.942891550] LOG: I (3239) example: Task[0x3ffb7840]: allocated 396 bytes @ 0x3ffb9d08
|
||||
[2.943024150] LOG: I (3239) example: Task[0x3ffb6d04]: free memory @ 0x3ffb9c3c
|
||||
[2.943035600] HEAP: Freed bytes @ 0x3ffb9c3c from task "free0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:24 (discriminator 9)
|
||||
/home/user/projects/esp/esp-idf/components/freertos/port.c:145
|
||||
|
||||
[2.943212125] LOG: I (3239) example: Task[0x3ffb83ec]: free memory @ 0x3ffb9d08
|
||||
[2.943223500] HEAP: Freed bytes @ 0x3ffb9d08 from task "free1" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:24 (discriminator 9)
|
||||
/home/user/projects/esp/esp-idf/components/freertos/port.c:145
|
||||
|
||||
[2.943649025] HEAP: Allocated 594 bytes @ 0x3ffb9c3c from task "alloc2" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:59
|
||||
/home/user/projects/esp/esp-idf/components/freertos/port.c:145
|
||||
|
||||
[2.943734250] LOG: I (3240) example: Task[0x3ffb8f28]: allocated 594 bytes @ 0x3ffb9c3c
|
||||
[2.943867850] LOG: I (3240) example: Task[0x3ffb9ad4]: free memory @ 0x3ffb9c3c
|
||||
[2.943879200] HEAP: Freed bytes @ 0x3ffb9c3c from task "free2" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:24 (discriminator 9)
|
||||
/home/user/projects/esp/esp-idf/components/freertos/port.c:145
|
||||
|
||||
[2.972813425] LOG: I (3269) example: Got notify val 2
|
||||
[2.972870400] LOG: I (3269) example: Wait notify 1
|
||||
[2.972932800] LOG: I (3269) example: Got notify val 1
|
||||
[2.972989825] LOG: I (3269) example: Wait notify 2
|
||||
[2.973756125] LOG: I (3270) example: Got notify val 1
|
||||
Processed 13467 events
|
||||
=============== LOG TRACE REPORT ===============
|
||||
Processed 600 log messages.
|
||||
=============== HEAP TRACE REPORT ===============
|
||||
Processed 612 heap events.
|
||||
[0.002272225] HEAP: Allocated 8 bytes @ 0x3ffaff6c from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:85
|
||||
/home/user/projects/esp/esp-idf/components/esp32/cpu_start.c:570
|
||||
|
||||
[0.002307300] HEAP: Allocated 2500 bytes @ 0x3ffb580c from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:804
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:84 (discriminator 2)
|
||||
|
||||
[0.002323775] HEAP: Allocated 356 bytes @ 0x3ffb61d4 from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:809
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:84 (discriminator 2)
|
||||
|
||||
[0.002427700] HEAP: Allocated 120 bytes @ 0x3ffaff78 from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/queue.c:391
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:46
|
||||
|
||||
[0.002471225] HEAP: Allocated 2500 bytes @ 0x3ffb633c from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:804
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:55
|
||||
|
||||
[0.002487725] HEAP: Allocated 356 bytes @ 0x3ffb6d04 from task "alloc0" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:809
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:55
|
||||
|
||||
[0.003102175] HEAP: Allocated 8 bytes @ 0x3ffb6e6c from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:85
|
||||
/home/user/projects/esp/esp-idf/components/esp32/cpu_start.c:570
|
||||
|
||||
....
|
||||
|
||||
[0.003713175] HEAP: Allocated 356 bytes @ 0x3ffb8f28 from task "main" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:809
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:84 (discriminator 2)
|
||||
|
||||
[0.003814375] HEAP: Allocated 120 bytes @ 0x3ffb9090 from task "alloc2" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/queue.c:391
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:46
|
||||
|
||||
[0.003845875] HEAP: Allocated 2500 bytes @ 0x3ffb910c from task "alloc2" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:804
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:55
|
||||
|
||||
[0.003862350] HEAP: Allocated 356 bytes @ 0x3ffb9ad4 from task "alloc2" on core 0 by:
|
||||
/home/user/projects/esp/esp-idf/components/freertos/tasks.c:809
|
||||
/home/user/projects/esp/esp-idf/examples/system/sysview_tracing_heap_log/build/../main/sysview_heap_log.c:55
|
||||
|
||||
Found 17520 leaked bytes in 18 blocks.
|
||||
```
|
||||
@@ -0,0 +1,107 @@
|
||||
128 vTaskAllocateMPURegions xTask=%t pxRegions=%u
|
||||
33 vTaskDelete xTaskToDelete=%t
|
||||
34 vTaskDelay xTicksToDelay=%u
|
||||
35 vTaskDelayUntil
|
||||
129 uxTaskPriorityGet xTask=%t
|
||||
56 uxTaskPriorityGetFromISR xTask=%t
|
||||
130 eTaskGetState xTask=%t
|
||||
55 vTaskPrioritySet xTask=%t uxNewPriority=%u
|
||||
36 vTaskSuspend xTaskToSuspend=%t
|
||||
40 vTaskResume xTaskToResume=%t
|
||||
43 xTaskResumeFromISR xTaskToResume=%t
|
||||
131 vTaskStartScheduler
|
||||
132 vTaskEndScheduler
|
||||
133 vTaskSuspendAll
|
||||
134 xTaskResumeAll
|
||||
135 xTaskGetTickCount
|
||||
57 xTaskGetTickCountFromISR
|
||||
136 uxTaskGetNumberOfTasks
|
||||
137 pcTaskGetTaskName xTaskToQuery=%t
|
||||
138 uxTaskGetStackHighWaterMark xTask=%t
|
||||
139 vTaskSetApplicationTaskTag xTask=%t pxHookFunction=%u
|
||||
140 xTaskGetApplicationTaskTag xTask=%t
|
||||
141 vTaskSetThreadLocalStoragePointer xTaskToSet=%T xIndex=%u pvValue=%u
|
||||
142 pvTaskGetThreadLocalStoragePointer xTaskToQuery=%T xIndex=%u
|
||||
143 xTaskCallApplicationTaskHook xTask=%T pvParameter=%u
|
||||
144 xTaskGetIdleTaskHandle
|
||||
145 uxTaskGetSystemState pxTaskStatusArray=%u uxArraySize=%u pulTotalRunTime=%u
|
||||
146 vTaskList pcWriteBuffer=%u
|
||||
147 vTaskGetRunTimeStats pcWriteBuffer=%u
|
||||
44 xTaskGenericNotify xTaskToNotify=%t ulValue=%u eAction=%u pulPreviousNotificationValue=%u
|
||||
45 xTaskGenericNotifyFromISR xTaskToNotify=%t ulValue=%u eAction=%u pulPreviousNotificationValue=%u pxHigherPriorityTaskWoken=%u
|
||||
46 xTaskNotifyWait ulBitsToClearOnEntry=%u ulBitsToClearOnExit=%u pulNotificationValue=%u xTicksToWait=%u
|
||||
38 vTaskNotifyGiveFromISR xTaskToNotify=%t pxHigherPriorityTaskWoken=%u
|
||||
37 ulTaskNotifyTake xClearCountOnExit=%u xTicksToWait=%u
|
||||
148 xTaskNotifyStateClear xTask=%t
|
||||
149 xTaskGetCurrentTaskHandle
|
||||
150 vTaskSetTimeOutState pxTimeOut=%u
|
||||
151 xTaskCheckForTimeOut pxTimeOut=%u pxTicksToWait=%u
|
||||
152 vTaskMissedYield
|
||||
153 xTaskGetSchedulerState
|
||||
39 vTaskPriorityInherit pxMutexHolder=%p
|
||||
42 xTaskPriorityDisinherit pxMutexHolder=%p
|
||||
154 xTaskGenericCreate pxTaskCode=%u pcName=%u usStackDepth=%u pvParameters=%u uxPriority=%u pxCreatedTask=%u puxStackBuffer=%u xRegions=%u
|
||||
155 uxTaskGetTaskNumber xTask=%u
|
||||
156 vTaskSetTaskNumber xTask=%u uxHandle=%u
|
||||
41 vTaskStepTick xTicksToJump=%u
|
||||
157 eTaskConfirmSleepModeStatus
|
||||
158 xTimerCreate pcTimerName=%u xTimerPeriodInTicks=%u uxAutoReload=%u pvTimerID=%u pxCallbackFunction=%u
|
||||
159 pvTimerGetTimerID xTimer=%u
|
||||
160 vTimerSetTimerID xTimer=%u pvNewID=%u
|
||||
161 xTimerIsTimerActive xTimer=%u
|
||||
162 xTimerGetTimerDaemonTaskHandle
|
||||
163 xTimerPendFunctionCallFromISR xFunctionToPend=%u pvParameter1=%u ulParameter2=%u pxHigherPriorityTaskWoken=%u
|
||||
164 xTimerPendFunctionCall xFunctionToPend=%u pvParameter1=%u ulParameter2=%u xTicksToWait=%u
|
||||
165 pcTimerGetTimerName xTimer=%u
|
||||
166 xTimerCreateTimerTask
|
||||
167 xTimerGenericCommand xTimer=%u xCommandID=%u xOptionalValue=%u pxHigherPriorityTaskWoken=%u xTicksToWait=%u
|
||||
53 xQueueGenericSend xQueue=%I pvItemToQueue=%p xTicksToWait=%u xCopyPosition=%u
|
||||
50 xQueuePeekFromISR xQueue=%I pvBuffer=%p
|
||||
49 xQueueGenericReceive xQueue=%I pvBuffer=%p xTicksToWait=%u xJustPeek=%u
|
||||
168 uxQueueMessagesWaiting xQueue=%I
|
||||
169 uxQueueSpacesAvailable xQueue=%I
|
||||
48 vQueueDelete xQueue=%I
|
||||
54 xQueueGenericSendFromISR xQueue=%I pvItemToQueue=%p pxHigherPriorityTaskWoken=%u xCopyPosition=%u
|
||||
61 xQueueGiveFromISR xQueue=%I pxHigherPriorityTaskWoken=%u
|
||||
51 xQueueReceiveFromISR xQueue=%I pvBuffer=%p pxHigherPriorityTaskWoken=%u
|
||||
62 xQueueIsQueueEmptyFromISR xQueue=%I
|
||||
63 xQueueIsQueueFullFromISR xQueue=%I
|
||||
170 uxQueueMessagesWaitingFromISR xQueue=%I
|
||||
171 xQueueAltGenericSend xQueue=%I pvItemToQueue=%p xTicksToWait=%u xCopyPosition=%u
|
||||
172 xQueueAltGenericReceive xQueue=%I pvBuffer=%p xTicksToWait=%u xJustPeeking=%u
|
||||
173 xQueueCRSendFromISR xQueue=%I pvItemToQueue=%p xCoRoutinePreviouslyWoken=%u
|
||||
174 xQueueCRReceiveFromISR xQueue=%I pvBuffer=%p pxTaskWoken=%u
|
||||
175 xQueueCRSend xQueue=%I pvItemToQueue=%p xTicksToWait=%u
|
||||
176 xQueueCRReceive xQueue=%I pvBuffer=%p xTicksToWait=%u
|
||||
177 xQueueCreateMutex ucQueueType=%u
|
||||
178 xQueueCreateCountingSemaphore uxMaxCount=%u uxInitialCount=%u
|
||||
179 xQueueGetMutexHolder xSemaphore=%u
|
||||
180 xQueueTakeMutexRecursive xMutex=%u xTicksToWait=%u
|
||||
181 xQueueGiveMutexRecursive pxMutex=%u
|
||||
52 vQueueAddToRegistry xQueue=%I pcName=%u
|
||||
182 vQueueUnregisterQueue xQueue=%I
|
||||
47 xQueueGenericCreate uxQueueLength=%u uxItemSize=%u ucQueueType=%u
|
||||
183 xQueueCreateSet uxEventQueueLength=%u
|
||||
184 xQueueAddToSet xQueueOrSemaphore=%u xQueueSet=%u
|
||||
185 xQueueRemoveFromSet xQueueOrSemaphore=%u xQueueSet=%u
|
||||
186 xQueueSelectFromSet xQueueSet=%u xTicksToWait=%u
|
||||
187 xQueueSelectFromSetFromISR xQueueSet=%u
|
||||
188 xQueueGenericReset xQueue=%I xNewQueue=%u
|
||||
189 vListInitialise pxList=%u
|
||||
190 vListInitialiseItem pxItem=%u
|
||||
191 vListInsert pxList=%u pxNewListItem=%u
|
||||
192 vListInsertEnd pxList=%u pxNewListItem=%u
|
||||
193 uxListRemove pxItemToRemove=%u
|
||||
194 xEventGroupCreate
|
||||
195 xEventGroupWaitBits xEventGroup=%u uxBitsToWaitFor=%u xClearOnExit=%u xWaitForAllBits=%u xTicksToWait=%u
|
||||
196 xEventGroupClearBits xEventGroup=%u uxBitsToClear=%u
|
||||
58 xEventGroupClearBitsFromISR xEventGroup=%u uxBitsToSet=%u
|
||||
197 xEventGroupSetBits xEventGroup=%u uxBitsToSet=%u
|
||||
59 xEventGroupSetBitsFromISR xEventGroup=%u uxBitsToSet=%u pxHigherPriorityTaskWoken=%u
|
||||
198 xEventGroupSync xEventGroup=%u uxBitsToSet=%u uxBitsToWaitFor=%u xTicksToWait=%u
|
||||
60 xEventGroupGetBitsFromISR xEventGroup=%u
|
||||
199 vEventGroupDelete xEventGroup=%u
|
||||
200 uxEventGroupGetNumber xEventGroup=%u
|
||||
|
||||
512 esp_sysview_heap_trace_alloc addr=%p size=%u callers=%x
|
||||
513 esp_sysview_heap_trace_free addr=%p callers=%x
|
||||
@@ -0,0 +1,59 @@
|
||||
from __future__ import unicode_literals
|
||||
from io import open
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
def test_examples_sysview_tracing_heap_log(env, extra_data):
|
||||
|
||||
rel_project_path = os.path.join('examples', 'system', 'sysview_tracing_heap_log')
|
||||
dut = env.get_dut('sysview_tracing_heap_log', rel_project_path)
|
||||
idf_path = dut.app.get_sdk_path()
|
||||
proj_path = os.path.join(idf_path, rel_project_path)
|
||||
elf_path = os.path.join(dut.app.get_binary_path(rel_project_path), 'sysview_tracing_heap_log.elf')
|
||||
|
||||
def get_temp_file():
|
||||
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||
return f.name
|
||||
|
||||
try:
|
||||
tempfiles = [get_temp_file(), get_temp_file()]
|
||||
|
||||
with open(os.path.join(proj_path, 'gdbinit')) as f_in, open(tempfiles[0], 'w') as f_out:
|
||||
new_content = f_in.read()
|
||||
# localhost connection issue occurs in docker unless:
|
||||
new_content = new_content.replace(':3333', '127.0.0.1:3333', 1)
|
||||
new_content = new_content.replace('file:///tmp/heap_log.svdat', 'file://{}'.format(tempfiles[1]), 1)
|
||||
f_out.write(new_content)
|
||||
|
||||
with ttfw_idf.OCDProcess(os.path.join(proj_path, 'openocd.log')):
|
||||
dut.start_app()
|
||||
dut.expect('esp_apptrace: Initialized TRAX on CPU0')
|
||||
|
||||
gdb_args = '-x {} --directory={}'.format(tempfiles[0], os.path.join(proj_path, 'main'))
|
||||
with ttfw_idf.GDBProcess(os.path.join(proj_path, 'gdb.log'), elf_path, dut.app.target, gdb_args) as gdb:
|
||||
gdb.pexpect_proc.expect_exact('Thread 1 hit Temporary breakpoint 2, heap_trace_stop ()')
|
||||
gdb.pexpect_proc.expect_exact('(gdb)')
|
||||
|
||||
# dut has been restarted by gdb since the last dut.expect()
|
||||
dut.expect('esp_apptrace: Initialized TRAX on CPU0')
|
||||
|
||||
with ttfw_idf.CustomProcess(' '.join([os.path.join(idf_path, 'tools/esp_app_trace/sysviewtrace_proc.py'),
|
||||
'-p',
|
||||
'-b', elf_path,
|
||||
tempfiles[1]]),
|
||||
logfile='sysviewtrace_proc.log') as sysviewtrace:
|
||||
sysviewtrace.pexpect_proc.expect(re.compile(r'Found \d+ leaked bytes in \d+ blocks.'), timeout=120)
|
||||
finally:
|
||||
for x in tempfiles:
|
||||
try:
|
||||
os.unlink(x)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_sysview_tracing_heap_log()
|
||||
@@ -0,0 +1,18 @@
|
||||
set pagination off
|
||||
target remote :3333
|
||||
|
||||
mon reset halt
|
||||
flushregs
|
||||
|
||||
tb heap_trace_start
|
||||
commands
|
||||
mon esp sysview start file:///tmp/heap_log.svdat
|
||||
c
|
||||
end
|
||||
|
||||
tb heap_trace_stop
|
||||
commands
|
||||
mon esp sysview stop
|
||||
end
|
||||
|
||||
c
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "sysview_heap_log.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,3 @@
|
||||
#
|
||||
# Main Makefile. This is basically the same as a component makefile.
|
||||
#
|
||||
@@ -0,0 +1,103 @@
|
||||
/* Application Trace to Host Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include "esp_sysview_trace.h"
|
||||
#include "esp_heap_trace.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
|
||||
static const char *TAG = "example";
|
||||
|
||||
// waits on queue for memory addresses and frees memory allocated by 'alloc_task'
|
||||
static void free_task(void *p)
|
||||
{
|
||||
QueueHandle_t queue = (QueueHandle_t)p;
|
||||
while (1) {
|
||||
void *p = NULL;
|
||||
if (xQueueReceive(queue, ( void * )&p, portMAX_DELAY) != pdPASS) {
|
||||
ESP_LOGE(TAG, "Failed to send to queue!");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Task[%p]: free memory @ %p", xTaskGetCurrentTaskHandle(), p);
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct alloc_args {
|
||||
int idx;
|
||||
TaskHandle_t waiter;
|
||||
};
|
||||
|
||||
// allocates memory and puts addresses to the queue
|
||||
static void alloc_task(void *p)
|
||||
{
|
||||
struct alloc_args *task_args = (struct alloc_args *)p;
|
||||
char task_name[20];
|
||||
|
||||
QueueHandle_t queue = xQueueCreate(10, sizeof(void *));
|
||||
if(queue == 0) {
|
||||
ESP_LOGE(TAG, "Failed to create queue!");
|
||||
return;
|
||||
}
|
||||
snprintf(task_name, sizeof(task_name), "free%d", task_args->idx);
|
||||
xTaskCreatePinnedToCore(free_task, task_name, 2500, queue, 5, NULL, portNUM_PROCESSORS-1);
|
||||
|
||||
// here GDB will stop at brekpoint and execute OpenOCD command to start tracing
|
||||
for(int i = 1; i < 100; i++) {
|
||||
uint32_t sz = 2*i*(task_args->idx + 1);
|
||||
void *p = malloc(sz/2);
|
||||
// WARNING: the previous allocated memory is intentionally not deallocated in order to cause memory leak!
|
||||
p = malloc(sz);
|
||||
ESP_LOGI(TAG, "Task[%p]: allocated %d bytes @ %p", xTaskGetCurrentTaskHandle(), sz, p);
|
||||
if (xQueueSend(queue, ( void * )&p, portMAX_DELAY) != pdPASS) {
|
||||
ESP_LOGE(TAG, "Failed to send to queue!");
|
||||
}
|
||||
vTaskDelay(30/portTICK_PERIOD_MS);
|
||||
}
|
||||
xTaskNotifyGive(task_args->waiter);
|
||||
while(1){
|
||||
vTaskDelay(100/portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
const int num_allocers = 3;
|
||||
char task_name[20];
|
||||
// redirect log messages to the host using SystemView tracing module
|
||||
esp_log_set_vprintf(&esp_sysview_vprintf);
|
||||
// init host-based heap tracing
|
||||
if(heap_trace_init_tohost() != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to init heap trace!");
|
||||
return;
|
||||
}
|
||||
heap_trace_start(HEAP_TRACE_ALL);
|
||||
for (int i = 0; i < num_allocers; i++) {
|
||||
struct alloc_args *task_args = malloc(sizeof(struct alloc_args));
|
||||
if (task_args == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to alloc task args!");
|
||||
heap_trace_stop();
|
||||
return;
|
||||
}
|
||||
task_args->idx = i;
|
||||
task_args->waiter = xTaskGetCurrentTaskHandle();
|
||||
snprintf(task_name, sizeof(task_name), "alloc%d", i);
|
||||
xTaskCreatePinnedToCore(alloc_task, task_name, 2500, task_args, 5, NULL, 0);
|
||||
}
|
||||
for (int i = 0; i < num_allocers; i++) {
|
||||
ESP_LOGI(TAG, "Wait notify %d", i);
|
||||
uint32_t val = ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
ESP_LOGI(TAG, "Got notify val %d", val);
|
||||
}
|
||||
// here GDB will stop at brekpoint and execute OpenOCD command to stop tracing
|
||||
heap_trace_stop();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
# Enable single core mode by default
|
||||
CONFIG_MEMMAP_SMP=n
|
||||
CONFIG_FREERTOS_UNICORE=y
|
||||
# 1ms tick period
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
# Enable application tracing by default
|
||||
CONFIG_APPTRACE_DEST_TRAX=y
|
||||
CONFIG_APPTRACE_ENABLE=y
|
||||
# Enable FreeRTOS SystemView Tracing by default
|
||||
CONFIG_SYSVIEW_ENABLE=y
|
||||
CONFIG_SYSVIEW_TS_SOURCE_TIMER_00=y
|
||||
CONFIG_SYSVIEW_EVT_OVERFLOW_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_ISR_ENTER_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_ISR_EXIT_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_ISR_TO_SCHEDULER_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TASK_START_EXEC_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TASK_STOP_EXEC_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TASK_START_READY_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TASK_STOP_READY_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TASK_CREATE_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TASK_TERMINATE_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_IDLE_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TIMER_ENTER_ENABLE=y
|
||||
CONFIG_SYSVIEW_EVT_TIMER_EXIT_ENABLE=y
|
||||
# Disable color output in logs
|
||||
CONFIG_LOG_COLORS=n
|
||||
# Enable heap tracing to host
|
||||
CONFIG_HEAP_TRACING_TOHOST=y
|
||||
CONFIG_HEAP_TRACING_STACK_DEPTH=10
|
||||
Reference in New Issue
Block a user