1# @ohos.hiSysEvent (System Event Logging) (System API) 2 3The **hiSysEvent** 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. 4 5> **NOTE** 6> 7> - 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. 8> - The APIs provided by this module are system APIs. 9 10## Modules to Import 11 12```ts 13import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 14``` 15 16## EventType 17 18Enumerates event types. 19 20**System capability**: SystemCapability.HiviewDFX.HiSysEvent 21 22| Name| Value| Description| 23| -------- | -------- | -------- | 24| FAULT | 1 | Error event.| 25| STATISTIC | 2 | Statistic event.| 26| SECURITY | 3 | Security event.| 27| BEHAVIOR | 4 | User behavior event.| 28 29## SysEventInfo 30 31Defines a system event. 32 33**System capability**: SystemCapability.HiviewDFX.HiSysEvent 34 35| Name| Type| Mandatory| Description| 36| -------- | -------- | -------- | -------- | 37| domain | string | Yes| Event domain.| 38| name | string | Yes| Event name.| 39| eventType | [EventType](#eventtype) | Yes| Event type.| 40| params | object | No| Event parameters.| 41 42 43## hiSysEvent.write 44 45write(info: SysEventInfo, callback: AsyncCallback<void>): void 46 47Writes event information to the event file. This API uses an asynchronous callback to return the result. 48 49**System capability**: SystemCapability.HiviewDFX.HiSysEvent 50 51**Parameters** 52 53| Name | Type | Mandatory| Description | 54| --------- | ------------------------- | ---- | ------------------------------------------------------------ | 55| info | [SysEventInfo](#syseventinfo) | Yes| System event information.| 56| callback | AsyncCallback<void> | 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.| 57 58**Error codes** 59 60For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 61 62| ID| Error Message| 63| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 64| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 65| 11200001 | Invalid event domain. | 66| 11200002 | Invalid event name. | 67| 11200003 | Abnormal environment. | 68| 11200004 | The event length exceeds the limit. | 69| 11200051 | Invalid event parameter. | 70| 11200052 | The size of the event parameter of the string type exceeds the limit. | 71| 11200053 | The number of event parameters exceeds the limit. | 72| 11200054 | The number of event parameters of the array type exceeds the limit. | 73 74**Example** 75 76```ts 77import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 78import { BusinessError } from '@kit.BasicServicesKit'; 79 80try { 81 let customizedParams: Record<string, string | number> = { 82 'PID': 487, 83 'UID': 103, 84 'PACKAGE_NAME': "com.ohos.hisysevent.test", 85 'PROCESS_NAME': "syseventservice", 86 'MSG': "no msg." 87 }; 88 let eventInfo: hiSysEvent.SysEventInfo = { 89 domain: "RELIABILITY", 90 name: "STACK", 91 eventType: hiSysEvent.EventType.FAULT, 92 params: customizedParams 93 }; 94 hiSysEvent.write(eventInfo, (err: BusinessError) => { 95 // do something here. 96 }); 97} catch (err) { 98 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 99} 100``` 101 102 103## hiSysEvent.write 104 105write(info: SysEventInfo): Promise<void> 106 107Writes event information to the event file. This API uses a promise to return the result. 108 109**System capability**: SystemCapability.HiviewDFX.HiSysEvent 110 111**Parameters** 112 113| Name | Type | Mandatory| Description| 114| --------- | ----------------------- | ---- | --------------- | 115| info | [SysEventInfo](#syseventinfo) | Yes | System event information.| 116 117**Return value** 118 119| Type | Description | 120| ------------------- | ------------------------------------------------------------ | 121| Promise<void> | 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.| 122 123**Error codes** 124 125For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 126 127| ID| Error Message| 128| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 129| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 130| 11200001 | Invalid event domain. | 131| 11200002 | Invalid event name. | 132| 11200003 | Abnormal environment. | 133| 11200004 | The event length exceeds the limit. | 134| 11200051 | Invalid event parameter. | 135| 11200052 | The size of the event parameter of the string type exceeds the limit. | 136| 11200053 | The number of event parameters exceeds the limit. | 137| 11200054 | The number of event parameters of the array type exceeds the limit. | 138 139**Example** 140 141```ts 142import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 143import { BusinessError } from '@kit.BasicServicesKit'; 144 145try { 146 let customizedParams: Record<string, string | number> = { 147 'PID': 487, 148 'UID': 103, 149 'PACKAGE_NAME': "com.ohos.hisysevent.test", 150 'PROCESS_NAME': "syseventservice", 151 'MSG': "no msg." 152 }; 153 let eventInfo: hiSysEvent.SysEventInfo = { 154 domain: "RELIABILITY", 155 name: "STACK", 156 eventType: hiSysEvent.EventType.FAULT, 157 params: customizedParams 158 }; 159 hiSysEvent.write(eventInfo).then( 160 () => { 161 // do something here. 162 } 163 ).catch( 164 (err: BusinessError) => { 165 console.error(`error code: ${err.code}, error msg: ${err.message}`); 166 } 167 ); 168} catch (err) { 169 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 170} 171``` 172 173## RuleType 174 175Enumerates matching rule types. 176 177**System capability**: SystemCapability.HiviewDFX.HiSysEvent 178 179| Name| Value| Description| 180| -------- | -------- | -------- | 181| WHOLE_WORD | 1 | Whole word matching.| 182| PREFIX | 2 | Prefix matching.| 183| REGULAR | 3 | Regular expression matching.| 184 185## WatchRule 186 187Defines event subscription rules. 188 189**System capability**: SystemCapability.HiviewDFX.HiSysEvent 190 191| Name| Type| Mandatory| Description| 192| -------- | -------- | -------- | -------- | 193| domain | string | Yes| Event domain.| 194| name | string | Yes| Event name.| 195| tag | string | No| Event tag.| 196| ruleType | [RuleType](#ruletype) | Yes| Matching rule type.| 197 198## Watcher 199 200Defines a watcher for event subscription. 201 202**System capability**: SystemCapability.HiviewDFX.HiSysEvent 203 204| Name| Type| Mandatory| Description| 205| -------- | -------- | -------- | -------- | 206| rules | [WatchRule](#watchrule)[] | Yes| Array of matching event subscription rules.| 207| onEvent | function | Yes| Callback for event subscription: (info: [SysEventInfo](#syseventinfo)) => void| 208| onServiceDied | function | Yes| Callback for disabling of event subscription: () => void| 209 210## hiSysEvent.addWatcher 211 212addWatcher(watcher: Watcher): void 213 214Adds a watcher for event subscription. 215 216**Required permission**: ohos.permission.READ_DFX_SYSEVENT 217 218**System capability**: SystemCapability.HiviewDFX.HiSysEvent 219 220**Parameters** 221 222| Name| Type| Mandatory| Description| 223| ------ | ----------------------------- | ---- | ------------------------ | 224| watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.| 225 226**Error codes** 227 228For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 229 230| ID| Error Message| 231| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 232| 201 | Permission denied. An attempt was made to read system event forbidden by permission: ohos.permission.READ_DFX_SYSEVENT. | 233| 202 | System API is not allowed called by Non-system application. | 234| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 235| 11200101 | The number of watchers exceeds the limit. | 236| 11200102 | The number of watch rules exceeds the limit. | 237 238**Example** 239 240```ts 241import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 242import { BusinessError } from '@kit.BasicServicesKit'; 243 244let watchRules: hiSysEvent.WatchRule[] = [{ 245 domain: "RELIABILITY", 246 name: "STACK", 247 tag: "STABILITY", 248 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 249 } as hiSysEvent.WatchRule]; 250let watcher: hiSysEvent.Watcher = { 251 rules: watchRules, 252 onEvent: (info: hiSysEvent.SysEventInfo) => { 253 // do something here. 254 }, 255 onServiceDied: () => { 256 // do something here. 257 } 258}; 259try { 260 hiSysEvent.addWatcher(watcher); 261} catch (err) { 262 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 263} 264``` 265 266## hiSysEvent.removeWatcher 267 268removeWatcher(watcher: Watcher): void 269 270Removes a watcher used for event subscription. 271 272**Required permission**: ohos.permission.READ_DFX_SYSEVENT 273 274**System capability**: SystemCapability.HiviewDFX.HiSysEvent 275 276**Parameters** 277 278| Name| Type | Mandatory| Description | 279| ------ | ------------- | ---- | ------------------------- | 280| watcher | [Watcher](#watcher) | Yes| Watcher for event subscription.| 281 282**Error codes** 283 284For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 285 286| ID| Error Message| 287| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 288| 201 | Permission denied. An attempt was made to read system event forbidden by permission: ohos.permission.READ_DFX_SYSEVENT. | 289| 202 | System API is not allowed called by Non-system application. | 290| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 291| 11200201 | The watcher does not exist. | 292 293**Example** 294 295```ts 296import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 297import { BusinessError } from '@kit.BasicServicesKit'; 298 299let watchRules: hiSysEvent.WatchRule[] = [{ 300 domain: "RELIABILITY", 301 name: "STACK", 302 tag: "STABILITY", 303 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 304 } as hiSysEvent.WatchRule ]; 305let watcher: hiSysEvent.Watcher = { 306 rules: watchRules, 307 onEvent: (info: hiSysEvent.SysEventInfo) => { 308 // do something here. 309 }, 310 onServiceDied: () => { 311 // do something here. 312 } 313}; 314try { 315 hiSysEvent.addWatcher(watcher); 316 hiSysEvent.removeWatcher(watcher); 317} catch (err) { 318 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 319} 320``` 321 322## QueryArg 323 324Defines arguments for an event query. 325 326**System capability**: SystemCapability.HiviewDFX.HiSysEvent 327 328| Name| Type| Mandatory| Description| 329| -------- | -------- | -------- | -------- | 330| beginTime | number | Yes| Start time (13-digit timestamp) for the event query.| 331| endTime | number | Yes| End time (13-digit timestamp) for the event query.| 332| maxEvents | number | Yes| Maximum number of events that can be queried.| 333| fromSeq<sup>10+</sup> | number | No | Start SN of the events to be queried. The default value is **-1**.| 334| toSeq<sup>10+</sup> | number | No | End SN of the system events to be queried. The default value is **-1**.| 335 336## QueryRule 337 338Defines event query rules. 339 340**System capability**: SystemCapability.HiviewDFX.HiSysEvent 341 342| Name| Type| Mandatory| Description| 343| -------- | -------- | -------- | -------- | 344| domain | string | Yes| Event domain.| 345| names | string[] | Yes| Array of event names. A **QueryRule** object contains multiple system event names.| 346| condition<sup>10+</sup> | string | No| Additional event conditions. The value of this parameter is in the format of {"version":"V1","condition":{"and":[{"param":"*Parameter*","op":"*Operator*","value":"*Comparison value*"}]}}.| 347 348## Querier 349 350Defines an event query instance. 351 352**System capability**: SystemCapability.HiviewDFX.HiSysEvent 353 354| Name| Type| Mandatory| Description| 355| -------- | -------- | -------- | -------- | 356| onQuery | function | Yes| Callback used to return the queried system events: (infos: [SysEventInfo](#syseventinfo)[]) => void.| 357| onComplete | function | Yes| Callback used to return the query result statistics: (reason: number, total: number) => void| 358 359## hiSysEvent.query 360 361query(queryArg: QueryArg, rules: QueryRule[], querier: Querier): void 362 363Queries system events. 364 365**Required permission**: ohos.permission.READ_DFX_SYSEVENT 366 367**System capability**: SystemCapability.HiviewDFX.HiSysEvent 368 369**Parameters** 370 371| Name| Type| Mandatory| Description| 372| ------ | ----------------------------- | ---- | ------------------------ | 373| queryArg | [QueryArg](#queryarg) | Yes | Arguments for event query.| 374| rules | [QueryRule](#queryrule)[] | Yes | Array of event query rules.| 375| querier | [Querier](#querier) | Yes | Event query instance.| 376 377**Error codes** 378 379For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 380 381| ID| Error Message| 382| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 383| 201 | Permission denied. An attempt was made to read system event forbidden by permission: ohos.permission.READ_DFX_SYSEVENT. | 384| 202 | System API is not allowed called by Non-system application. | 385| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 386| 11200301 | The number of query rules exceeds the limit. | 387| 11200302 | Invalid query rule. | 388| 11200303 | The number of concurrent queriers exceeds the limit. | 389| 11200304 | The query frequency exceeds the limit. | 390 391**Example** 392 393```ts 394import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 395import { BusinessError } from '@kit.BasicServicesKit'; 396 397try { 398 let customizedParams: Record<string, string | number> = { 399 'PID': 487, 400 'UID': 103, 401 'PACKAGE_NAME': "com.ohos.hisysevent.test", 402 'PROCESS_NAME': "syseventservice", 403 'MSG': "no msg." 404 }; 405 let eventInfo: hiSysEvent.SysEventInfo = { 406 domain: "RELIABILITY", 407 name: "STACK", 408 eventType: hiSysEvent.EventType.FAULT, 409 params: customizedParams 410 }; 411 hiSysEvent.write(eventInfo, (err: BusinessError) => { 412 // do something here. 413 }); 414 415 let queryArg: hiSysEvent.QueryArg = { 416 beginTime: -1, 417 endTime: -1, 418 maxEvents: 5, 419 }; 420 let queryRules: hiSysEvent.QueryRule[] = [{ 421 domain: "RELIABILITY", 422 names: ["STACK"], 423 } as hiSysEvent.QueryRule]; 424 let querier: hiSysEvent.Querier = { 425 onQuery: (infos: hiSysEvent.SysEventInfo[]) => { 426 // do something here. 427 }, 428 onComplete: (reason: number, total: number) => { 429 // do something here. 430 } 431 }; 432 hiSysEvent.query(queryArg, queryRules, querier); 433} catch (err) { 434 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 435} 436``` 437 438## hiSysEvent.exportSysEvents<sup>10+</sup> 439 440exportSysEvents(queryArg: QueryArg, rules: QueryRule[]): number 441 442Exports system events in batches and writes them as a file to the fixed directory of the application sandbox (that is, **/data/storage/el2/base/cache/hiview/event/**). 443 444**Required permission**: ohos.permission.READ_DFX_SYSEVENT 445 446**System capability**: SystemCapability.HiviewDFX.HiSysEvent 447 448**Parameters** 449 450| Name | Type | Mandatory| Description | 451| -------- | ------------------------- | ---- | ------------------------------------------ | 452| queryArg | [QueryArg](#queryarg) | Yes | Event query parameters for the export. | 453| rules | [QueryRule](#queryrule)[] | Yes | Array of event query rules for the export.| 454 455**Return value** 456 457| Type | Description | 458| ------ | ---------------- | 459| number | API call timestamp.| 460 461**Error codes** 462 463For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 464 465| ID| Error Message| 466| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 467| 201 | Permission denied. An attempt was made to read system event forbidden by permission: ohos.permission.READ_DFX_SYSEVENT. | 468| 202 | System API is not allowed called by Non-system application. | 469| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 470| 11200301 | The number of query rules exceeds the limit. | 471| 11200302 | Invalid query rule. | 472| 11200304 | The query frequency exceeds the limit. | 473 474**Example** 475 476```ts 477import { fileIo } from '@kit.CoreFileKit'; 478import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 479import { BusinessError } from '@kit.BasicServicesKit'; 480 481try { 482 let customizedParams: Record<string, string | number> = { 483 'PID': 487, 484 'UID': 103, 485 'PACKAGE_NAME': "com.ohos.hisysevent.test", 486 'PROCESS_NAME': "syseventservice", 487 'MSG': "no msg." 488 }; 489 let eventInfo: hiSysEvent.SysEventInfo = { 490 domain: "RELIABILITY", 491 name: "STACK", 492 eventType: hiSysEvent.EventType.FAULT, 493 params: customizedParams 494 }; 495 hiSysEvent.write(eventInfo, (err: BusinessError) => { 496 // do something here. 497 }); 498 499 let queryArg: hiSysEvent.QueryArg = { 500 beginTime: -1, 501 endTime: -1, 502 maxEvents: 1, 503 }; 504 let queryRules: hiSysEvent.QueryRule[] = [{ 505 domain: "RELIABILITY", 506 names: ["STACK"], 507 } as hiSysEvent.QueryRule]; 508 let time = hiSysEvent.exportSysEvents(queryArg, queryRules); 509 console.log(`receive export task time is : ${time}`); 510 511 // Postpone reading of exported events. 512 setTimeout(() => { 513 let eventDir = '/data/storage/el2/base/cache/hiview/event'; 514 let filenames = fileIo.listFileSync(eventDir); 515 for (let i = 0; i < filenames.length; i++) { 516 if (filenames[i].indexOf(time.toString()) != -1) { 517 let res = fileIo.readTextSync(eventDir + '/' + filenames[i]); 518 let events: string = JSON.parse('[' + res.slice(0, res.length - 1) + ']'); 519 console.log("read file end, events is :" + JSON.stringify(events)); 520 } 521 } 522 }, 10000); 523} catch (err) { 524 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 525} 526``` 527 528## hiSysEvent.subscribe<sup>10+</sup> 529 530subscribe(rules: QueryRule[]): number 531 532Subscribes to real-time system events that occur occasionally or occur in a low frequency. These events are written as a file to the fixed directory of the application sandbox (that is, **/data/storage/el2/base/cache/hiview/event/**). 533 534**Required permission**: ohos.permission.READ_DFX_SYSEVENT 535 536**System capability**: SystemCapability.HiviewDFX.HiSysEvent 537 538**Parameters** 539 540| Name| Type | Mandatory| Description | 541| ------ | ------------------------- | ---- | ------------------------------------------ | 542| rules | [QueryRule](#queryrule)[] | Yes | Array of event query rules for the subscription.| 543 544**Return value** 545 546| Type | Description | 547| ------ | ---------------- | 548| number | API call timestamp.| 549 550**Error codes** 551 552For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 553 554| ID| Error Message| 555| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 556| 201 | Permission denied. An attempt was made to read system event forbidden by permission: ohos.permission.READ_DFX_SYSEVENT. | 557| 202 | System API is not allowed called by Non-system application. | 558| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 559| 11200301 | The number of query rules exceeds the limit. | 560| 11200302 | Invalid query rule. | 561 562**Example** 563 564```ts 565import { fileIo } from '@kit.CoreFileKit'; 566import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 567import { BusinessError } from '@kit.BasicServicesKit'; 568 569try { 570 let rules: hiSysEvent.QueryRule[] = [{ 571 domain: "RELIABILITY", 572 names: ["STACK"], 573 } as hiSysEvent.QueryRule, 574 { 575 domain: "BUNDLE_MANAGER", 576 names: ["BUNDLE_UNINSTALL"], 577 } as hiSysEvent.QueryRule]; 578 hiSysEvent.subscribe(rules); 579 580 let customizedParams: Record<string, string | number> = { 581 'PID': 487, 582 'UID': 103, 583 'PACKAGE_NAME': "com.ohos.hisysevent.test", 584 'PROCESS_NAME': "syseventservice", 585 'MSG': "no msg." 586 }; 587 let eventInfo: hiSysEvent.SysEventInfo = { 588 domain: "RELIABILITY", 589 name: "STACK", 590 eventType: hiSysEvent.EventType.FAULT, 591 params: customizedParams 592 }; 593 hiSysEvent.write(eventInfo, (err: BusinessError) => { 594 // do something here. 595 }); 596 597 // Postpone reading of subscribed events. 598 setTimeout(() => { 599 let eventDir = '/data/storage/el2/base/cache/hiview/event'; 600 let filenames = fileIo.listFileSync(eventDir); 601 for (let i = 0; i < filenames.length; i++) { 602 let res = fileIo.readTextSync(eventDir + '/' + filenames[i]); 603 let events: string = JSON.parse('[' + res.slice(0, res.length - 1) + ']'); 604 console.log("read file end, events is :" + JSON.stringify(events)); 605 } 606 }, 10000); 607} catch (err) { 608 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 609} 610``` 611 612## hiSysEvent.unsubscribe<sup>10+</sup> 613 614unsubscribe(): void 615 616Unsubscribes from system events. 617 618**Required permission**: ohos.permission.READ_DFX_SYSEVENT 619 620**System capability**: SystemCapability.HiviewDFX.HiSysEvent 621 622**Error codes** 623 624For details about the following error codes, see [HiSysEvent Error Codes](errorcode-hisysevent-sys.md). 625 626| ID| Error Message| 627| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | 628| 201 | Permission denied. An attempt was made to read system event forbidden by permission: ohos.permission.READ_DFX_SYSEVENT. | 629| 202 | System API is not allowed called by Non-system application. | 630| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 631| 11200305 | Failed to unsubscribe. | 632 633**Example** 634 635```ts 636import { hiSysEvent } from '@kit.PerformanceAnalysisKit'; 637import { BusinessError } from '@kit.BasicServicesKit'; 638 639try { 640 let rules: hiSysEvent.QueryRule[] = [{ 641 domain: "RELIABILITY", 642 names: ["STACK"], 643 } as hiSysEvent.QueryRule, 644 { 645 domain: "BUNDLE_MANAGER", 646 names: ["BUNDLE_UNINSTALL"], 647 } as hiSysEvent.QueryRule]; 648 hiSysEvent.subscribe(rules); 649 hiSysEvent.unsubscribe(); 650} catch (err) { 651 console.error(`error code: ${(err as BusinessError).code}, error msg: ${(err as BusinessError).message}`); 652} 653``` 654