Skip to content

Commit 8e19ee4

Browse files
committed
Merge branch 'docs/synchronize_cn_heap_debug' into 'master'
docs: Update CN translation for heap_debug.rst Closes DOC-10169 See merge request espressif/esp-idf!36779
2 parents c776de6 + 03840f4 commit 8e19ee4

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

docs/en/api-reference/system/heap_debug.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Heap Allocation and Free Function Hooks
3232

3333
Users can use allocation and free detection hooks to be notified of every successful allocation and free operation:
3434

35-
- Providing a definition of :cpp:func:`esp_heap_trace_alloc_hook` allows you to be notified of every successful memory allocation operation
36-
- Providing a definition of :cpp:func:`esp_heap_trace_free_hook` allows you to be notified of every successful memory-free operations
35+
- Providing a definition of :cpp:func:`esp_heap_trace_alloc_hook` allows you to be notified of every successful memory allocation operation.
36+
- Providing a definition of :cpp:func:`esp_heap_trace_free_hook` allows you to be notified of every successful memory-free operations.
3737

3838
This feature can be enabled by setting the :ref:`CONFIG_HEAP_USE_HOOKS` option. :cpp:func:`esp_heap_trace_alloc_hook` and :cpp:func:`esp_heap_trace_free_hook` have weak declarations (e.g., ``__attribute__((weak))``), thus it is not necessary to provide declarations for both hooks. Given that it is technically possible to allocate and free memory from an ISR (**though strongly discouraged from doing so**), the :cpp:func:`esp_heap_trace_alloc_hook` and :cpp:func:`esp_heap_trace_free_hook` can potentially be called from an ISR.
3939

docs/zh_CN/api-reference/system/heap_debug.rst

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ ESP-IDF 集成了用于请求 :ref:`堆内存信息 <heap-information>`、:ref:`
3232

3333
你可以使用堆内存分配和释放检测钩子,接收每次成功分配或释放堆内存操作的通知:
3434

35-
- 定义 :cpp:func:`esp_heap_trace_alloc_hook` 获取堆内存分配操作成功的提示
36-
- 定义 :cpp:func:`esp_heap_trace_free_hook` 获取堆内存释放操作成功的提示
35+
- 定义 :cpp:func:`esp_heap_trace_alloc_hook` 获取堆内存分配操作成功的提示
36+
- 定义 :cpp:func:`esp_heap_trace_free_hook` 获取堆内存释放操作成功的提示
3737

3838
要启用此功能,请设置 :ref:`CONFIG_HEAP_USE_HOOKS` 选项。:cpp:func:`esp_heap_trace_alloc_hook` 和 :cpp:func:`esp_heap_trace_free_hook` 具有弱声明(即 ``__attribute__((weak))``),因此无需为这两个钩子提供声明。鉴于从 ISR 中分配和释放堆内存在技术上是可行的(**但强烈不建议**),:cpp:func:`esp_heap_trace_alloc_hook` 和 :cpp:func:`esp_heap_trace_free_hook` 可能会从 ISR 中调用。
3939

@@ -267,12 +267,33 @@ ESP-IDF 集成了用于请求 :ref:`堆内存信息 <heap-information>`、:ref:`
267267
...
268268
}
269269
270-
堆内存跟踪堆输出将类似以下格式的内容
270+
堆内存跟踪会输出类似以下格式的内容
271271

272-
.. only:: CONFIG_IDF_TARGET_ARCH_XTENSA
272+
.. only:: CONFIG_IDF_TARGET_ARCH_RISCV
273273

