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

!12357 翻译已完成10599+10646+10711+10687+10449

Merge pull request !12357 from shawn_he/10599-a
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## When to Use ## When to Use
In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer. In Host mode, you can obtain the list of connected USB devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer.
## APIs ## APIs
...@@ -16,6 +16,7 @@ The following table lists the USB APIs currently available. For details, see the ...@@ -16,6 +16,7 @@ The following table lists the USB APIs currently available. For details, see the
| ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| hasRight(deviceName: string): boolean | Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise. | | hasRight(deviceName: string): boolean | Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise. |
| requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. | | requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. |
| removeRight(deviceName: string): boolean | Removes the permission for a given application to access the USB device. |
| connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device information returned by `getDevices()`. | | connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device information returned by `getDevices()`. |
| getDevices(): Array<Readonly\<USBDevice>> | Obtains the USB device list. | | getDevices(): Array<Readonly\<USBDevice>> | Obtains the USB device list. |
| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. | | setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. |
......
...@@ -8,7 +8,7 @@ The event logging function helps applications log various information generated ...@@ -8,7 +8,7 @@ The event logging function helps applications log various information generated
JS application event logging APIs are provided by the **hiAppEvent** module. JS application event logging APIs are provided by the **hiAppEvent** module.
The following table provides only a brief description of related APIs. For details, see [HiAppEvent](../reference/apis/js-apis-hiappevent.md). The following table provides only a brief description of related APIs. For details, see [HiAppEvent](../reference/apis/js-apis-hiviewdfx-hiappevent.md).
**Table 1** APIs for application event logging **Table 1** APIs for application event logging
...@@ -17,17 +17,11 @@ The following table provides only a brief description of related APIs. For detai ...@@ -17,17 +17,11 @@ The following table provides only a brief description of related APIs. For detai
| write(AppEventInfo info, AsyncCallback\<void> callback): void | Logs application events in asynchronous mode. This API uses an asynchronous callback to return the result.| | write(AppEventInfo info, AsyncCallback\<void> callback): void | Logs application events in asynchronous mode. This API uses an asynchronous callback to return the result.|
| write(AppEventInfo info): Promise\<void> | Logs application events in asynchronous mode. This API uses a promise to return the result. | | write(AppEventInfo info): Promise\<void> | Logs application events in asynchronous mode. This API uses a promise to return the result. |
When an asynchronous callback is used, the return value can be processed directly in the callback.
If a promise is used, the return value can also be processed in the promise in a similar way.
For details about the result codes, see [Event Verification Result Codes](#event-verification-result-codes).
**Table 2** APIs for event logging configuration **Table 2** APIs for event logging configuration
| API | Description | | API | Description |
| --------------------------------------- | ---------------------------------------------------- | | ------------------------------------ | ---------------------------------------------------- |
| configure(ConfigOption config): boolean | Sets the configuration options for application event logging.| | configure(ConfigOption config): void | Sets the configuration options for application event logging.|
**Table 3** APIs for watcher management **Table 3** APIs for watcher management
...@@ -42,32 +36,14 @@ For details about the result codes, see [Event Verification Result Codes](#event ...@@ -42,32 +36,14 @@ For details about the result codes, see [Event Verification Result Codes](#event
| ----------------- | -------------------- | | ----------------- | -------------------- |
| clearData(): void | Clears local logging data.| | clearData(): void | Clears local logging data.|
### Event Verification Result Codes ## How to Develop
| Result Code| Cause | Verification Rules | Handling Method |
| ------ | ----------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------- |
| 0 | N/A | Event verification is successful. | Event logging is normal. No action is required. |
| -1 | Invalid event name | The name is not empty and contains a maximum of 48 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore \(_).<br>The name does not start with a digit or underscore \(_).| Ignore this event and do not perform logging. |
| -2 | Invalid event parameter type | The event name must be a string.<br>The event type must be a number.<br>The event parameter must be an object.| Ignore this event and do not perform logging. |
| -4 | Invalid event domain name | The name is not empty and contains a maximum of 32 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore \(_).<br>The name does not start with a digit or underscore \(_).| Ignore this event and do not perform logging. |
| -99 | Application event logging disabled | Application event logging is disabled. | Ignore this event and do not perform logging. |
| -100 | Unknown error | None. | Ignore this event and do not perform logging. |
| 1 | Invalid key name | The name is not empty and contains a maximum of 16 characters.<br>The name consists of only the following characters: digits (0 to 9), letters (a to z), and underscore \(_).<br>The name does not start with a digit or underscore \(_).<br>The name does not end with an underscore \(_).| Ignore the key-value pair and continue to perform logging. |
| 2 | Invalid key type | The key must be a string. | Ignore the key-value pair and continue to perform logging. |
| 3 | Invalid value type | The supported value types vary depending on the programming language:<br>boolean, number, string, or Array [basic element]| Ignore the key-value pair and continue to perform logging. |
| 4 | Invalid length for values of the string type| For a value of the string type, the maximum length is 8*1024 characters. | Truncate the value with the first 8*1024 characters retained, and continue to perform logging.|
| 5 | Excess key-value pairs | The number of key-value pairs must be less than or equal to 32. | Ignore the excess key-value pairs and continue to perform logging. |
| 6 | Invalid number of elements in values of the array type | For a value of the array type, the number of elements must be less than or equal to 100. | Truncate the array with the first 100 elements retained, and continue to perform logging. |
| 7 | Invalid parameters in values of the array type | For a value of the array type, all the parameters must be of the same type, which can only be boolean, number, or string.| Ignore the key-value pair and continue to perform logging. |
## Development Procedure
The following uses a one-time event watcher as an example to illustrate the development procedure. The following uses a one-time event watcher as an example to illustrate the development procedure.
1. Create an ArkTS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **ets** > **pages** > **index.ets**, and double-click **index.ets**. Then, add three buttons to simulate the process of watching for application events. Wherein, button 1 is used to invoke application event logging, button 2 to add an event watcher that automatically triggers a callback, and button 3 to remove the watcher. The complete sample code is as follows: 1. Create an eTS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **ets** > **pages** > **index.ets**, and double-click **index.ets**. Then, add three buttons to simulate the process of watching for application events. Wherein, button 1 is used to invoke application event logging, button 2 to add an event watcher that automatically triggers a callback, and button 3 to remove the watcher. The complete sample code is as follows:
```ts ```ts
import hiAppEvent from '@ohos.hiAppEvent'; import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent';
@Entry @Entry
@Component @Component
...@@ -91,10 +67,10 @@ The following uses a one-time event watcher as an example to illustrate the deve ...@@ -91,10 +67,10 @@ The following uses a one-time event watcher as an example to illustrate the deve
int_data: 100, int_data: 100,
str_data: "strValue" str_data: "strValue"
} }
}).then((value) => { }).then(() => {
console.log(`HiAppEvent success to write event: ${value}`); console.log(`HiAppEvent success to write event`);
}).catch((err) => { }).catch((err) => {
console.error(`HiAppEvent failed to write event because ${err.code}`); console.error(`code: ${err.code}, message: ${err.message}`);
}); });
}) })
...@@ -120,12 +96,12 @@ The following uses a one-time event watcher as an example to illustrate the deve ...@@ -120,12 +96,12 @@ The following uses a one-time event watcher as an example to illustrate the deve
// Obtain the event package based on the configured size threshold. If returned event package is null, all event data has been obtained. // Obtain the event package based on the configured size threshold. If returned event package is null, all event data has been obtained.
while ((eventPkg = holder.takeNext()) != null) { while ((eventPkg = holder.takeNext()) != null) {
// Parse the obtained event package and display the result on the Log page. // Parse the obtained event package and display the result on the Log page.
console.info('HiAppEvent eventPkg.packageId=' + eventPkg.packageId); console.info(`HiAppEvent eventPkg.packageId=${eventPkg.packageId}`);
console.info('HiAppEvent eventPkg.row=' + eventPkg.row); console.info(`HiAppEvent eventPkg.row=${eventPkg.row}`);
console.info('HiAppEvent eventPkg.size=' + eventPkg.size); console.info(`HiAppEvent eventPkg.size=${eventPkg.size}`);
// Traverse and parse event string arrays in the obtained event package. // Traverse and parse event string arrays in the obtained event package.
for (const eventInfo of eventPkg.data) { for (const eventInfo of eventPkg.data) {
console.info('HiAppEvent eventPkg.data=' + eventInfo); console.info(`HiAppEvent eventPkg.data=${eventInfo}`);
} }
} }
} }
...@@ -169,4 +145,4 @@ The following uses a one-time event watcher as an example to illustrate the deve ...@@ -169,4 +145,4 @@ The following uses a one-time event watcher as an example to illustrate the deve
The following sample is provided to help you better understand how to develop the application event logging feature: The following sample is provided to help you better understand how to develop the application event logging feature:
- [`JsDotTest` (JS) (API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/DFX/JsDotTest) - [`JsDotTest`: Event Logging (JS) (API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/DFX/JsDotTest)
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
This module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration. This module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration.
> **NOTE** > **NOTE**
> > - The APIs provided by this module are deprecated since API version 9. You are advised to use [`@ohos.hiviewdfx.hiAppEvent`](js-apis-hiviewdfx-hiappevent.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. > - 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 ## Modules to Import
...@@ -17,13 +17,9 @@ import hiAppEvent from '@ohos.hiAppEvent'; ...@@ -17,13 +17,9 @@ import hiAppEvent from '@ohos.hiAppEvent';
Before using application event logging, you need to understand the requirements for related parameters. Before using application event logging, you need to understand the requirements for related parameters.
**Event Domain**
An event domain is a string that contains a maximum of 32 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It cannot start with an underscore (\_).
**Event Name** **Event Name**
An event name is a string that contains a maximum of 48 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It cannot start with an underscore (\_). An event name is a string that contains a maximum of 48 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter and cannot end with an underscore (_).
**Event Type** **Event Type**
...@@ -33,7 +29,7 @@ An event type is an enumerated value of [EventType](#eventtype). ...@@ -33,7 +29,7 @@ An event type is an enumerated value of [EventType](#eventtype).
An event parameter is an object in key-value pair format, where the key is the parameter name and the value is the parameter value. The requirements are as follows: An event parameter is an object in key-value pair format, where the key is the parameter name and the value is the parameter value. The requirements are as follows:
- The parameter name is a string that contains a maximum of 16 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It cannot start or end with an underscore (\_). - A parameter name is a string that contains a maximum of 16 characters, including digits (0 to 9), letters (a to z), and underscores (\_). It must start with a lowercase letter and cannot end with an underscore (\_).
- The parameter value is a string, number, boolean, or array. - The parameter value is a string, number, boolean, or array.
- When the parameter value is a string, its maximum length is 8*1024 characters. If this limit is exceeded, excess characters will be truncated. - When the parameter value is a string, its maximum length is 8*1024 characters. If this limit is exceeded, excess characters will be truncated.
- When the parameter value is an array, the elements in the array must be of the same type, which can only be string, number, or boolean. In addition, the number of elements must be less than 100. If this limit is exceeded, excess elements will be discarded. - When the parameter value is an array, the elements in the array must be of the same type, which can only be string, number, or boolean. In addition, the number of elements must be less than 100. If this limit is exceeded, excess elements will be discarded.
...@@ -47,20 +43,10 @@ Event callback can be a callback or promise that carries the return value obtain ...@@ -47,20 +43,10 @@ Event callback can be a callback or promise that carries the return value obtain
- If the return value is greater than **0**, invalid parameters are present in the event, and the event will be written to the event file after the invalid parameters are ignored. - If the return value is greater than **0**, invalid parameters are present in the event, and the event will be written to the event file after the invalid parameters are ignored.
- If the return value is smaller than **0**, the event parameter verification fails, and the event will not be written to the event file. - If the return value is smaller than **0**, the event parameter verification fails, and the event will not be written to the event file.
**Subscription Callback** ## hiAppEvent.write
A subscription callback carries the subscription data obtained by invoking the watcher API. The input parameters are defined as follows:
- **curRow**: number of events.
- **curSize**: event data size, in bytes.
- **holder**: event data holder, which can be used for processing subscription events.
## hiAppEvent.write<sup>(deprecated)</sup>
write(eventName: string, eventType: EventType, keyValues: object, callback: AsyncCallback&lt;void&gt;): void write(eventName: string, eventType: EventType, keyValues: object, callback: AsyncCallback&lt;void&gt;): void
> **NOTE**<br>This API is discarded since API version 9. You are advised to use [hiAppEvent.write](#hiappeventwrite9) instead.
Writes event information to the event file of the current day. This API uses an asynchronous callback to return the result. Writes event information to the event file of the current day. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent **System capability**: SystemCapability.HiviewDFX.HiAppEvent
...@@ -72,7 +58,7 @@ Writes event information to the event file of the current day. This API uses an ...@@ -72,7 +58,7 @@ Writes event information to the event file of the current day. This API uses an
| eventName | string | Yes | Event name. | | eventName | string | Yes | Event name. |
| eventType | [EventType](#eventtype) | Yes | Event type. | | eventType | [EventType](#eventtype) | Yes | Event type. |
| keyValues | object | Yes | Event parameters. | | keyValues | object | Yes | Event parameters. |
| callback | AsyncCallback&lt;void&gt; | No | Event callback.| | callback | AsyncCallback&lt;void&gt; | Yes | Event callback.|
**Example** **Example**
...@@ -90,12 +76,10 @@ hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str ...@@ -90,12 +76,10 @@ hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str
``` ```
## hiAppEvent.write<sup>(deprecated)</sup> ## hiAppEvent.write
write(eventName: string, eventType: EventType, keyValues: object): Promise&lt;void&gt; write(eventName: string, eventType: EventType, keyValues: object): Promise&lt;void&gt;
> **NOTE**<br>This API is discarded since API version 9. You are advised to use [hiAppEvent.write](#hiappeventwrite9-1) instead.
Writes event information to the event file of the current day. This API uses a promise to return the result. Writes event information to the event file of the current day. This API uses a promise to return the result.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent **System capability**: SystemCapability.HiviewDFX.HiAppEvent
...@@ -127,97 +111,6 @@ hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str ...@@ -127,97 +111,6 @@ hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str
}); });
``` ```
## hiAppEvent.write<sup>9+</sup>
write(info: [AppEventInfo](#appeventinfo9), callback: AsyncCallback&lt;void&gt;): void
Writes events to the event file of the current day through [AppEventInfo](#appeventinfo9) objects. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | -------------- |
| info | [AppEventInfo](#appeventinfo9) | Yes | Application event object.|
| callback | AsyncCallback&lt;void&gt; | No | Event callback.|
**Example**
```js
hiAppEvent.write({
domain: "test_domain",
name: "test_event",
eventType: hiAppEvent.EventType.FAULT,
params: {
int_data: 100,
str_data: "strValue"
}
}, (err, value) => {
if (err) {
// Event writing error: Write the event to the event file after the invalid parameters in the event are ignored, or stop writing the event if the event verification fails.
console.error(`failed to write event because ${err.code}`);
return;
}
// Event writing success
console.log(`success to write event: ${value}`);
});
```
## hiAppEvent.write<sup>9+</sup>
write(info: [AppEventInfo](#appeventinfo9)): Promise&lt;void&gt;
Writes events to the event file of the current day through [AppEventInfo](#appeventinfo9) objects. This API uses a promise to return the result.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | -------------- |
| info | [AppEventInfo](#appeventinfo9) | Yes | Application event object.|
**Return value**
| Type | Description |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to asynchronously process the callback in the **then()** and **catch()** methods when event writing succeeded or failed.|
**Example**
```js
hiAppEvent.write({
domain: "test_domain",
name: "test_event",
eventType: hiAppEvent.EventType.FAULT,
params: {
int_data: 100,
str_data: "strValue"
}
}).then((value) => {
// Event writing success
console.log(`success to write event: ${value}`);
}).catch((err) => {
// Event writing error: Write the event to the event file after the invalid parameters in the event are ignored, or stop writing the event if the event verification fails.
console.error(`failed to write event because ${err.code}`);
});
```
## AppEventInfo<sup>9+</sup>
Defines parameters for an **AppEventInfo** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------- |
| domain | string | Yes | Event domain.|
| name | string | Yes | Event name.|
| eventType | [EventType](#eventtype) | Yes | Event type.|
| params | object | Yes | Event parameters.|
## hiAppEvent.configure ## hiAppEvent.configure
configure(config: ConfigOption): boolean configure(config: ConfigOption): boolean
...@@ -258,230 +151,11 @@ Provides the configuration items for application event logging. ...@@ -258,230 +151,11 @@ Provides the configuration items for application event logging.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent **System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------- | ---- | ------------------------------------------------------------ | | ---------- | ------- | ---- | ------------------------------------------------------------ |
| disable | boolean | No | Application event logging switch. The value **true** means to disable the application event logging function, and the value **false** means the opposite.| | disable | boolean | No | Application event logging switch. The value **true** means to disable the application event logging function, and the value **false** means the opposite.|
| maxStorage | string | No | Maximum size of the event file storage directory. The default value is <strong>10M</strong>. If the specified size is exceeded, the oldest event logging files in the directory will be deleted to free up space.| | maxStorage | string | No | Maximum size of the event file storage directory. The default value is <strong>10M</strong>. If the specified size is exceeded, the oldest event logging files in the directory will be deleted to free up space.|
## hiAppEvent.addWatcher<sup>9+</sup>
addWatcher(watcher: [Watcher](#watcher9)): [AppEventPackageHolder](#appeventpackageholder9)
Adds an event watcher.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------------------- | ---- | ---------------- |
| watcher | [Watcher](#watcher9) | Yes | Event watcher.|
**Return value**
| Type | Description |
| ------------------------------------------------ | ------------------------------------ |
| [AppEventPackageHolder](#appeventpackageholder9) | Subscription data holder. If the subscription fails, **null** will be returned.|
**Example**
```js
// 1. If callback parameters are passed to the watcher, you can have subscription events processed in the callback that is automatically triggered.
hiAppEvent.addWatcher({
name: "watcher1",
appEventFilters: [
{
domain: "domain_test1",
eventTypes: [hiAppEvent.EventType.FAULT, hiAppEvent.EventType.BEHAVIOR]
}
],
triggerCondition: {
row: 10,
size: 1000,
timeOut: 1
},
onTrigger: function (curRow, curSize, holder) {
if (holder == null) {
console.error("holder is null");
return;
}
let eventPkg = null;
while ((eventPkg = holder.takeNext()) != null) {
console.info("eventPkg.packageId=" + eventPkg.packageId);
console.info("eventPkg.row=" + eventPkg.row);
console.info("eventPkg.size=" + eventPkg.size);
for (const eventInfo of eventPkg.data) {
console.info("eventPkg.data=" + eventInfo);
}
}
}
});
// 2. If no callback parameters are passed to the watcher, you can have subscription events processed manually through the subscription data holder.
let holder = hiAppEvent.addWatcher({
name: "watcher2",
});
if (holder != null) {
let eventPkg = null;
while ((eventPkg = holder.takeNext()) != null) {
console.info("eventPkg.packageId=" + eventPkg.packageId);
console.info("eventPkg.row=" + eventPkg.row);
console.info("eventPkg.size=" + eventPkg.size);
for (const eventInfo of eventPkg.data) {
console.info("eventPkg.data=" + eventInfo);
}
}
}
```
## hiAppEvent.removeWatcher<sup>9+</sup>
removeWatcher(watcher: [Watcher](#watcher9)): void
Removes an event watcher.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------------------- | ---- | ---------------- |
| watcher | [Watcher](#watcher9) | Yes | Event watcher.|
**Example**
```js
// 1. Define a watcher.
let watcher = {
name: "watcher1",
}
// 2. Add the watcher to subscribe to application events.
hiAppEvent.addWatcher(watcher);
// 3. Remove the watcher to unsubscribe from application events.
hiAppEvent.removeWatcher(watcher);
```
## Watcher<sup>9+</sup>
Defines parameters for a **Watcher** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| ---------------- | ------------------------------------------------------------ | ---- | -------------------------------- |
| name | string | Yes | Unique watcher name.|
| triggerCondition | [TriggerCondition](#triggercondition9) | No | Subscription callback trigger condition. |
| appEventFilters | [AppEventFilter](#appeventfilter9)[] | No | Application event filter criteria. |
| onTrigger | (curRow: number, curSize: number, holder: [AppEventPackageHolder](#appeventpackageholder9)) => void | No | Subscription callback. |
## TriggerCondition<sup>9+</sup>
Defines parameters for a **TriggerCondition** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type| Mandatory| Description |
| ------- | -------- | ---- | -------------------------------------- |
| row | number | No | Number of events. |
| size | number | No | Event data size, in bytes.|
| timeOut | number | No | Timeout interval, in unit of 30s. |
## AppEventFilter<sup>9+</sup>
Defines parameters for an **AppEventFilter** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ------------------------ |
| domain | string | Yes | Event domain. |
| eventTypes | [EventType](#eventtype)[] | No | Event types.|
## AppEventPackageHolder<sup>9+</sup>
Defines a subscription data holder for processing subscription events.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
### constructor<sup>9+</sup>
constructor(watcherName: string);
A constructor used to create a **holder** object. It is called automatically when a **Watcher** object is added.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Example**
```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
```
### setSize<sup>9+</sup>
setSize(size: number): void
Sets the data size threshold for fetching an application event package. The default value is **512*1024**, in bytes.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Example**
```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
holder.setSize(1000);
```
### takeNext<sup>9+</sup>
takeNext(): [AppEventPackage](#appeventpackage9)
Extracts subscription event data based on the configured data size threshold. If all subscription event data has been extracted, **null** will be returned.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Example**
```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
let eventPkg = holder.takeNext();
```
## AppEventPackage<sup>9+</sup>
Defines parameters for an **AppEventPackage** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type| Description |
| --------- | -------- | ------------------------------ |
| packageId | number | Event package ID, which is named from **0** in ascending order. |
| row | number | Number of events in the event package. |
| size | number | Data size of the event package, in bytes.|
| data | string[] | Event data in the event package. |
## hiAppEvent.clearData<sup>9+</sup>
clearData(): void
Clears local logging data.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Example**
```js
hiAppEvent.clearData();
```
## EventType ## EventType
...@@ -489,12 +163,12 @@ Enumerates event types. ...@@ -489,12 +163,12 @@ Enumerates event types.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent **System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Default Value| Description | | Name | Value | Description |
| --------- | ------ | -------------- | | --------- | ---- | -------------- |
| FAULT | 1 | Fault event.| | FAULT | 1 | Fault event.|
| STATISTIC | 2 | Statistical event.| | STATISTIC | 2 | Statistical event.|
| SECURITY | 3 | Security event.| | SECURITY | 3 | Security event.|
| BEHAVIOR | 4 | Behavior event.| | BEHAVIOR | 4 | Behavior event.|
## Event ## Event
...@@ -503,11 +177,11 @@ Provides constants that define the names of all predefined events. ...@@ -503,11 +177,11 @@ Provides constants that define the names of all predefined events.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent **System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type| Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------- | -------- | ---- | ---- | -------------------- | | ------------------------- | ------ | ---- | ---- | -------------------- |
| USER_LOGIN | string | Yes | No | User login event. | | USER_LOGIN | string | Yes | No | User login event. |
| USER_LOGOUT | string | Yes | No | User logout event. | | USER_LOGOUT | string | Yes | No | User logout event. |
| DISTRIBUTED_SERVICE_START | string | Yes | No | Distributed service startup event.| | DISTRIBUTED_SERVICE_START | string | Yes | No | Distributed service startup event.|
## Param ## Param
...@@ -516,8 +190,8 @@ Provides constants that define the names of all predefined event parameters. ...@@ -516,8 +190,8 @@ Provides constants that define the names of all predefined event parameters.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent **System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type| Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------------- | -------- | ---- | ---- | ------------------ | | ------------------------------- | ------ | ---- | ---- | ------------------ |
| USER_ID | string | Yes | No | Custom user ID. | | USER_ID | string | Yes | No | Custom user ID. |
| DISTRIBUTED_SERVICE_NAME | string | Yes | No | Distributed service name. | | DISTRIBUTED_SERVICE_NAME | string | Yes | No | Distributed service name. |
| DISTRIBUTED_SERVICE_INSTANCE_ID | string | Yes | No | Distributed service instance ID.| | DISTRIBUTED_SERVICE_INSTANCE_ID | string | Yes | No | Distributed service instance ID.|
# HiDebug # HiDebug
> **NOTE** > **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. > 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. This module provides APIs for you 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 ## Modules to Import
...@@ -17,7 +16,7 @@ import hidebug from '@ohos.hidebug'; ...@@ -17,7 +16,7 @@ import hidebug from '@ohos.hidebug';
getNativeHeapSize(): bigint getNativeHeapSize(): bigint
Obtains the total size of the heap memory of this application. Obtains the total heap memory size of this application.
This API is defined but not implemented in OpenHarmony 3.1 Release. This API is defined but not implemented in OpenHarmony 3.1 Release.
...@@ -27,7 +26,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. ...@@ -27,7 +26,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
| Type | Description | | Type | Description |
| ------ | --------------------------- | | ------ | --------------------------- |
| bigint | Total size of the heap memory of this application, in kB.| | bigint | Total heap memory size of the application, in KB.|
**Example** **Example**
...@@ -40,17 +39,17 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. ...@@ -40,17 +39,17 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
getNativeHeapAllocatedSize(): bigint getNativeHeapAllocatedSize(): bigint
Obtains the size of the allocated heap memory of this application. Obtains the allocated heap memory size of this application.
This API is defined but not implemented in OpenHarmony 3.1 Release. This API is defined but not implemented in OpenHarmony 3.1 Release.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | --------------------------------- | | ------ | --------------------------------- |
| bigint | Size of the allocated heap memory of this application, in kB.| | bigint | Allocated heap memory of the application, in KB.|
**Example** **Example**
...@@ -63,18 +62,17 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. ...@@ -63,18 +62,17 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
getNativeHeapFreeSize(): bigint getNativeHeapFreeSize(): bigint
Obtains the size of the free heap memory of this application. Obtains the free heap memory size of this application.
This API is defined but not implemented in OpenHarmony 3.1 Release. This API is defined but not implemented in OpenHarmony 3.1 Release.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------------------------------- | | ------ | ------------------------------- |
| bigint | Size of the free heap memory of this application, in kB.| | bigint | Free heap memory size of the application, in KB.|
**Example** **Example**
```js ```js
...@@ -86,16 +84,15 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. ...@@ -86,16 +84,15 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
getPss(): bigint getPss(): bigint
Obtains the size of the used physical memory of this process. Obtains the size of the physical memory actually used by the application process.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------------------------- | | ------ | ------------------------- |
| bigint | Used physical memory of this process, in kB.| | bigint | Size of the physical memory actually used by the application process, in KB.|
**Example** **Example**
```js ```js
...@@ -107,15 +104,15 @@ Obtains the size of the used physical memory of this process. ...@@ -107,15 +104,15 @@ Obtains the size of the used physical memory of this process.
getSharedDirty(): bigint getSharedDirty(): bigint
Obtains the size of the shared dirty memory of this process. Obtains the size of the shared dirty memory of a process.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------------- | | ------ | -------------------------- |
| bigint | Size of the shared dirty memory of this process, in kB.| | bigint | Size of the shared dirty memory of the process, in KB.|
**Example** **Example**
...@@ -127,15 +124,15 @@ Obtains the size of the shared dirty memory of this process. ...@@ -127,15 +124,15 @@ Obtains the size of the shared dirty memory of this process.
getPrivateDirty(): bigint getPrivateDirty(): bigint
Obtains the size of the private dirty memory of this process. Obtains the size of the private dirty memory of a process.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------------- | | ------ | -------------------------- |
| bigint | Size of the private dirty memory of this process, in kB.| | bigint | Size of the private dirty memory of the process, in KB.|
**Example** **Example**
...@@ -147,17 +144,17 @@ Obtains the size of the private dirty memory of this process. ...@@ -147,17 +144,17 @@ Obtains the size of the private dirty memory of this process.
getCpuUsage(): number getCpuUsage(): number
Obtains the CPU usage of this process. Obtains the CPU usage of a process.
For example, if the CPU usage is **50%**, **0.5** is returned. For example, if the CPU usage is **50%**, **0.5** is returned.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------------- | | ------ | -------------------------- |
| number | CPU usage of this process.| | number | CPU usage of the process.|
**Example** **Example**
...@@ -165,11 +162,13 @@ For example, if the CPU usage is **50%**, **0.5** is returned. ...@@ -165,11 +162,13 @@ For example, if the CPU usage is **50%**, **0.5** is returned.
let cpuUsage = hidebug.getCpuUsage(); let cpuUsage = hidebug.getCpuUsage();
``` ```
## hidebug.startProfiling ## hidebug.startProfiling<sup>(deprecated)</sup>
startProfiling(filename : string) : void 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`. > **NOTE**<br>This API is deprecated since API version 9. You are advised to use [hidebug.startJsCpuProfiling](#hidebugstartjscpuprofiling9) instead.
Starts the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
...@@ -191,11 +190,13 @@ hidebug.stopProfiling(); ...@@ -191,11 +190,13 @@ hidebug.stopProfiling();
## hidebug.stopProfiling ## hidebug.stopProfiling<sup>(deprecated)</sup>
stopProfiling() : void stopProfiling() : void
Stops 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`. > **NOTE**<br>This API is deprecated since API version 9. You are advised to use [hidebug.stopJsCpuProfiling](#hidebugstopjscpuprofiling9) instead.
Stops the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
...@@ -209,17 +210,19 @@ hidebug.startProfiling("cpuprofiler-20220216"); ...@@ -209,17 +210,19 @@ hidebug.startProfiling("cpuprofiler-20220216");
hidebug.stopProfiling(); hidebug.stopProfiling();
``` ```
## hidebug.dumpHeapData ## hidebug.dumpHeapData<sup>(deprecated)</sup>
dumpHeapData(filename : string) : void dumpHeapData(filename : string) : void
Exports data from the specified heap file. > **NOTE**<br>This API is deprecated since API version 9. You are advised to use [hidebug.dumpJsHeapData](#hidebugdumpjsheapdata9) instead.
Exports the heap data.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filename | string | Yes | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the application based on the specified `filename`.| | filename | string | Yes | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the application based on the specified `filename`.|
...@@ -231,11 +234,11 @@ hidebug.dumpHeapData("heap-20220216"); ...@@ -231,11 +234,11 @@ hidebug.dumpHeapData("heap-20220216");
## hidebug.getServiceDump<sup>9+<sup> ## hidebug.getServiceDump<sup>9+<sup>
getServiceDump(serviceid : number) : string getServiceDump(serviceid : number, fd : number, args : Array\<string>) : void
Obtains information on the specified system service. Obtains system service information.
This is a system API and cannot be called by third-party applications. **Required permissions**: ohos.permission.DUMP
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
...@@ -243,16 +246,116 @@ This is a system API and cannot be called by third-party applications. ...@@ -243,16 +246,116 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| serviceid | number | Yes | ID of the system service. | | serviceid | number | Yes | Obtains the system service information based on the specified service ID.|
| fd | number | Yes | File descriptor to which data is written by the API.|
| args | Array\<string> | Yes | Parameter list corresponding to the **Dump** API of the system service.|
**Return value**
| Type | Description |
| ------ | -------------------------- |
| string | Absolute path of the file that contains the service information to dump. |
**Example** **Example**
```js ```js
let serviceId = 10; import fileio from '@ohos.fileio'
let pathName = hidebug.getServiceDump(serviceId); import hidebug from '@ohos.hidebug'
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext();
context.getFilesDir().then((data) => {
var path = data + "/serviceInfo.txt"
console.info("output path: " + path)
let fd = fileio.openSync(path, 0o102, 0o666)
var serviceId = 10
var args = new Array("allInfo")
try {
hidebug.getServiceDump(serviceId, fd, args)
} catch (error) {
console.info(error.code)
console.info(error.message)
}
fileio.closeSync(fd);
})
```
## hidebug.startJsCpuProfiling<sup>9+</sup>
startJsCpuProfiling(filename : string) : void
Starts the profiling method. `startJsCpuProfiling()` and `stopJsCpuProfiling()` are called in pairs. `startJsCpuProfiling()` always occurs before `stopJsCpuProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**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
import hidebug from '@ohos.hidebug'
try {
hidebug.startJsCpuProfiling("cpu_profiling");
...
hidebug.stopJsCpuProfiling();
} catch (error) {
console.info(error.code)
console.info(error.message)
}
```
## hidebug.stopJsCpuProfiling<sup>9+</sup>
stopJsCpuProfiling() : void
Stops the profiling method. `startJsCpuProfiling()` and `stopJsCpuProfiling()` are called in pairs. `startJsCpuProfiling()` always occurs before `stopJsCpuProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**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
import hidebug from '@ohos.hidebug'
try {
hidebug.startJsCpuProfiling("cpu_profiling");
...
hidebug.stopJsCpuProfiling();
} catch (error) {
console.info(error.code)
console.info(error.message)
}
```
## hidebug.dumpJsHeapData<sup>9+</sup>
dumpJsHeapData(filename : string) : void
Exports the heap data.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**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 application based on the specified `filename`.|
**Example**
```js
import hidebug from '@ohos.hidebug'
try {
hidebug.dumpJsHeapData("heapData");
} catch (error) {
console.info(error.code)
console.info(error.message)
}
``` ```
# System Event Logging # HiSysEvent
Provides system event logging APIs for system HAP applications. This module provides the system event logging functions, such as configuring trace points, subscribing to system events, and querying system events written to the event file.
> **NOTE** > **NOTE**
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs. > - The APIs provided by this module are system APIs.
## Modules to Import ## Modules to Import
...@@ -19,7 +19,7 @@ Enumerates event types. ...@@ -19,7 +19,7 @@ Enumerates event types.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name | Default Value | Description | | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| FAULT | 1 | Error event.| | FAULT | 1 | Error event.|
| STATISTIC | 2 | Statistic event.| | STATISTIC | 2 | Statistic event.|
...@@ -32,7 +32,7 @@ Defines a system event. ...@@ -32,7 +32,7 @@ Defines a system event.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| domain | string | Yes| Event domain.| | domain | string | Yes| Event domain.|
| name | string | Yes| Event name.| | name | string | Yes| Event name.|
...@@ -50,11 +50,26 @@ Writes event information to the event file. This API uses an asynchronous callba ...@@ -50,11 +50,26 @@ Writes event information to the event file. This API uses an asynchronous callba
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------------- | ---- | ------------------------------------------------------------ |
| info | [SysEventInfo](#syseventinfo) | Yes| System event information.| | info | [SysEventInfo](#syseventinfo) | Yes| System event information.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to process the received return value.<br>- Value **0**: The event verification is successful, and the event will be written to the event file asynchronously. <br>- A value greater than **0**: Invalid parameters are present in the event, and the event will be written to the event file asynchronously after the invalid parameters are ignored.<br>- A value smaller than **0**: The event parameter verification fails, and the event will not be written to the event file.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to process the received return value.<br>- Value **0**: The event verification is successful, and the event will be written to the event file asynchronously. <br>- A value greater than **0**: Invalid parameters are present in the event, and the event will be written to the event file asynchronously after the invalid parameters are ignored.<br>- A value smaller than **0**: The event parameter verification fails, and the event will not be written to the event file.|
**Error codes**
For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-hisysevent.md).
| ID| Error Message|
| ------- | ----------------------------------------------------------------- |
| 11200001 | Invalid event domain. |
| 11200002 | Invalid event name. |
| 11200003 | Abnormal environment. |
| 11200004 | Length of the event is over limit. |
| 11200051 | Invalid event parameter. |
| 11200052 | Size of the event parameter of the string type is over limit. |
| 11200053 | Count of event parameters is over limit. |
| 11200054 | Count of event parameter of the array type is over limit. |
**Example** **Example**
```js ```js
...@@ -91,16 +106,31 @@ Writes event information to the event file. This API uses a promise to return th ...@@ -91,16 +106,31 @@ Writes event information to the event file. This API uses a promise to return th
**Parameters** **Parameters**
| Name | Type | Mandatory | Description| | Name | Type | Mandatory| Description|
| --------- | ----------------------- | ---- | --------------- | | --------- | ----------------------- | ---- | --------------- |
| info | [SysEventInfo](#syseventinfo) | Yes | System event information.| | info | [SysEventInfo](#syseventinfo) | Yes | System event information.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------------------------------------ | | ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result. Depending on whether event writing is successful, you can use the **then()** or **catch()** method to process the callback.| | Promise&lt;void&gt; | Promise used to return the result. Depending on whether event writing is successful, you can use the **then()** or **catch()** method to process the callback.|
**Error codes**
For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-hisysevent.md).
| ID| Error Message|
| -------- | ---------------------------------------------------------------- |
| 11200001 | Invalid event domain. |
| 11200002 | Invalid event name. |
| 11200003 | Abnormal environment. |
| 11200004 | Length of the event is over limit. |
| 11200051 | Invalid event parameter. |
| 11200052 | Size of the event parameter of the string type is over limit. |
| 11200053 | Count of event parameters is over limit. |
| 11200054 | Count of event parameter of the array type is over limit. |
**Example** **Example**
```js ```js
...@@ -138,7 +168,7 @@ Enumerates matching rule types. ...@@ -138,7 +168,7 @@ Enumerates matching rule types.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name | Default Value | Description | | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| WHOLE_WORD | 1 | Whole word matching.| | WHOLE_WORD | 1 | Whole word matching.|
| PREFIX | 2 | Prefix matching.| | PREFIX | 2 | Prefix matching.|
...@@ -146,11 +176,11 @@ Enumerates matching rule types. ...@@ -146,11 +176,11 @@ Enumerates matching rule types.
## WatchRule ## WatchRule
Defines rules for event subscription. Defines event subscription rules.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| domain | string | Yes| Event domain.| | domain | string | Yes| Event domain.|
| name | string | Yes| Event name.| | name | string | Yes| Event name.|
...@@ -163,15 +193,15 @@ Defines a watcher for event subscription. ...@@ -163,15 +193,15 @@ Defines a watcher for event subscription.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| rules | [WatchRule](#watchrule)[] | Yes| Array of matching rules for event subscription.| | rules | [WatchRule](#watchrule)[] | Yes| Array of matching event subscription rules.|
| onEvent | function | Yes| Callback for event subscription: (info: [SysEventInfo](#syseventinfo)) => void| | onEvent | function | Yes| Callback for event subscription: (info: [SysEventInfo](#syseventinfo)) => void|
| onServiceDied | function | Yes| Callback for disabling of event subscription: () => void| | onServiceDied | function | Yes| Callback for disabling of event subscription: () => void|
## hiSysEvent.addWatcher ## hiSysEvent.addWatcher
addWatcher(watcher: Watcher): number addWatcher(watcher: Watcher): void
Adds a watcher for event subscription. Adds a watcher for event subscription.
...@@ -181,10 +211,19 @@ Adds a watcher for event subscription. ...@@ -181,10 +211,19 @@ Adds a watcher for event subscription.
**Parameters** **Parameters**
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| ------ | ----------------------------- | ---- | ------------------------ | | ------ | ----------------------------- | ---- | ------------------------ |
| watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.| | watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.|
**Error codes**
For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-hisysevent.md).
| ID| Error Message|
| -------- | ----------------------------------- |
| 11200101 | Count of watchers is over limit. |
| 11200102 | Count of watch rules is over limit. |
**Example** **Example**
```js ```js
...@@ -213,7 +252,7 @@ try { ...@@ -213,7 +252,7 @@ try {
## hiSysEvent.removeWatcher ## hiSysEvent.removeWatcher
removeWatcher(wathcer: Watcher): number removeWatcher(watcher: Watcher): void
Removes a watcher used for event subscription. Removes a watcher used for event subscription.
...@@ -223,10 +262,18 @@ Removes a watcher used for event subscription. ...@@ -223,10 +262,18 @@ Removes a watcher used for event subscription.
**Parameters** **Parameters**
| Name| Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ------ | ------------- | ---- | ------------------------ | | ------ | ------------- | ---- | ------------------------- |
| watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.| | watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.|
**Error codes**
For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-hisysevent.md).
| ID| Error Message|
| -------- | --------------------------- |
| 11200201 | The watcher does not exist. |
**Example** **Example**
```js ```js
...@@ -256,26 +303,26 @@ try { ...@@ -256,26 +303,26 @@ try {
## QueryArg ## QueryArg
Defines arguments for event query. Defines arguments for an event query.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| beginTime | number | Yes| Start time (13-digit timestamp) for event query.| | beginTime | number | Yes| Start time (13-digit timestamp) for the event query.|
| endTime | number | Yes| End time (13-digit timestamp) for event query.| | endTime | number | Yes| End time (13-digit timestamp) for the event query.|
| maxEvents | number | Yes| Maximum number of events that can be queried.| | maxEvents | number | Yes| Maximum number of events that can be queried.|
## QueryRule ## QueryRule
Defines rules for event query. Defines event query rules.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| domain | string | Yes| Event domain.| | domain | string | Yes| Event domain.|
| names | string[] | Yes| Array of event names.| | names | string[] | Yes| Array of event names. A **QueryRule** object contains multiple system event names.|
## Querier ## Querier
...@@ -283,14 +330,14 @@ Defines an event query instance. ...@@ -283,14 +330,14 @@ Defines an event query instance.
**System capability**: SystemCapability.HiviewDFX.HiSysEvent **System capability**: SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| onQuery | function | Yes| Callback of queried events: (infos: [SysEventInfo](#syseventinfo)[]) => void| | onQuery | function | Yes| Callback used to return the queried system events: (infos: [SysEventInfo](#syseventinfo)[]) => void.|
| onComplete | function | Yes| Callback of query result statistics: (reason: number, total: number) => void| | onComplete | function | Yes| Callback used to return the query result statistics: (reason: number, total: number) => void|
## hiSysEvent.query ## hiSysEvent.query
query(queryArg: QueryArg, rules: QueryRule[], querier: Querier): number query(queryArg: QueryArg, rules: QueryRule[], querier: Querier): void
Queries system events. Queries system events.
...@@ -300,12 +347,23 @@ Queries system events. ...@@ -300,12 +347,23 @@ Queries system events.
**Parameters** **Parameters**
| Name| Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| ------ | ----------------------------- | ---- | ------------------------ | | ------ | ----------------------------- | ---- | ------------------------ |
| queryArg | [QueryArg](#queryarg) | Yes | Arguments for event query.| | queryArg | [QueryArg](#queryarg) | Yes | Arguments for event query.|
| rules | [QueryRule](#queryrule)[] | Yes | Array of event query rules.| | rules | [QueryRule](#queryrule)[] | Yes | Array of event query rules.|
| querier | [Querier](#querier) | Yes | Event query instance.| | querier | [Querier](#querier) | Yes | Event query instance.|
**Error codes**
For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-hisysevent.md).
| ID| Error Message|
| -------- | ------------------------------------------- |
| 11200301 | Count of query rules is over limit. |
| 11200302 | Invalid query rule. |
| 11200303 | Count of concurrent queriers is over limit. |
| 11200304 | Query frequency is over limit. |
**Example** **Example**
```js ```js
......
# Application Event Logging
This module provides application event-related functions, including flushing application events to a disk, querying and clearing application events, and customizing application event logging configuration.
> **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent';
```
## hiAppEvent.write
write(info: [AppEventInfo](#appeventinfo), callback: AsyncCallback&lt;void&gt;): void
Writes events to the event file of the current day through [AppEventInfo](#appeventinfo) objects. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | -------------- |
| info | [AppEventInfo](#appeventinfo) | Yes | Application event object.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Application Event Logging Error Codes](../errorcodes/errorcode-hiappevent.md).
| ID| Error Message |
| -------- | --------------------------------------------- |
| 11100001 | Function is disabled. |
| 11101001 | Invalid event domain. |
| 11101002 | Invalid event name. |
| 11101003 | Invalid number of event parameters. |
| 11101004 | Invalid string length of the event parameter. |
| 11101005 | Invalid event parameter name. |
| 11101006 | Invalid array length of the event parameter. |
**Example**
```js
hiAppEvent.write({
domain: "test_domain",
name: "test_event",
eventType: hiAppEvent.EventType.FAULT,
params: {
int_data: 100,
str_data: "strValue"
}
}, (err) => {
if (err) {
console.error(`code: ${err.code}, message: ${err.message}`);
return;
}
console.log(`success to write event`);
});
```
## hiAppEvent.write
write(info: [AppEventInfo](#appeventinfo)): Promise&lt;void&gt;
Writes events to the event file of the current day through [AppEventInfo](#appeventinfo) objects. This API uses a promise to return the result.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | -------------- |
| info | [AppEventInfo](#appeventinfo) | Yes | Application event object.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Application Event Logging Error Codes](../errorcodes/errorcode-hiappevent.md).
| ID| Error Message |
| -------- | --------------------------------------------- |
| 11100001 | Function is disabled. |
| 11101001 | Invalid event domain. |
| 11101002 | Invalid event name. |
| 11101003 | Invalid number of event parameters. |
| 11101004 | Invalid string length of the event parameter. |
| 11101005 | Invalid event parameter name. |
| 11101006 | Invalid array length of the event parameter. |
**Example**
```js
hiAppEvent.write({
domain: "test_domain",
name: "test_event",
eventType: hiAppEvent.EventType.FAULT,
params: {
int_data: 100,
str_data: "strValue"
}
}).then(() => {
console.log(`success to write event`);
}).catch((err) => {
console.error(`code: ${err.code}, message: ${err.message}`);
});
```
## AppEventInfo
Defines parameters for an **AppEventInfo** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| --------- | ----------------------- | ---- | ---------- |
| domain | string | Yes | Event domain.|
| name | string | Yes | Event name.|
| eventType | [EventType](#eventtype) | Yes | Event type.|
| params | object | Yes | Event parameters.|
## hiAppEvent.configure
configure(config: [ConfigOption](configoption)): void
Configures the application event logging function, such as setting the event logging switch and maximum size of the directory that stores the event logging files.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | ------------------------ |
| config | [ConfigOption](#configoption) | Yes | Configuration items for application event logging.|
**Error codes**
For details about the error codes, see [Application Event Logging Error Codes](../errorcodes/errorcode-hiappevent.md).
| ID| Error Message |
| -------- | -------------------------------- |
| 11103001 | Invalid max storage quota value. |
**Example**
```js
// Disable the event logging function.
hiAppEvent.configure({
disable: true
});
// Set the maximum size of the file storage directory to 100 MB.
hiAppEvent.configure({
maxStorage: '100M'
});
```
## ConfigOption
Configures options for application event logging.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| ---------- | ------- | ---- | ------------------------------------------------------------ |
| disable | boolean | No | Whether to enable the event logging function. The default value is **false**. The value **true** means to disable the event logging function, and the value **false** means the opposite.|
| maxStorage | string | No | Maximum size of the directory that stores event logging files. The default value is **10M**.<br>If the directory size exceeds the specified quota when application event logging is performed, event logging files in the directory will be cleared one by one based on the generation time to ensure that directory size does not exceed the quota.|
## hiAppEvent.addWatcher
addWatcher(watcher: [Watcher](#watcher)): [AppEventPackageHolder](#appeventpackageholder)
Adds a watcher to subscribe to application events.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------------------- | ---- | ---------------- |
| watcher | [Watcher](#watcher) | Yes | Watcher for application events.|
**Return value**
| Type | Description |
| ------------------------------------------------ | ------------------------------------ |
| [AppEventPackageHolder](#appeventpackageholder) | Subscription data holder. If the subscription fails, **null** will be returned.|
**Error codes**
For details about the error codes, see [Application Event Logging Error Codes](../errorcodes/errorcode-hiappevent.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 11102001 | Invalid watcher name. |
| 11102002 | Invalid filtering event domain. |
| 11102003 | Invalid row value. |
| 11102004 | Invalid size value. |
| 11102005 | Invalid timeout value. |
**Example**
```js
// 1. If callback parameters are passed to the watcher, you can have subscription events processed in the callback that is automatically triggered.
hiAppEvent.addWatcher({
name: "watcher1",
appEventFilters: [
{
domain: "test_domain",
eventTypes: [hiAppEvent.EventType.FAULT, hiAppEvent.EventType.BEHAVIOR]
}
],
triggerCondition: {
row: 10,
size: 1000,
timeOut: 1
},
onTrigger: function (curRow, curSize, holder) {
if (holder == null) {
console.error("holder is null");
return;
}
let eventPkg = null;
while ((eventPkg = holder.takeNext()) != null) {
console.info(`eventPkg.packageId=${eventPkg.packageId}`);
console.info(`eventPkg.row=${eventPkg.row}`);
console.info(`eventPkg.size=${eventPkg.size}`);
for (const eventInfo of eventPkg.data) {
console.info(`eventPkg.data=${eventInfo}`);
}
}
}
});
// 2. If no callback parameters are passed to the watcher, you can have subscription events processed manually through the subscription data holder.
let holder = hiAppEvent.addWatcher({
name: "watcher2",
});
if (holder != null) {
let eventPkg = null;
while ((eventPkg = holder.takeNext()) != null) {
console.info(`eventPkg.packageId=${eventPkg.packageId}`);
console.info(`eventPkg.row=${eventPkg.row}`);
console.info(`eventPkg.size=${eventPkg.size}`);
for (const eventInfo of eventPkg.data) {
console.info(`eventPkg.data=${eventInfo}`);
}
}
}
```
## hiAppEvent.removeWatcher
removeWatcher(watcher: [Watcher](#watcher)): void
Removes a watcher to unsubscribe from application events.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------------------- | ---- | ---------------- |
| watcher | [Watcher](#watcher) | Yes | Watcher for application events.|
**Error codes**
For details about the error codes, see [Application Event Logging Error Codes](../errorcodes/errorcode-hiappevent.md).
| ID| Error Message |
| -------- | --------------------- |
| 11102001 | Invalid watcher name. |
**Example**
```js
// 1. Define a watcher for application events.
let watcher = {
name: "watcher1",
}
// 2. Add the watcher to subscribe to application events.
hiAppEvent.addWatcher(watcher);
// 3. Remove the watcher to unsubscribe from application events.
hiAppEvent.removeWatcher(watcher);
```
## Watcher
Defines parameters for a **Watcher** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| name | string | Yes | Unique name of the watcher. |
| triggerCondition | [TriggerCondition](#triggercondition) | No | Subscription callback triggering condition. This parameter takes effect only when it is passed together with the callback. |
| appEventFilters | [AppEventFilter](#appeventfilter)[] | No | Subscription filtering condition. This parameter is passed only when subscription events need to be filtered. |
| onTrigger | (curRow: number, curSize: number, holder: [AppEventPackageHolder](#appeventpackageholder)) => void | No | Subscription callback, which takes effect only when it is passed together with the callback triggering condition. The input arguments are described as follows:<br>**curRow**: total number of subscription events when the callback is triggered.<br>**curSize**: total size of subscribed events when the callback is triggered, in bytes.<br>**holder**: subscription data holder, which can be used to process subscribed events.|
## TriggerCondition
Defines callback triggering conditions. Subscription callback is triggered when any condition is met.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | -------------------------------------- |
| row | number | No | Number of events. |
| size | number | No | Event data size, in bytes.|
| timeOut | number | No | Timeout interval, in unit of 30s. |
## AppEventFilter
Defines parameters for an **AppEventFilter** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ------------------------ |
| domain | string | Yes | Event domain. |
| eventTypes | [EventType](#eventtype)[] | No | Event types.|
## AppEventPackageHolder
Defines a subscription data holder for processing subscription events.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
### constructor
constructor(watcherName: string)
Constructor of the **Watcher** class. When a watcher is added, the system automatically calls this API to create a subscription data holder object for the watcher and returns the holder object to the application.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------- | ---- | ------------------------ |
| watcherName | string | Yes | Watcher name.|
**Example**
```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
```
### setSize
setSize(size: number): void
Sets the threshold for the data size of the application event package obtained each time.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------------- |
| size | number | Yes | Data size threshold, in bytes. The default value is **512*1024**.|
**Error codes**
For details about the error codes, see [Application Event Logging Error Codes](../errorcodes/errorcode-hiappevent.md).
| ID| Error Message |
| -------- | ------------------- |
| 11104001 | Invalid size value. |
**Example**
```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
holder.setSize(1000);
```
### takeNext
takeNext(): [AppEventPackage](#appeventpackage)
Extracts subscription event data based on the configured data size threshold. If all subscription event data has been extracted, **null** will be returned.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Example**
```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
let eventPkg = holder.takeNext();
```
## AppEventPackage
Defines parameters for an **AppEventPackage** object.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Mandatory| Description |
| --------- | -------- | ---- | ------------------------------ |
| packageId | number | Yes | Event package ID, which is named from **0** in ascending order. |
| row | number | Yes | Number of events in the event package. |
| size | number | Yes | Event size of the event package, in bytes.|
| data | string[] | Yes | Event data in the event package. |
## hiAppEvent.clearData
clearData(): void
Clears local application event logging data.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
**Example**
```js
hiAppEvent.clearData();
```
## EventType
Enumerates event types.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Value | Description |
| --------- | ---- | -------------- |
| FAULT | 1 | Fault event.|
| STATISTIC | 2 | Statistical event.|
| SECURITY | 3 | Security event.|
| BEHAVIOR | 4 | Behavior event.|
## Event
Provides constants that define the names of all predefined events.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Readable| Writable| Description |
| ------------------------- | ------ | ---- | ---- | -------------------- |
| USER_LOGIN | string | Yes | No | User login event. |
| USER_LOGOUT | string | Yes | No | User logout event. |
| DISTRIBUTED_SERVICE_START | string | Yes | No | Distributed service startup event.|
## Param
Provides constants that define the names of all predefined event parameters.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Type | Readable| Writable| Description |
| ------------------------------- | ------ | ---- | ---- | ------------------ |
| USER_ID | string | Yes | No | Custom user ID. |
| DISTRIBUTED_SERVICE_NAME | string | Yes | No | Distributed service name. |
| DISTRIBUTED_SERVICE_INSTANCE_ID | string | Yes | No | Distributed service instance ID.|
# Application Event Logging Error Codes
## 11100001 Application Event Logging Disabled
**Error Message**
Function is disabled.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system ignores related events because the logging function is disabled.
**Possible Causes**
The application event logging function is disabled.
**Solution**
Invoke the **configure** API to enable the application event logging function.
```js
hiAppEvent.configure({
disable: false
});
```
## 11101001 Invalid Event Domain Name
**Error Message**
Invalid event domain.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system ignores related events because the input event domain name is invalid.
**Possible Causes**
The specified event domain name does not comply with the following rules:
- The event domain name contains only digits, lowercase letters, and underscores (\_).
- The event domain name starts with a lowercase letter and does not end with an underscore (\_).
- The event domain name is not empty and contains a maximum of 32 characters.
**Solution**
Specify a valid event domain name.
## 11101002 Invalid Event Name
**Error Message**
Invalid event name.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system ignores related events because the input event name is invalid.
**Possible Causes**
The specified event name does not comply with the following rules:
- The event name contains only digits, lowercase letters, and underscores (\_).
- The event name starts with a lowercase letter and does not end with an underscore (\_).
- The event name is not empty and contains a maximum of 48 characters.
**Solution**
Specify a valid event name.
## 11101003 Invalid Number of Event Parameters
**Error Message**
Invalid number of event parameters.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system discards extra event parameters because the number of input event parameters exceeds the limit.
**Possible Causes**
The number of input event parameters exceeds 32.
**Solution**
Specify a valid number of event parameters.
## 11101004 Invalid Event Parameter String Length
**Error Message**
Invalid string length of the event parameter.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system ignores related event parameters because the value of the input event parameter is excessively long.
**Possible Causes**
The length of the input event parameter value exceeds 8 x 1024 characters.
**Solution**
Specify an event parameter value with a valid length.
## 11101005 Invalid Event Parameter Name
**Error Message**
Invalid event parameter name.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system ignores related event parameters because the input event parameter name is invalid.
**Possible Causes**
The specified event parameter name does not comply with the following rules:
- The event parameter name contains only digits, lowercase letters, and underscores (\_).
- The event parameter name starts with a lowercase letter and does not end with an underscore (\_).
- The event parameter name is not empty and contains a maximum of 16 characters.
**Solution**
Specify a valid event parameter name.
## 11101006 Invalid Array Length of Event Parameter Values
**Error Message**
Invalid array length of the event parameter.
**Description**
This error code is reported if the **write** API is called to perform application event logging but the system discards extra array elements because the array of the event parameter value is excessively long.
**Possible Causes**
The array length of the event parameter value exceeds 100.
**Solution**
Specify a valid array length for the event parameter value.
## 11102001 Invalid Watcher Name
**Error Message**
Invalid watcher name.
**Description**
This error code is reported if the **addWatcher** API is called to subscribe to application events but the system ignores the subscription because the specified watcher name is invalid.
**Possible Causes**
The specified watcher name does not comply with the following rules:
- The watcher name can contain only digits, lowercase letters, and underscores (\_).
- The watcher name starts with a lowercase letter and does not end with an underscore (\_).
- The watcher name is not empty and contains a maximum of 32 characters.
**Solution**
Specify a valid watcher name.
## 11102002 Invalid Filtering Event Domain Name
**Error Message**
Invalid filtering event domain.
**Description**
This error code is reported if the **addWatcher** API is called to subscribe to application events but the system ignores the subscription because the specified filtering event domain name is invalid.
**Possible Causes**
The specified filtering event domain name does not comply with the following rules:
- The event domain name contains only digits, lowercase letters, and underscores (\_).
- The event domain name starts with a lowercase letter and does not end with an underscore (\_).
- The event domain name is not empty and contains a maximum of 32 characters.
**Solution**
Specify a valid filtering event domain name.
## 11102003 Invalid Event Number
**Error Message**
Invalid row value.
**Description**
This error code is reported if the **addWatcher** API is called to subscribe to application events but the system ignores the subscription because an invalid event number is passed in the callback trigger condition.
**Possible Causes**
The event number passed in the input callback triggering condition is a negative number.
**Solution**
Specify a valid event number.
## 11102004 Invalid Event Size
**Error Message**
Invalid size value.
**Description**
This error code is reported if the **addWatcher** API is called to subscribe to application events but the system ignores the subscription because an invalid event size is passed in the callback trigger condition.
**Possible Causes**
The event size passed in the input callback triggering condition is a negative number.
**Solution**
Specify a valid event size.
## 11102005 Invalid Timeout Value
**Error Message**
Invalid timeout value.
**Description**
This error code is reported if the **addWatcher** API is called to subscribe to application events but the system ignores the subscription because an invalid timeout value is passed in the callback trigger condition.
**Possible Causes**
The timeout value passed in the input callback triggering condition is a negative number.
**Solution**
Specify a valid timeout value.
## 11103001 Invalid Maximum Storage Quota
**Error Message**
Invalid max storage quota value.
**Description**
This error code is reported if the **configure** API is called to subscribe to application events but the system ignores the setting because the specified maximum storage quota is invalid.
**Possible Causes**
The maximum storage quota does not meet the following rules:
- The quota value consists of only digits and a unit (including b|k|kb|m|mb|g|gb|t|tb, which are case-insensitive).
- The quota value must start with a digit. You can determine whether to pass the unit. If the unit is left empty, **b** (that is, byte) is used by default.
**Solution**
Specify a valid maximum storage quota.
## 11104001 Invalid Event Package Size
**Error Message**
Invalid size value.
**Description**
This error code is reported if the **setSize** API is called to set the threshold of the event package size but the system ignores the setting because the specified event package size is invalid.
**Possible Causes**
The specified event package size is a negative number.
**Solution**
Specify a valid event package size.
# HiSysEvent Error Codes
## 1120001 Invalid Event Domain
**Error Message**
Invalid event domain.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system ignores the logging operation because the input event domain name is invalid.
**Possible Causes**
1. The event domain name contains more than 16 characters.
2. The event domain name contains special characters.
3. The event domain name is empty.
**Solution**
Specify a valid event domain name.
## 1120002 Invalid Event Name
**Error Message**
Invalid event name.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system ignores the logging operation because the input event name is invalid.
**Possible Causes**
1. The event name contains more than 32 characters.
2. The event name contains special characters.
3. The event name is empty.
**Solution**
Check whether the event name is valid.
## 11200003 Environment Error
**Error Message**
Abnormal environment.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system ignores the logging operation because the environment is abnormal.
**Possible Causes**
1. The hiview service fails to be started.
2. The socket of the hiview service is abnormal.
**Solution**
Call the **write** API again to perform event logging.
## 11200004 Invalid Event Length
**Error Message**
Length of the event is over limit.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system ignores the logging operation because the total event length is invalid.
**Possible Causes**
The total event length exceeds 384 KB.
**Solution**
Check whether the total event length is greater than 384 KB.
## 11200051 Invalid Event Parameter
**Error Message**
Invalid event parameter.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system throws an exception because the input parameter name is invalid. However, the system will continue to complete the logging operation.
**Possible Causes**
1. The event parameter name contains more than 32 characters.
2. The event parameter name contains special characters.
3. The event parameter name is empty.
**Solution**
Check whether the event parameter name is valid.
## 11200052 Length of Event Parameter Values of the String Type Exceeding the Limit
**Error Message**
Size of the event parameter of the string type is over limit.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system throws an exception because the length of event parameter values of the string type is invalid. However, the system will continue to complete the logging operation.
**Possible Causes**
The length of parameter values of the string type exceeds 10 KB.
**Solution**
Check whether the length of parameter values of the string type exceeds 10 KB.
## 11200053 Number of Event Parameters Exceeding the Limit
**Error Message**
Count of event parameters is over limit.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system throws an exception because the number of event parameters is invalid. However, the system will continue to complete the logging operation.
**Possible Causes**
The number of event parameters exceeds 128.
**Solution**
Check whether the number of event parameters exceeds 128.
## 11200054 Length of Event Parameter Values of the Array Type Exceeding the Limit
**Error Message**
Count of event parameter of the array type is over limit.
**Description**
This error code is reported if the **write** API is called to perform system event logging but the system throws an exception because the length of event parameter values of the array type is invalid. However, the system will continue to complete the logging operation.
**Possible Causes**
The length of a parameter values of the array type exceeds 100.
**Solution**
Check whether the length of the parameter value of the array type exceeds 100.
## 11200101 Number of Event Watchers Exceeding the Limit
**Error Message**
Count of watchers is over limit.
**Description**
This error code is reported if the **addWatcher** API is called to add an event watcher but the system rejects the operation because the number of watchers has exceeded the limit.
**Possible Causes**
A total of 30 event watchers have been added.
**Solution**
Check whether the number of event watchers exceeds 30.
## 11200102 Number of Event Watcher Rules Exceeding the Limit
**Error Message**
Count of watch rules is over limit.
**Description**
This error code is reported if the **addWatcher** API is called to add an event watcher but the system rejects the operation because the number of watcher rules has exceeded the limit.
**Possible Causes**
A total of 20 event watcher rules have been added.
**Solution**
Check whether the number of event watcher rules exceeds 20.
## 11200201 Event Watcher Not Exist
**Error Message**
The watcher does not exist.
**Description**
This error code is reported if the **removeWatcher** API is called to remove an event watcher but the system rejects the operation because the watcher does not exist.
**Possible Causes**
1. The event watcher to be removed is empty.
2. The event watcher to be removed has not been successfully added.
**Solution**
Check whether the event watcher to the removed is empty or whether the event watcher has been successfully added.
## 11200301 Number of Query Rules Exceeding the Limit
**Error Message**
Count of query rules is over limit.
**Description**
This error code is reported if the **query** API is called to query system events but the system ignores the operation because the number of query rules has exceeded the limit.
**Possible Causes**
The number of query rules exceeds 10.
**Solution**
Check whether the number of query rules exceeds 10.
## 11200302 Invalid Query Rule
**Error Message**
Invalid query rule.
**Description**
This error code is reported if the **query** API is called to query system events but the system ignores the operation because the input query rule is invalid.
**Possible Causes**
1. The event domain name in the query rule contains more than 16 characters or the event name contains more than 32 characters.
2. The event domain name or event name in the query rule contains special characters.
3. The event domain name or event name in the query rule is empty.
**Solution**
Check whether the event domain name and event name configured in the query rule are valid.
## 11200303 Number of Concurrent Queries Exceeding the Limit
**Error Message**
Count of concurrent queries is over limit.
**Description**
This error code is reported if the **query** API is called to query system events but the system ignores the operation because the number of concurrent queries has exceeded the limit.
**Possible Causes**
The number of concurrent queries exceeds 4.
**Solution**
Check whether more than four queries are performed at the same time.
## 11200304 Query Frequency Exceeding the Limit
**Error Message**
Query frequency is over limit.
**Description**
This error code is reported if the **query** API is called to query system events but the system ignores the operation because the query frequency has exceeded the limit.
**Possible Causes**
More than one query is performed in one second.
**Solution**
Check whether more than one query is performed in one second.
# HiDebug Error Codes
## 11400101 Failed to Obtain the System Service
**Error Message**
ServiceId is invalid, systemAbility is not exist.
**Description**
No system service is found based on the specified service ID.
**Possible Causes**
The specified service ID is incorrect.
**Solution**
Specify a correct system service ID.
# USB Error Codes
## 14400001 USB Device Connection Denied
**Error Message**
Permission denied. Need call requestRight to get permission.
**Description**
This error code is reported if a certain API of the USB module is called but the required permission is not granted.
**Possible Causes**
The permission to access the USB device is not granted.
**Solution**
Call **requestRight** to request for the permission to access the USB device.
...@@ -24,6 +24,7 @@ The sandbox management module is available only for the standard system. ...@@ -24,6 +24,7 @@ The sandbox management module is available only for the standard system.
| src-path | Source path of the directory or file to mount.| | src-path | Source path of the directory or file to mount.|
| sandbox-path | Target path in the sandbox.| | sandbox-path | Target path in the sandbox.|
| sandbox-flags | Mount flag. The default value is **bind rec**.| | sandbox-flags | Mount flag. The default value is **bind rec**.|
| ignore | Whether to ignore a mounting failure. If the value is set to 1, the system ignores the mounting failure and proceeds with the subsequent step. |
| target-name | Directory to link.| | target-name | Directory to link.|
| link-name | Target link in the sandbox.| | link-name | Target link in the sandbox.|
...@@ -44,13 +45,13 @@ Logical storage structure of the sandbox: ...@@ -44,13 +45,13 @@ Logical storage structure of the sandbox:
bool InitSandboxWithName(const char *name); // Parsing to the JSON structure bool InitSandboxWithName(const char *name); // Parsing to the JSON structure
typedef struct { typedef struct {
mountlist_t *mounts; // Directory to mount ListNode pathMountsHead; // sandbox mount_path list head
mountlist_t *fileMounts; // File to mount ListNode fileMountsHead; // sandbox mount_file list head
linklist_t *links; // Directory to link ListNode linksHead; // sandbox symbolic link list head
char *rootPath; // Root path of the sandbox: /mnt/sandbox/system|vendor|xxx char *rootPath; // /mnt/sandbox/system|vendor|xxx
char name[MAX_BUFFER_LEN]; // Sandbox name, for example, system sandbox or chipset sandbox char name[MAX_BUFFER_LEN]; // name of sandbox. i.e system, chipset etc.
bool isCreated; // Sandbox creation flag bool isCreated; // sandbox already created or not
int ns; // namespace int ns; // namespace // namespace
} sandbox_t; } sandbox_t;
``` ```
### How to Develop ### How to Develop
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册