diff --git a/en/application-dev/reference/apis/js-apis-battery-info.md b/en/application-dev/reference/apis/js-apis-battery-info.md index a84c0cb9477cbdbbee02eba14c041fe18c7c8d29..9c0a816ef556a0d6bb80266e4a4a77730783c2a7 100644 --- a/en/application-dev/reference/apis/js-apis-battery-info.md +++ b/en/application-dev/reference/apis/js-apis-battery-info.md @@ -8,7 +8,7 @@ The Battery Info module provides APIs for querying the charger type, battery hea ## Modules to Import -``` +```js import batteryInfo from '@ohos.batteryInfo'; ``` @@ -126,7 +126,7 @@ Describes battery information. - Example - ``` + ```js import batteryInfo from '@ohos.batteryInfo'; var batterySoc = batteryInfo.batterySOC; ``` diff --git a/en/application-dev/reference/apis/js-apis-brightness.md b/en/application-dev/reference/apis/js-apis-brightness.md index c76047bde1b92f0e213a58091aafcf2a41d8793d..6bbea8b08a752972bcc9354b63841831ae837a88 100644 --- a/en/application-dev/reference/apis/js-apis-brightness.md +++ b/en/application-dev/reference/apis/js-apis-brightness.md @@ -8,7 +8,7 @@ The Brightness module provides an API for setting the screen brightness. ## Modules to Import -``` +```js import brightness from '@ohos.brightness'; ``` @@ -30,6 +30,6 @@ This is a system API and cannot be called by third-party applications. **Example** -``` +```js brightness.setValue(128); ``` diff --git a/en/application-dev/reference/apis/js-apis-power.md b/en/application-dev/reference/apis/js-apis-power.md index ca7e76cf6defcf233d399b4c0b5c9e5a8d588299..ad6e437f09767e362b2787f5ee78dd58d1a65165 100644 --- a/en/application-dev/reference/apis/js-apis-power.md +++ b/en/application-dev/reference/apis/js-apis-power.md @@ -8,7 +8,7 @@ The Power Manager module provides APIs for rebooting and shutting down the syste ## Modules to Import -``` +```js import power from '@ohos.power'; ``` @@ -35,7 +35,7 @@ This is a system API and cannot be called by third-party applications. **Example** -``` +```js power.shutdownDevice("shutdown_test"); console.info('power_shutdown_device_test success') ``` @@ -57,7 +57,7 @@ Reboots the system. **Example** -``` +```js power.rebootDevice("reboot_test"); console.info('power_reboot_device_test success') ``` @@ -77,7 +77,7 @@ Checks the screen status of the current device. **Example** -``` +```js power.isScreenOn((error, screenOn) => { if (typeof error === "undefined") { console.info('screenOn status is ' + screenOn); @@ -101,7 +101,7 @@ Checks the screen status of the current device. **Example** -``` +```js power.isScreenOn() .then(screenOn => { console.info('screenOn status is ' + screenOn); diff --git a/en/application-dev/reference/apis/js-apis-screen-lock.md b/en/application-dev/reference/apis/js-apis-screen-lock.md index 3c2bea19bafdba3fe50485852c8945a926b20932..fa0689478926d241372095e4dcb7dcb2e0177b15 100644 --- a/en/application-dev/reference/apis/js-apis-screen-lock.md +++ b/en/application-dev/reference/apis/js-apis-screen-lock.md @@ -8,7 +8,7 @@ ## Modules to Import -``` +```js import screenlock from '@ohos.screenLock'; ``` @@ -28,7 +28,7 @@ Checks whether the screen is locked. This method uses an asynchronous callback t - Example - ``` + ```js screenlock.isScreenLocked((err, data)=>{ if (err) { console.error('isScreenLocked callback error -> ${JSON.stringify(err)}'); @@ -54,7 +54,7 @@ Checks whether the screen is locked. This method uses a promise to return the re - Example - ``` + ```js screenlock.isScreenLocked().then((data) => { console.log('isScreenLocked success: data -> ${JSON.stringify(data)}'); }).catch((err) => { @@ -81,7 +81,7 @@ Checks whether a device is in secure mode. This method uses an asynchronous call - Example - ``` + ```js screenlock.isSecureMode((err, data)=>{ if (err) { console.error('isSecureMode callback error -> ${JSON.stringify(err)}'); @@ -107,7 +107,7 @@ Checks whether a device is in secure mode. This method uses a promise to return - Example - ``` + ```js screenlock.isSecureMode().then((data) => { console.log('isSecureMode success: data->${JSON.stringify(data)}'); }).catch((err) => { @@ -134,7 +134,7 @@ Unlocks the screen. This method uses an asynchronous callback to return the resu - Example - ``` + ```js screenlock.unlockScreen((err)=>{ if (err) { console.error('unlockScreen callback error -> ${JSON.stringify(err)}'); @@ -160,7 +160,7 @@ Unlocks the screen. This method uses a promise to return the result. - Example - ``` + ```js screenlock.unlockScreen().then(() => { console.log('unlockScreen success'); }).catch((err) => { diff --git a/en/application-dev/reference/apis/js-apis-system-battery.md b/en/application-dev/reference/apis/js-apis-system-battery.md index c65bc13c40412db14b9e0f624db9e37a18f1098e..596084f8483fad2e3c0971fdd6161a1062a23fcf 100644 --- a/en/application-dev/reference/apis/js-apis-system-battery.md +++ b/en/application-dev/reference/apis/js-apis-system-battery.md @@ -9,7 +9,7 @@ ## Modules to Import -``` +```js import battery from '@system.battery'; ``` @@ -39,7 +39,7 @@ The following value will be returned when the check result is obtained. **Example** -``` +```js export default { getStatus() { battery.getStatus({ diff --git a/en/application-dev/reference/apis/js-apis-system-brightness.md b/en/application-dev/reference/apis/js-apis-system-brightness.md index ce21ce2e7c13ac2b22e5ae026259d685b401c5e9..3b1731b865d28bab4708e8613e6969529ed21cb9 100644 --- a/en/application-dev/reference/apis/js-apis-system-brightness.md +++ b/en/application-dev/reference/apis/js-apis-system-brightness.md @@ -9,7 +9,7 @@ ## Modules to Import -``` +```js import brightness from '@system.brightness'; ``` @@ -38,7 +38,7 @@ The following values will be returned when the operation is successful. **Example** -``` +```js export default { getValue() { brightness.getValue({ @@ -73,7 +73,7 @@ Sets the screen brightness. **Example** -``` +```js export default { setValue() { brightness.setValue({ @@ -114,7 +114,7 @@ The following values will be returned when the operation is successful. **Example** -``` +```js export default { getMode() { brightness.getMode({ @@ -149,7 +149,7 @@ Sets the screen brightness adjustment mode. **Example** -``` +```js export default { setMode() { brightness.setMode({ @@ -185,7 +185,7 @@ Sets whether to always keep the screen on. Call this API in **onShow()**. **Example** -``` +```js export default { setKeepScreenOn() { brightness.setKeepScreenOn({ diff --git a/en/application-dev/reference/apis/js-apis-thermal.md b/en/application-dev/reference/apis/js-apis-thermal.md index f1b246f11ff17c4b2b31a1ca16210d5ce11c48bc..a71897b34211faccfe2254e77f89dc10ff644244 100644 --- a/en/application-dev/reference/apis/js-apis-thermal.md +++ b/en/application-dev/reference/apis/js-apis-thermal.md @@ -8,7 +8,7 @@ This module provides thermal level-related callback and query APIs to obtain the ## Modules to Import -``` +```js import thermal from '@ohos.thermal'; ``` @@ -46,7 +46,7 @@ Subscribes to thermal level changes. **Example** -``` +```js var lev = 0; thermal.subscribeThermalLevel((lev) => { console.info("Thermal level is: " + lev); @@ -69,7 +69,7 @@ Unsubscribes from thermal level changes. **Example** -``` +```js thermal.unsubscribeThermalLevel(() => { console.info("Unsubscribe completed."); }); @@ -91,7 +91,7 @@ Obtains the current thermal level. **Example** -``` +```js var lev = thermal.getThermalLevel(); console.info("Thermal level is: " + lev); ``` diff --git a/en/device-dev/subsystems/subsys-dfx-hichecker.md b/en/device-dev/subsystems/subsys-dfx-hichecker.md new file mode 100644 index 0000000000000000000000000000000000000000..afcb93bf9caac772e7afa714495ab6e72629c478 --- /dev/null +++ b/en/device-dev/subsystems/subsys-dfx-hichecker.md @@ -0,0 +1,110 @@ +# HiChecker Development + + +## Overview + +HiChecker is a framework provided by OpenHarmony for checking code errors and runtime results. It can be used for checking runtime errors during application and system development. This section applies only to the standard system. + + +## Development Guidelines + + +### Use Cases + +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 notice them and take correction measures. + + +### Available APIs + +HiChecker provides the APIs listed in the following table. + + **Table 1** HiChecker APIs + +| **API**| **Description**| +| -------- | -------- | +| uint_64_t RULE_CAUTION_PRINT_LOG
= 1<<63; | Defines an alarm rule, which is programmed to record a log when an alarm is generated.| +| uint_64_t RULE_CAUTION_TRIGGER_CRASH = 1<<62; | Defines an alarm rule, which is programmed to force the application to exit when an alarm is generated.| +| uint_64_t RULE_THREAD_CHECK_SLOW_PROCESS = 1; | Defines a check rule, which is programmed to check whether any time-consuming function is called.| +| uint_64_t RULE_CHECK_SLOW_EVENT = 1<<32; | Defines a check rule, which is programmed to check whether the event distribution or processing time has exceeded the specified time threshold.| +| uint_64_t RULE_CHECK_ABILITY_CONNECTION_LEAK = 1<<33; | Defines a check rule, which is programmed to check ability leakage.| +| AddRule(uint_64_t rule) : void | Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules.| +| RemoveRule(uint_64_t rule) : void | Removes one or more rules. The removed rules will no longer take effect.| +| GetRule() : uint_64_t | Obtains a collection of thread, process, and alarm rules that have been added.| +| Contains(uint_64_t rule) : bool | Checks whether the collection of added rules contains a specific rule. If a thread-level rule is specified, the system only checks whether it is contained in the current thread.| +| NotifySlowProcess(std::string tag) : void | Notifies your application of a slow process so that your application avoids calling it directly in key threads.| +| NotifySlowEvent(std::string tag) : void | Notifies your application that event distribution or execution has timed out.| +| NotifyAbilityConnectionLeak(Caution caution) : void | Notifies your application that AbilityConnection leakage has occurred.| +| GetTriggerRule() : uint_64_t | Obtains the rule that triggers the current alarm.| +| GetCautionMsg() : std::string | Obtains the alarm message.| +| GetStackTrace() : std::string | Obtains the stack when an alarm is triggered.| + + +### Development Example + +C++ + +1. Include the following HiChecker header file in the code file: + + ``` + #include "hichecker.h" + ``` + + For a non-DFX subsystem, add the **HiviewDFX** field. + + + ``` + using namespace OHOS::HiviewDFX; + ``` + + Use related APIs through static calls. + + + ``` + HiChecker::AddRule(Rule::RULE_THREAD_CHECK_SLOW_PROCESS); // Add a rule. + HiChecker::AddRule(Rule::RULE_CHECK_SLOW_EVENT | Rule::RULE_CAUTION_PRINT_LOG); // Add multiple rules. + HiChecker::Contains(Rule::RULE_CAUTION_PRINT_LOG); // true + HiChecker::GetRule(); //RULE_THREAD_CHECK_SLOW_PROCESS | RULE_CHECK_SLOW_EVENT | RULE_CAUTION_PRINT_LOG + ``` + + When a rule is triggered, an alarm is generated based on the rule, and a log is recorded by default. + + - RULE_CAUTION_PRINT_LOG + The log prints information such as the rule, thread ID, thread name, and stack that triggers the alarm. + + - RULE_CAUTION_TRIGGER_CRASH + The process exits directly, and the log prints the exit prompt and other auxiliary information. + + Usage of the **Notify** APIs: + + - NotifySlowProcess(std::string tag) + Notifies your application that a slow process has been called. The following is an example of the input arguments: + + + ``` + "threadId: xx,threadName:xx,actualTime:xx,delayTime:xx" + ``` + + - NotifySlowEvent(std::string tag) + Notifies your application that event distribution or execution has timed out. The following is an example of the input arguments: + + + ``` + "threadId: xx,threadName:xx,eventName:xx,actualTime:xx,delayTime:xx" + ``` + + - NotifyAbilityConnectionLeak(Caution caution) + Notifies your application that AbilityConnection leakage has occurred. The following example shows that a **Caution** instance is passed into this API. + + + ``` + Caution caution(Rule::RULE_CHECK_ABILITY_CONNECTION_LEAK , cautionMessage, stackTrace) + // cautionMessage is similar to other Notify APIs. + // stackTrace indicates the stack information when leakage occurs. + ``` + +2. Add the subsystem dependency to the **BUILD.gn** file that has imported the HiChecker module. + + ``` + include_dirs = [ "//base/hiviewdfx/interfaces/innerkits/libhichecker/include" ] + external_deps = [ "hichecker_native:libhichecker" ] + ``` diff --git a/en/device-dev/subsystems/subsys-dfx-hidumper.md b/en/device-dev/subsystems/subsys-dfx-hidumper.md new file mode 100644 index 0000000000000000000000000000000000000000..d647101d9117deb01b1e7389321aa6d81f75b314 --- /dev/null +++ b/en/device-dev/subsystems/subsys-dfx-hidumper.md @@ -0,0 +1,180 @@ +# HiDumper Development + + +## Overview + + +### Introduction + +HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool engineers to obtain system information necessary for analyzing and locating faults. This section applies only to the standard system. + +### Source Code Directories + + +``` +/base/hiviewdfx/hidumper +├── frameworks # Framework code +│ ├── native # Core function code +│ │ │── include # Header files +│ │ │── src # Source files +│ │ │── common # Common function code +│ │ │── executor # Process executor code +│ │ │── factory # Factory code +│ │ │── manager # Core manager code +│ │ │── util # Utility source code +│── sa_profile # HiDumper SA profile +│── services # HiDumper service code +│ │── native # C++ service code +│ │── zidl # Communication function +│ │ │── include # Header files of the communication function +│ │ │── src # Source code of the communication function +├── test # Test cases +│ ├── unittest # Unit test code +│ ├── moduletest # Module-level test code +``` + + +## Usage + + +### Command-Line Options + + **Table 1** HiDumper command-line options + +| Option| Description| +| -------- | -------- | +| -h | Shows the help Information.| +| -t [timeout] | Specifies the timeout period, in seconds. The default value is **30**. Value **0** indicates no timeout limit.| +| -lc | Shows the system information cluster list.| +| -ls | Shows the system ability list.| +| -c | Exports system cluster information.| +| -c [base system] | Exports system cluster information based on **base** or **system** tags.| +| -s | Exports all system ability information.| +| -s [SA0 SA1] | Exports ability information corresponding to SA0 and SA1.| +| -s [SA] -a ['-h'] | Exports the system ability information **SA** using the **-h** parameter.| +| -e | Exports crash logs generated by the FaultLogger module.| +| --net | Exports network information.| +| --storage | Exports storage information.| +| -p | Exports the process list and all process information.| +| -p [pid] | Exports all information about a specified process.| +| --cpuusage [pid] | Exports the CPU usage information based on **pid**.| +| --cpufreq | Exports the actual CPU frequency.| +| --mem [pid] | Exports the memory usage information based on **pid**.| +| --zip | Compresses the exported information to a specified folder.| + + +### Development Example + +HiDumper helps you export basic system information to locate and analyze faults. Complex parameters passed to sub-services and abilities must be enclosed in double quotation marks. + +The procedure is as follows: + +1. Access the device CLI, and run the **hidumper -h** command to obtain the help information, which includes basic information and function syntax. + + ``` + hidumper -h + ``` + +2. Run the **hidumper -lc** command to obtain the system information cluster list. + + ``` + hidumper -lc + ``` + +3. Run the **hidumper -c** command to obtain all information that is classified by **base** and **system**. + + ``` + hidumper -c + ``` + +4. Run the **hidumper -c [base | system]** to obtain the system cluster information that is classified by **base** or **system**. + + ``` + hidumper -c base + hidumper -c system + ``` + +5. Run the **hidumper -ls** command to obtain the system ability list. + + ``` + hidumper -ls + ``` + +6. Run the **hidumper -s** command to obtain all system ability information. + + ``` + hidumper -s + ``` + +7. Run the **hidumper -s 3301 -a "-h"** command to obtain the help information about the ability whose ID is **3301**. + + ``` + hidumper -s 3301 -a "-h" + ``` + +8. Run the **hidumper -s 3008** command to obtain all information about the ability whose ID is **3008**. + + ``` + hidumper -s 3008 + ``` + +9. Run the **hidumper -e** command to obtain the crash information generated by the FaultLogger module. + + ``` + hidumper -e + ``` + +10. Run the **hidumper --net** command to obtain network information. + + ``` + hidumper --net + ``` + +11. Run the **hidumper --storage** command to obtain storage information. + + ``` + hidumper --storage + ``` + +12. Run the **hidumper -p** command to obtain process information, including the list and information of processes and threads. + + ``` + hidumper -p + ``` + +13. Run the **hidumper -p 1024** command to obtain information about the process whose PID is **1024**. + + ``` + hidumper -p 1024 + ``` + +14. Run the **hidumper --cpuusage [pid]** command to obtain the CPU usage information of the process whose PID has been specified. + + ``` + hidumper --cpuusage + hidumper --cpuusage 1024 + ``` + +15. Run the **hidumper --cpufreq** command to obtain the actual operating frequency of each CPU core. + + ``` + hidumper --cpufreq + ``` + +16. Run the **hidumper --mem [pid]** command to obtain all memory usage information of the process whose PID has been specified. + + ``` + hidumper --mem [pid] + ``` + +17. Run the **hidumper --zip** command to compress data to the **/data/dumper** directory. + + ``` + hidumper --zip + ``` + +18. Run the **hidumper -t timeout** command to set the timeout period, in seconds. The default value is **30**. Value **0** indicates no timeout limit. + + ``` + hidumper -t [timeout] + ``` diff --git a/en/device-dev/subsystems/subsys-dfx-overview.md b/en/device-dev/subsystems/subsys-dfx-overview.md index 6f10a07749d9fea236f098555710eb29a857fbab..ad0ada15bbcde99d901ea4e8d914467cc95aa63d 100644 --- a/en/device-dev/subsystems/subsys-dfx-overview.md +++ b/en/device-dev/subsystems/subsys-dfx-overview.md @@ -4,11 +4,14 @@ The DFX subsystem provides the following functions: -- HiLog: implements the logging function. It is applicable to Mini-System Devices \(reference memory ≥ 128 KiB\), Small-System Devices \(reference memory ≥ 1 MiB\), and Standard-System Devices \(reference memory ≥ 128 MB\). +- HiLog: implements the logging function. It is applicable to mini-system devices \(reference memory ≥ 128 KiB\), small-system devices \(reference memory ≥ 1 MiB\), and standard-system devices \(reference memory ≥ 128 MB\). -- HiTrace: implements distributed call chain tracing. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\). -- HiCollie: implements thread suspension detection. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\). -- HiSysEvent: implements system event logging. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\). +- HiTrace: implements distributed call chain tracing. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\). +- HiCollie: implements thread suspension detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\). +- HiSysEvent: implements system event logging. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\). +- HiChecker: implements defect scanning. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\). +- HiDumper: exports system information. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\). +- FaultLogger: implements crash detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\). ## Basic Concepts @@ -31,4 +34,3 @@ Event logging means to collect and log events reported during system running. Th **System event** A system event is an indication of the system status at a given time point during system running. You can use these events to analyze the status change of the system. -