openharmony 鸿蒙 js-apis-hichecker

2025-06-12 浏览 (1)

@ohos.hichecker (HiChecker)

The HiChecker module allows you to check issues that may be easily ignored during development of 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

import { hichecker } from '@kit.PerformanceAnalysisKit';

Constants

Provides the constants of all rule types.

System capability: SystemCapability.HiviewDFX.HiChecker

NameTypeValueDescription
RULE_CAUTION_PRINT_LOGbigint1ULL << 63Alarm rule, which is programmed to print a log when an alarm is generated.
RULE_CAUTION_TRIGGER_CRASHbigint1ULL << 62Alarm rule, which is programmed to force the application to exit when an alarm is generated.
RULE_THREAD_CHECK_SLOW_PROCESSbigint1ULLCaution rule, which is programmed to detect whether any time-consuming function is invoked.
RULE_CHECK_ABILITY_CONNECTION_LEAKbigint1ULL << 33Caution rule, which is programmed to detect whether ability leakage has occurred.
RULE_CHECK_ARKUI_PERFORMANCE11+bigint1ULL << 34Caution rule, which is programmed to detect the ArkUI performance.

hichecker.addCheckRule9+

addCheckRule(rule: bigint): void

Adds one or more check rules. HiChecker detects unexpected operations or gives feedback based on the added rules. You can use grep HiChecker to check for the application running information in the hilog.

System capability: SystemCapability.HiviewDFX.HiChecker

Parameters

NameTypeMandatoryDescription
rulebigintYesRule to be added.

Error codes

IDError Message
401the parameter check failed, only one bigint type parameter is needed

Example

import { BusinessError } from '@kit.BasicServicesKit';

try {
    // Add a rule.
    hichecker.addCheckRule(hichecker.RULE_CAUTION_PRINT_LOG);
    // Add multiple rules.
    // hichecker.addCheckRule(
    //     hichecker.RULE_CAUTION_PRINT_LOG|hichecker.RULE_CAUTION_TRIGGER_CRASH);
} catch (err) {
    console.error(`code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`);
}

hichecker.removeCheckRule9+

removeCheckRule(rule: bigint): void

Removes one or more rules. The removed rules will become ineffective.

System capability: SystemCapability.HiviewDFX.HiChecker

Parameters

NameTypeMandatoryDescription
rulebigintYesRule to be removed.

Error codes

IDError Message
401the parameter check failed, only one bigint type parameter is needed

Example

import { BusinessError } from '@kit.BasicServicesKit';

try {
    // Remove a rule.
    hichecker.removeCheckRule(hichecker.RULE_CAUTION_PRINT_LOG);
    // Remove multiple rules.
    // hichecker.removeCheckRule(
    //     hichecker.RULE_CAUTION_PRINT_LOG|hichecker.RULE_CAUTION_TRIGGER_CRASH);
} catch (err) {
    console.error(`code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`);
}

hichecker.containsCheckRule9+

containsCheckRule(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

NameTypeMandatoryDescription
rulebigintYesRule to be checked.

Return value

TypeDescription
booleanCheck result. If the rule exists in the collection of added rules, true is returned; otherwise, false is returned.

Error codes

IDError Message
401the parameter check failed, only one bigint type parameter is needed

Example

import { BusinessError } from '@kit.BasicServicesKit';

try {
    // Add a rule.
    hichecker.addCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);

    // Check whether the added rule exists in the collection of added rules.
    hichecker.containsCheckRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // return true;
    hichecker.containsCheckRule(hichecker.RULE_CAUTION_PRINT_LOG); // return false;
} catch (err) {
    console.error(`code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`);
}

hichecker.addRule(deprecated)

addRule(rule: bigint): void

NOTE

This API is deprecated since API version 9. You are advised to use hichecker.addCheckRule.

Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules.

System capability: SystemCapability.HiviewDFX.HiChecker

Parameters

NameTypeMandatoryDescription
rulebigintYesRule to be added.

Example

// 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(deprecated)

removeRule(rule: bigint): void

NOTE

This API is deprecated since API version 9. You are advised to use hichecker.removeCheckRule.

Removes one or more rules. The removed rules will become ineffective.

System capability: SystemCapability.HiviewDFX.HiChecker

Parameters

NameTypeMandatoryDescription
rulebigintYesRule to be removed.

Example

// 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

TypeDescription
bigintCollection of added rules.

Example

// Add a rule.
hichecker.addCheckRule(hichecker.RULE_CAUTION_PRINT_LOG);

// Obtain the collection of added rules.
hichecker.getRule();   // return 1n;

hichecker.contains(deprecated)

contains(rule: bigint): boolean

NOTE

This API is deprecated since API version 9. You are advised to use hichecker.containsCheckRule.

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

NameTypeMandatoryDescription
rulebigintYesRule to be checked.

Return value

TypeDescription
booleanCheck result. If the rule exists in the collection of added rules, true is returned; otherwise, false is returned.

Example

// 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;

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Performance Analysis Kit

harmony 鸿蒙Performance Analysis Kit

harmony 鸿蒙HiAppEvent

harmony 鸿蒙HiAppEvent_AppEventGroup

harmony 鸿蒙HiAppEvent_AppEventInfo

harmony 鸿蒙HiCollie

harmony 鸿蒙HiCollie_DetectionParam

harmony 鸿蒙HiCollie_SetTimerParam

harmony 鸿蒙HiDebug

harmony 鸿蒙HiDebug_MemoryLimit

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/Qrgy6O