274274
.. code-block:: none
275275
276+
====== Heap Trace: 8 records (8 capacity) ======
277+
3 bytes (@ 0x3fcb26f8, Internal) allocated CPU 0 ccount 0x1e7af728 freed
278+
6 bytes (@ 0x3fcb4ff0, Internal) allocated CPU 0 ccount 0x1e7afc38 freed
279+
9 bytes (@ 0x3fcb5000, Internal) allocated CPU 0 ccount 0x1e7b01d4 freed
280+
12 bytes (@ 0x3fcb5010, Internal) allocated CPU 0 ccount 0x1e7b0778 freed
281+
15 bytes (@ 0x3fcb5020, Internal) allocated CPU 0 ccount 0x1e7b0d18 freed
282+
18 bytes (@ 0x3fcb5034, Internal) allocated CPU 0 ccount 0x1e7b12b8 freed
283+
21 bytes (@ 0x3fcb504c, Internal) allocated CPU 0 ccount 0x1e7b1858 freed
284+
24 bytes (@ 0x3fcb5068, Internal) allocated CPU 0 ccount 0x1e7b1dfc freed
285+
====== Heap Trace Summary ======
286+
Mode: Heap Trace All
287+
0 bytes alive in trace (0/8 allocations)
288+
records: 8 (8 capacity, 8 high water mark)
289+
total allocations: 8
290+
total frees: 8
291+
================================
292+
293+
或者,启用了 ``CONFIG_ESP_SYSTEM_USE_FRAME_POINTER`` 选项并且正确配置了栈深度,会输出以下内容:
294+
295+
.. code-block:: none
296+
276297
====== Heap Trace: 8 records (8 capacity) ======
277298
6 bytes (@ 0x3fc9f620, Internal) allocated CPU 0 ccount 0x1a31ac84 caller 0x40376321:0x40376379
278299
0x40376321: heap_caps_malloc at /path/to/idf/examples/components/heap/heap_caps.c:84
@@ -342,27 +363,6 @@ ESP-IDF 集成了用于请求 :ref:`堆内存信息 <heap-information>`、:ref:`
342363
total frees: 8
343364
================================
344365
345-
.. only:: CONFIG_IDF_TARGET_ARCH_RISCV
346-
347-
.. code-block:: none
348-
349-
====== Heap Trace: 8 records (8 capacity) ======
350-
3 bytes (@ 0x3fcb26f8, Internal) allocated CPU 0 ccount 0x1e7af728 freed
351-
6 bytes (@ 0x3fcb4ff0, Internal) allocated CPU 0 ccount 0x1e7afc38 freed
352-
9 bytes (@ 0x3fcb5000, Internal) allocated CPU 0 ccount 0x1e7b01d4 freed
353-
12 bytes (@ 0x3fcb5010, Internal) allocated CPU 0 ccount 0x1e7b0778 freed
354-
15 bytes (@ 0x3fcb5020, Internal) allocated CPU 0 ccount 0x1e7b0d18 freed
355-
18 bytes (@ 0x3fcb5034, Internal) allocated CPU 0 ccount 0x1e7b12b8 freed
356-
21 bytes (@ 0x3fcb504c, Internal) allocated CPU 0 ccount 0x1e7b1858 freed
357-
24 bytes (@ 0x3fcb5068, Internal) allocated CPU 0 ccount 0x1e7b1dfc freed
358-
====== Heap Trace Summary ======
359-
Mode: Heap Trace All
360-
0 bytes alive in trace (0/8 allocations)
361-
records: 8 (8 capacity, 8 high water mark)
362-
total allocations: 8
363-
total frees: 8
364-
================================
365-
366366
.. note::
367367

368368
以上示例输出使用 :doc:`IDF 监视器 </api-guides/tools/idf-monitor>`,自动将 PC 地址解码为其源文件和行号。
@@ -396,6 +396,10 @@ ESP-IDF 集成了用于请求 :ref:`堆内存信息 <heap-information>`、:ref:`
396396

397397
每个跟踪条目记录的调用栈深度可以在项目配置菜单下进行配置,选择 ``Heap Memory Debugging`` > ``Enable heap tracing`` > :ref:`CONFIG_HEAP_TRACING_STACK_DEPTH`。每个内存分配最多可以记录 32 个栈帧(默认为 2),每增加一个栈帧,每个 ``heap_trace_record_t`` 记录的内存使用量将增加 8 个字节。
398398

399+
.. only:: CONFIG_IDF_TARGET_ARCH_RISCV
400+
401+
默认情况下,每个跟踪条目记录的调用栈深度为 0,所以只能检索到内存分配函数的直接调用者。但是,启用 ``CONFIG_ESP_SYSTEM_USE_FRAME_POINTER`` 选项后,可以在项目配置菜单下配置此调用栈深度,选择 ``Heap Memory Debugging`` > ``Enable heap tracing`` > :ref:`CONFIG_HEAP_TRACING_STACK_DEPTH`。每个内存分配最多可以记录 32 个栈帧(默认为 2),每增加一个栈帧,每个 ``heap_trace_record_t`` 记录的内存使用量将增加 8 个字节。
402+
399403
最后,将打印“泄漏”的总字节数(即在跟踪期间分配但未释放的总字节数),以及它所代表的总分配次数。
400404

401405
使用哈希表提高性能

0 commit comments

Comments
 (0)