• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# HiDebug
2
3> **NOTE**<br>
4> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
5
6You can run the hidebug command to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data.
7
8## Modules to Import
9
10```js
11import hidebug from '@ohos.hidebug';
12```
13
14
15## hidebug.getNativeHeapSize
16
17getNativeHeapSize(): bigint
18
19Obtains the total size of the native heap memory.
20
21This API is defined but not implemented in OpenHarmony 3.1 Release.
22
23**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
24
25**Return value**
26
27| Type  | Description                       |
28| ------ | --------------------------- |
29| bigint | Total size of the native heap memory.|
30
31
32**Example**
33  ```js
34  let nativeHeapSize = hidebug.getNativeHeapSize();
35  ```
36
37
38## hidebug.getNativeHeapAllocatedSize
39
40getNativeHeapAllocatedSize(): bigint
41
42Obtains the size of the allocated native heap memory.
43
44This API is defined but not implemented in OpenHarmony 3.1 Release.
45
46**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
47
48
49**Return value**
50| Type  | Description                             |
51| ------ | --------------------------------- |
52| bigint | Size of the allocated native heap memory.|
53
54
55**Example**
56  ```js
57  let nativeHeapAllocatedSize = hidebug.getNativeHeapAllocatedSize();
58  ```
59
60
61## hidebug.getNativeHeapFreeSize
62
63getNativeHeapFreeSize(): bigint
64
65Obtains the size of the free native heap memory.
66
67This API is defined but not implemented in OpenHarmony 3.1 Release.
68
69**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
70
71
72**Return value**
73| Type  | Description                           |
74| ------ | ------------------------------- |
75| bigint | Size of the free native heap memory.|
76
77
78**Example**
79  ```js
80  let nativeHeapFreeSize = hidebug.getNativeHeapFreeSize();
81  ```
82
83
84## hidebug.getPss
85
86getPss(): bigint
87
88Obtains the PSS of this process.
89
90**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
91
92
93**Return value**
94| Type  | Description                     |
95| ------ | ------------------------- |
96| bigint | PSS of the process.|
97
98
99**Example**
100  ```js
101  let pss = hidebug.getPss();
102  ```
103
104
105## hidebug.getSharedDirty
106
107getSharedDirty(): bigint
108
109Obtains the size of the shared dirty memory of this process.
110
111**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
112
113
114**Return value**
115| Type  | Description                      |
116| ------ | -------------------------- |
117| bigint | Size of the shared dirty memory of the process.|
118
119
120**Example**
121  ```js
122  let sharedDirty = hidebug.getSharedDirty();
123  ```
124
125## hidebug.getPrivateDirty<sup>9+<sup>
126
127getPrivateDirty(): bigint
128
129Obtains the size of the private dirty memory of this process.
130
131**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
132
133
134**Return value**
135| Type  | Description                      |
136| ------ | -------------------------- |
137| bigint | Size of the private dirty memory of the process.|
138
139
140**Example**
141  ```js
142  let privateDirty = hidebug.getPrivateDirty();
143  ```
144
145## hidebug.getCpuUsage<sup>9+<sup>
146
147getCpuUsage(): number
148
149Obtains the CPU usage of this process.
150
151For example, if the CPU usage is **50%**, **0.5** is returned.
152
153**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
154
155
156**Return value**
157| Type  | Description                      |
158| ------ | -------------------------- |
159| number | CPU usage of the process.|
160
161
162**Example**
163  ```js
164  let cpuUsage = hidebug.getCpuUsage();
165  ```
166
167## hidebug.startProfiling
168
169startProfiling(filename : string) : void
170
171Starts the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the following sequences is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
172
173**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
174
175**Parameters**
176
177| Name  | Type  | Mandatory| Description                                                        |
178| -------- | ------ | ---- | ------------------------------------------------------------ |
179| filename | string | Yes  | User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.|
180
181**Example**
182
183```js
184hidebug.startProfiling("cpuprofiler-20220216");
185// code block
186// ...
187// code block
188hidebug.stopProfiling();
189```
190
191
192
193## hidebug.stopProfiling
194
195stopProfiling() : void
196
197Stops the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the following sequences is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
198
199**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
200
201**Example**
202
203```js
204hidebug.startProfiling("cpuprofiler-20220216");
205// code block
206// ...
207// code block
208hidebug.stopProfiling();
209```
210
211## hidebug.dumpHeapData
212
213dumpHeapData(filename : string) : void
214
215Exports data from the specified heap file.
216
217**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
218
219**Parameters**
220
221| Name  | Type  | Mandatory | Description                                                        |
222| -------- | ------ | ---- | ------------------------------------------------------------ |
223| filename | string | Yes  | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the app based on the specified `filename`.|
224
225**Example**
226
227```js
228hidebug.dumpHeapData("heap-20220216");
229```
230
231## hidebug.getServiceDump<sup>9+<sup>
232
233getServiceDump(serviceid : number) : string
234
235Obtains information on the specified system service.
236
237This is a system API and cannot be called by third-party applications.
238
239**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
240
241**Parameters**
242
243| Name  | Type  | Mandatory| Description                                                        |
244| -------- | ------ | ---- | ------------------------------------------------------------ |
245| serviceid | number | Yes  | ID of the system service. |
246
247**Return value**
248| Type  | Description                      |
249| ------ | -------------------------- |
250| string | Absolute path of the file that contains the service information to dump. |
251
252**Example**
253
254```js
255let serviceId = 10;
256let pathName = hidebug.getServiceDump(serviceId);
257```
258