目录

rawheap-translator

When to Use

To help you locate issues, the app automatically performs HeapDump when ArkTS Out of Memory (OOM) occurs. This operation saves all object information on the current VM heap to a binary file with the .rawheap extension. In addition, you can call hidebug.dumpJsRawHeapData to obtain the rawheap file of the current thread, or use the command hidumper --mem-jsheap pid [-T tid] --raw to proactively obtain the rawheap file of a specified process or JS thread. You can use the rawheap_translator tool to parse the .rawheap file and generate a .heapsnapshot file. This file can be imported and viewed through Heap Snapshot offline import in DevEco Studio or the memory tool in Chrome DevTools.

Operation Guide

[h2]How to Obtain

This tool supports Windows, Linux, and macOS platforms. The acquisition methods are as follows:

[h2]Environment Configuration

It is recommended that you place the rawheap_translator tool obtained from the SDK in a stable path and configure that path as a system environment variable. This way, you can use the tool directly in the terminal without specifying the path each time.

The methods of configuring environment variables vary depending on the system. The following provides some configuration examples for your reference.

How to Use

[h2]Parsing Command

rawheap_translator [rawheap_file] [heapsnapshot_file]

[h2]Parameters

Parameter Mandatory Description
[rawheap_file] Yes Path of the .rawheap file generated upon an OOM error of the application to be parsed.
[heapsnapshot_file] No

File path of the generated heapsnapshot file. The path must have read and write permissions.

If this parameter is omitted, the default is the path where the command is executed, and the generated file is named hprof_yyyy-MM-dd-HH-mm-ss.heapsnapshot, where yyyy-MM-dd-HH-mm-ss is the time when the file is parsed.

If this parameter is specified, the file extension must be heapsnapshot.

Using Parsing Commands

[h2]Examples

On Windows

Open the cmd window, go to the .rawheap file path, and run the parsing command to generate the .heapsnapshot file in the current path.

> rawheap_translator.exe memleak-js-com.example.myapplication-7979-7979-20241215191332.rawheap myapplication-7979-7979.heapsnapshot

On Linux

Go to the path of the .rawheap file, and run the parsing command to generate the .heapsnapshot file in the current path.

> rawheap_translator memleak-js-com.example.myapplication-7979-7979-20241215191332.rawheap myapplication-7979-7979.heapsnapshot

On macOS

Open the device, go to the .rawheap file path, and run the parsing command to generate the .heapsnapshot file in the current path.

> rawheap_translator memleak-js-com.example.myapplication-7979-7979-20241215191332.rawheap myapplication-7979-7979.heapsnapshot

Output example

[INFO ] ParseVersion            current metadata version is 1.0.0
[INFO ] ParseTypeEnums          total JSType count 214
[INFO ] ParseTypeList           total metadata count 220
[INFO ] SetBitField             set BitField offset 8
[INFO ] SetBitField             set BindingSize offset 32
[INFO ] SetBitField             set Length offset 8
[INFO ] SetBitField             set Data offset 16
[INFO ] ReadVersion             current rawheap version is 1.0.0
[INFO ] RawHeap                 start to translate rawheap
[INFO ] ReadRootTable           root node count 6244
[INFO ] ReadStringTable         string table count 11208
[INFO ] ReadObjTable            section objects count 96432
[INFO ] Translate               success
[INFO ] Serialize               start to serialize
[INFO ] Translate               file save to /data/local/tmp/myapplication-7979-7979.heapsnapshot

File Specifications

The rawheap-file size and generation time are strongly and positively correlated with the current ArkTS heap size and the number of live objects. When the ArkTS heap memory usage is high and the number of live objects is large, the generated rawheap file is larger and the generation takes longer. You can subscribe to the resource leak events and customize the event processing logic.

Starting from API version 20, the VM supports two HeapDump specifications. For details about switching between them, see setJsRawHeapTrimLevel, which sets the trim level for dumping the raw heap snapshot of the VM in the current process.

