未验证 提交 1399190f 编写于 作者: O openharmony_ci 提交者: Gitee

!16806...

!16806 翻译已完成16196+16305+16243+16301+16417+16439+16528+16583+16583+16543+16593+16590+16599+16609+16333
Merge pull request !16806 from shawn_he/16196-d
......@@ -18,5 +18,4 @@
- [Native API Usage](faqs-native.md)
- [Usage of Third- and Fourth-Party Libraries](faqs-third-party-library.md)
- [IDE Usage](faqs-ide.md)
- [hdc_std Command Usage](faqs-hdc-std.md)
- [Development Board](faqs-development-board.md)
\ No newline at end of file
# hdc_std Command Usage
## Common Log Commands
Applicable to: OpenHarmony SDK 3.2.2.5
Clearing logs: hdc_std shell hilog -r
Increasing the buffer size to 20 MB: hdc_std shell hilog -G 20M
Capturing logs: hdc_std shell hilog > log.txt
## What should I do to avoid log flow control?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
- Disabling log flow control: hdc_std shell hilog -Q pidoff
- Disabling the privacy flag: hdc_std shell hilog -p off
- Increasing the log buffer to 200 MB: hdc_std shell hilog -G 200M
- Enabling the log function of the specific domain (that is, disabling the global log function): hdc_std shell hilog –b D –D 0xd0xxxxx
After performing the preceding operations, restart the DevEco Studio.
## What should I do if the HAP installed on the development board through the IDE cannot be opened?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Check whether the SDK version is consistent with the system version on the development board. You are advised to use the SDK version and system version that are released on the same day.
## How do I upload files using the hdc command?
Applicable to: OpenHarmony SDK 3.2.2.5
Run the **hdc_std file send** command.
## How do I prevent the screen of the RK3568 development board from turning off?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Run the **hdc_std shell "power-shell setmode 602"** command.
## How do I start an ability using the hdc command?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Run the **hdc\_std shell aa start -a AbilityName -b bundleName -m moduleName** command.
## How do I change the read and write permissions on a file directory on the development board?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
Run the **hdc\_std shell mount -o remount,rw /** command.
## What should I do if the error message "Unknown file option -r" is displayed when hdc_std file recv is run?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
1. Use the the hdc tool in the device image or SDK of the same version.
2. Remove any Chinese characters or spaces from the directory specified for the hdc tool.
## How do I uninstall an application using the hdc command?
Applicable to: OpenHarmony SDK 3.2.2.5
Run the **hdc\_std uninstall [-k] [package_name]** command.
## How do I check whether the system is 32-bit or 64-bit?
Applicable to: OpenHarmony SDK 3.2.5.5
Run the **hdc\_std shell getconf LONG_BIT** command.
If **64** is returned, the system is a 64-bit one. Otherwise, the system is a 32-bit one.
## How do I view the component tree structure?
Applicable to: OpenHarmony SDK 3.2.5.5
1. Run the **hdc\_std shell** command to launch the CLI.
2. Run the **aa dump -a** command to find **abilityID**.
3. Run the **aa dump -i [abilityID] -c -render** command to view the component tree.
......@@ -14,110 +14,6 @@ To subscribe to the call status, use [`observer.on('callStateChange')`](js-apis-
import call from '@ohos.telephony.call';
```
## call.dial<sup>(deprecated)</sup>
dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
Initiates a call. This API uses an asynchronous callback to return the result.
>**NOTE**
>
>This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9).
**Required Permissions**: ohos.permission.PLACE_CALL
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ---------------------------- | ---- | --------------------------------------- |
| phoneNumber | string | Yes | Phone number. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.<br>- **true**: success<br>- **false**: failure|
**Example**
```js
call.dial("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.dial<sup>(deprecated)</sup>
dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean\>\): void
Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the result.
>**NOTE**
>
>This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9).
**Required Permissions**: ohos.permission.PLACE_CALL
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ---------------------------- | ---- | --------------------------------------- |
| phoneNumber | string | Yes | Phone number. |
| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.<br>- **true**: success<br>- **false**: failure|
**Example**
```js
call.dial("138xxxxxxxx", {
extras: false
}, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.dial<sup>(deprecated)</sup>
dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\>
Initiates a call. You can set call options as needed. This API uses a promise to return the result.
>**NOTE**
>
>This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9).
**Required Permissions**: ohos.permission.PLACE_CALL
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | -------------------------------------- |
| phoneNumber | string | Yes | Phone number. |
| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call.|
**Return value**
| Type | Description |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result.<br>- **true**: success<br>- **false**: failure|
**Example**
```js
let promise = call.dial("138xxxxxxxx", {
extras: false
});
promise.then(data => {
console.log(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.dialCall<sup>9+</sup>
dialCall\(phoneNumber: string, callback: AsyncCallback<void\>\): void
......@@ -158,7 +54,6 @@ call.dialCall("138xxxxxxxx", (err) => {
});
```
## call.dialCall<sup>9+</sup>
dialCall\(phoneNumber: string, options: DialCallOptions, callback: AsyncCallback<void\>\): void
......@@ -205,7 +100,6 @@ call.dialCall("138xxxxxxxx", {
});
```
## call.dialCall<sup>9+</sup>
dialCall\(phoneNumber: string, options?: DialCallOptions\): Promise<void\>
......@@ -260,6 +154,108 @@ promise.then(() => {
});
```
## call.dial<sup>(deprecated)</sup>
dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
Initiates a call. This API uses an asynchronous callback to return the result.
>**NOTE**
>
> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). The substitute API is available only for system applications.
**Required Permissions**: ohos.permission.PLACE_CALL
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ---------------------------- | ---- | --------------------------------------- |
| phoneNumber | string | Yes | Phone number. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.<br>- **true**: success<br>- **false**: failure|
**Example**
```js
call.dial("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.dial<sup>(deprecated)</sup>
dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean\>\): void
Initiates a call. You can set call options as needed. This API uses an asynchronous callback to return the result.
>**NOTE**
>
> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). The substitute API is available only for system applications.
**Required Permissions**: ohos.permission.PLACE_CALL
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ---------------------------- | ---- | --------------------------------------- |
| phoneNumber | string | Yes | Phone number. |
| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.<br>- **true**: success<br>- **false**: failure|
**Example**
```js
call.dial("138xxxxxxxx", {
extras: false
}, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.dial<sup>(deprecated)</sup>
dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\>
Initiates a call. You can set call options as needed. This API uses a promise to return the result.
>**NOTE**
>
> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [dialCall](#calldialcall9). The substitute API is available only for system applications.
**Required Permissions**: ohos.permission.PLACE_CALL
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | -------------------------------------- |
| phoneNumber | string | Yes | Phone number. |
| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call.|
**Return value**
| Type | Description |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result.<br>- **true**: success<br>- **false**: failure|
**Example**
```js
let promise = call.dial("138xxxxxxxx", {
extras: false
});
promise.then(data => {
console.log(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.makeCall<sup>7+</sup>
......
......@@ -488,8 +488,6 @@ selectContact(callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Selects a contact. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
**System capability**: SystemCapability.Applications.Contacts
**Parameters**
......@@ -517,8 +515,6 @@ selectContact(): Promise&lt;Array&lt;Contact&gt;&gt;
Selects a contact. This API uses a promise to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
**System capability**: SystemCapability.Applications.Contacts
**Return Value**
......
# @ohos.hichecker (HiChecker)
The **hichecker** module is provided for you to check issues that may be easily ignored during development of OpenHarmony applications (including system-built and third-party applications). Such issues include calling of time-consuming functions by key application threads, event distribution and execution timeout in application processes, and ability resource leakage in application processes. The issues are recorded in logs or lead to process crashes explicitly so that you can find and rectify them.
The HiChecker module allows you to check issues that may be easily ignored during development of applications (including system-built and third-party applications). Such issues include calling of time-consuming functions by key application threads, event distribution and execution timeout in application processes, and ability resource leakage in application processes. The issues are recorded in logs or lead to process crashes explicitly so that you can find and rectify them.
> **NOTE**<br>
> **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.
......@@ -13,7 +14,7 @@ import hichecker from '@ohos.hichecker';
```
## Constant
## Constants
Provides the constants of all rule types.
......@@ -26,10 +27,8 @@ Provides the constants of all rule types.
| RULE_THREAD_CHECK_SLOW_PROCESS | bigint | Caution rule, which is programmed to detect whether any time-consuming function is invoked. |
| RULE_CHECK_ABILITY_CONNECTION_LEAK | bigint | Caution rule, which is programmed to detect whether ability leakage has occurred. |
## hichecker.addCheckRule<sup>9+</sup>
## hichecker.addRule
addCheckRule(rule: bigint): void
Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules.
......@@ -121,12 +120,12 @@ try {
## hichecker.addRule<sup>(deprecated)</sup>
## hichecker.addRule
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [hichecker.addCheckRule](#hicheckeraddcheckrule9) instead.
addRule(rule: bigint): void
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [hichecker.addCheckRule](#hicheckeraddcheckrule9).
Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules.
**System capability**: SystemCapability.HiviewDFX.HiChecker
......@@ -152,7 +151,9 @@ hichecker.addRule(
removeRule(rule: bigint): void
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [hichecker.removeCheckRule](#hicheckerremovecheckrule9) instead.
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [hichecker.removeCheckRule](#hicheckerremovecheckrule9).
Removes one or more rules. The removed rules will become ineffective.
......@@ -203,7 +204,9 @@ hichecker.getRule(); // return 1n;
contains(rule: bigint): boolean
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [hichecker.containsCheckRule](#hicheckercontainscheckrule9) instead.
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [hichecker.containsCheckRule](#hicheckercontainscheckrule9).
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.
......
......@@ -336,7 +336,7 @@ on(type: 'headerReceive', callback: AsyncCallback\<Object\>): void
Registers an observer for HTTP Response Header events.
>**NOTE**
>This API has been deprecated. You are advised to use [on('headersReceive')<sup>8+</sup>](#onheadersreceive8) instead.
>This API has been deprecated. You are advised to use [on('headersReceive')<sup>8+</sup>](#onheadersreceive8).
**System capability**: SystemCapability.Communication.NetStack
......@@ -363,7 +363,7 @@ Unregisters the observer for HTTP Response Header events.
>**NOTE**
>
>1. This API has been deprecated. You are advised to use [off('headersReceive')<sup>8+</sup>](#offheadersreceive8) instead.
>1. This API has been deprecated. You are advised to use [off('headersReceive')<sup>8+</sup>](#offheadersreceive8).
>
>2. You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
......
......@@ -275,8 +275,8 @@ Binds an application to the specified network, so that the application can acces
```js
connection.getDefaultNet().then(function (netHandle) {
connection.setAppNet(netHandle).then((error, data) => {
console.log(JSON.stringify(data))
connection.setAppNet(netHandle).then(() => {
console.log("success")
}).catch(error => {
console.log(JSON.stringify(error))
})
......@@ -936,7 +936,7 @@ getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>):
Resolves the host name by using the default network to obtain all IP addresses. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetManager.Core
......@@ -973,7 +973,7 @@ getAddressesByName(host: string): Promise\<Array\<NetAddress>>
Resolves the host name by using the default network to obtain all IP addresses. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetManager.Core
......@@ -1478,7 +1478,7 @@ getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>):
Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetManager.Core
......@@ -1517,7 +1517,7 @@ getAddressesByName(host: string): Promise\<Array\<NetAddress>>
Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetManager.Core
......@@ -1560,7 +1560,7 @@ getAddressByName(host: string, callback: AsyncCallback\<NetAddress>): void
Resolves the host name by using the corresponding network to obtain the first IP address. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetManager.Core
......@@ -1599,7 +1599,7 @@ getAddressByName(host: string): Promise\<NetAddress>
Resolves the host name by using the corresponding network to obtain the first IP address. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetManager.Core
......
......@@ -91,6 +91,19 @@ Sends an SMS message.
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [SendMessageOptions](#sendmessageoptions) | Yes | Options (including the callback) for sending an SMS message.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
**Example**
```js
......@@ -178,6 +191,7 @@ Sets the default slot ID of the SIM card used to send SMS messages. This API use
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -193,8 +207,8 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
sms.setDefaultSmsSlotId(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
sms.setDefaultSmsSlotId(0, (err) => {
console.log(`callback: err->${JSON.stringify(err)}.`);
});
```
......@@ -224,6 +238,7 @@ Sets the default slot ID of the SIM card used to send SMS messages. This API use
| Promise\<void\> | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -240,9 +255,9 @@ For details about the following error codes, see [Telephony Error Codes](../../r
```js
let promise = sms.setDefaultSmsSlotId(0);
promise.then(data => {
console.log(`setDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
promise.then(() => {
console.log(`setDefaultSmsSlotId success.`);
}).catch((err) => {
console.error(`setDefaultSmsSlotId failed, promise: err->${JSON.stringify(err)}`);
});
```
......@@ -268,6 +283,7 @@ Sets the short message service center (SMSC) address. This API uses an asynchron
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -284,8 +300,8 @@ For details about the following error codes, see [Telephony Error Codes](../../r
```js
let slotId = 0;
let smscAddr = '+861xxxxxxxxxx';
sms.setSmscAddr(slotId, smscAddr, (err,data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
sms.setSmscAddr(slotId, smscAddr, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`);
});
```
......@@ -316,6 +332,7 @@ Sets the SMSC address. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -333,9 +350,9 @@ For details about the following error codes, see [Telephony Error Codes](../../r
let slotId = 0;
let smscAddr = '+861xxxxxxxxxx';
let promise = sms.setSmscAddr(slotId, smscAddr);
promise.then(data => {
console.log(`setSmscAddr success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
promise.then(() => {
console.log(`setSmscAddr success.`);
}).catch((err) => {
console.error(`setSmscAddr failed, promise: err->${JSON.stringify(err)}`);
});
```
......@@ -361,6 +378,7 @@ Obtains the SMSC address. This API uses an asynchronous callback to return the r
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -407,6 +425,7 @@ Obtains the SMSC address. This API uses a promise to return the result.
| Promise&lt;string&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -469,6 +488,7 @@ Splits an SMS message into multiple segments. This API uses an asynchronous call
| callback | AsyncCallback<Array<string\>> | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -515,6 +535,7 @@ Splits an SMS message into multiple segments. This API uses a promise to return
| Promise<Array<string\>> | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -558,6 +579,7 @@ Adds a SIM message. This API uses an asynchronous callback to return the result.
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -578,8 +600,8 @@ let simMessageOptions = {
pdu: "xxxxxx",
status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ
};
sms.addSimMessage(simMessageOptions, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
sms.addSimMessage(simMessageOptions, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`);
});
```
......@@ -609,6 +631,7 @@ Adds a SIM message. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -630,9 +653,9 @@ let simMessageOptions = {
status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ
};
let promise = sms.addSimMessage(simMessageOptions);
promise.then(data => {
console.log(`addSimMessage success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
promise.then(() => {
console.log(`addSimMessage success.`);
}).catch((err) => {
console.error(`addSimMessage failed, promise: err->${JSON.stringify(err)}`);
});
```
......@@ -658,6 +681,7 @@ Deletes a SIM message. This API uses an asynchronous callback to return the resu
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -674,8 +698,8 @@ For details about the following error codes, see [Telephony Error Codes](../../r
```js
let slotId = 0;
let msgIndex = 1;
sms.delSimMessage(slotId, msgIndex, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
sms.delSimMessage(slotId, msgIndex, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`);
});
```
......@@ -706,6 +730,7 @@ Deletes a SIM message. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -723,9 +748,9 @@ For details about the following error codes, see [Telephony Error Codes](../../r
let slotId = 0;
let msgIndex = 1;
let promise = sms.delSimMessage(slotId, msgIndex);
promise.then(data => {
console.log(`delSimMessage success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
promise.then(() => {
console.log(`delSimMessage success.`);
}).catch((err) => {
console.error(`delSimMessage failed, promise: err->${JSON.stringify(err)}`);
});
```
......@@ -750,6 +775,7 @@ Updates a SIM message. This API uses an asynchronous callback to return the resu
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -771,8 +797,8 @@ let updateSimMessageOptions = {
pdu: "xxxxxxx",
smsc: "test"
};
sms.updateSimMessage(updateSimMessageOptions, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
sms.updateSimMessage(updateSimMessageOptions, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`);
});
```
......@@ -802,6 +828,7 @@ Updates a SIM message. This API uses a promise to return the result.
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -824,9 +851,9 @@ let updateSimMessageOptions = {
smsc: "test"
};
let promise = sms.updateSimMessage(updateSimMessageOptions);
promise.then(data => {
console.log(`updateSimMessage success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
promise.then(() => {
console.log(`updateSimMessage success.`);
}).catch((err) => {
console.error(`updateSimMessage failed, promise: err->${JSON.stringify(err)}`);
});
```
......@@ -851,6 +878,7 @@ Obtains all SIM card messages. This API uses an asynchronous callback to return
| callback | AsyncCallback<Array<[SimShortMessage](#simshortmessage7)\>> | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -897,6 +925,7 @@ Obtains all SIM card messages. This API uses a promise to return the result.
| PromiseArray<[SimShortMessage](#simshortmessage7)\>&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -940,6 +969,7 @@ Sets the cell broadcast configuration. This API uses an asynchronous callback to
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -961,8 +991,8 @@ let cbConfigOptions = {
endMessageId: 200,
ranType: sms.RanType.TYPE_GSM
};
sms.setCBConfig(cbConfigOptions, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
sms.setCBConfig(cbConfigOptions, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`);
});
```
......@@ -992,6 +1022,7 @@ Sets the cell broadcast configuration. This API uses a promise to return the res
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1014,9 +1045,9 @@ let cbConfigOptions = {
ranType: sms.RanType.TYPE_GSM
};
let promise = sms.setCBConfig(cbConfigOptions);
promise.then(data => {
console.log(`setCBConfig success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
promise.then(() => {
console.log(`setCBConfig success.`);
}).catch((err) => {
console.error(`setCBConfig failed, promise: err->${JSON.stringify(err)}`);
});
```
......@@ -1041,6 +1072,7 @@ Obtains SMS message segment information. This API uses an asynchronous callback
| callback | AsyncCallback&lt;[SmsSegmentsInfo](#smssegmentsinfo8)&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1086,6 +1118,7 @@ Obtains SMS message segment information. This API uses a promise to return the r
| Promise&lt;[SmsSegmentsInfo](#smssegmentsinfo8)&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1126,6 +1159,7 @@ Checks whether SMS is supported on IMS. This API uses an asynchronous callback t
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1169,6 +1203,7 @@ This API uses an asynchronous callback to return the result. This API uses a pro
| Promise&lt;boolean&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1208,11 +1243,11 @@ Obtains the SMS format supported by the IMS. This API uses an asynchronous callb
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
......@@ -1245,11 +1280,11 @@ Obtains the SMS format supported by the IMS. This API uses a promise to return t
| Promise&lt;string&gt; | Promise used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
......@@ -1285,6 +1320,7 @@ Decodes MMS messages. This API uses an asynchronous callback to return the resul
| callback | AsyncCallback&lt;[MmsInformation](#mmsinformation8)&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1328,6 +1364,7 @@ Decodes MMS messages. This API uses a promise to return the result.
| Promise&lt;&lt;[MmsInformation](#mmsinformation8)&gt;&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1368,6 +1405,7 @@ MMS message code. This API uses an asynchronous callback to return the result.
| callback | AsyncCallback&lt;Array<number\>&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1419,6 +1457,7 @@ MMS message code. This API uses a promise to return the result.
| Promise&lt;Array<number\>&gt; | Promise used to return the result.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
......@@ -1955,7 +1994,7 @@ Defines an MMS response index.
| Name | Type | Mandatory| Description |
| ------------- | ---------------------------------- | ---- | -------- |
| transactionId | string | Yes | Event ID. |
| status | number | Yes | Status. |
| status | number | Yes | Status |
| version | [MmsVersionType](#mmsversiontype8) | Yes | Version. |
| reportAllowed | [ReportType](#reporttype8) | No | Report allowed.|
......
# # @ohos.net.socket (Socket Connection)
The **socket** module implements data transfer over TCPSocket, UDPSocket, WebSocket, and TLSSocket connections.
> **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.
......
......@@ -1303,5 +1303,4 @@
- [Native API Usage](faqs/faqs-native.md)
- [Usage of Third- and Fourth-Party Libraries](faqs/faqs-third-party-library.md)
- [IDE Usage](faqs/faqs-ide.md)
- [hdc_std Command Usage](faqs/faqs-hdc-std.md)
- [Development Board](faqs/faqs-development-board.md)
......@@ -100,7 +100,6 @@
- [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md)
- [HiSysEvent Query](subsys-dfx-hisysevent-query.md)
- [HiSysEvent Tool Usage](subsys-dfx-hisysevent-tool.md)
- [HiDumper Development](subsys-dfx-hidumper.md)
- [HiChecker Development](subsys-dfx-hichecker.md)
- [FaultLogger Development](subsys-dfx-faultlogger.md)
- [Hiview Development](subsys-dfx-hiview.md)
......@@ -108,3 +107,4 @@
- [bytrace](subsys-toolchain-bytrace-guide.md)
- [hdc](subsys-toolchain-hdc-guide.md)
- [hiperf](subsys-toolchain-hiperf.md)
- [HiDumper](subsys-dfx-hidumper.md)
......@@ -4,72 +4,75 @@
## Overview
### Function
### Function Introduction
FaultLogger is a maintenance and debugging log framework provided by OpenHarmony. It enables unified detection, log collection, log storage, and log reporting for application, ability, and system service process crashes. It is available for the standard system and the Linux kernel-based small system.
FaultLogger is responsible for fault recording of OpenHarmony. It runs on the following two components based on the service object:
- HiView: serves functional modules at the application layer and native layer. It manages various fault information in the system and provides APIs for modules to query faults.
- Hiview: serves functional modules at the application layer and native layer. It manages various fault information in the system and provides APIs for modules to query faults.
- FaultLoggerd: serves the crash process. It collects information about abnormal daemon processes in C/C++ and obtains the process call stack.
- Faultloggerd: serves the crash process. It collects information about the abnormal daemon process in C/C++ and obtains call stack information of the process.
The following figure shows the process of handling a process crash based on the FaultLogger service.
**Figure 1** Process crash handling flowchart
![process_crash_handling](figures/process_crash_handling.png)
![Process crash handling flowchart](figures/process_crash_handling_flowchart.png)
1. After the signal processor is installed, the **DFX_SignalHandler** function detects and responds to the process crash exception signal.
1. After the signal processor is installed, SignalHandler uses the **DFX_SignalHandler** function to detect and respond to the process crash exception signal thrown by the kernel.
2. **SignalHandler** forks a child process after detecting the exception signal and runs **ProcessDump** to dump the stack information of the crashed process and thread.
2. When detecting a process crash exception signal, SignalHandler forks a child process and runs ProcessDump to dump the stack information of the crashed process and thread.
3. **ProcessDump** then writes a log to the temporary storage directory in FaultLoggerd, generating a full crash log.
3. ProcessDump applies to Faultloggerd for a file handle for storing fault logs. After reading the exception stack information, ProcessDump writes the information to the file to generate a complete crash log.
4. FaultLoggerd reports the fault through the **AddFaultLog()** API provided by HiView. HiView handles the fault, generates a simple crash log, and reports a HiSysEvent.
4. After collecting the complete crash log, ProcessDump reports the log to Hiview by using the **AddFaultLog()** API. Hiview generates a simplified crash log and reports a system event through HiSysEvent.
With this design, a small-system with limited resources can obtain logs for locating crash faults as long as FaultLoggerd is deployed.
With this design, a small-system with limited resources can obtain logs for locating crash faults as long as Faultloggerd is deployed.
### Use Cases
FaultLoggerd provides a lightweight approach for you to locate crash or suspension problems during development and testing.
Faultloggerd provides a lightweight approach for you to locate crash or suspension problems during development and testing.
It is applicable to the following scenarios:
The following table describes the application scenarios.
**Table 1** Application scenarios of the Faultloggerd module
| Scenario| Tool| Usage|
| -------- | -------- | -------- |
| To understand the function call sequence| DumpCatcher&nbsp;API | See [Using DumpCatcher to Obtain the Call Stack](#using-dumpcatcher-to-obtain-the-call-stack).|
| Application suspension or high CPU usage| ProcessDump | See [Using ProcessDump to Obtain the Call Stack](#using-processdump-to-obtain-the-call-stack).|
| Signal crash not handled by the process| Crash log and addr2line tool| See [Locating Faults Based on Crash Logs](#locating-faults-based-on-crash-logs).|
| Understanding of the function call sequence| DumpCatcher API | See [Using DumpCatcher APIs to Obtain Call Stack Information](#using-dumpcatcher-apis-to-obtain-call-stack-information).|
| Application suspension or high CPU usage| DumpCatcher Command Tool | See [Using DumpCatcher Commands to Obtain Call Stack Information](#using-dumpcatcher-commands-to-obtain-call-stack-information).|
| Crash fault location| Crash log and addr2line tool| For details, see [Locating Faults Based on the Crash Log](#locating-faults-based-on-the-crash-log).|
## Using DumpCatcher to Obtain the Call Stack
## Using DumpCatcher APIs to Obtain Call Stack Information
### Available APIs
DumpCatcher can capture the call stack of a specified process (thread) on OpenHarmony.
DumpCatcher can capture the call stack information of the specified process (thread) on OpenHarmony.
Table 2 DumpCatcher APIs
**Table 2** DumpCatcher APIs
| Class| API| Description|
| -------- | -------- | -------- |
| DfxDumpCatcher | bool&nbsp;DumpCatch(const&nbsp;int&nbsp;pid,&nbsp;const&nbsp;int&nbsp;tid,&nbsp;std::string&amp;&nbsp;msg) | Return value:<br>**true**: Back trace is successful. Related information is stored in the **msg** string object.<br>**false**: Back trace failed.<br>Input arguments:<br>**pid**: target process ID.<br>**tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br>Output argument:<br>**msg**: return message. If back trace is successful, the call stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatch(const int pid, const int tid, std::string&amp; msg) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>- **pid**: target process ID.<br>- **tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br> Output arguments:<br>- **msg**: If back trace is successful, call stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatchMix(const int pid, const int tid, std::string&amp; msg) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>**pid**: target process ID.<br>- **tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br> Output arguments:<br>- **msg**: If back trace is successful, hybrid stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatchFd(const int pid, const int tid, std::string&amp; msg, int fd) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>**pid**: target process ID.<br>- **tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br>- **fd**: handle of the file to be written.<br> Output parameters:<br>- **msg**: If back trace is successful, call stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatchMultiPid(const std::vector\<int> pidV, std::string&amp; msg) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>- **pidV**: target process ID list.<br> Output arguments:<br>- **msg**: If back trace is successful, call stack information is returned through **msg**.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> If the PID that calls this API is different from the target PID, the caller must be the **system** or **root** user. To capture the call stack of a process that does not belong to the current user group, ensure that you have permissions to read **/proc/pid/maps** and implement **ptrace** on the peer process.
> **NOTE**
> If the PID that calls this API is different from the target PID, the caller must be the **system** or **root** user.
### Development Example
### How to Develop
You can use DumpCatcher to obtain the call stack of a specified process (thread) in your applications. The following uses the **dumpcatcherdemo** module as an example to describe how to use the DumpCatcher API to obtain the call stack.
You can use DumpCatcher to obtain call stack information for the specified process (thread) of an application. The following uses the **dumpcatcherdemo** module as an example to describe how to use the DumpCatcher APIs to obtain the call stack information.
1. Add the DumpCatcher dependency to the build file. Take /base/hiviewdfx/faultloggerd/example/BUILD.gn as an example. Add the **dfx_dump_catcher.h** file path to **include_dirs** and add the required **//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher** module to **deps**.
1. Add the DumpCatcher dependency to the build file. Take /base/hiviewdfx/faultloggerd/example/BUILD.gn as an example. Add the **dump_catcher.h** file path to **include_dirs** and add the required **//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher** module to **deps**.
```
import("//base/hiviewdfx/faultloggerd/faultloggerd.gni")
......@@ -85,7 +88,17 @@ You can use DumpCatcher to obtain the call stack of a specified process (thread)
]
}
ohos_executable("dumpcatcherdemo") { sources = [ "dump_catcher_demo.cpp" ] configs = [ ":dumpcatcherdemo_config" ] deps = [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher", # Add the DumpCatcher module dependency. "//utils/native/base:utils", ] external_deps = [ "hilog_native:libhilog" ] install_enable = true part_name = "faultloggerd" subsystem_name = "hiviewdfx"
ohos_executable("dumpcatcherdemo") {
sources = [ "dump_catcher_demo.cpp" ]
configs = [ ":dumpcatcherdemo_config" ]
deps = [
"//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher", # Add the DumpCatcher module dependency.
"//utils/native/base:utils",
]
external_deps = [ "hilog_native:libhilog" ]
install_enable = true
part_name = "faultloggerd"
subsystem_name = "hiviewdfx"
}
```
......@@ -138,7 +151,7 @@ You can use DumpCatcher to obtain the call stack of a specified process (thread)
{
OHOS::HiviewDFX::DfxDumpCatcher dumplog;
string msg = "";
bool ret = dumplog.DumpCatch(getpid(), gettid(), msg); // Call the DumpCatch API to obtain the call stack.
bool ret = dumplog.DumpCatch(getpid(), gettid(), msg); // Call the DumpCatch API to obtain the call stack information.
if (ret) {
cout << msg << endl;
}
......@@ -165,50 +178,52 @@ You can use DumpCatcher to obtain the call stack of a specified process (thread)
```
## Using ProcessDump to Obtain the Call Stack
## Using DumpCatcher Commands to Obtain Call Stack Information
### Tool Description
ProcessDump is a command line interface (CLI) based tool for capturing call stacks on OpenHarmony. It uses the **-p** and **-t** parameters to specify the process and thread. After the command is executed, the thread stack information of the specified process is displayed in the CLI window.
DumpCatcher Command Tool is a command line interface (CLI)-based tool for capturing call stack information on OpenHarmony. It uses the **-p** and **-t** parameters to specify the process and thread. After the command is executed, the thread stack information of the specified process is displayed in the CLI window. By specifying the **-m** parameter, you can also capture the JS and Native hybrid stack information of an application process.
**Table 3** Usage of the CLI-based ProcessDump
**Table 3** Usage of the DumpCatcher Command Tool
| Tool| Path| Command| Description|
| -------- | -------- | -------- | -------- |
| processdump | /system/bin | -&nbsp;processdump&nbsp;-p&nbsp;[pid]<br>-&nbsp;processdump&nbsp;-p&nbsp;[pid]&nbsp;-t&nbsp;[tid] | **Arguments:**<br>**- -p [pid]**: prints stack information for all threads of the specified process.<br>**- -p [pid] -t [tid]**: prints information for the specified thread of the specified process.<br>**Return value:**<br>If the stack information is parsed successfully, the information is displayed in the standard output. If the stack information fails to be parsed, error information is displayed.|
| dumpcatcher | /system/bin | - dumpcatcher -p [pid]<br>- dumpcatcher -p [pid] -t [tid]<br>- dumpcatcher -m -p [pid]<br>- dumpcatcher -m -p [pid] -t [tid]<br>| **Description:**<br>- **-p [pid]**: prints all thread stack information of the specified process.<br>- **-p [pid] -t [tid]**: prints stack information for the specified thread of the specified process.<br>- **-m -p [pid]**: prints hybrid stack information for all threads of the specified process.<br>- **-m -p [pid] -t [tid]**: prints hybrid stack information for the specified thread of the specified process.<br>**Return value:**<br>If the stack information is parsed successfully, the information is displayed in the standard output. If the stack information fails to be parsed, error information is displayed.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> This tool must be used by the **root** user, or the caller must have the permission to ptrace the target process and read the smaps of the target process.
### Development Example
### Example
Use ProcessDump to print the call stack of the **hiview** process.
Print call stack information of the **hiview** process.
```
# ps -A | grep hiview
114 ? 00:00:00 hiview
# processdump -p 114 -t 114
Tid:114, Name:hiview
#00 pc 0000000000089824(00000000b6f44824) /system/lib/ld-musl-arm.so.1(ioctl+68)
#01 pc 000000000002a709(00000000b6c56709) /system/lib/libipc_core.z.so(_ZN4OHOS15BinderConnector11WriteBinderEmPv+16)
#02 pc 000000000002ba75(00000000b6c57a75) /system/lib/libipc_core.z.so(_ZN4OHOS13BinderInvoker18TransactWithDriverEb+224)
#03 pc 000000000002bb37(00000000b6c57b37) /system/lib/libipc_core.z.so(_ZN4OHOS13BinderInvoker13StartWorkLoopEv+22)
#04 pc 000000000002c211(00000000b6c58211) /system/lib/libipc_core.z.so(_ZN4OHOS13BinderInvoker10JoinThreadEb+36)
#05 pc 0000000000038d07(00000000004bcd07) /system/bin/hiview(_ZNSt3__h6vectorINS_9sub_matchINS_11__wrap_iterIPKcEEEENS_9allocatorIS6_EEE8__appendEj+596)
#06 pc 0000000000028655(00000000004ac655) /system/bin/hiview
#07 pc 00000000000c2b08(00000000b6f7db08) /system/lib/ld-musl-arm.so.1(__libc_start_main+116)
#08 pc 00000000000285f4(00000000004ac5f4) /system/bin/hiview
#09 pc 0000000000028580(00000000004ac580) /system/bin/hiview
# ps -ef |grep hiview
hiview 240 1 0 17:01:49 ? 00:00:14 hiview
root 1822 1560 7 20:56:36 pts/0 00:00:00 grep hiview
# dumpcatcher -p 240 -t 240
Result: 0 ( no error )
Timestamp:2017-08-05 20:56:43.000
Pid:240
Uid:1201
Process name:/system/bin/hiview
Tid:240, Name:hiview
#00 pc 00098f8c /system/lib/ld-musl-arm.so.1(ioctl+68)
#01 pc 0000e2a1 /system/lib/chipset-pub-sdk/libipc_single.z.so
#02 pc 0000ed59 /system/lib/chipset-pub-sdk/libipc_single.z.so
#03 pc 0000ee1f /system/lib/chipset-pub-sdk/libipc_single.z.so
#04 pc 0000f745 /system/lib/chipset-pub-sdk/libipc_single.z.so
#05 pc 00037577 /system/bin/hiview
#06 pc 00025973 /system/bin/hiview
#07 pc 000db210 /system/lib/ld-musl-arm.so.1
#08 pc 000258d8 /system/bin/hiview
#09 pc 0002587c /system/bin/hiview
```
## Locating Faults Based on Crash Logs
## Locating Faults Based on the Crash Log
You can locate faults based on the crash stack logs generated by FaultLoggerd. This section describes how to use the addr2line tool to locate a crash fault.
You can locate faults based on the crash stack logs generated by Faultloggerd. This section describes how to use the addr2line tool to locate a crash fault.
1. Find a program crash or construct a crash.
For example, insert the following code into your code to trigger an invalid memory access fault (SIGSEGV).
......@@ -233,35 +248,36 @@ You can locate faults based on the crash stack logs generated by FaultLoggerd. T
cppcrash-pid-time
```
The generated call stack is as follows:
The generated call stack information is as follows:
```
Timestamp:2017-08-05 17:35:03.000
Pid:816
Uid:0
Process name:./crasher
Process name:./crasher_c
Reason:Signal:SIGSEGV(SEGV_ACCERR)@0x0042d33d
Fault thread Info:
Tid:816, Name:crasher
#00 pc 0000332c /data/crasher(TriggerSegmentFaultException+15)(8bc37ceb8d6169e919d178fdc7f5449e)
#01 pc 000035c7 /data/crasher(ParseAndDoCrash+277)(8bc37ceb8d6169e919d178fdc7f5449e)
#02 pc 00003689 /data/crasher(main+39)(8bc37ceb8d6169e919d178fdc7f5449e)
#03 pc 000c3b08 /system/lib/ld-musl-arm.so.1(__libc_start_main+116)
#04 pc 000032f8 /data/crasher(_start_c+112)(8bc37ceb8d6169e919d178fdc7f5449e)
#05 pc 00003284 /data/crasher(_start+32)(8bc37ceb8d6169e919d178fdc7f5449e)
Registers:
r0:0042d33d r1:0000000b r2:1725d4c4 r3:b6f9fa84
r4:bec97e69 r5:b6fc0268 r6:0042d661 r7:bec97d60
r8:00000000 r9:00000000 r10:00000000
fp:bec97d20 ip:00000020 sp:bec97cd0 lr:b6f9fae4 pc:0042d32c
#00 pc 000000000000332c(000000000042d32c) /data/crasher(TriggerSegmentFaultException+15)
#01 pc 00000000000035c7(000000000042d5c7) /data/crasher(ParseAndDoCrash+277)
#02 pc 0000000000003689(000000000042d689) /data/crasher(main+39)
#03 pc 00000000000c3b08(00000000b6fbbb08) /system/lib/ld-musl-arm.so.1(__libc_start_main+116)
#04 pc 00000000000032f8(000000000042d2f8) /data/crasher(_start_c+112)
#05 pc 0000000000003284(000000000042d284) /data/crasher(_start+32)
```
3. Use the addr2line tool to analyze the call stack.
3. Use the addr2line tool to analyze the call stack information.
Then, parse the line number based on the offset address.
```
root:~/OpenHarmony/out/hi3516dv300/exe.unstripped/hiviewdfx/faultloggerd$ addr2line -e crasher 000332c
root:~/OpenHarmony/out/hi3516dv300/exe.unstripped/hiviewdfx/faultloggerd$ addr2line -e crasher 0000332c
base/hiviewdfx/faultloggerd/tools/crasher/dfx_crasher.c:57
```
......
# HiCollie Development<a name="EN-US_TOPIC_0000001231255509"></a>
# HiCollie Development
## Overview<a name="section3432134085116"></a>
## Overview
HiCollie provides the software watchdog function. It provides a unified framework for fault detection and fault log generation to help you locate software timeout faults resulting from system service deadlock, application main thread blocking, and service process timeout.
## Available APIs<a name="section139261151145116"></a>
**Table 1** Description of C++ APIs
<a name="table19452225011"></a>
<table><thead align="left"><tr id="row1517803543518"><th class="cellrowborder" valign="top" width="19.698030196980305%" id="mcps1.2.4.1.1"><p id="p484763319529"><a name="p484763319529"></a><a name="p484763319529"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="35.82641735826417%" id="mcps1.2.4.1.2"><p id="p1684719339523"><a name="p1684719339523"></a><a name="p1684719339523"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="44.47555244475552%" id="mcps1.2.4.1.3"><p id="p284773315220"><a name="p284773315220"></a><a name="p284773315220"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1361184632117"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p6700155032113"><a name="p6700155032113"></a><a name="p6700155032113"></a>XCollieChecker</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p18699115019217"><a name="p18699115019217"></a><a name="p18699115019217"></a>virtual void CheckBlock()</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p18700175062115"><a name="p18700175062115"></a><a name="p18700175062115"></a>Provides the callback of the suspension detection result.</p>
<p id="p13700125012216"><a name="p13700125012216"></a><a name="p13700125012216"></a>Input arguments: none</p>
<p id="p13700650162114"><a name="p13700650162114"></a><a name="p13700650162114"></a>Output arguments: none</p>
<p id="p3700850192115"><a name="p3700850192115"></a><a name="p3700850192115"></a>Return value: none</p>
</td>
</tr>
<tr id="row8945182185017"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p79451227506"><a name="p79451227506"></a><a name="p79451227506"></a>XCollieChecker</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p647534064612"><a name="p647534064612"></a><a name="p647534064612"></a>virtual void CheckThreadBlock()</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p127630177475"><a name="p127630177475"></a><a name="p127630177475"></a>Provides the callback of the thread suspension detection result.</p>
<p id="p18763111794719"><a name="p18763111794719"></a><a name="p18763111794719"></a>Input arguments: none</p>
<p id="p87631176478"><a name="p87631176478"></a><a name="p87631176478"></a>Output arguments: none</p>
<p id="p3764111718473"><a name="p3764111718473"></a><a name="p3764111718473"></a>Return value: none</p>
</td>
</tr>
<tr id="row149924222486"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p11643173114810"><a name="p11643173114810"></a><a name="p11643173114810"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p16289114074812"><a name="p16289114074812"></a><a name="p16289114074812"></a>void RegisterXCollieChecker(const sptr&lt;XCollieChecker&gt; &amp;checker, unsigned int type)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p186437319482"><a name="p186437319482"></a><a name="p186437319482"></a>Registers the callback of the thread suspension detection result.</p>
<p id="p112011591133"><a name="p112011591133"></a><a name="p112011591133"></a>Input arguments:</p>
<a name="ul7783192181413"></a><a name="ul7783192181413"></a><ul id="ul7783192181413"><li><strong id="b64637561712"><a name="b64637561712"></a><a name="b64637561712"></a>checker</strong>: Indicates the pointer to the XCollieChecker instance.</li><li><strong id="b1947711661711"><a name="b1947711661711"></a><a name="b1947711661711"></a>type</strong>: Indicates the suspension detection type. Set it to <strong id="b259214119717"><a name="b259214119717"></a><a name="b259214119717"></a>XCOLLIE_THREAD</strong>.</li></ul>
<p id="p166439314482"><a name="p166439314482"></a><a name="p166439314482"></a>Output arguments: none</p>
<p id="p564393112485"><a name="p564393112485"></a><a name="p564393112485"></a>Return value: none</p>
</td>
</tr>
<tr id="row594519275012"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p294512211505"><a name="p294512211505"></a><a name="p294512211505"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p81561310145215"><a name="p81561310145215"></a><a name="p81561310145215"></a>int SetTimer(const std::string &amp;name, unsigned int timeout, std::function&lt;void (void *)&gt; func, void *arg, unsigned int flag)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p174279246538"><a name="p174279246538"></a><a name="p174279246538"></a>Adds timers.</p>
<p id="p1998141221410"><a name="p1998141221410"></a><a name="p1998141221410"></a>Input arguments:</p>
<a name="ul845512153147"></a><a name="ul845512153147"></a><ul id="ul845512153147"><li><strong id="b44651010141715"><a name="b44651010141715"></a><a name="b44651010141715"></a>name</strong>: Indicates the timer name.</li><li><strong id="b266981221717"><a name="b266981221717"></a><a name="b266981221717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li><li><strong id="b17158171421710"><a name="b17158171421710"></a><a name="b17158171421710"></a>func</strong>: Indicates the timeout callback.</li><li><strong id="b1950162581810"><a name="b1950162581810"></a><a name="b1950162581810"></a>arg</strong>: Indicates the pointer to the timeout callback.</li><li><strong id="b4949151521714"><a name="b4949151521714"></a><a name="b4949151521714"></a>flag</strong>: Indicates the timer operation type.<p id="p1242762435310"><a name="p1242762435310"></a><a name="p1242762435310"></a>XCOLLIE_FLAG_DEFAULT // Indicates the default flag, which is the combination of the other three options.</p>
<p id="p1542712435312"><a name="p1542712435312"></a><a name="p1542712435312"></a>XCOLLIE_FLAG_NOOP // Calls only the timeout callback.</p>
<p id="p15427112416531"><a name="p15427112416531"></a><a name="p15427112416531"></a>XCOLLIE_FLAG_LOG // Generates a timeout fault log.</p>
<p id="p242762455314"><a name="p242762455314"></a><a name="p242762455314"></a>XCOLLIE_FLAG_RECOVERY // Exits the process.</p>
</li></ul>
<p id="p15427102445311"><a name="p15427102445311"></a><a name="p15427102445311"></a>Output arguments: none</p>
<p id="p144271424155316"><a name="p144271424155316"></a><a name="p144271424155316"></a>Return value: Returns the timer ID if the operation is successful; returns <strong id="b2229713291"><a name="b2229713291"></a><a name="b2229713291"></a>-1</strong> otherwise.</p>
</td>
</tr>
<tr id="row1294692165010"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p19461929506"><a name="p19461929506"></a><a name="p19461929506"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p119467215012"><a name="p119467215012"></a><a name="p119467215012"></a>bool UpdateTimer(int id, unsigned int timeout)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p3831253185713"><a name="p3831253185713"></a><a name="p3831253185713"></a>Updates timers.</p>
<p id="p10649172815148"><a name="p10649172815148"></a><a name="p10649172815148"></a>Input arguments:</p>
<a name="ul1628783221411"></a><a name="ul1628783221411"></a><ul id="ul1628783221411"><li><strong id="b61651021161710"><a name="b61651021161710"></a><a name="b61651021161710"></a>id</strong>: Indicates the timer ID.</li><li><strong id="b24661423141717"><a name="b24661423141717"></a><a name="b24661423141717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li></ul>
<p id="p11831115375719"><a name="p11831115375719"></a><a name="p11831115375719"></a>Output arguments: none</p>
<p id="p38311853105716"><a name="p38311853105716"></a><a name="p38311853105716"></a>Return value: Returns <strong id="b95701352192819"><a name="b95701352192819"></a><a name="b95701352192819"></a>true</strong> if the operation is successful; returns <strong id="b175761652152814"><a name="b175761652152814"></a><a name="b175761652152814"></a>false</strong> otherwise.</p>
</td>
</tr>
<tr id="row594682175013"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p194614212504"><a name="p194614212504"></a><a name="p194614212504"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p1435552713588"><a name="p1435552713588"></a><a name="p1435552713588"></a>void CancelTimer(int id)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p06791131580"><a name="p06791131580"></a><a name="p06791131580"></a>Cancels timers.</p>
<p id="p868013165815"><a name="p868013165815"></a><a name="p868013165815"></a>Input arguments:</p>
<p id="p9311488283"><a name="p9311488283"></a><a name="p9311488283"></a><strong id="b9666749171816"><a name="b9666749171816"></a><a name="b9666749171816"></a>id</strong>: Indicates the timer ID.</p>
<p id="p12680537587"><a name="p12680537587"></a><a name="p12680537587"></a>Output arguments: none</p>
<p id="p768015317586"><a name="p768015317586"></a><a name="p768015317586"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## Example<a name="section1589120102458"></a>
Print logs.
```
timeout: TimeoutTimer start at 1611040305 to check 1s ago
----------StacktraceCatcher CurrentTime:2021-01-19 15:11:45 Unexecuted(-1)(LogType:Stacktrace Pid:27689 Process:XCollieTimeoutModuleTest)----------
----- pid 27689 at 2021-01-19 15:11:45 -----
Cmd line: ./XCollieTimeoutModuleTest
ABI: 'arm64'
"XCollieTimeoutM" sysTid=27689
#01 pc 00000000000174cc /data/test/XCollieTimeoutModuleTest
```
## How to Develop<a name="section13905646534"></a>
### C++<a name="section9797199145316"></a>
### Thread Suspension Monitoring<a name="section1734221332"></a>
## Available APIs
**Table 1** Description of XCollieChecker APIs
| API| Description|
| -------- | -------- |
| virtual void CheckBlock() | Provides the callback of the suspension detection result.<br>Input arguments: none<br>Output arguments: none<br>Return value: none|
| virtual void CheckThreadBlock() | Provides the callback of the thread suspension detection result.<br>Input arguments: none<br>Output arguments: none<br>Return value: none|
**Table 2** Description of XCollie APIs
| API| Description|
| -------- | -------- |
| void RegisterXCollieChecker(const sptr&lt;XCollieChecker&gt; &amp;checker, unsigned int type) | Registers the callback of the thread suspension detection result.<br>Input arguments:<br>- **checker**: pointer to the XCollieChecker instance.<br>- **type**: suspension detection type. Set it to **XCOLLIE_THREAD**.<br>Output arguments: none<br>Return value: none|
| int SetTimer(const std::string &amp;name, unsigned int timeout, std::function&lt;void(void*)&gt; func, void *arg, unsigned int flag) | Adds timers.<br>Input arguments:<br>- **name**: timer name.<br>- **timeout**: timeout duration, in seconds.<br>- **func**: timeout callback.<br>- **arg**: pointer to the timeout callback.<br>- **flag**: timer operation type.<br> - **XCOLLIE_FLAG_DEFAULT**: default flag, which is the combination of the other three options.<br> - **XCOLLIE_FLAG_NOOP**: Calls only the timeout callback.<br> - **XCOLLIE_FLAG_LOG**: Generates a timeout fault log.<br> - **XCOLLIE_FLAG_RECOVERY**: Exits the process.<br>Output arguments: none<br>Return value: timer ID if the operation is successful; **-1** otherwise.|
| bool UpdateTimer(int id, unsigned int timeout) | Updates timers.<br>Input arguments:<br>- **id**: timer ID.<br>- **timeout**: timeout duration, in seconds.<br>Output arguments: none<br>Return value: **true** if the operation is successful; **false** otherwise.|
| void CancelTimer(int id) | Cancels a timer.<br>Input arguments:<br>- **id**: timer ID.<br>Output arguments: none<br>Return value: none|
## How to Develop
### Thread Suspension Monitoring
This function requires you to implement two callback functions: **CheckBlock** and **CheckThreadBlock** of the **XCollieChecker** class. After the callbacks are implemented, you need to use the **RegisterXCollieChecker** function of the **XCollie** class to register their instances. The suspension monitoring thread periodically executes all successfully registered callbacks, checks the thread logic completion flag, and determines whether the service logic of any registered thread is suspended.
1. Develop the source code.
Include the **xcollie** header file in the source file.
```
......@@ -124,6 +42,7 @@ This function requires you to implement two callback functions: **CheckBlock**
Add the following code to the service code:
```
void MyXCollieChecker::CheckLock()
{
......@@ -138,7 +57,7 @@ This function requires you to implement two callback functions: **CheckBlock**
sptr<XCollieChecker> checker = new MyXCollieChecker("MyXCollieChecker");
XCollie::GetInstance().RegisterXCollieChecker(checker,
(XCOLLIE_LOCK | XCOLLIE_THREAD));
...
......
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
......@@ -148,12 +67,11 @@ This function requires you to implement two callback functions: **CheckBlock**
```
### Timeout Monitoring<a name="section2186947140"></a>
### Timeout Monitoring
You can add a maximum of 128 timers for a single process by using the **SetTimer** function. Adding timers will fail if the number of timers has reached the upper limit.
1. Develop the source code.
Include the **xcollie** header file in the source file.
```
......@@ -173,7 +91,7 @@ You can add a maximum of 128 timers for a single process by using the **SetTime
XCollie::GetInstance().UpdateTimer(id, 5);
/* time consuming job */
XCollie::GetInstance().CancelTimer(id);
...
......
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
......@@ -181,5 +99,3 @@ You can add a maximum of 128 timers for a single process by using the **SetTime
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
# HiDumper Development
# HiDumper
## Overview
### Introduction
HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool engineers to obtain system information necessary for analyzing and locating faults. This section applies only to the standard system.
### Source Code Directories
## Source Code Directories
```
......@@ -34,14 +31,14 @@ HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool
```
## Usage
# Usage
### Command-Line Options
## Command-Line Options
**Table 1** HiDumper command-line options
| Option| Description|
| Option| **Description**|
| -------- | -------- |
| -h | Shows the help Information.|
| -t&nbsp;[timeout] | Specifies the timeout period, in seconds. The default value is **30**. Value **0** indicates no timeout limit.|
......@@ -56,14 +53,14 @@ HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool
| --net | Exports network information.|
| --storage | Exports storage information.|
| -p | Exports the process list and all process information.|
| -p&nbsp;[pid] | Exports all information about a specified process.|
| --cpuusage&nbsp;[pid] | Exports the CPU usage information based on **pid**.|
| -p&nbsp;[pid] | Exports all information about the specified process.|
| --cpuusage&nbsp;[pid] | Exports the CPU usage information. If **pid** is specified, the CPU usage of the corresponding process is exported.|
| --cpufreq | Exports the actual CPU frequency.|
| --mem&nbsp;[pid] | Exports the memory usage information based on **pid**.|
| --mem&nbsp;[pid] | Export memory usage information. If **pid** is specified, the memory usage of the corresponding process is exported.|
| --zip | Compresses the exported information to a specified folder.|
### Development Example
## Development Example
HiDumper helps you export basic system information to locate and analyze faults. Complex parameters passed to sub-services and abilities must be enclosed in double quotation marks.
......@@ -118,7 +115,7 @@ The procedure is as follows:
hidumper -s 3008
```
9. Run the **hidumper -e** command to obtain the crash information generated by the FaultLogger module.
9. Run the **hidumper -e** command to obtain the crash information generated by the FaultLoger module.
```
hidumper -e
......@@ -148,7 +145,7 @@ The procedure is as follows:
hidumper -p 1024
```
14. Run the **hidumper --cpuusage [pid]** command to obtain the CPU usage information of the process whose PID has been specified.
14. Run the **hidumper --cpuusage [pid]** command to obtain the CPU usage information. If the PID of a process is specified, only the CPU usage of the process is returned.
```
hidumper --cpuusage
......@@ -161,7 +158,7 @@ The procedure is as follows:
hidumper --cpufreq
```
16. Run the **hidumper --mem [pid]** command to obtain all memory usage information of the process whose PID has been specified.
16. Run the **hidumper --mem [pid]** command to obtain all memory usage information. If the PID of a process is specified, only the memory usage of the process is returned.
```
hidumper --mem [pid]
......
......@@ -2,16 +2,17 @@
## Introduction
HiTraceMeter is the OpenHarmony subsystem that provides APIs to implement call chain trace throughout a service process. With HiTraceMeter, you can quickly obtain the run log specific to the call chain of a service process and locate faults in inter-device, inter-process, or inter-thread communications. HiTraceMeter supports event logging in user mode and can collect trace data in user mode and kernel mode for performance tracing and analysis.
HiTraceMeter is the OpenHarmony subsystem that provides APIs to implement call chain trace throughout a service process. With HiTraceMeter, you can quickly obtain the run log specific to the call chain of a service process and locate faults in inter-device, inter-process, or inter-thread communications. HiTraceMeter supports event logging in user mode and can collect trace data in user mode and kernel mode for performance trace and analysis.
## Basic Concepts
The HiTraceMeter subsystem consists of three parts:
- JS/C++ HiTraceMeter APIs for application logging
- hitrace CLI tool for data collection
- smartperf tool for graphical data analysis
Wherein, HiTraceMeter APIs and the hitrace CLI tool run on the device side, and the smartperf tool runs on the PC side. HiTraceMeter APIs are provided in C++ and JS for event logging, which aims to generate the trace data necessary for performance tracing and analysis during the development process.
Wherein, HiTraceMeter APIs and the hitrace CLI tool run on the device side, and the smartperf tool runs on the PC side. HiTraceMeter APIs are provided in C++ and JS for event logging, which aims to generate the trace data necessary for performance trace and analysis during the development process.
The hitrace CLI tool is used to collect trace data. It captures trace data flows and saves the data as a text file.
......@@ -80,7 +81,6 @@ HiTraceMeter provides the hitrace CLI tool for capturing trace data in user mode
## Constraints
- The implementation of HiTraceMeter functions and APIs depends on the ftrace functionality, a framework provided by the kernel. It enables developers to add more trace functions via plug-ins. Therefore, make sure that ftrace is enabled before you use HiTraceMeter.
......@@ -95,7 +95,6 @@ HiTraceMeter development focuses on two parts: JS/C++ event logging APIs and the
## When to Use
You may encounter unexpected issues like app freezing during app development or need to view the code's call chain during code debugging. With the APIs provided by HiTraceMeter, you'll be able to trace the application delay and call chain to identify performance problems.
......@@ -106,18 +105,17 @@ Only C++ APIs are now open for system developers. If you're developing a JS app,
**Table 1** Sync APIs
| Sync trace | Function |Parameter Description |
| :----------------------------------------------------------- | ------------- |------------- |
| void StartTrace(uint64_t label, const std::string& value, float limit = -1); | Starts a synchronous trace.|**label**: trace category.<br>**value**: trace data that indicates the specific status, such as the memory size and queue length.|
| void FinishTrace(uint64_t label); | Stops a synchronous trace.|**label**: trace category.|
| Sync trace | Function | Parameter Description |
|:---------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------- |
| void StartTrace(uint64_t label, const std::string& value, float limit = -1); | Starts a synchronous trace.| **label**: trace category.<br>**value**: trace data that indicates the specific status, such as the memory size and queue length.|
| void FinishTrace(uint64_t label); | Stops a synchronous trace.| **label**: trace category. |
**StartTrace** and **FinishTrace** must be used in pairs, and **FinishTrace** matches the latest **StartTrace**. The two APIs can be used in nested mode. The stack data structure is used for matching during trace data parsing. The **limit** parameter is used for flow control, and you are advised to use the default value.
**Table 2** Async APIs
| Async trace | Function |Parameter Description |
| ------------------------------------------------------------ | ------------- |------------- |
| Async trace | Function | Parameter Description |
| ------------------------------------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------- |
| void StartAsyncTrace(uint64_t label, const std::string& value, int32_t taskId, float limit = -1); | Starts an asynchronous trace.| **label**: trace category.<br>**value**: trace data that indicates the specific status, such as the memory size and queue length.<br>**taskId**: ID used to indicate the association of APIs in an asynchronous trace.|
| void FinishAsyncTrace(uint64_t label, const std::string& value, int32_t taskId); | Stops an asynchronous trace.| **label**: trace category.<br>**value**: trace data that indicates the specific status, such as the memory size and queue length.<br>**taskId**: ID used to indicate the association of APIs in an asynchronous trace.|
......@@ -127,17 +125,18 @@ The trace data of **StartAsyncTrace** and **FinishAsyncTrace** is matched based
**Table 3** Counter APIs
| Counter Trace | Function |Parameter Description |
| ------------------------------------------------------------ | --------- |--------- |
| void CountTrace(uint64_t label, const std::string& name, int64_t); | Count trace.|**label**: trace category.<br>**name**: trace name displayed in the IDE.|
| Counter Trace | Function | Parameter Description |
| ------------------------------------------------------------------ | ------- | -------------------------------------------------------------- |
| void CountTrace(uint64_t label, const std::string& name, int64_t); | Count trace.| **label**: trace category.<br>**name**: trace name displayed in the IDE.|
## How to Develop
1. Add the build dependencies to the build configuration file **base\hiviewdfx\hitrace\cmd\BUILD.gn**.
```
external_deps = [ "hitrace_native:hitrace_meter"]
```
2. Add the header file dependencies.
```cpp
......@@ -146,13 +145,12 @@ The trace data of **StartAsyncTrace** and **FinishAsyncTrace** is matched based
3. When calling an API, pass the trace value as an input parameter. The trace tags currently supported are listed in **hitrace_meter.h**. Assume that the trace tag is **OHOS** and trace data of **func1** and **func2** needs to be captured. After the hitrace command is executed in the shell, the trace data is automatically captured. The captured data includes the function call process and the memory and time consumed during this process. You can use the data to analyze the call process to identify performance problems.
```cpp
#include "hitrace_meter.h" // Include hitrace_meter.h
using namespace std;
```cpp
#include "hitrace_meter.h" // Include hitrace_meter.h
using namespace std;
int main()
{
int main()
{
uint64_t label = BYTRACE_TAG_OHOS;
sleep(1);
CountTrace(label, "count number", 2000); // Integer trace
......@@ -166,7 +164,7 @@ int main()
FinishTrace(label); // Trace end point of func1Trace
StartAsyncTrace(label, "asyncTrace1", 1234); // Trace start point of asyncTrace1
FinishAsyncTrace(label, "asyncTrace1", 1234); // Trace end point of asyncTrace2
FinishAsyncTrace(label, "asyncTrace1", 1234); // Trace end point of asyncTrace1
return 0;
}
......@@ -180,7 +178,6 @@ int main()
You can open the captured data by clicking **Open trace file** in the smartperf tool or dragging the data to the graphics area. For details, see [smartperf](https://toscode.gitee.com/openharmony-sig/smartperf).
## Verification
The following is a demo debugging process, where the **StartTrace** and **FinishTrace** APIs are used in synchronization mode.
......@@ -274,10 +271,10 @@ The hitrace CLI tool is an executable binary program. On an OpenHarmony-powered
**Table 4** Command list
| Option | Description |
| ------------------------------ | ------------------------------------------------------------ |
| ----------------------------- | -------------------------------------------------------- |
| -h, --help | Views the help Information. |
| -b *n*, --buffer_size *n* | Sets the buffer size for trace data in KB. The default value is **2048**. |
| -t *n*, --time *n* | Sets the trace uptime in seconds, which depends on the time required for analysis.|
| -t *n*, --time *n* | Sets the trace uptime in seconds, which depends on the time required for analysis. |
| --trace_clock clock | Sets the type of the clock for adding a timestamp to a trace. The value can be **boot** (default), **global**, **mono**, **uptime**, or **perf**.|
| --trace_begin | Starts capturing trace data. |
| --trace_dump | Dumps trace data to the specified position. The default position is the console. |
......@@ -292,34 +289,41 @@ Examples:
- Query supported labels.
```
hitrace -l
```
Alternatively, run the following command:
```
hitrace --list_categories
```
```
- Trace ability information for 10 seconds and store the trace data in a buffer of 4 MB.
```
hitrace -b 4096 -t 10 --overwrite ability > /data/log/mytrace.ftrace
```
```
- Set the clock type to **mono**.
```
hitrace --trace_clock mono -b 4096 -t 10 --overwrite ability > /data/log/mytrace.ftrace
```
```
- Compress the trace data.
```
hitrace -z -b 4096 -t 10 --overwrite ability > /data/log/mytrace.ftrace
```
......@@ -330,14 +334,18 @@ Examples:
#### Symptom
The data captured by running the hitrace command is incomplete or no data is captured.
The data captured by running the hitrace command is incomplete or no data is captured.
#### **Root Cause**
The value of **-t** or **-b** buffer is too small, leading to data loss.
#### Solution
Check the value of the **-t** and **-b** parameters. If the value is too small, data loss will occur. You are advised to set **-t** to **60** and **-b** to **204800** to increase the trace capture time and buffer, respectively.
You can set **-t** to **60** and **-b** to **204800** to increase the trace time and buffer size.
# Reference
For details about HiTraceMeter, see [hiviewdfx_hitrace: A Lightweight Distributed Tracing](https://gitee.com/openharmony/hiviewdfx_hitrace).
For details about HiTraceMeter, see [hiviewdfx_hitrace: Lightweight Distributed Trace](https://gitee.com/openharmony/hiviewdfx_hitrace).
# DFX Overview<a name="EN-US_TOPIC_0000001185974398"></a>
# DFX Overview
## Introduction
[Design for X](https://en.wikipedia.org/wiki/Design_for_X) \(DFX\) refers to the software design that aims to improve the quality attributes in OpenHarmony. It mainly consists of two parts: design for reliability \(DFR\) and design for testability \(DFT\).
The DFX subsystem provides the following functions:
- HiLog: implements the logging function. It is applicable to mini-system devices \(reference memory ≥ 128 KiB\), small-system devices \(reference memory ≥ 1 MiB\), and standard-system devices \(reference memory ≥ 128 MB\).
- HiTraceChain: implements distributed call chain tracing. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiLog: implements the logging function. It is applicable to mini-system devices \(reference memory ≥ 128 KiB\), small-system devices \(reference memory ≥ 1 MiB\), and standard-system devices \(reference memory ≥ 128 MiB\).
- HiTraceChain: implements distributed call chain trace. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiTraceMeter: implements performance trace. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiCollie: implements thread suspension detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiSysEvent: implements system event logging. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiDumper: exports system information. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- FaultLogger: implements crash detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- Faultlogger: implements crash detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- Hiview: implements device maintenance across different platforms. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiAppEvent and HiChecker are only hap developer oriented。
- HiAppEvent and HiChecker are applicable only for HAP developers.
![dfx features overview](figure/dfx-overview.png)
## Basic Concepts<a name="section5635178134811"></a>
## Basic Concepts
**Logging**
Logging means to record the log information generated during system running so you can understand the running process and status of the system or applications.
**Distributed call chain tracing**
**Distributed call chain trace**
In a distributed system, the initiation of a service may involve multiple software modules, with control commands and data transmitted over intra-process, inter-process, and inter-device communication interfaces. To help you understand such complex communication processes and locate service faults efficiently, the DFX subsystem provides a distributed call chain tracing framework.
In a distributed system, the initiation of a service may involve multiple software modules, with control commands and data transmitted over intra-process, inter-process, and inter-device communication interfaces. To help you understand such complex communication processes and locate service faults efficiently, the DFX subsystem provides a distributed call chain trace framework.
**Thread suspension detection**
If a thread is trapped in an infinite loop or the kernel state \(for example, Uninterruptable Sleep, Traced, Zombie, or synchronous wait\) when it is running, the thread cannot respond to normal service requests and cannot detect and recover from faults by itself. To detect and locate this type of faults, the DFX subsystem provides a simple watchdog mechanism by inserting detection probes to the process nodes that are prone to suspension. This ensures that suspension faults can be detected and logs can be collected.
If a thread is trapped in an infinite loop or the kernel state (for example, Uninterruptable Sleep, Traced, Zombie, or synchronous wait) when it is running, the thread cannot respond to normal service requests and cannot detect and recover from faults by itself. To detect and locate this type of faults, the DFX subsystem provides a simple watchdog mechanism by inserting detection probes to the process nodes that are prone to suspension. This ensures that suspension faults can be detected and logs can be collected.
**Event logging**
**Logging**
Event logging means to collect and log events reported during system running. The log information will help you better analyze the product usage.
**System event**
A system event is an indication of the system status at a given time point during system running. You can use these events to analyze the status change of the system.
<!--no_check-->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册