> - The APIs of this module are no longer maintained since API version 8. It is recommended that you use the APIs of [hiTraceMeter](js-apis-hitracemeter.md) instead.
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p2084833211463"><a name="p2084833211463"></a><a name="p2084833211463"></a>Name of the trace task to start.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p22262111381"><a name="p22262111381"></a><a name="p22262111381"></a>Expected duration of the trace, in ms.</p>
>If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different **taskId**s must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same **taskId** can be used. For details, see the **bytrace.finishTrace** example.
- Example
```
bytrace.startTrace("myTestFunc", 1);
bytrace.startTrace("myTestFunc", 1, 5); // The expected duration of the trace is 5 ms.
> If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same taskId can be used. For details, see the bytrace.finishTrace example.
**Example**
```
bytrace.startTrace("myTestFunc", 1);
bytrace.startTrace("myTestFunc", 1, 5); // The expected duration of the trace is 5 ms.
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1989674810124"><a name="p1989674810124"></a><a name="p1989674810124"></a>Name of the trace task to stop.</p>
>To stop a trace task, the values of **name** and **taskId** in **finishTrace** must be the same as those in **startTrace**.
- Example
```
bytrace.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name concurrently.
bytrace.startTrace("myTestFunc", 1);
...... // Service flow
bytrace.startTrace ("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
...... // Service flow
bytrace.finishTrace("myTestFunc", 1);
...... // Service flow
bytrace.finishTrace("myTestFunc", 2);
```
```
// Start track tasks with the same name at different times.
bytrace.startTrace("myTestFunc", 1);
...... // Service flow
bytrace.finishTrace("myTestFunc", 1); // The first trace task ends.
...... // Service flow
bytrace.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
> To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in **startTrace**.
**Example**
```
bytrace.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name concurrently.
bytrace.startTrace("myTestFunc", 1);
// Service flow
bytrace.startTrace("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
// Service flow
bytrace.finishTrace("myTestFunc", 1);
// Service flow
bytrace.finishTrace("myTestFunc", 2);
```
```
// Start track tasks with the same name at different times.
bytrace.startTrace("myTestFunc", 1);
// Service flow
bytrace.finishTrace("myTestFunc", 1); // The first trace task ends.
// Service flow
bytrace.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p17884517161715"><a name="p17884517161715"></a><a name="p17884517161715"></a>Name of the variable to trace.</p>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p178842174174"><a name="p178842174174"></a><a name="p178842174174"></a>Value of the variable to trace.</p>
> 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.
| RULE_CAUTION_PRINT_LOG | BigInt | Alarm rule, which is programmed to print a log when an alarm is generated.|
| RULE_CAUTION_TRIGGER_CRASH | BigInt | Alarm rule. When an alarm is generated, the application exits.|
| RULE_THREAD_CHECK_SLOW_PROCESS | BigInt | Caution rule, which is programmed to detect whether any time-consuming function is invoked.|
| RULE_CHECK_SLOW_EVENT | BigInt | Caution rule, which is programmed to detect whether the event distribution or processing time has exceeded the specified time threshold.|
| RULE_CHECK_ABILITY_CONNECTION_LEAK | BigInt | Caution rule, which is programmed to detect whether ability leakage has occurred.|
## hichecker.addRule
addRule(rule: BigInt): void
Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules.
Checks whether the specified rule exists in the collection of added rules. If the rule is of the thread level, this operation is performed only on the current thread.
> 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.
You 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.
## Modules to Import
```
import hidebug from '@ohos.hidebug';
```
## System Capabilities
SystemCapability.HiviewDFX.HiProfiler.HiDebug
## hidebug.getNativeHeapSize
getNativeHeapSize(): bigint
Obtains the total size of the native heap memory.
-**Return value**
| Type| Description|
| -------- | -------- |
| bigint | Total size of the native heap memory.|
-**Example**
```
let nativeHeapSize = hidebug.getNativeHeapSize();
```
## hidebug.getNativeHeapAllocatedSize
getNativeHeapAllocatedSize(): bigint
Obtains the size of the allocated native heap memory.
-**Return value**
| Type| Description|
| -------- | -------- |
| bigint | Size of the allocated native heap memory.|
-**Example**
```
let nativeHeapAllocatedSize = hidebug.getNativeHeapAllocatedSize();
```
## hidebug.getNativeHeapFreeSize
getNativeHeapFreeSize(): bigint
Obtains the size of the free native heap memory.
-**Return value**
| Type| Description|
| -------- | -------- |
| bigint | Size of the free native heap memory.|
-**Example**
```
let nativeHeapFreeSize = hidebug.getNativeHeapFreeSize();
```
## hidebug.getPss
getPss(): bigint
Obtains the PSS of this process.
-**Return value**
| Type| Description|
| -------- | -------- |
| bigint | PSS of the process.|
-**Example**
```
let pss = hidebug.getPss();
```
## hidebug.getSharedDirty
getSharedDirty(): bigint
Obtains the size of the shared dirty memory of this process.
-**Return value**
| Type| Description|
| -------- | -------- |
| bigint | Size of the shared dirty memory of the process.|
-**Example**
```
let sharedDirty = hidebug.getSharedDirty());
```
## hidebug.startProfiling
startProfiling(filename : string) : void
Starts 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`.
| 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`.|
**Example**
```js
hidebug.startProfiling("cpuprofiler-20220216");
// Code block
// ...
// Code block
hidebug.stopProfiling();
```
## hidebug.stopProfiling
stopProfiling() : void
Stops the profiling method. `stopProfiling()` and `startProfiling()` are called in pairs. `stopProfiling()` always occurs after `startProfiling()`; that is, calling the functions in the following sequences is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
| 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`.|
> 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.
> 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.
Starts a trace task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace.
If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
| taskId | number | Yes| Task ID.|
| expectedTime | number | No| Expected duration of the trace, in ms.|
If the trace tasks with the same name are not performed at the same time, the same taskId can be used. For a specific example, refer to an example in [hiTraceMeter.finishTrace](#hitracemeterfinishtrace).
> If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same task ID can be used. For details, see the **hiTraceMeter.finishTrace** example.
**Parameters**
- Example
```
hiTraceMeter.startTrace("myTestFunc", 1);
hiTraceMeter.startTrace("myTestFunc", 1, 5); // The expected duration of the trace task is 5 ms.
```
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
| taskId | number | Yes| Task ID.|
| expectedTime | number | No| Expected duration of the trace, in ms.|
**Example**
```
hiTraceMeter.startTrace("myTestFunc", 1);
hiTraceMeter.startTrace("myTestFunc", 1, 5); // The expected duration of the trace task is 5 ms.
To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in [startTrace](#hitracemeterstarttrace).
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
| taskId | number | Yes| Task ID.|
**Example**
```
hiTraceMeter.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name concurrently.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.startTrace("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 2);
```
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
> To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in **startTrace**.
- Example
```
hiTraceMeter.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name concurrently.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.startTrace("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 2);
```
```
// Start track tasks with the same name at different times.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1); // The first trace task ends.
// Service flow
hiTraceMeter.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name at different times.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1); // The first trace task ends.
// Service flow
hiTraceMeter.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
## Modules to Import
```
import power from '@ohos.power';
...
...
@@ -14,163 +15,94 @@ import power from '@ohos.power';
<td class="cellrowborder" valign="top" width="46.1%" headers="mcps1.1.5.1.4 "><p id="p163691850191515"><a name="p163691850191515"></a><a name="p163691850191515"></a>Callback used to obtain the return value.</p>
<p id="p3566124615812"><a name="p3566124615812"></a><a name="p3566124615812"></a>The value <strong id="b4350172620165"><a name="b4350172620165"></a><a name="b4350172620165"></a>true</strong> indicates that the screen is on, and value <strong id="b035432613168"><a name="b035432613168"></a><a name="b035432613168"></a>false</strong> indicates the opposite.</p>
Before using this API, you must declare the **ohos.permission.REBOOT** permission (to reboot) or the **ohos.permission.REBOOT_RECOVERY** permission (to reboot and enter the recovery mode)
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| reason | string | Yes| Reason for system reboot.|
<td class="cellrowborder" valign="top" width="76.13%" headers="mcps1.1.3.1.2 "><p id="p163041531916"><a name="p163041531916"></a><a name="p163041531916"></a>Promise used to asynchronously obtain the return value. The value <strong id="b1934154320392"><a name="b1934154320392"></a><a name="b1934154320392"></a>true</strong> indicates that the screen is on, and value <strong id="b1693454393914"><a name="b1693454393914"></a><a name="b1693454393914"></a>false</strong> indicates the opposite.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
power.isScreenOn()
.then(screenOn => {
**Parameters**
| Type| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to obtain the return value. <br/>The value **true** indicates that the screen is on, and value **false** indicates the opposite.|
**Example**
```
power.isScreenOn((error, screenOn) => {
if (typeof error === "undefined") {
console.info('screenOn status is ' + screenOn);
})
.catch(error => {
} else {
console.log('error: ' + error);
})
```
}
})
```
## power.isScreenOn
isScreenOn(): Promise<boolean>
Checks the screen status of the current device.
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to asynchronously obtain the return value. <br/>The value **true** indicates that the screen is on, and value **false** indicates the opposite.|