• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Resource Leak Event Overview
2
3<!--Kit: Performance Analysis Kit-->
4<!--Subsystem: HiviewDFX-->
5<!--Owner: @xuxinao-->
6<!--Designer: @peterhuangyu-->
7<!--Tester: @gcw_KuLfPSbe-->
8<!--Adviser: @foryourself-->
9
10## Overview
11
12Resource leaks occur when resources, such as handles, threads, or memory, are not properly released during application running. As a result, the resources are occupied for a long time and cannot be used by other applications. If a certain type of resource is exhausted, the system may crash or restart. To address resource leak problems, the system provides the resource leak detection and determination, maintenance and debugging logs, and log reporting capabilities for you to locate faults.
13
14## Event Detection Principles
15
16For details, see [Analyzing Resource Leaks](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/resource-leak-guidelines).
17
18## Available APIs
19
20You can call the API provided by HiAppEvent to subscribe to the system resource leak event **hiAppEvent.event.RESOURCE_OVERLIMIT**. When detecting a leak in an application process, the system captures maintenance and debugging information and sends the leak event to the application process through HiAppEvent.
21
22- - [Subscribing to Resource Leak Events (ArkTS)](hiappevent-watcher-resourceleak-events-arkts.md)
23
24- - [Subscribing to Resource Leak Events (C/C++)](hiappevent-watcher-resourceleak-events-ndk.md)
25
26## params
27
28The **params** parameter in the event information is described as follows.
29
30| Name| Type| Description|
31| -------- | -------- | -------- |
32| time | number | Event triggering time, in ms.|
33| bundle_version | string | Application version.|
34| bundle_name | string | Application name.|
35| pid | number | Process ID of an application.|
36| uid | number | User ID of an application.|
37| resource_type | string | Resource type. For details, see **resource_type**.|
38| memory | object | Memory information (only available for **pss_memory** and **js_heap**). For details, see **memory**.|
39| fd | object | File descriptor information (only available for **fd**). For details, see **fd**.|
40| thread | object | Thread information (only available for **thread**). For details, see **thread**.|
41| external_log | string[] | Path of the error log file. If the directory files exceed the threshold (for details, see **log_over_limit**), new log files may fail to be written. Therefore, delete the log files immediately after they are processed.|
42| log_over_limit | boolean | Whether the size of generated fault log files and existing log files exceeds the upper limit (2 GB). The value **true** indicates that the upper limit is exceeded and logs fail to be written. The value **false** indicates that the upper limit is not exceeded.|
43
44### **resource_type**
45
46| Value| Description|
47| -------- | -------- |
48| pss_memory | PSS memory leak.|
49| ion_memory | ION memory leak.|
50| gpu_memory | GPU memory leak.|
51| js_heap | JS memory leak.|
52| fd | Handle leak.|
53| thread | Thread leak.|
54
55### **memory**
56
57| Name| Type| Description|
58| -------- | -------- | -------- |
59| rss | number | Size of the memory allocated for a process (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
60| vss | number | Size of the virtual memory applied by a process from the system (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
61| pss | number | Size of the physical memory actually used by a process (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
62| ion | number | Size of the ION memory actually used by a process (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
63| gpu | number | Size of the GPU memory actually used by a process (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
64| sys_free_mem | number | Size of the free memory (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
65| sys_avail_mem | number | Size of the available memory (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
66| sys_total_mem | number | Size of the total memory (only available for **pss_memory**, **ion_memory**, and **gpu_memory**), in KB.|
67| limit_size | number | Limit of memory size (only available for **js_heap**), in KB.|
68| live_object_size | number | Size of the used memory (only available for **js_heap**), in KB.|
69
70### **fd**
71
72| Name| Type| Description|
73| -------- | -------- | -------- |
74| num | number | Total number of FDs.|
75| top_fd_type | string | FD type that is most frequently used.|
76| top_fd_num | number | Number of FDs that are most frequently used.|
77
78### **thread**
79
80| Name| Type| Description|
81| -------- | -------- | -------- |
82| num | number | Total number of threads.|
83
84## Customizing Parameters for Resource Leak Events
85
86Currently, the resource leak event reports the JS memory leak event information, which may not meet your personal requirements. Therefore, the **setEventParam** method is provided to customize event reporting information.
87
88### APIs
89
90| Name| Description|
91| -------- | -------- |
92| setEventParam(params: Record&lt;string, ParamType>, domain: string, name?: string): Promise&lt;void> | Sets custom event parameters.<br>Note: This API is supported since API version 20.|
93