# HiChecker HiChecker 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. > **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. ## Modules to Import ```js import hichecker from '@ohos.hichecker'; ``` ## Constant Provides the constants of all rule types. **System capability**: SystemCapability.HiviewDFX.HiChecker | Name | Type| Description | | ---------------------------------- | -------- | ------------------------------------------------------ | | RULE_CAUTION_PRINT_LOG | bigInt | Alarm rule, which is programmed to print a log when an alarm is generated. | | RULE_CAUTION_TRIGGER_CRASH | bigInt | Alarm rule, which is programmed to force the application to exit when an alarm is generated. | | RULE_THREAD_CHECK_SLOW_PROCESS | bigInt | Caution rule, which is programmed to detect whether any time-consuming function is invoked. | | RULE_CHECK_ABILITY_CONNECTION_LEAK | bigInt | Caution rule, which is programmed to detect whether ability leakage has occurred. | ## hichecker.addRule addRule(rule: bigInt): void Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules. **System capability**: SystemCapability.HiviewDFX.HiChecker **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ---------------- | | rule | bigInt | Yes | Rule to be added.| **Example** ```js // Add a rule. hichecker.addRule(hichecker.RULE_CAUTION_PRINT_LOG); // Add multiple rules. hichecker.addRule( hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH); ``` ## hichecker.removeRule removeRule(rule: bigInt): void Removes one or more rules. The removed rules will become ineffective. **System capability**: SystemCapability.HiviewDFX.HiChecker **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ---------------- | | rule | bigInt | Yes | Rule to be removed.| **Example** ```js // Remove a rule. hichecker.removeRule(hichecker.RULE_CAUTION_PRINT_LOG); // Remove multiple rules. hichecker.removeRule( hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH); ``` ## hichecker.getRule getRule(): bigInt Obtains a collection of thread, process, and alarm rules that have been added. **System capability**: SystemCapability.HiviewDFX.HiChecker **Return value** | Type | Description | | ------ | ---------------------- | | bigInt | Collection of added rules.| **Example** ```js // Add a rule. hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // Obtain the collection of added rules. hichecker.getRule(); // return 1n; ``` ## hichecker.contains contains(rule: bigInt): boolean Checks 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. **System capability**: SystemCapability.HiviewDFX.HiChecker **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ---------------- | | rule | bigInt | Yes | Rule to be checked.| **Return value** | Type | Description | | ------- | ---------------------------------------------------------- | | boolean | Returns **true** if the rule exists in the collection of added rules; returns **false** otherwise.| **Example** ```js // Add a rule. hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // Check whether the added rule exists in the collection of added rules. hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // return true; hichecker.contains(hichecker.RULE_CAUTION_PRINT_LOG); // return false; ```