提交 fb0d545d 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 2e7a2cff
......@@ -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.
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
......@@ -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): 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
| API | Description |
| --------------------------------------- | ---------------------------------------------------- |
| configure(ConfigOption config): boolean | Sets the configuration options for application event logging.|
| API | Description |
| ------------------------------------ | ---------------------------------------------------- |
| configure(ConfigOption config): void | Sets the configuration options for application event logging.|
**Table 3** APIs for watcher management
......@@ -42,32 +36,14 @@ For details about the result codes, see [Event Verification Result Codes](#event
| ----------------- | -------------------- |
| clearData(): void | Clears local logging data.|
### Event Verification Result Codes
| 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
## How to Develop
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
import hiAppEvent from '@ohos.hiAppEvent';
import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent';
@Entry
@Component
......@@ -91,10 +67,10 @@ The following uses a one-time event watcher as an example to illustrate the deve
int_data: 100,
str_data: "strValue"
}
}).then((value) => {
console.log(`HiAppEvent success to write event: ${value}`);
}).then(() => {
console.log(`HiAppEvent success to write event`);
}).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
// 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) {
// Parse the obtained event package and display the result on the Log page.
console.info('HiAppEvent eventPkg.packageId=' + eventPkg.packageId);
console.info('HiAppEvent eventPkg.row=' + eventPkg.row);
console.info('HiAppEvent eventPkg.size=' + eventPkg.size);
console.info(`HiAppEvent eventPkg.packageId=${eventPkg.packageId}`);
console.info(`HiAppEvent eventPkg.row=${eventPkg.row}`);
console.info(`HiAppEvent eventPkg.size=${eventPkg.size}`);
// Traverse and parse event string arrays in the obtained event package.
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
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 @@
This module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - 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.
## Modules to Import
......@@ -17,13 +17,9 @@ import hiAppEvent from '@ohos.hiAppEvent';
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**
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**
......@@ -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:
- 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.
- 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.
......@@ -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 smaller than **0**, the event parameter verification fails, and the event will not be written to the event file.
**Subscription Callback**
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>
## hiAppEvent.write
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.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
......@@ -72,7 +58,7 @@ Writes event information to the event file of the current day. This API uses an
| eventName | string | Yes | Event name. |
| eventType | [EventType](#eventtype) | Yes | Event type. |
| keyValues | object | Yes | Event parameters. |
| callback | AsyncCallback&lt;void&gt; | No | Event callback.|
| callback | AsyncCallback&lt;void&gt; | Yes | Event callback.|
**Example**
......@@ -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;
> **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.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
......@@ -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
configure(config: ConfigOption): boolean
......@@ -258,230 +151,11 @@ Provides the configuration items for application event logging.
**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.|
| 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
......@@ -489,12 +163,12 @@ Enumerates event types.
**System capability**: SystemCapability.HiviewDFX.HiAppEvent
| Name | Default Value| Description |
| --------- | ------ | -------------- |
| FAULT | 1 | Fault event.|
| STATISTIC | 2 | Statistical event.|
| SECURITY | 3 | Security event.|
| BEHAVIOR | 4 | Behavior event.|
| Name | Value | Description |
| --------- | ---- | -------------- |
| FAULT | 1 | Fault event.|
| STATISTIC | 2 | Statistical event.|
| SECURITY | 3 | Security event.|
| BEHAVIOR | 4 | Behavior event.|
## Event
......@@ -503,11 +177,11 @@ 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.|
| 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
......@@ -516,8 +190,8 @@ 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.|
| 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.|
# HiDebug
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
You can run the hidebug command to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data.
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
......@@ -17,7 +16,7 @@ import hidebug from '@ohos.hidebug';
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.
......@@ -27,7 +26,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
| 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**
......@@ -40,17 +39,17 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
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.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value**
| Type | Description |
| ------ | --------------------------------- |
| bigint | Size of the allocated heap memory of this application, in kB.|
| bigint | Allocated heap memory of the application, in KB.|
**Example**
......@@ -63,18 +62,17 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
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.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value**
| 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**
```js
......@@ -86,16 +84,15 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
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
**Return value**
| 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**
```js
......@@ -107,15 +104,15 @@ Obtains the size of the used physical memory of this process.
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
**Return value**
| 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**
......@@ -127,15 +124,15 @@ Obtains the size of the shared dirty memory of this process.
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
**Return value**
| 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**
......@@ -147,17 +144,17 @@ Obtains the size of the private dirty memory of this process.
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.
**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug
**Return value**
| Type | Description |
| ------ | -------------------------- |
| number | CPU usage of this process.|
| number | CPU usage of the process.|
**Example**
......@@ -165,11 +162,13 @@ For example, if the CPU usage is **50%**, **0.5** is returned.
let cpuUsage = hidebug.getCpuUsage();
```
## hidebug.startProfiling
## hidebug.startProfiling<sup>(deprecated)</sup>
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
......@@ -191,11 +190,13 @@ hidebug.stopProfiling();
## hidebug.stopProfiling
## hidebug.stopProfiling<sup>(deprecated)</sup>
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
......@@ -209,17 +210,19 @@ hidebug.startProfiling("cpuprofiler-20220216");
hidebug.stopProfiling();
```
## hidebug.dumpHeapData
## hidebug.dumpHeapData<sup>(deprecated)</sup>
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
**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`.|
......@@ -231,11 +234,11 @@ hidebug.dumpHeapData("heap-20220216");
## 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
......@@ -243,16 +246,116 @@ This is a system API and cannot be called by third-party applications.
| 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**
```js
let serviceId = 10;
let pathName = hidebug.getServiceDump(serviceId);
import fileio from '@ohos.fileio'
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
# 系统事件打点
Provides system event logging APIs for system HAP applications.
本模块提供了系统事件打点能力,包括系统事件的埋点、落盘系统事件的订阅及已落盘的系统事件的查询能力。
> **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 APIs of this module are system APIs.
> **说明:**
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块的接口为系统接口。
## Modules to Import
## 导入模块
```js
import hiSysEvent from '@ohos.hiSysEvent';
......@@ -15,47 +15,62 @@ import hiSysEvent from '@ohos.hiSysEvent';
## EventType
Enumerates event types.
系统事件类型枚举。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name | Default Value | Description |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| FAULT | 1 | Error event.|
| STATISTIC | 2 | Statistic event.|
| SECURITY | 3 | Security event.|
| BEHAVIOR | 4 | User behavior event.|
| FAULT | 1 | 错误事件类型。 |
| STATISTIC | 2 | 统计事件类型。 |
| SECURITY | 3 | 安全事件类型。 |
| BEHAVIOR | 4 | 用户行为事件类型。 |
## SysEventInfo
Defines a system event.
系统事件信息对象接口。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| domain | string | Yes| Event domain.|
| name | string | Yes| Event name.|
| eventType | [EventType](#eventtype) | Yes| Event type.|
| params | object | No| Event parameters.|
| domain | string | 是 | 事件领域。 |
| name | string | 是 | 事件名称。 |
| eventType | [EventType](#eventtype) | 是 | 事件类型。 |
| params | object | 否 | 事件参数。 |
## hiSysEvent.write
write(info: SysEventInfo, callback: AsyncCallback&lt;void&gt;): void
Writes event information to the event file. This API uses an asynchronous callback to return the result.
系统事件打点方法,接收[SysEventInfo](#syseventinfo)类型的对象作为事件参数,使用callback方式作为异步回调。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
**Parameters**
**参数:**
| Name | Type | Mandatory | Description |
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| info | [SysEventInfo](#syseventinfo) | 是 | 系统事件。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。<br/>- 0表示事件校验成功,事件正常异步写入事件文件;<br/>- 正值表示事件打点存在异常,但可以正常写入;<br/>- 负值表示事件打点失败。 |
**Example**
**错误码:**
以下错误码的详细介绍请参见[系统事件错误码](../errorcodes/errorcode-hisysevent.md)
| 错误码ID | 错误信息 |
| ------- | ----------------------------------------------------------------- |
| 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. |
**示例:**
```js
import hiSysEvent from '@ohos.hiSysEvent';
......@@ -85,23 +100,38 @@ try {
write(info: SysEventInfo): Promise&lt;void&gt;
Writes event information to the event file. This API uses a promise to return the result.
系统事件打点方法,接收[SysEventInfo](#syseventinfo)类型的对象作为事件参数,使用promise方式作为异步回调。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
**Parameters**
**参数:**
| Name | Type | Mandatory | Description|
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | --------------- |
| info | [SysEventInfo](#syseventinfo) | Yes | System event information.|
| info | [SysEventInfo](#syseventinfo) | 是 | 系统事件。 |
**Return value**
**返回值:**
| 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实例,可以在其then()、catch()方法中分别对系统事件写入成功、写入异常的回调进行处理。 |
**错误码:**
**Example**
以下错误码的详细介绍请参见[系统事件错误码](../errorcodes/errorcode-hisysevent.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------------------------------- |
| 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. |
**示例:**
```js
import hiSysEvent from '@ohos.hiSysEvent';
......@@ -134,58 +164,67 @@ try {
## RuleType
Enumerates matching rule types.
匹配规则类型枚举。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name | Default Value | Description |
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| WHOLE_WORD | 1 | Whole word matching.|
| PREFIX | 2 | Prefix matching.|
| REGULAR | 3 | Regular expression matching.|
| WHOLE_WORD | 1 | 全词匹配类型。 |
| PREFIX | 2 | 前缀匹配类型。 |
| REGULAR | 3 | 正则匹配类型。 |
## WatchRule
Defines rules for event subscription.
系统事件订阅规则对象接口。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| domain | string | Yes| Event domain.|
| name | string | Yes| Event name.|
| tag | string | No| Event tag.|
| ruleType | [RuleType](#ruletype) | Yes| Matching rule type.|
| domain | string | 是 | 事件领域。 |
| name | string | 是 | 事件名称。 |
| tag | string | 否 | 事件标签。 |
| ruleType | [RuleType](#ruletype) | 是 | 匹配规则类型。 |
## Watcher
Defines a watcher for event subscription.
系统事件订阅者对象接口。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| rules | [WatchRule](#watchrule)[] | Yes| Array of matching rules for event subscription.|
| onEvent | function | Yes| Callback for event subscription: (info: [SysEventInfo](#syseventinfo)) => void|
| onServiceDied | function | Yes| Callback for disabling of event subscription: () => void|
| rules | [WatchRule](#watchrule)[] | 是 | 订阅对象数组,每个订阅者对象包含多个订阅规则。 |
| onEvent | function | 是 | 订阅事件的回调方法(info: [SysEventInfo](#syseventinfo)) => void。 |
| onServiceDied | function | 是 | 系统事件服务关闭的回调方法() => void。 |
## hiSysEvent.addWatcher
addWatcher(watcher: Watcher): number
addWatcher(watcher: Watcher): void
Adds a watcher for event subscription.
订阅系统事件,接收[Watcher](#watcher)类型的对象作为事件参数。
**Required permission**: ohos.permission.READ_DFX_SYSEVENT
**需要权限:** ohos.permission.READ_DFX_SYSEVENT
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
**Parameters**
**参数:**
| Name| Type | Mandatory | Description |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | ------------------------ |
| watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.|
| watcher | [Watcher](#watcher) | 是 | 系统事件订阅者对象。 |
**错误码:**
以下错误码的详细介绍请参见[系统事件错误码](../errorcodes/errorcode-hisysevent.md)
**Example**
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 11200101 | Count of watchers is over limit. |
| 11200102 | Count of watch rules is over limit. |
**示例:**
```js
import hiSysEvent from '@ohos.hiSysEvent';
......@@ -213,21 +252,29 @@ try {
## hiSysEvent.removeWatcher
removeWatcher(wathcer: Watcher): number
removeWatcher(watcher: Watcher): void
取消订阅系统事件,接收[Watcher](#watcher)类型的对象作为事件参数。
**需要权限:** ohos.permission.READ_DFX_SYSEVENT
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
Removes a watcher used for event subscription.
**参数:**
**Required permission**: ohos.permission.READ_DFX_SYSEVENT
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------- | ---- | ------------------------- |
| watcher | [Watcher](#watcher) | 是 | 系统事件订阅者对象。 |
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**错误码:**
**Parameters**
以下错误码的详细介绍请参见[系统事件错误码](../errorcodes/errorcode-hisysevent.md)
| Name| Type | Mandatory | Description |
| ------ | ------------- | ---- | ------------------------ |
| watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.|
| 错误码ID | 错误信息 |
| -------- | --------------------------- |
| 11200201 | The watcher does not exist. |
**Example**
**示例:**
```js
import hiSysEvent from '@ohos.hiSysEvent';
......@@ -256,57 +303,68 @@ try {
## QueryArg
Defines arguments for event query.
系统事件查询参数对象接口。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| beginTime | number | Yes| Start time (13-digit timestamp) for event query.|
| endTime | number | Yes| End time (13-digit timestamp) for event query.|
| maxEvents | number | Yes| Maximum number of events that can be queried.|
| beginTime | number | 是 | 查询的系统事件起始时间(13位时间戳)。 |
| endTime | number | 是 | 查询的系统事件结束时间(13位时间戳)。 |
| maxEvents | number | 是 | 查询的系统事件最多条数。 |
## QueryRule
Defines rules for event query.
系统事件查询规则对象接口。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| domain | string | Yes| Event domain.|
| names | string[] | Yes| Array of event names.|
| domain | string | 是 | 查询包含的事件领域。 |
| names | string[] | 是 | 查询所包含的多个事件名称,每个查询规则对象包含多个系统事件名称。 |
## Querier
Defines an event query instance.
系统事件查询者对象接口。
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
| Name| Type | Mandatory | Description |
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| onQuery | function | Yes| Callback of queried events: (infos: [SysEventInfo](#syseventinfo)[]) => void|
| onComplete | function | Yes| Callback of query result statistics: (reason: number, total: number) => void|
| onQuery | function | 是 | 返回查询到的系统事件的回调方法(infos: [SysEventInfo](#syseventinfo)[]) => void。 |
| onComplete | function | 是 | 查询结果统计的回调方法(reason: number, total: number) => void。 |
## hiSysEvent.query
query(queryArg: QueryArg, rules: QueryRule[], querier: Querier): number
query(queryArg: QueryArg, rules: QueryRule[], querier: Querier): void
Queries system events.
查询系统事件。
**Required permission**: ohos.permission.READ_DFX_SYSEVENT
**需要权限:** ohos.permission.READ_DFX_SYSEVENT
**System capability**: SystemCapability.HiviewDFX.HiSysEvent
**系统能力:** SystemCapability.HiviewDFX.HiSysEvent
**Parameters**
**参数:**
| Name| Type | Mandatory | Description |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | ------------------------ |
| queryArg | [QueryArg](#queryarg) | Yes | Arguments for event query.|
| rules | [QueryRule](#queryrule)[] | Yes | Array of event query rules.|
| querier | [Querier](#querier) | Yes | Event query instance.|
| queryArg | [QueryArg](#queryarg) | 是 | 查询需要配置的查询参数。 |
| rules | [QueryRule](#queryrule)[] | 是 | 查询规则数组,每次查询可配置多个查询规则。 |
| querier | [Querier](#querier) | 是 | 查询者对象,包含查询结果及结束的相关回调。 |
**Example**
**错误码:**
以下错误码的详细介绍请参见[系统事件错误码](../errorcodes/errorcode-hisysevent.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------- |
| 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. |
**示例:**
```js
import hiSysEvent from '@ohos.hiSysEvent';
......@@ -344,4 +402,4 @@ try {
} catch (error) {
console.error(`error code: ${error.code}, error msg: ${error.message}`);
}
```
```
\ No newline at end of file
# 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.
# 系统事件错误码
## 1120001 非法的事件领域
**错误信息**
Invalid event domain.
**错误描述**
在调用write接口进行系统事件打点时,由于传入了非法的事件领域名称,系统将忽略此次系统事件打点。
**可能原因**
1.系统事件领域名称长度超过16个字符;
2.系统事件领域名称包含特殊字符;
3.系统事件领域名称为空。
**处理步骤**
检查系统事件领域名称是否合法。
## 1120002 非法的事件名称
**错误信息**
Invalid event name.
**错误描述**
在调用write接口进行系统事件打点时,由于传入了非法的事件名称,系统将忽略此次系统事件打点。
**可能原因**
1.系统事件名称长度超过32个字符;
2.系统事件名称包含特殊字符;
3.系统事件名称为空。
**处理步骤**
检查系统事件名称是否合法。
## 11200003 环境异常
**错误信息**
Abnormal environment.
**错误描述**
在调用write接口进行系统事件打点时,由于环境异常,系统将忽略此次系统事件打点。
**可能原因**
1.hiview服务未成功启动;
2.hiview服务socket异常。
**处理步骤**
尝试重新调用write接口进行打点。
## 11200004 事件长度超过限制
**错误信息**
Length of the event is over limit.
**错误描述**
在调用write接口进行系统事件打点时,由于传入的事件总长度超过限制,系统将忽略此次系统事件打点。
**可能原因**
系统事件总长度超过384K。
**处理步骤**
检查系统事件总长度是否大于384K。
## 11200051 非法的事件参数
**错误信息**
Invalid event parameter.
**错误描述**
在调用write接口进行系统事件打点时,由于传入了非法的参数名称,系统以抛出错误的形式提示,但会完成此次系统事件打点。
**可能原因**
1.系统事件参数名称长度超过32个字符;
2.系统事件参数名称包含特殊字符;
3.系统事件参数名为空。
**处理步骤**
检查系统事件参数名称是否合法。
## 11200052 字符串类型的事件参数值的长度超过限制
**错误信息**
Size of the event parameter of the string type is over limit.
**错误描述**
在调用write接口进行系统事件打点时,由于传入了长度超限的字符串类型参数,系统以抛出错误的形式提示,但会完成此次系统事件打点。
**可能原因**
字符串类型的参数值的长度超过10K。
**处理步骤**
检查系统事件中字符串类型的参数值的长度是否超过10K。
## 11200053 事件参数的数量超过限制
**错误信息**
Count of event parameters is over limit.
**错误描述**
在调用write接口进行系统事件打点时,由于传入的事件参数数量超过限制,系统以抛出错误的形式提示,但会完成此次系统事件打点。
**可能原因**
系统事件的参数数量超过128个。
**处理步骤**
检查系统事件的参数数量是否超过了128个。
## 11200054 数组类型的事件参数值的长度超过限制
**错误信息**
Count of event parameter of the array type is over limit.
**错误描述**
在调用write接口进行系统事件打点时,由于传入了长度超过限制的数组类型的参数,系统以抛出错误的形式提示,但会完成此次系统事件打点。
**可能原因**
系统事件中有数组类型的参数值的长度超过100。
**处理步骤**
检查数组类型的参数值的长度是否超过100.
## 11200101 事件监听者的数量超过限制
**错误信息**
Count of watchers is over limit.
**错误描述**
在调用addWatcher接口添加系统事件监听者时,由于添加的监听者数量超过限制,系统将拒绝此系统事件监听者的添加。
**可能原因**
hiview服务已添加30个系统事件监听者,无法添加新的系统事件监听者。
**处理步骤**
检查已成功添加的系统事件监听者数量是否超过了30个。
## 11200102 事件监听者包含的监听规则数量超过限制
**错误信息**
Count of watch rules is over limit.
**错误描述**
在调用addWatcher接口添加系统事件监听者时,由于该系统事件监听者包含的监听规则数量超过限制,系统将拒绝此系统事件监听者的添加。
**可能原因**
系统事件监听者包含的监听规则的数量超过20个。
**处理步骤**
检查系统事件监听者包含的监听规则数量是否超过20个。
## 11200201 事件监听者不存在
**错误信息**
The watcher does not exist.
**错误描述**
在调用removeWatcher移除系统事件监听者时,由于该系统事件监听者不在监听队列,系统将拒绝此系统事件监听者的移除。
**可能原因**
1.尝试移除的系统事件监听者为空;
2.尝试移除的系统事件监听者没有被成功添加过。
**处理步骤**
检查移除的系统事件监听者是否为空,或者是否成功添加过此系统事件监听者。
## 11200301 查询规则的数量超过限制
**错误信息**
Count of query rules is over limit.
**错误描述**
在调用query接口查询系统事件时,由于传入的查询规则数量超限,系统将忽略此次系统事件的查询。
**可能原因**
查询规则个数超过10个。
**处理步骤**
检查查询规则数量是否超过10个。
## 11200302 非法的查询规则
**错误信息**
Invalid query rule.
**错误描述**
在调用query接口查询系统事件时,由于传入了非法的查询规则,系统将忽略此次系统事件的查询。
**可能原因**
1.查询规则中的事件领域名称长度超过16个字符或者事件名称长度超过32个字符;
2.查询规则中的事件领域名称或者事件名称包含特殊字符;
3.查询规则中的事件领域名称或者事件名称为空。
**处理步骤**
检查查询规则中配置的事件领域名称及事件名称是否合法。
## 11200303 并发查询的数量超过限制
**错误信息**
Count of concurrent queriers is over limit.
**错误描述**
在调用query接口查询系统事件时,由于在同一时间点并发查询的数量超过限制,系统将忽略此次系统事件的查询。
**可能原因**
并发查询的数量超过4个。
**处理步骤**
检查在同一时间点是否有4个以上的查询操作。
## 11200304 查询频率超过限制
**错误信息**
Query frequency is over limit.
**错误描述**
在调用query接口查询系统事件时,由于查询频率超过限制,系统将忽略此次系统事件的查询。
**可能原因**
查询频率超过1次/秒。
**处理步骤**
检查是否在1秒内进行1次以上的查询。
# 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.
......@@ -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.|
| sandbox-path | Target path in the sandbox.|
| 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.|
| link-name | Target link in the sandbox.|
......@@ -44,13 +45,13 @@ Logical storage structure of the sandbox:
bool InitSandboxWithName(const char *name); // Parsing to the JSON structure
typedef struct {
mountlist_t *mounts; // Directory to mount
mountlist_t *fileMounts; // File to mount
linklist_t *links; // Directory to link
char *rootPath; // Root path of the sandbox: /mnt/sandbox/system|vendor|xxx
char name[MAX_BUFFER_LEN]; // Sandbox name, for example, system sandbox or chipset sandbox
bool isCreated; // Sandbox creation flag
int ns; // namespace
ListNode pathMountsHead; // sandbox mount_path list head
ListNode fileMountsHead; // sandbox mount_file list head
ListNode linksHead; // sandbox symbolic link list head
char *rootPath; // /mnt/sandbox/system|vendor|xxx
char name[MAX_BUFFER_LEN]; // name of sandbox. i.e system, chipset etc.
bool isCreated; // sandbox already created or not
int ns; // namespace // namespace
} sandbox_t;
```
### How to Develop
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册