1# HiChecker 2 3HiChecker is provided for you to check issues that may be easily ignored during development of OpenHarmony applications (including system-built and third-party applications). Such issues include calling of time-consuming functions by key application threads, event distribution and execution timeout in application processes, and ability resource leakage in application processes. The issues are recorded in logs or lead to process crashes explicitly so that you can find and rectify them. 4 5> **NOTE**<br> 6> 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. 7 8 9## Modules to Import 10 11```js 12import hichecker from '@ohos.hichecker'; 13``` 14 15 16## Constant 17 18Provides the constants of all rule types. 19 20**System capability**: SystemCapability.HiviewDFX.HiChecker 21 22| Name | Type| Description | 23| ---------------------------------- | -------- | ------------------------------------------------------ | 24| RULE_CAUTION_PRINT_LOG | bigint | Alarm rule, which is programmed to print a log when an alarm is generated. | 25| RULE_CAUTION_TRIGGER_CRASH | bigint | Alarm rule, which is programmed to force the application to exit when an alarm is generated. | 26| RULE_THREAD_CHECK_SLOW_PROCESS | bigint | Caution rule, which is programmed to detect whether any time-consuming function is invoked. | 27| RULE_CHECK_ABILITY_CONNECTION_LEAK | bigint | Caution rule, which is programmed to detect whether ability leakage has occurred. | 28 29 30## hichecker.addRule 31 32addRule(rule: bigint): void 33 34Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules. 35 36**System capability**: SystemCapability.HiviewDFX.HiChecker 37 38**Parameters** 39 40| Name| Type | Mandatory| Description | 41| ------ | ------ | ---- | ---------------- | 42| rule | bigint | Yes | Rule to be added.| 43 44**Example** 45 46```js 47// Add a rule. 48hichecker.addRule(hichecker.RULE_CAUTION_PRINT_LOG); 49 50// Add multiple rules. 51hichecker.addRule( 52 hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH); 53``` 54 55## hichecker.removeRule 56 57removeRule(rule: bigint): void 58 59Removes one or more rules. The removed rules will become ineffective. 60 61**System capability**: SystemCapability.HiviewDFX.HiChecker 62 63**Parameters** 64 65| Name| Type | Mandatory| Description | 66| ------ | ------ | ---- | ---------------- | 67| rule | bigint | Yes | Rule to be removed.| 68 69**Example** 70 71```js 72// Remove a rule. 73hichecker.removeRule(hichecker.RULE_CAUTION_PRINT_LOG); 74 75// Remove multiple rules. 76hichecker.removeRule( 77 hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH); 78``` 79 80## hichecker.getRule 81 82getRule(): bigint 83 84Obtains a collection of thread, process, and alarm rules that have been added. 85 86**System capability**: SystemCapability.HiviewDFX.HiChecker 87 88**Return value** 89 90| Type | Description | 91| ------ | ---------------------- | 92| bigint | Collection of added rules.| 93 94**Example** 95 96```js 97// Add a rule. 98hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); 99 100// Obtain the collection of added rules. 101hichecker.getRule(); // return 1n; 102``` 103 104## hichecker.contains 105 106contains(rule: bigint): boolean 107 108Checks whether the specified rule exists in the collection of added rules. If the rule is of the thread level, this operation is performed only on the current thread. 109 110**System capability**: SystemCapability.HiviewDFX.HiChecker 111 112**Parameters** 113 114| Name| Type | Mandatory| Description | 115| ------ | ------ | ---- | ---------------- | 116| rule | bigint | Yes | Rule to be checked.| 117 118**Return value** 119 120| Type | Description | 121| ------- | ---------------------------------------------------------- | 122| boolean | Returns **true** if the rule exists in the collection of added rules; returns **false** otherwise.| 123 124**Example** 125 126```js 127// Add a rule. 128hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); 129 130// Check whether the added rule exists in the collection of added rules. 131hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // return true; 132hichecker.contains(hichecker.RULE_CAUTION_PRINT_LOG); // return false; 133``` 134