Starting from API version 22, TRIM_LEVEL_1 mode adds the capability to parse object property names. As a result, the generated rawheap file is larger than before, and the specific increase depends on the number of object property names and the string size.

Specifications Features
TRIM_LEVEL_1

The dump speed is fast, and the generated rawheap file is large.

Before API version 20, the VM uses TRIM_LEVEL_1 by default.

TRIM_LEVEL_2 The dump speed is slower, and the size of the generated rawheap file is about 40% smaller than that of TRIM_LEVEL_1.

To understand the performance and traffic overhead caused by reporting the .rawheap file to the server, you can refer to the following table to obtain the size of the .rawheap file, file generation duration, and file parsing duration of heap dumps of different specifications.

Specifications Heap Size (MB) .rawheap File Size (MB) File Generation Duration (s) Parsing Duration (s)
TRIM_LEVEL_1 690 629 2.64 14
TRIM_LEVEL_2 690 376 3.47 14
TRIM_LEVEL_1 653 618 2.63 13
TRIM_LEVEL_2 653 347 3.36 13
TRIM_LEVEL_1 576 563 3.63 15
TRIM_LEVEL_2 576 294 4.53 15

FAQs

[h2]What should I do if the tool version does not match?

Symptom

During parsing, the message "The rawheap file's version 2.0.0 is not matched the current rawheap translator, please use the newest version of the translator!" is displayed.

[INFO ] ParseVersion            current metadata version is 1.0.0
[INFO ] ParseTypeEnums          total JSType count 214
[INFO ] ParseTypeList           total metadata count 220
[INFO ] SetBitField             set BitField offset 8
[INFO ] SetBitField             set BindingSize offset 32
[INFO ] SetBitField             set Length offset 8
[INFO ] SetBitField             set Data offset 16
[INFO ] ReadVersion             current rawheap version is 2.0.0
[ERROR] ParseRawheap            The rawheap file's version 2.0.0 is not matched the current rawheap translator, please use the newest version of the translator!

Possible Causes

The current tool version is earlier than the .rawheap file version.

Solution

Upgrade the tool version to 2.0.0.

[h2]What should I do if the file cannot be opened?

Symptom

The message "open file failed!" is displayed during parsing.

[INFO ] ParseVersion            current metadata version is 1.0.0
[INFO ] ParseTypeEnums          total JSType count 214
[INFO ] ParseTypeList           total metadata count 220
[INFO ] SetBitField             set BitField offset 8
[INFO ] SetBitField             set BindingSize offset 32
[INFO ] SetBitField             set Length offset 8
[INFO ] SetBitField             set Data offset 16
[INFO ] ReadVersion             current rawheap version is 1.0.0
[INFO ] RawHeap                 start to translate rawheap
[INFO ] ReadRootTable           root node count 6244
[INFO ] ReadStringTable         string table count 11208
[INFO ] ReadObjTable            section objects count 96432
[INFO ] Translate               success
[ERROR] Initialize              open file failed

Possible Causes

You do not have the write permission on the specified file generation path.

Solution

Change the path to a path on which you have the write permission.

[h2]File Parsing Failure

Problem Symptom

Tool parsing completes, but the conversion fails and no heapsnapshot file is generated.

[INFO ] ParseVersion            current metadata version is 1.0.0
[INFO ] ParseTypeEnums          total JSType count 214
[INFO ] ParseTypeList           total metadata count 220
[INFO ] SetBitField             set BitField offset 8
[INFO ] SetBitField             set BindingSize offset 32
[INFO ] SetBitField             set Length offset 8
[INFO ] SetBitField             set Data offset 16
[INFO ] ReadVersion             current rawheap version is 1.0.0
[INFO ] RawHeap                 start to translate rawheap
[INFO ] ReadRootTable           root node count 6244
[INFO ] ReadStringTable         string table count 11208
[INFO ] ReadObjTable            section objects count 96432

Cause

The parsing tool version is too old.

Solution

Use DevEco Studio 6.1.1 Release or a later version.