1/* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit PerformanceAnalysisKit 19 */ 20 21import type { AsyncCallback } from './@ohos.base'; 22 23/** 24 * Provides the event logging function for applications to log the fault, statistical, security, 25 * and user behavior events reported during running. Based on event information, 26 * you will be able to analyze the running status of applications. 27 * 28 * @namespace hiAppEvent 29 * @syscap SystemCapability.HiviewDFX.HiAppEvent 30 * @since 9 31 */ 32/** 33 * Provides the event logging function for applications to log the fault, statistical, security, 34 * and user behavior events reported during running. Based on event information, 35 * you will be able to analyze the running status of applications. 36 * 37 * @namespace hiAppEvent 38 * @syscap SystemCapability.HiviewDFX.HiAppEvent 39 * @atomicservice 40 * @since 11 41 */ 42declare namespace hiAppEvent { 43 /** 44 * Enumerate application event types. 45 * 46 * @enum { number } 47 * @syscap SystemCapability.HiviewDFX.HiAppEvent 48 * @since 9 49 */ 50 /** 51 * Enumerate application event types. 52 * 53 * @enum { number } 54 * @syscap SystemCapability.HiviewDFX.HiAppEvent 55 * @atomicservice 56 * @since 11 57 */ 58 enum EventType { 59 /** 60 * Fault event. 61 * 62 * @syscap SystemCapability.HiviewDFX.HiAppEvent 63 * @since 9 64 */ 65 /** 66 * Fault event. 67 * 68 * @syscap SystemCapability.HiviewDFX.HiAppEvent 69 * @atomicservice 70 * @since 11 71 */ 72 FAULT = 1, 73 74 /** 75 * Statistic event. 76 * 77 * @syscap SystemCapability.HiviewDFX.HiAppEvent 78 * @since 9 79 */ 80 /** 81 * Statistic event. 82 * 83 * @syscap SystemCapability.HiviewDFX.HiAppEvent 84 * @atomicservice 85 * @since 11 86 */ 87 STATISTIC = 2, 88 89 /** 90 * Security event. 91 * 92 * @syscap SystemCapability.HiviewDFX.HiAppEvent 93 * @since 9 94 */ 95 /** 96 * Security event. 97 * 98 * @syscap SystemCapability.HiviewDFX.HiAppEvent 99 * @atomicservice 100 * @since 11 101 */ 102 SECURITY = 3, 103 104 /** 105 * User behavior event. 106 * 107 * @syscap SystemCapability.HiviewDFX.HiAppEvent 108 * @since 9 109 */ 110 /** 111 * User behavior event. 112 * 113 * @syscap SystemCapability.HiviewDFX.HiAppEvent 114 * @atomicservice 115 * @since 11 116 */ 117 BEHAVIOR = 4 118 } 119 120 /** 121 * Preset domain. 122 * 123 * @namespace domain 124 * @syscap SystemCapability.HiviewDFX.HiAppEvent 125 * @atomicservice 126 * @since 11 127 */ 128 namespace domain { 129 /** 130 * the domain of operating system. 131 * 132 * @constant 133 * @syscap SystemCapability.HiviewDFX.HiAppEvent 134 * @atomicservice 135 * @since 11 136 */ 137 const OS: string; 138 } 139 140 /** 141 * Preset event. 142 * 143 * @namespace event 144 * @syscap SystemCapability.HiviewDFX.HiAppEvent 145 * @since 9 146 */ 147 /** 148 * Preset event. 149 * 150 * @namespace event 151 * @syscap SystemCapability.HiviewDFX.HiAppEvent 152 * @atomicservice 153 * @since 11 154 */ 155 namespace event { 156 /** 157 * User login event. 158 * 159 * @constant 160 * @syscap SystemCapability.HiviewDFX.HiAppEvent 161 * @since 9 162 */ 163 /** 164 * User login event. 165 * 166 * @constant 167 * @syscap SystemCapability.HiviewDFX.HiAppEvent 168 * @atomicservice 169 * @since 11 170 */ 171 const USER_LOGIN: string; 172 173 /** 174 * User logout event. 175 * 176 * @constant 177 * @syscap SystemCapability.HiviewDFX.HiAppEvent 178 * @since 9 179 */ 180 /** 181 * User logout event. 182 * 183 * @constant 184 * @syscap SystemCapability.HiviewDFX.HiAppEvent 185 * @atomicservice 186 * @since 11 187 */ 188 const USER_LOGOUT: string; 189 190 /** 191 * Distributed service event. 192 * 193 * @constant 194 * @syscap SystemCapability.HiviewDFX.HiAppEvent 195 * @since 9 196 */ 197 /** 198 * Distributed service event. 199 * 200 * @constant 201 * @syscap SystemCapability.HiviewDFX.HiAppEvent 202 * @atomicservice 203 * @since 11 204 */ 205 const DISTRIBUTED_SERVICE_START: string; 206 207 /** 208 * crash event. 209 * 210 * @constant 211 * @syscap SystemCapability.HiviewDFX.HiAppEvent 212 * @atomicservice 213 * @since 11 214 */ 215 const APP_CRASH: string; 216 217 /** 218 * freeze event. 219 * 220 * @constant 221 * @syscap SystemCapability.HiviewDFX.HiAppEvent 222 * @atomicservice 223 * @since 11 224 */ 225 const APP_FREEZE: string; 226 227 /** 228 * launch event. 229 * 230 * @constant 231 * @syscap SystemCapability.HiviewDFX.HiAppEvent 232 * @atomicservice 233 * @since 12 234 */ 235 const APP_LAUNCH: string; 236 237 /** 238 * scroll jank event. 239 * 240 * @constant 241 * @syscap SystemCapability.HiviewDFX.HiAppEvent 242 * @atomicservice 243 * @since 12 244 */ 245 const SCROLL_JANK: string; 246 247 /** 248 * cpu usage high event. 249 * 250 * @constant 251 * @syscap SystemCapability.HiviewDFX.HiAppEvent 252 * @atomicservice 253 * @since 12 254 */ 255 const CPU_USAGE_HIGH: string; 256 257 /** 258 * battery usage event. 259 * 260 * @constant 261 * @syscap SystemCapability.HiviewDFX.HiAppEvent 262 * @atomicservice 263 * @since 12 264 */ 265 const BATTERY_USAGE: string; 266 267 /** 268 * resource overlimit event. 269 * 270 * @constant 271 * @syscap SystemCapability.HiviewDFX.HiAppEvent 272 * @atomicservice 273 * @since 12 274 */ 275 const RESOURCE_OVERLIMIT: string; 276 277 /** 278 * address sanitizer event. 279 * 280 * @constant 281 * @syscap SystemCapability.HiviewDFX.HiAppEvent 282 * @atomicservice 283 * @since 12 284 */ 285 const ADDRESS_SANITIZER: string; 286 287 /** 288 * main thread jank event. 289 * 290 * @constant 291 * @syscap SystemCapability.HiviewDFX.HiAppEvent 292 * @atomicservice 293 * @since 12 294 */ 295 const MAIN_THREAD_JANK: string; 296 } 297 298 /** 299 * Preset param. 300 * 301 * @namespace param 302 * @syscap SystemCapability.HiviewDFX.HiAppEvent 303 * @since 9 304 */ 305 /** 306 * Preset param. 307 * 308 * @namespace param 309 * @syscap SystemCapability.HiviewDFX.HiAppEvent 310 * @atomicservice 311 * @since 11 312 */ 313 namespace param { 314 /** 315 * User id. 316 * 317 * @constant 318 * @syscap SystemCapability.HiviewDFX.HiAppEvent 319 * @since 9 320 */ 321 /** 322 * User id. 323 * 324 * @constant 325 * @syscap SystemCapability.HiviewDFX.HiAppEvent 326 * @atomicservice 327 * @since 11 328 */ 329 const USER_ID: string; 330 331 /** 332 * Distributed service name. 333 * 334 * @constant 335 * @syscap SystemCapability.HiviewDFX.HiAppEvent 336 * @since 9 337 */ 338 /** 339 * Distributed service name. 340 * 341 * @constant 342 * @syscap SystemCapability.HiviewDFX.HiAppEvent 343 * @atomicservice 344 * @since 11 345 */ 346 const DISTRIBUTED_SERVICE_NAME: string; 347 348 /** 349 * Distributed service instance id. 350 * 351 * @constant 352 * @syscap SystemCapability.HiviewDFX.HiAppEvent 353 * @since 9 354 */ 355 /** 356 * Distributed service instance id. 357 * 358 * @constant 359 * @syscap SystemCapability.HiviewDFX.HiAppEvent 360 * @atomicservice 361 * @since 11 362 */ 363 const DISTRIBUTED_SERVICE_INSTANCE_ID: string; 364 } 365 366 /** 367 * Application event logging configuration interface. 368 * 369 * @param { ConfigOption } config Application event logging configuration item object. 370 * @throws { BusinessError } 401 - Parameter error. 371 * @throws { BusinessError } 11103001 - Invalid max storage quota value. 372 * @static 373 * @syscap SystemCapability.HiviewDFX.HiAppEvent 374 * @since 9 375 */ 376 /** 377 * Application event logging configuration interface. 378 * 379 * @param { ConfigOption } config Application event logging configuration item object. 380 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 381 * <br>2. Incorrect parameter types. 382 * @throws { BusinessError } 11103001 - Invalid max storage quota value. 383 * @static 384 * @syscap SystemCapability.HiviewDFX.HiAppEvent 385 * @atomicservice 386 * @since 11 387 */ 388 function configure(config: ConfigOption): void; 389 390 /** 391 * Describe the options for the configuration. 392 * 393 * @interface ConfigOption 394 * @syscap SystemCapability.HiviewDFX.HiAppEvent 395 * @since 9 396 */ 397 /** 398 * Describe the options for the configuration. 399 * 400 * @interface ConfigOption 401 * @syscap SystemCapability.HiviewDFX.HiAppEvent 402 * @atomicservice 403 * @since 11 404 */ 405 interface ConfigOption { 406 /** 407 * Configuration item: application event logging switch. 408 * 409 * @type { ?boolean } 410 * @syscap SystemCapability.HiviewDFX.HiAppEvent 411 * @since 9 412 */ 413 /** 414 * Configuration item: application event logging switch. 415 * 416 * @type { ?boolean } 417 * @syscap SystemCapability.HiviewDFX.HiAppEvent 418 * @atomicservice 419 * @since 11 420 */ 421 disable?: boolean; 422 423 /** 424 * Configuration item: event file directory storage quota size. 425 * 426 * @type { ?string } 427 * @syscap SystemCapability.HiviewDFX.HiAppEvent 428 * @since 9 429 */ 430 /** 431 * Configuration item: event file directory storage quota size. 432 * 433 * @type { ?string } 434 * @syscap SystemCapability.HiviewDFX.HiAppEvent 435 * @atomicservice 436 * @since 11 437 */ 438 maxStorage?: string; 439 } 440 441 /** 442 * Definition of written application event information. 443 * 444 * @interface AppEventInfo 445 * @syscap SystemCapability.HiviewDFX.HiAppEvent 446 * @since 9 447 */ 448 /** 449 * Definition of written application event information. 450 * 451 * @interface AppEventInfo 452 * @syscap SystemCapability.HiviewDFX.HiAppEvent 453 * @atomicservice 454 * @since 11 455 */ 456 interface AppEventInfo { 457 /** 458 * The domain of the event. 459 * 460 * @type { string } 461 * @syscap SystemCapability.HiviewDFX.HiAppEvent 462 * @since 9 463 */ 464 /** 465 * The domain of the event. 466 * 467 * @type { string } 468 * @syscap SystemCapability.HiviewDFX.HiAppEvent 469 * @atomicservice 470 * @since 11 471 */ 472 domain: string; 473 474 /** 475 * The name of the event. 476 * 477 * @type { string } 478 * @syscap SystemCapability.HiviewDFX.HiAppEvent 479 * @since 9 480 */ 481 /** 482 * The name of the event. 483 * 484 * @type { string } 485 * @syscap SystemCapability.HiviewDFX.HiAppEvent 486 * @atomicservice 487 * @since 11 488 */ 489 name: string; 490 491 /** 492 * The type of the event. 493 * 494 * @type { EventType } 495 * @syscap SystemCapability.HiviewDFX.HiAppEvent 496 * @since 9 497 */ 498 /** 499 * The type of the event. 500 * 501 * @type { EventType } 502 * @syscap SystemCapability.HiviewDFX.HiAppEvent 503 * @atomicservice 504 * @since 11 505 */ 506 eventType: EventType; 507 508 /** 509 * The params of the event. 510 * 511 * @type { object } 512 * @syscap SystemCapability.HiviewDFX.HiAppEvent 513 * @since 9 514 */ 515 /** 516 * The params of the event. 517 * 518 * @type { object } 519 * @syscap SystemCapability.HiviewDFX.HiAppEvent 520 * @atomicservice 521 * @since 11 522 */ 523 params: object; 524 } 525 526 /** 527 * Write application event. 528 * 529 * @param { AppEventInfo } info Application event information to be written. 530 * @returns { Promise<void> } Return Promise. 531 * @throws { BusinessError } 401 - Parameter error. 532 * @throws { BusinessError } 11100001 - Function disabled. 533 * @throws { BusinessError } 11101001 - Invalid event domain. 534 * @throws { BusinessError } 11101002 - Invalid event name. 535 * @throws { BusinessError } 11101003 - Invalid number of event parameters. 536 * @throws { BusinessError } 11101004 - Invalid string length of the event parameter. 537 * @throws { BusinessError } 11101005 - Invalid event parameter name. 538 * @throws { BusinessError } 11101006 - Invalid array length of the event parameter. 539 * @static 540 * @syscap SystemCapability.HiviewDFX.HiAppEvent 541 * @since 9 542 */ 543 /** 544 * Write application event. 545 * 546 * @param { AppEventInfo } info Application event information to be written. 547 * @returns { Promise<void> } Return Promise. 548 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 549 * <br>2. Incorrect parameter types. 550 * @throws { BusinessError } 11100001 - Function disabled. 551 * @throws { BusinessError } 11101001 - Invalid event domain. 552 * @throws { BusinessError } 11101002 - Invalid event name. 553 * @throws { BusinessError } 11101003 - Invalid number of event parameters. 554 * @throws { BusinessError } 11101004 - Invalid string length of the event parameter. 555 * @throws { BusinessError } 11101005 - Invalid event parameter name. 556 * @throws { BusinessError } 11101006 - Invalid array length of the event parameter. 557 * @static 558 * @syscap SystemCapability.HiviewDFX.HiAppEvent 559 * @atomicservice 560 * @since 11 561 */ 562 function write(info: AppEventInfo): Promise<void>; 563 564 /** 565 * Write application event. 566 * 567 * @param { AppEventInfo } info Application event information to be written. 568 * @param { AsyncCallback<void> } callback Callback function. 569 * @throws { BusinessError } 401 - Parameter error. 570 * @throws { BusinessError } 11100001 - Function disabled. 571 * @throws { BusinessError } 11101001 - Invalid event domain. 572 * @throws { BusinessError } 11101002 - Invalid event name. 573 * @throws { BusinessError } 11101003 - Invalid number of event parameters. 574 * @throws { BusinessError } 11101004 - Invalid string length of the event parameter. 575 * @throws { BusinessError } 11101005 - Invalid event parameter name. 576 * @throws { BusinessError } 11101006 - Invalid array length of the event parameter. 577 * @static 578 * @syscap SystemCapability.HiviewDFX.HiAppEvent 579 * @since 9 580 */ 581 /** 582 * Write application event. 583 * 584 * @param { AppEventInfo } info Application event information to be written. 585 * @param { AsyncCallback<void> } callback Callback function. 586 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 587 * <br>2. Incorrect parameter types. 588 * @throws { BusinessError } 11100001 - Function disabled. 589 * @throws { BusinessError } 11101001 - Invalid event domain. 590 * @throws { BusinessError } 11101002 - Invalid event name. 591 * @throws { BusinessError } 11101003 - Invalid number of event parameters. 592 * @throws { BusinessError } 11101004 - Invalid string length of the event parameter. 593 * @throws { BusinessError } 11101005 - Invalid event parameter name. 594 * @throws { BusinessError } 11101006 - Invalid array length of the event parameter. 595 * @static 596 * @syscap SystemCapability.HiviewDFX.HiAppEvent 597 * @atomicservice 598 * @since 11 599 */ 600 function write(info: AppEventInfo, callback: AsyncCallback<void>): void; 601 602 /** 603 * Indicates possible parameter types. 604 * 605 * @typedef {number | string | boolean | Array<string>} 606 * @syscap SystemCapability.HiviewDFX.HiAppEvent 607 * @atomicservice 608 * @since 12 609 */ 610 type ParamType = number | string | boolean | Array<string>; 611 612 /** 613 * It is used to set custom parameters for events, including both system-subscribed events and custom events. 614 * Existing parameter will be overwritten, and non-existing parameter will be created. 615 * 616 * @param { Record<string, ParamType> } params The parameters of the event. 617 * @param { string } domain The domain of the event. 618 * @param { string } name The name of the event. 619 * @returns { Promise<void> } Return Promise. 620 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 621 * <br>2. Incorrect parameter types. 622 * @throws { BusinessError } 11101007 - The number of parameter keys exceeds the limit. 623 * @static 624 * @syscap SystemCapability.HiviewDFX.HiAppEvent 625 * @atomicservice 626 * @since 12 627 */ 628 function setEventParam(params: Record<string, ParamType>, domain: string, name?: string): Promise<void>; 629 630 /** 631 * Definition of the read event package. 632 * 633 * @interface AppEventPackage 634 * @syscap SystemCapability.HiviewDFX.HiAppEvent 635 * @since 9 636 */ 637 /** 638 * Definition of the read event package. 639 * 640 * @interface AppEventPackage 641 * @syscap SystemCapability.HiviewDFX.HiAppEvent 642 * @atomicservice 643 * @since 11 644 */ 645 interface AppEventPackage { 646 /** 647 * The id of the package. 648 * 649 * @type { number } 650 * @syscap SystemCapability.HiviewDFX.HiAppEvent 651 * @since 9 652 */ 653 /** 654 * The id of the package. 655 * 656 * @type { number } 657 * @syscap SystemCapability.HiviewDFX.HiAppEvent 658 * @atomicservice 659 * @since 11 660 */ 661 packageId: number; 662 663 /** 664 * The number of events contained in the package. 665 * 666 * @type { number } 667 * @syscap SystemCapability.HiviewDFX.HiAppEvent 668 * @since 9 669 */ 670 /** 671 * The number of events contained in the package. 672 * 673 * @type { number } 674 * @syscap SystemCapability.HiviewDFX.HiAppEvent 675 * @atomicservice 676 * @since 11 677 */ 678 row: number; 679 680 /** 681 * The total size of events contained in the package. 682 * 683 * @type { number } 684 * @syscap SystemCapability.HiviewDFX.HiAppEvent 685 * @since 9 686 */ 687 /** 688 * The total size of events contained in the package. 689 * 690 * @type { number } 691 * @syscap SystemCapability.HiviewDFX.HiAppEvent 692 * @atomicservice 693 * @since 11 694 */ 695 size: number; 696 697 /** 698 * The events data contained in the package. 699 * 700 * @type { string[] } 701 * @syscap SystemCapability.HiviewDFX.HiAppEvent 702 * @since 9 703 */ 704 /** 705 * The events data contained in the package. 706 * 707 * @type { string[] } 708 * @syscap SystemCapability.HiviewDFX.HiAppEvent 709 * @atomicservice 710 * @since 11 711 */ 712 data: string[]; 713 714 /** 715 * The event json format data contained in the package. 716 * 717 * @type { Array<AppEventInfo> } 718 * @syscap SystemCapability.HiviewDFX.HiAppEvent 719 * @atomicservice 720 * @since 12 721 */ 722 appEventInfos: Array<AppEventInfo>; 723 } 724 725 /** 726 * Definition of event holder object, which is used to read the event data monitored by the watcher. 727 * 728 * @syscap SystemCapability.HiviewDFX.HiAppEvent 729 * @since 9 730 */ 731 /** 732 * Definition of event holder object, which is used to read the event data monitored by the watcher. 733 * 734 * @syscap SystemCapability.HiviewDFX.HiAppEvent 735 * @atomicservice 736 * @since 11 737 */ 738 class AppEventPackageHolder { 739 /** 740 * Constructor for AppEventPackageHolder. 741 * 742 * @param { string } watcherName Name of the watcher to read. 743 * @syscap SystemCapability.HiviewDFX.HiAppEvent 744 * @since 9 745 */ 746 /** 747 * Constructor for AppEventPackageHolder. 748 * 749 * @param { string } watcherName Name of the watcher to read. 750 * @syscap SystemCapability.HiviewDFX.HiAppEvent 751 * @atomicservice 752 * @since 11 753 */ 754 constructor(watcherName: string); 755 756 /** 757 * Set the threshold size per read. 758 * 759 * @param { number } size Threshold size. 760 * @throws { BusinessError } 401 - Parameter error. 761 * @throws { BusinessError } 11104001 - Invalid size value. 762 * @syscap SystemCapability.HiviewDFX.HiAppEvent 763 * @since 9 764 */ 765 /** 766 * Set the threshold size per read. 767 * 768 * @param { number } size Threshold size. 769 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 770 * <br>2. Incorrect parameter types. 771 * @throws { BusinessError } 11104001 - Invalid size value. 772 * @syscap SystemCapability.HiviewDFX.HiAppEvent 773 * @atomicservice 774 * @since 11 775 */ 776 setSize(size: number): void; 777 778 /** 779 * Set the number of rows per read. 780 * 781 * @param { number } size Row size. 782 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 783 * <br>2. Incorrect parameter types. 784 * @throws { BusinessError } 11104001 - Invalid size value. 785 * @syscap SystemCapability.HiviewDFX.HiAppEvent 786 * @atomicservice 787 * @since 12 788 */ 789 setRow(size: number): void; 790 791 /** 792 * Read the event data monitored by the watcher. 793 * 794 * @returns { AppEventPackage } The read event package. 795 * @syscap SystemCapability.HiviewDFX.HiAppEvent 796 * @since 9 797 */ 798 /** 799 * Read the event data monitored by the watcher. 800 * 801 * @returns { AppEventPackage } The read event package. 802 * @syscap SystemCapability.HiviewDFX.HiAppEvent 803 * @atomicservice 804 * @since 11 805 */ 806 takeNext(): AppEventPackage; 807 } 808 809 /** 810 * Definition of the condition for triggering callback when the watcher monitors event data. 811 * 812 * @interface TriggerCondition 813 * @syscap SystemCapability.HiviewDFX.HiAppEvent 814 * @since 9 815 */ 816 /** 817 * Definition of the condition for triggering callback when the watcher monitors event data. 818 * 819 * @interface TriggerCondition 820 * @syscap SystemCapability.HiviewDFX.HiAppEvent 821 * @atomicservice 822 * @since 11 823 */ 824 interface TriggerCondition { 825 /** 826 * The number of write events that trigger callback. 827 * 828 * @type { ?number } 829 * @syscap SystemCapability.HiviewDFX.HiAppEvent 830 * @since 9 831 */ 832 /** 833 * The number of write events that trigger callback. 834 * 835 * @type { ?number } 836 * @syscap SystemCapability.HiviewDFX.HiAppEvent 837 * @atomicservice 838 * @since 11 839 */ 840 row?: number; 841 842 /** 843 * The size of write events that trigger callback. 844 * 845 * @type { ?number } 846 * @syscap SystemCapability.HiviewDFX.HiAppEvent 847 * @since 9 848 */ 849 /** 850 * The size of write events that trigger callback. 851 * 852 * @type { ?number } 853 * @syscap SystemCapability.HiviewDFX.HiAppEvent 854 * @atomicservice 855 * @since 11 856 */ 857 size?: number; 858 859 /** 860 * The interval for triggering callback. 861 * 862 * @type { ?number } 863 * @syscap SystemCapability.HiviewDFX.HiAppEvent 864 * @since 9 865 */ 866 /** 867 * The interval for triggering callback. 868 * 869 * @type { ?number } 870 * @syscap SystemCapability.HiviewDFX.HiAppEvent 871 * @atomicservice 872 * @since 11 873 */ 874 timeOut?: number; 875 } 876 877 /** 878 * Definition of event filter object, which is used to filter events monitored by the watcher. 879 * 880 * @interface AppEventFilter 881 * @syscap SystemCapability.HiviewDFX.HiAppEvent 882 * @since 9 883 */ 884 /** 885 * Definition of event filter object, which is used to filter events monitored by the watcher. 886 * 887 * @interface AppEventFilter 888 * @syscap SystemCapability.HiviewDFX.HiAppEvent 889 * @atomicservice 890 * @since 11 891 */ 892 interface AppEventFilter { 893 /** 894 * The name of the event domain to be monitored by the watcher. 895 * 896 * @type { string } 897 * @syscap SystemCapability.HiviewDFX.HiAppEvent 898 * @since 9 899 */ 900 /** 901 * The name of the event domain to be monitored by the watcher. 902 * 903 * @type { string } 904 * @syscap SystemCapability.HiviewDFX.HiAppEvent 905 * @atomicservice 906 * @since 11 907 */ 908 domain: string; 909 910 /** 911 * The types of the events to be monitored by the watcher. 912 * 913 * @type { ?EventType[] } 914 * @syscap SystemCapability.HiviewDFX.HiAppEvent 915 * @since 9 916 */ 917 /** 918 * The types of the events to be monitored by the watcher. 919 * 920 * @type { ?EventType[] } 921 * @syscap SystemCapability.HiviewDFX.HiAppEvent 922 * @atomicservice 923 * @since 11 924 */ 925 eventTypes?: EventType[]; 926 927 /** 928 * The names of the events to be monitored by the watcher. 929 * 930 * @type { ?string[] } 931 * @syscap SystemCapability.HiviewDFX.HiAppEvent 932 * @atomicservice 933 * @since 11 934 */ 935 names?: string[]; 936 } 937 938 /** 939 * Definition of event group. 940 * 941 * @interface AppEventGroup 942 * @syscap SystemCapability.HiviewDFX.HiAppEvent 943 * @atomicservice 944 * @since 11 945 */ 946 interface AppEventGroup { 947 /** 948 * The name of the event. 949 * 950 * @type { string } 951 * @syscap SystemCapability.HiviewDFX.HiAppEvent 952 * @atomicservice 953 * @since 11 954 */ 955 name: string; 956 957 /** 958 * The event array which is group by the name. 959 * 960 * @type { Array<AppEventInfo> } 961 * @syscap SystemCapability.HiviewDFX.HiAppEvent 962 * @atomicservice 963 * @since 11 964 */ 965 appEventInfos: Array<AppEventInfo>; 966 } 967 968 /** 969 * Definition of event watcher object, which is used to monitor written event data. 970 * 971 * @interface Watcher 972 * @syscap SystemCapability.HiviewDFX.HiAppEvent 973 * @since 9 974 */ 975 /** 976 * Definition of event watcher object, which is used to monitor written event data. 977 * 978 * @interface Watcher 979 * @syscap SystemCapability.HiviewDFX.HiAppEvent 980 * @atomicservice 981 * @since 11 982 */ 983 interface Watcher { 984 /** 985 * The name of watcher. 986 * 987 * @type { string } 988 * @syscap SystemCapability.HiviewDFX.HiAppEvent 989 * @since 9 990 */ 991 /** 992 * The name of watcher. 993 * 994 * @type { string } 995 * @syscap SystemCapability.HiviewDFX.HiAppEvent 996 * @atomicservice 997 * @since 11 998 */ 999 name: string; 1000 1001 /** 1002 * The condition for triggering callback. 1003 * 1004 * @type { ?TriggerCondition } 1005 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1006 * @since 9 1007 */ 1008 /** 1009 * The condition for triggering callback. 1010 * 1011 * @type { ?TriggerCondition } 1012 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1013 * @atomicservice 1014 * @since 11 1015 */ 1016 triggerCondition?: TriggerCondition; 1017 1018 /** 1019 * The event filters for monitoring events. 1020 * 1021 * @type { ?AppEventFilter[] } 1022 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1023 * @since 9 1024 */ 1025 /** 1026 * The event filters for monitoring events. 1027 * 1028 * @type { ?AppEventFilter[] } 1029 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1030 * @atomicservice 1031 * @since 11 1032 */ 1033 appEventFilters?: AppEventFilter[]; 1034 1035 /** 1036 * The callback function of watcher. 1037 * 1038 * @type { ?function } 1039 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1040 * @since 9 1041 */ 1042 /** 1043 * The callback function of watcher. 1044 * 1045 * @type { ?function } 1046 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1047 * @atomicservice 1048 * @since 11 1049 */ 1050 onTrigger?: (curRow: number, curSize: number, holder: AppEventPackageHolder) => void; 1051 1052 /** 1053 * The callback function, when watcher receive the event. 1054 * 1055 * @type { ?function } 1056 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1057 * @atomicservice 1058 * @since 11 1059 */ 1060 onReceive?: (domain: string, appEventGroups: Array<AppEventGroup>) => void; 1061 } 1062 1063 /** 1064 * Add event watcher. 1065 * 1066 * @param { Watcher } watcher Watcher object for monitoring events. 1067 * @returns { AppEventPackageHolder } Holder object, which is used to read the monitoring data of the watcher. 1068 * @throws { BusinessError } 401 - Parameter error. 1069 * @throws { BusinessError } 11102001 - Invalid watcher name. 1070 * @throws { BusinessError } 11102002 - Invalid filtering event domain. 1071 * @throws { BusinessError } 11102003 - Invalid row value. 1072 * @throws { BusinessError } 11102004 - Invalid size value. 1073 * @throws { BusinessError } 11102005 - Invalid timeout value. 1074 * @static 1075 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1076 * @since 9 1077 */ 1078 /** 1079 * Add event watcher. 1080 * 1081 * @param { Watcher } watcher Watcher object for monitoring events. 1082 * @returns { AppEventPackageHolder } Holder object, which is used to read the monitoring data of the watcher. 1083 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1084 * <br>2. Incorrect parameter types. 1085 * @throws { BusinessError } 11102001 - Invalid watcher name. 1086 * @throws { BusinessError } 11102002 - Invalid filtering event domain. 1087 * @throws { BusinessError } 11102003 - Invalid row value. 1088 * @throws { BusinessError } 11102004 - Invalid size value. 1089 * @throws { BusinessError } 11102005 - Invalid timeout value. 1090 * @static 1091 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1092 * @atomicservice 1093 * @since 11 1094 */ 1095 function addWatcher(watcher: Watcher): AppEventPackageHolder; 1096 1097 /** 1098 * Remove event watcher. 1099 * 1100 * @param { Watcher } watcher Watcher object for monitoring events. 1101 * @throws { BusinessError } 401 - Parameter error. 1102 * @throws { BusinessError } 11102001 - Invalid watcher name. 1103 * @static 1104 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1105 * @since 9 1106 */ 1107 /** 1108 * Remove event watcher. 1109 * 1110 * @param { Watcher } watcher Watcher object for monitoring events. 1111 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1112 * <br>2. Incorrect parameter types. 1113 * @throws { BusinessError } 11102001 - Invalid watcher name. 1114 * @static 1115 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1116 * @atomicservice 1117 * @since 11 1118 */ 1119 function removeWatcher(watcher: Watcher): void; 1120 1121 /** 1122 * Clear all local logging data of the application. 1123 * 1124 * @static 1125 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1126 * @since 9 1127 */ 1128 /** 1129 * Clear all local logging data of the application. 1130 * 1131 * @static 1132 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1133 * @atomicservice 1134 * @since 11 1135 */ 1136 function clearData(): void; 1137 1138 /** 1139 * Set user ID. 1140 * 1141 * @param { string } name The key of the user ID. 1142 * @param { string } value The value of the user ID. 1143 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1144 * <br>2. Incorrect parameter types. 1145 * @static 1146 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1147 * @atomicservice 1148 * @since 11 1149 */ 1150 function setUserId(name: string, value: string): void; 1151 1152 /** 1153 * Get user ID. 1154 * 1155 * @param { string } name The key of the user ID. 1156 * @returns { string } the user ID value. 1157 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1158 * <br>2. Incorrect parameter types. 1159 * @static 1160 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1161 * @atomicservice 1162 * @since 11 1163 */ 1164 function getUserId(name: string): string; 1165 1166 /** 1167 * Set user property. 1168 * 1169 * @param { string } name The key of the user property. 1170 * @param { string } value The value of the user property. 1171 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1172 * <br>2. Incorrect parameter types. 1173 * @static 1174 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1175 * @atomicservice 1176 * @since 11 1177 */ 1178 function setUserProperty(name: string, value: string): void; 1179 1180 /** 1181 * Get user property. 1182 * 1183 * @param { string } name The key of the user property. 1184 * @returns { string } the user property value. 1185 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1186 * <br>2. Incorrect parameter types. 1187 * @static 1188 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1189 * @atomicservice 1190 * @since 11 1191 */ 1192 function getUserProperty(name: string): string; 1193 1194 /** 1195 * Describe the event config to be reported by processor. 1196 * 1197 * @interface AppEventReportConfig 1198 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1199 * @atomicservice 1200 * @since 11 1201 */ 1202 interface AppEventReportConfig { 1203 /** 1204 * The domain of the event. 1205 * 1206 * @type { ?string } 1207 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1208 * @atomicservice 1209 * @since 11 1210 */ 1211 domain?: string; 1212 1213 /** 1214 * The name of the event. 1215 * 1216 * @type { ?string } 1217 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1218 * @atomicservice 1219 * @since 11 1220 */ 1221 name?: string; 1222 1223 /** 1224 * The realtime report event. 1225 * 1226 * @type { ?boolean } 1227 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1228 * @atomicservice 1229 * @since 11 1230 */ 1231 isRealTime?: boolean; 1232 } 1233 1234 /** 1235 * Definition of the processor. 1236 * 1237 * @interface Processor 1238 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1239 * @atomicservice 1240 * @since 11 1241 */ 1242 interface Processor { 1243 /** 1244 * The name of the processor. 1245 * 1246 * @type { string } 1247 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1248 * @atomicservice 1249 * @since 11 1250 */ 1251 name: string; 1252 1253 /** 1254 * The processor enable the developer to debug. 1255 * 1256 * @type { ?boolean } 1257 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1258 * @atomicservice 1259 * @since 11 1260 */ 1261 debugMode?: boolean; 1262 1263 /** 1264 * The server location which used for the processor to receive the data, defined by the processor. 1265 * 1266 * @type { ?string } 1267 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1268 * @atomicservice 1269 * @since 11 1270 */ 1271 routeInfo?: string; 1272 1273 /** 1274 * The app ID is provided by the processor. 1275 * 1276 * @type { ?string } 1277 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1278 * @atomicservice 1279 * @since 11 1280 */ 1281 appId?: string; 1282 1283 /** 1284 * The processor report the event when start. 1285 * 1286 * @type { ?boolean } 1287 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1288 * @atomicservice 1289 * @since 11 1290 */ 1291 onStartReport?: boolean; 1292 1293 /** 1294 * The processor report the event when the application onBackground. 1295 * 1296 * @type { ?boolean } 1297 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1298 * @atomicservice 1299 * @since 11 1300 */ 1301 onBackgroundReport?: boolean; 1302 1303 /** 1304 * The processor report the event according to the period. 1305 * 1306 * @type { ?number } 1307 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1308 * @atomicservice 1309 * @since 11 1310 */ 1311 periodReport?: number; 1312 1313 /** 1314 * The processor report the event according to the batch size. 1315 * 1316 * @type { ?number } 1317 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1318 * @atomicservice 1319 * @since 11 1320 */ 1321 batchReport?: number; 1322 1323 /** 1324 * The user ID names which the processor can report. 1325 * 1326 * @type { ?string[] } 1327 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1328 * @atomicservice 1329 * @since 11 1330 */ 1331 userIds?: string[]; 1332 1333 /** 1334 * The user property names which the processor can report. 1335 * 1336 * @type { ?string[] } 1337 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1338 * @atomicservice 1339 * @since 11 1340 */ 1341 userProperties?: string[]; 1342 1343 /** 1344 * The events which the processor can report. 1345 * 1346 * @type { ?AppEventReportConfig[] } 1347 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1348 * @atomicservice 1349 * @since 11 1350 */ 1351 eventConfigs?: AppEventReportConfig[]; 1352 1353 /** 1354 * The processor config id. 1355 * 1356 * @type { ?number } 1357 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1358 * @atomicservice 1359 * @since 12 1360 */ 1361 configId?: number; 1362 1363 /** 1364 * The processor set custom config data. 1365 * 1366 * @type { ?Record<string, string> } 1367 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1368 * @atomicservice 1369 * @since 12 1370 */ 1371 customConfigs?: Record<string, string>; 1372 } 1373 1374 /** 1375 * Add the processor, who can report the event. 1376 * 1377 * @param { Processor } processor The instance which report the event 1378 * @returns { number } The processor unique ID. 1379 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1380 * <br>2. Incorrect parameter types. 1381 * @static 1382 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1383 * @atomicservice 1384 * @since 11 1385 */ 1386 function addProcessor(processor: Processor): number; 1387 1388 /** 1389 * Remove the processor. 1390 * 1391 * @param { number } id The processor unique ID. 1392 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1393 * <br>2. Incorrect parameter types. 1394 * @static 1395 * @syscap SystemCapability.HiviewDFX.HiAppEvent 1396 * @atomicservice 1397 * @since 11 1398 */ 1399 function removeProcessor(id: number): void; 1400} 1401 1402export default hiAppEvent; 1403