提交 122e3050 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 3e9c571a
# Performance Tracing<a name="EN-US_TOPIC_0000001165886716"></a>
# Performance Tracing
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> - 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>
## Modules to Import
```
import bytrace from '@ohos.bytrace';
```
## Required Permissions<a name="section11257113618419"></a>
None
## bytrace.startTrace<a name="section785191510485"></a>
startTrace\(name: string, taskId: number, expectedTime?: number\): void
Starts a trace of a task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace.
- Parameters
<a name="table69661135912"></a>
<table><thead align="left"><tr id="row149668318915"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p7966738914"><a name="p7966738914"></a><a name="p7966738914"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="13.22%" id="mcps1.1.5.1.2"><p id="p296713699"><a name="p296713699"></a><a name="p296713699"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10.67%" id="mcps1.1.5.1.3"><p id="p196718315911"><a name="p196718315911"></a><a name="p196718315911"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p9967231197"><a name="p9967231197"></a><a name="p9967231197"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row99671533914"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p79671633910"><a name="p79671633910"></a><a name="p79671633910"></a>name</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p11967433914"><a name="p11967433914"></a><a name="p11967433914"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p19671336916"><a name="p19671336916"></a><a name="p19671336916"></a>Yes</p>
</td>
<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>
</tr>
<tr id="row18967831393"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p16813106387"><a name="p16813106387"></a><a name="p16813106387"></a>taskId</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p976115416386"><a name="p976115416386"></a><a name="p976115416386"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p149671932919"><a name="p149671932919"></a><a name="p149671932919"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p19675312911"><a name="p19675312911"></a><a name="p19675312911"></a>Task ID.</p>
</td>
</tr>
<tr id="row1225911163813"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p132250110380"><a name="p132250110380"></a><a name="p132250110380"></a>expectedTime</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p1622551113381"><a name="p1622551113381"></a><a name="p1622551113381"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p5226151110383"><a name="p5226151110383"></a><a name="p5226151110383"></a>No</p>
</td>
<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>
</td>
</tr>
</tbody>
</table>
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>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.
```
## bytrace.finishTrace<a name="section7895134841213"></a>
finishTrace\(name: string, taskId: number\): void
## System Capabilities
SystemCapability.Developtools.Bytrace
## bytrace.startTrace
startTrace(name: string, taskId: number, expectedTime?: number): void
Starts a trace task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace.
**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.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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.
```
## bytrace.finishTrace
finishTrace(name: string, taskId: number): void
Stops a trace task.
- Parameters
<a name="table1589613488127"></a>
<table><thead align="left"><tr id="row208961448131215"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p1089674831216"><a name="p1089674831216"></a><a name="p1089674831216"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="13.22%" id="mcps1.1.5.1.2"><p id="p1689613481128"><a name="p1689613481128"></a><a name="p1689613481128"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10.67%" id="mcps1.1.5.1.3"><p id="p989613483125"><a name="p989613483125"></a><a name="p989613483125"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p13896148111215"><a name="p13896148111215"></a><a name="p13896148111215"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row14896204817125"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p10896174817128"><a name="p10896174817128"></a><a name="p10896174817128"></a>name</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p189618483125"><a name="p189618483125"></a><a name="p189618483125"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p118961548101215"><a name="p118961548101215"></a><a name="p118961548101215"></a>Yes</p>
</td>
<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>
</td>
</tr>
<tr id="row5896548101211"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p10896164811121"><a name="p10896164811121"></a><a name="p10896164811121"></a>taskId</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p1789694821215"><a name="p1789694821215"></a><a name="p1789694821215"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p08962488128"><a name="p08962488128"></a><a name="p08962488128"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p8896194831214"><a name="p8896194831214"></a><a name="p8896194831214"></a>Task ID.</p>
</td>
</tr>
</tbody>
</table>
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>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.
...... // Service flow
bytrace.finishTrace("myTestFunc", 1);
```
## bytrace.traceByValue<a name="section1388414179173"></a>
traceByValue\(name: string, value: number\): void
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
| taskId | number | Yes| Task ID.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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.
// Service flow
bytrace.finishTrace("myTestFunc", 1);
```
## bytrace.traceByValue
traceByValue(name: string, value: number): void
Traces the value changes of a variable.
- Parameters
<a name="table0884617171718"></a>
<table><thead align="left"><tr id="row1188481771714"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p488419174178"><a name="p488419174178"></a><a name="p488419174178"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="13.22%" id="mcps1.1.5.1.2"><p id="p12884131721718"><a name="p12884131721718"></a><a name="p12884131721718"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10.67%" id="mcps1.1.5.1.3"><p id="p188481714178"><a name="p188481714178"></a><a name="p188481714178"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p188411174177"><a name="p188411174177"></a><a name="p188411174177"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row38849172174"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p7884121719172"><a name="p7884121719172"></a><a name="p7884121719172"></a>name</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p1488415174171"><a name="p1488415174171"></a><a name="p1488415174171"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p7884171711717"><a name="p7884171711717"></a><a name="p7884171711717"></a>Yes</p>
</td>
<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>
</tr>
<tr id="row188419179172"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p206756457267"><a name="p206756457267"></a><a name="p206756457267"></a>value</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p9884917111710"><a name="p9884917111710"></a><a name="p9884917111710"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p18841217141719"><a name="p18841217141719"></a><a name="p18841217141719"></a>Yes</p>
</td>
<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>
</td>
</tr>
</tbody>
</table>
- Example
```
let traceCount = 3;
bytrace.traceByValue("myTestCount", traceCount);
......
traceCount = 5;
bytrace.traceByValue("myTestCount", traceCount);
```
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the variable.|
| value | number | Yes| Value of the variable.|
**Example**
```
let traceCount = 3;
bytrace.traceByValue("myTestCount", traceCount);
traceCount = 4;
bytrace.traceByValue("myTestCount", traceCount);
// Service flow
```
# HiChecker
> **NOTE**
> 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.
## Modules to Import
```
import hichecker from '@ohos.hichecker';
```
## System Capabilities
SystemCapability.HiviewDFX.HiChecker
## Rule Constants
Provides the constants of all rule types.
| Name| Type| Description|
| ---------------------------------- | -------- | ------------------------------------------------------ |
| 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.
**Parameters**
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------------- |
| rule | BigInt | Yes| Rule to be added.|
**Example**
```
// Add a rule.
hichecker.addRule(hichecker.RULE_CAUTION_PRINT_LOG);
// Add multiple rules.
hichecker.addRule(
hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH);
```
## hichecker.removeRule
removeRule(rule: BigInt): void
Removes one or more rules. The removed rules will become ineffective.
**Parameters**
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------------- |
| rule | BigInt | Yes| Rule to be removed.|
**Example**
```
// Remove a rule.
hichecker.removeRule(hichecker.RULE_CAUTION_PRINT_LOG);
// Remove multiple rules.
hichecker.removeRule(
hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH);
```
## hichecker.getRule
getRule(): BigInt
Obtains a collection of thread, process, and alarm rules that have been added.
**Return value**
| Type| Description|
| ------ | ---------------------- |
| BigInt | Collection of added rules.|
**Example**
```
// Add a rule.
hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
// Obtain the collection of added rules.
hichecker.getRule(); // return 1n;
```
## hichecker.contains
contains(rule: BigInt): boolean
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.
**Parameters**
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------------- |
| rule | BigInt | Yes| Rule to be checked.|
**Return value**
| Type| Description|
| ------- | ---------------------------------------------------------- |
| boolean | Returns **true** if the rule exists in the collection of added rules; returns **false** otherwise.|
**Example**
```
// Add a rule.
hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
// Check whether the added rule exists in the collection of added rules.
hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // return true;
hichecker.contains(hichecker.RULE_CAUTION_PRINT_LOG); // return false;
```
# HiDebug
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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`.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | ------ | ---- | ------------------------------------------------------------ |
| 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`.
**Example**
```js
hidebug.startProfiling("cpuprofiler-20220216");
// Code block
// ...
// Code block
hidebug.stopProfiling();
```
## hidebug.dumpHeapData
dumpHeapData(filename : string) : void
Exports the heap data.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | ------ | ---- | ------------------------------------------------------------ |
| 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`.|
**Example**
```js
hidebug.dumpHeapData("heap-20220216");
```
# Distributed Call Chain Tracing
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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.
## Modules to Import
......@@ -68,20 +68,24 @@ begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId
Starts call chain tracing. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Traced service name.|
| flags | number | Yes| [Trace flag combination](#hitraceflag).|
- Return value
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
- Example
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
```
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Traced service name.|
| flags | number | Yes| Trace flag combination. For details, see [HiTraceFlag](#hitraceflag).|
**Return value**
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
**Example**
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
```
## hiTraceChain.end
......@@ -89,17 +93,19 @@ end(id: HiTraceId): void
Stops call chain tracing. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
**Example**
- Example
```
let asyncTraceId = hiTraceChain.begin("business");
// End the call chain tracing after the service logic is executed for several times.
hiTraceChain.end(asyncTraceId);
```
```
let asyncTraceId = hiTraceChain.begin("business");
// End the call chain tracing after the service logic is executed for several times.
hiTraceChain.end(asyncTraceId);
```
## hiTraceChain.getId
......@@ -107,17 +113,19 @@ getId(): HiTraceId
Obtains the trace ID. This API works in synchronous manner.
- Return value
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
- Example
```
let traceId = hiTraceChain.begin("business");
// Obtain the current trace ID after the service logic is executed for several times.
let curTraceId = hiTraceChain.getId();
```
**Example**
```
let traceId = hiTraceChain.begin("business");
// Obtain the current trace ID after the service logic is executed for several times.
let curTraceId = hiTraceChain.getId();
```
## hiTraceChain.setId
......@@ -125,17 +133,19 @@ setId(id: HiTraceId): void
Sets a trace ID. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
- Example
```
let traceId = hiTraceChain.begin("business");
// Set the current trace ID after the service logic is executed for several times.
hiTraceChain.setId(asyncTraceId);
```
**Example**
```
let traceId = hiTraceChain.begin("business");
// Set the current trace ID after the service logic is executed for several times.
hiTraceChain.setId(asyncTraceId);
```
## hiTraceChain.clearId
......@@ -143,12 +153,13 @@ clearId(): void
Clears the trace ID. This API works in synchronous manner.
- Example
```
let traceId = hiTraceChain.begin("business");
// Clear the current trace ID after the service logic is executed for several times.
hiTraceChain.clearId();
```
**Example**
```
let traceId = hiTraceChain.begin("business");
// Clear the current trace ID after the service logic is executed for several times.
hiTraceChain.clearId();
```
## hiTraceChain.createSpan
......@@ -156,17 +167,19 @@ createSpan(): HiTraceId
Creates a trace span. This API works in synchronous manner.
- Return value
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
**Return value**
- Example
```
let traceId = hiTraceChain.begin("business");
// Create a trace span after the service logic is executed for several times.
let spanTraceId = hiTraceChain.createSpan();
```
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
**Example**
```
let traceId = hiTraceChain.begin("business");
// Create a trace span after the service logic is executed for several times.
let spanTraceId = hiTraceChain.createSpan();
```
## hiTraceChain.tracepoint
......@@ -174,20 +187,22 @@ tracepoint(mode: HiTraceCommunicationMode, type: HiTraceTracepointType, id: HiTr
Triggers a trace point. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mode | [HiTraceCommunicationMode](#hitracecommunicationmode) | Yes| Communication mode for the trace point.|
| type | [HiTraceTracepointType](#hitracetracepointtype)| Yes| Trace point type.|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance for trace point triggering.|
| msg | string | No| Trace description passed for trace point triggering.|
- Example
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
// Trigger the trace point after the service logic is executed for several times.
hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.THREAD, hiTraceChain.HiTraceTracepointType.SS, asyncTraceId, "Just a example");
```
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mode | [HiTraceCommunicationMode](#hitracecommunicationmode) | Yes| Communication mode for the trace point.|
| type | [HiTraceTracepointType](#hitracetracepointtype)| Yes| Trace point type.|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance for trace point triggering.|
| msg | string | No| Trace description passed for trace point triggering.|
**Example**
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
// Trigger the trace point after the service logic is executed for several times.
hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.THREAD, hiTraceChain.HiTraceTracepointType.SS, asyncTraceId, "Just a example");
```
## hiTraceChain.isValid
......@@ -195,20 +210,24 @@ isValid(id: HiTraceId): boolean
Checks whether a **HiTraceId** instance is valid. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
- Return value
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the **HiTraceId** instance is valid; returns **false** otherwise.|
- Example
```
let traceId = hiTraceChain.begin("business");
let traceIdIsvalid = hiTraceChain.isValid(traceId);
```
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the **HiTraceId** instance is valid; returns **false** otherwise.|
**Example**
```
let traceId = hiTraceChain.begin("business");
let traceIdIsvalid = hiTraceChain.isValid(traceId);
```
## hiTraceChain.isFlagEnabled
......@@ -216,21 +235,26 @@ isFlagEnabled(id: HiTraceId, flag: HiTraceFlag): boolean
Checks whether the specified trace flag in the **HiTraceId** instance is enabled. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
| flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.|
- Return value
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the specified trace flag in the **HiTraceId** instance is enabled; returns **false** otherwise.|
- Example
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
// The value of enabledDoNotCreateSpanFlag is true.
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
```
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
| flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the specified trace flag in the **HiTraceId** instance is enabled; returns **false** otherwise.|
**Example**
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
// The value of enabledDoNotCreateSpanFlag is true.
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
```
## hiTraceChain.enableFlag
......@@ -238,16 +262,17 @@ enableFlag(id: HiTraceId, flag: HiTraceFlag): void
Enables the specified trace flag in the **HiTraceId** instance. This API works in synchronous manner.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
| flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.|
- Example
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
hiTraceChain.enable(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
// The value of enabledDoNotCreateSpanFlag is true.
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
```
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
| flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.|
**Example**
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
hiTraceChain.enable(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
// The value of enabledDoNotCreateSpanFlag is true.
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
```
# Performance Tracing
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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.
......@@ -22,22 +22,24 @@ startTrace(name: string, taskId: number, expectedTime?: number): void
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).
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> 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.
```
## hiTraceMeter.finishTrace
......@@ -46,42 +48,42 @@ finishTrace(name: string, taskId: number): void
Stops a trace task.
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.|
| taskId | number | Yes| Task ID.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> 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.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
```
## hiTraceMeter.traceByValue
......@@ -90,18 +92,18 @@ traceByValue(name: string, value: number): void
Traces the value changes of a variable.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the variable.|
| value | number | Yes| Value of the variable.|
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the variable.|
| value | number | Yes| Value of the variable.|
- Example
```
let traceCount = 3;
hiTraceMeter.traceByValue("myTestCount", traceCount);
traceCount = 4;
hiTraceMeter.traceByValue("myTestCount", traceCount);
// Service flow
```
**Example**
```
let traceCount = 3;
hiTraceMeter.traceByValue("myTestCount", traceCount);
traceCount = 4;
hiTraceMeter.traceByValue("myTestCount", traceCount);
// Service flow
```
# Power Management<a name="EN-US_TOPIC_0000001133775514"></a>
# Power Management
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>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.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> 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';
SystemCapability.PowerManager.PowerManager
## power.shutdownDevice<a name="section192192415554"></a>
## power.shutdownDevice
shutdownDevice\(reason: string\): void
shutdownDevice(reason: string): void
Shuts down the system.
- Parameters
<a name="table69661135912"></a>
<table><thead align="left"><tr id="row149668318915"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p7966738914"><a name="p7966738914"></a><a name="p7966738914"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="14.729999999999999%" id="mcps1.1.5.1.2"><p id="p296713699"><a name="p296713699"></a><a name="p296713699"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="9.16%" id="mcps1.1.5.1.3"><p id="p196718315911"><a name="p196718315911"></a><a name="p196718315911"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p9967231197"><a name="p9967231197"></a><a name="p9967231197"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row99671533914"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p5518501625"><a name="p5518501625"></a><a name="p5518501625"></a>reason</p>
</td>
<td class="cellrowborder" valign="top" width="14.729999999999999%" headers="mcps1.1.5.1.2 "><p id="p11967433914"><a name="p11967433914"></a><a name="p11967433914"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="9.16%" headers="mcps1.1.5.1.3 "><p id="p19671336916"><a name="p19671336916"></a><a name="p19671336916"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p69671631796"><a name="p69671631796"></a><a name="p69671631796"></a>Reason for system shutdown.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
power.shutdownDevice("shutdown_test");
console.info('power_shutdown_device_test success')
```
## power.rebootDevice<a name="section1773218207620"></a>
rebootDevice\(reason: string\): void
Reboots the system.
- Parameters
<a name="table8732192015611"></a>
<table><thead align="left"><tr id="row1173216204612"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p973222015615"><a name="p973222015615"></a><a name="p973222015615"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="16.830000000000002%" id="mcps1.1.5.1.2"><p id="p273232015612"><a name="p273232015612"></a><a name="p273232015612"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="11.88%" id="mcps1.1.5.1.3"><p id="p9732202013618"><a name="p9732202013618"></a><a name="p9732202013618"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="56.47%" id="mcps1.1.5.1.4"><p id="p167326201566"><a name="p167326201566"></a><a name="p167326201566"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row773292016614"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p57320201162"><a name="p57320201162"></a><a name="p57320201162"></a>reason</p>
</td>
<td class="cellrowborder" valign="top" width="16.830000000000002%" headers="mcps1.1.5.1.2 "><p id="p973216201164"><a name="p973216201164"></a><a name="p973216201164"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="11.88%" headers="mcps1.1.5.1.3 "><p id="p5732132020612"><a name="p5732132020612"></a><a name="p5732132020612"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="56.47%" headers="mcps1.1.5.1.4 "><p id="p4733720662"><a name="p4733720662"></a><a name="p4733720662"></a>Reason for system reboot.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
power.rebootDevice("reboot_test");
console.info('power_reboot_device_test success')
```
## power.isScreenOn<a name="section69511458115312"></a>
isScreenOn\(callback: AsyncCallback<boolean\>\): void
Before using this API, you must declare the **ohos.permission.SHUTDOWN** permission.
Checks the screen status of the current device.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| reason | string | Yes| Reason for system shutdown.|
**Example**
```
power.shutdownDevice("shutdown_test");
console.info('power_shutdown_device_test success')
```
## power.rebootDevice
- Parameters
<a name="table183681450191519"></a>
<table><thead align="left"><tr id="row20368050151519"><th class="cellrowborder" valign="top" width="15.989999999999998%" id="mcps1.1.5.1.1"><p id="p13681150121519"><a name="p13681150121519"></a><a name="p13681150121519"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="28.27%" id="mcps1.1.5.1.2"><p id="p1636895015154"><a name="p1636895015154"></a><a name="p1636895015154"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="9.64%" id="mcps1.1.5.1.3"><p id="p7565410191617"><a name="p7565410191617"></a><a name="p7565410191617"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="46.1%" id="mcps1.1.5.1.4"><p id="p43681350181515"><a name="p43681350181515"></a><a name="p43681350181515"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row636865081513"><td class="cellrowborder" valign="top" width="15.989999999999998%" headers="mcps1.1.5.1.1 "><p id="p4368165091513"><a name="p4368165091513"></a><a name="p4368165091513"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="28.27%" headers="mcps1.1.5.1.2 "><p id="p83691450151519"><a name="p83691450151519"></a><a name="p83691450151519"></a>AsyncCallback&lt;boolean&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="9.64%" headers="mcps1.1.5.1.3 "><p id="p17565310191610"><a name="p17565310191610"></a><a name="p17565310191610"></a>Yes</p>
</td>
<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>
</td>
</tr>
</tbody>
</table>
- Example
```
power.isScreenOn((error, screenOn) => {
if (typeof error === "undefined") {
console.info('screenOn status is ' + screenOn);
} else {
console.log('error: ' + error);
}
})
```
## power.isScreenOn<a name="section143367619119"></a>
isScreenOn\(\): Promise<boolean\>
rebootDevice(reason: string): void
Restarts the device.
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.|
**Example**
```
power.rebootDevice("reboot_test");
console.info('power_reboot_device_test success')
```
## power.isScreenOn
isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
Checks the screen status of the current device.
- Return values
<a name="table1730417311314"></a>
<table><thead align="left"><tr id="row1930412311018"><th class="cellrowborder" valign="top" width="23.87%" id="mcps1.1.3.1.1"><p id="p15304113117114"><a name="p15304113117114"></a><a name="p15304113117114"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="76.13%" id="mcps1.1.3.1.2"><p id="p830411311017"><a name="p830411311017"></a><a name="p830411311017"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row173045311711"><td class="cellrowborder" valign="top" width="23.87%" headers="mcps1.1.3.1.1 "><p id="p686517815914"><a name="p686517815914"></a><a name="p686517815914"></a>Promise&lt;boolean&gt;</p>
</td>
<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&lt;boolean&gt; | 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&lt;boolean&gt;
Checks the screen status of the current device.
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to asynchronously obtain the return value. <br/>The value **true** indicates that the screen is on, and value **false** indicates the opposite.|
**Example**
```
power.isScreenOn()
.then(screenOn => {
console.info('screenOn status is ' + screenOn);
})
.catch(error => {
console.log('error: ' + error);
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册