1e41f4b71Sopenharmony_ci# Plug-in Management 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ci### Basic Concepts 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci - Introduction to begetctl 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci begetctl is a CLI-based management tool. For details about this functions, see [Description of begetctl Commands](#table14737791480). 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci - bootchart plug-in 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci The bootchart plug-in is an open source tool used to evaluate system performance during Linux startup. It automatically collects information such as the CPU usage, disk throughput, and process status, and displays the evaluation result in graphics to facilitate system startup optimization. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci - bootevent plug-in 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci bootevent is a plug-in that records key startup events of the init process and each service. The recorded information includes the event name, startup time of the service associated with the event, and event occurrence time. By using the exported file for trace parsing, you can then optimize the system startup process. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### Constraints 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_cibootchart and bootevent are available only for the standard system, and begetctl is available for both the small system and the standard system. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci## How to Develop 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci### Parameters 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci **Table 1** Description of begetctl commands<a name="table14737791480"></a> 27e41f4b71Sopenharmony_ci| Command| Format and Example| Description| 28e41f4b71Sopenharmony_ci| :---------- | :---------- |:--------| 29e41f4b71Sopenharmony_ci| init group test [stage] | init group test | For details about **stage**, see **ServiceStatus**.| 30e41f4b71Sopenharmony_ci| param ls [-r] [name] | Displays system parameters.<br>Example:<br>begetctl param ls persist.sys.usb | N/A| 31e41f4b71Sopenharmony_ci| param get [name] | Obtains system parameter information.<br>Example:<br>begetctl param get or param get| N/A| 32e41f4b71Sopenharmony_ci| param set name value| Sets system parameters.<br>Example:<br>begetctl param set ohos.servicectrl.display 1 or param set ohos.servicectrl.display 1| N/A| 33e41f4b71Sopenharmony_ci| param wait name [value] [timeout] | Waits for system parameters.<br>Example:<br>begetctl param wait persist.sys.usb.config hdc or param wait persist.sys.usb.config hdc| The default value of **timeout** is **30**.| 34e41f4b71Sopenharmony_ci| param dump [verbose] | Dumps system parameter information.<br>Example:<br>begetctl param dump or param dump| N/A| 35e41f4b71Sopenharmony_ci| param shell [name] | Enters the parameter shell.<br>Example:<br>begetctl param shell or param shell| N/A| 36e41f4b71Sopenharmony_ci| timer_stop servicename | Stops the service timer.<br>Example:<br>begetctl timer_stop appspawn | The value of **servicename** can contain a maximum of 96 characters.| 37e41f4b71Sopenharmony_ci| timer_start servicename timeout | Starts the service timer.<br>Example:<br>begetctl timer_start appspawn | The value of **servicename** can contain a maximum of 96 characters. The default value of **timeout** is **10**. | 38e41f4b71Sopenharmony_ci| start_service servicename | Starts a service.<br>Example:<br>begetctl start_service appspawn or start_service appspawn| N/A| 39e41f4b71Sopenharmony_ci| stop_service servicename | Stops a service.<br>Example:<br>begetctl stop_service appspawn or stop_service appspawn| N/A| 40e41f4b71Sopenharmony_ci| service_control start servicename | Starts a service.<br>Example:<br>begetctl service_control start appspawn or service_control start appspawn| N/A| 41e41f4b71Sopenharmony_ci| service_control stop servicename | Stops a service.<br>Example:<br>begetctl service_control stop appspawn or service_control stop appspawn | N/A| 42e41f4b71Sopenharmony_ci| misc_daemon --write_logo xxx.rgb | Writes the startup logo.<br>Example:<br>begetctl misc_daemon --write_logo logo.rgb or misc_daemon --write_logo logo.rgb| The maximum size of an RGB file is **1024*2038**. Only Hi3516D V300 is supported.| 43e41f4b71Sopenharmony_ci| reboot | Restarts the system.<br>Example:<br>begetctl reboot or reboot|N/A| 44e41f4b71Sopenharmony_ci| reboot shutdown | Shuts down the system.<br>Example:<br>begetctl reboot shutdown or reboot shutdown|N/A| 45e41f4b71Sopenharmony_ci| reboot suspend | Suspends the system.<br>Example:<br>begetctl reboot suspend or reboot suspend| N/A| 46e41f4b71Sopenharmony_ci| reboot updater | Restarts the system and enters updater.<br>Example:<br>begetctl reboot updater or reboot updater| N/A| 47e41f4b71Sopenharmony_ci| reboot updater[:options] | Restarts the system and enters updater.<br>Example:<br>begetctl reboot updater or reboot updater| N/A| 48e41f4b71Sopenharmony_ci| reboot flashd | Restarts the system and enters flashd.<br>Example:<br>begetctl reboot flashd or reboot flashd| N/A| 49e41f4b71Sopenharmony_ci| reboot flashd[:options] | Restarts the system and enters flashd.<br>Example:<br>begetctl reboot flashd or reboot flashd| N/A| 50e41f4b71Sopenharmony_ci| reboot charge | Restarts the system and enters the charge mode.<br>Example:<br>begetctl reboot charge or reboot charge| N/A| 51e41f4b71Sopenharmony_ci| reboot loader | Restarts the system and enters the burning mode.<br>Example:<br>begetctl reboot loader or reboot loader| N/A| 52e41f4b71Sopenharmony_ci| bootchart stop | Stops chart analysis.<br>Example:<br>begetctl bootchart stop | Only rk3568 is supported.| 53e41f4b71Sopenharmony_ci| bootchart start | Starts chart analysis.<br>Example:<br>begetctl bootchart start | N/A| 54e41f4b71Sopenharmony_ci| bootchart disable | Disables chart analysis.<br>Example:<br>begetctl bootchart disable | N/A| 55e41f4b71Sopenharmony_ci| bootchart enable | Enables chart analysis.<br>Example:<br>begetctl bootchart enable | N/A| 56e41f4b71Sopenharmony_ci| sandbox -s service_name | Moves a service into the sandbox.<br>Example:<br>sandbox -s foundation | N/A| 57e41f4b71Sopenharmony_ci| sandbox -p process_name | Moves a process into the sandbox.<br>Example:<br>sandbox -p /bin/sh | N/A| 58e41f4b71Sopenharmony_ci| sandbox -n sandbox_name | Enters the configured system or chipset sandbox.<br>Example:<br>sandbox -n system | N/A| 59e41f4b71Sopenharmony_ci| sandbox -h | sandbox command help | N/A| 60e41f4b71Sopenharmony_ci| partitionslot getslot | Obtains the current active slot.<br>Example:<br>begetctl partitionslot getslot or partitionslot getslot| N/A| 61e41f4b71Sopenharmony_ci| partitionslot getsuffix slot | Obtains the current matching slot.<br>Example:<br>begetctl partitionslot getsuffix 1 or partitionslot getsuffix 1| N/A| 62e41f4b71Sopenharmony_ci| partitionslot setactive slot | Sets a partition slot as active.<br>Example:<br>begetctl partitionslot setactive 1 or partitionslot setactive 1| N/A| 63e41f4b71Sopenharmony_ci| partitionslot setunboot slot | Sets a partition slot as inactive.<br>Example:<br>begetctl partitionslot setunboot 1 or partitionslot setunboot 1| N/A| 64e41f4b71Sopenharmony_ci| modulectl uninstall moduleName | Uninstalls a dynamic plug-in.<br>Example:<br>modulectl uninstall bootchart | N/A| 65e41f4b71Sopenharmony_ci| modulectl install moduleName | Installs a dynamic plug-in.<br>Example:<br>modulectl install bootchart | N/A| 66e41f4b71Sopenharmony_ci| modulectl list | Views the list of dynamic plug-ins.<br>Example:<br>begetctl modulectl list | N/A| 67e41f4b71Sopenharmony_ci| setloglevel level | Sets the log level to **info**.<br>Example:<br>begetctl setloglevel 1 | The log level ranges from **0** to **4**.| 68e41f4b71Sopenharmony_ci| getloglevel | Obtains the log level of the init process.<br>Example:<br>begetctl getloglevel | N/A| 69e41f4b71Sopenharmony_ci| bootevent disable | Disables the bootevent plug-in.<br>Example:<br>begetctl bootevent disable| N/A| 70e41f4b71Sopenharmony_ci| bootevent enable | Enables the bootevent plug-in.<br>Example:<br>begetctl bootevent enable| N/A| 71e41f4b71Sopenharmony_ci| dump_service parameter_service trigger | Displays information about all triggers.<br>Example:<br>begetctl dump_service parameter_service trigger | N/A| 72e41f4b71Sopenharmony_ci| dump_service all | Displays information about all services.<br>Example:<br>begetctl dump_service all | N/A| 73e41f4b71Sopenharmony_ci| dump_service serviceName | Displays information about a single service.<br>Example:<br>begetctl dump_service param_watcher | N/A| 74e41f4b71Sopenharmony_ci| dump api | Displays information about APIs of the init process.<br>Example:<br>begetctl dump api | N/A| 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci### How to Develop 78e41f4b71Sopenharmony_ci Add a plug-in. The following uses bootchart as an example: 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci1. Install the **.so** file and define an independent file to implement the following functions: 81e41f4b71Sopenharmony_ci ```c 82e41f4b71Sopenharmony_ci static int bootchartEarlyHook(int stage, int prio, void *cookie) 83e41f4b71Sopenharmony_ci { 84e41f4b71Sopenharmony_ci char enable[4] = {}; // 4 enable size 85e41f4b71Sopenharmony_ci uint32_t size = sizeof(enable); 86e41f4b71Sopenharmony_ci SystemReadParam("persist.init.bootchart.enabled", enable, &size); 87e41f4b71Sopenharmony_ci if (strcmp(enable, "1") != 0) { 88e41f4b71Sopenharmony_ci PLUGIN_LOGI("bootchart disabled."); 89e41f4b71Sopenharmony_ci return 0; 90e41f4b71Sopenharmony_ci } 91e41f4b71Sopenharmony_ci InitModuleMgrInstall("libbootchart"); 92e41f4b71Sopenharmony_ci PLUGIN_LOGI("bootchart enabled."); 93e41f4b71Sopenharmony_ci return 0; 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci MODULE_CONSTRUCTOR(void) 97e41f4b71Sopenharmony_ci { 98e41f4b71Sopenharmony_ci // Depends on parameter service 99e41f4b71Sopenharmony_ci InitAddPostPersistParamLoadHook(0, bootchartEarlyHook); 100e41f4b71Sopenharmony_ci } 101e41f4b71Sopenharmony_ci ``` 102e41f4b71Sopenharmony_ci2. Compile the static library **libbootchart\_static** and add it to the **static\_modules** group. 103e41f4b71Sopenharmony_ci ``` 104e41f4b71Sopenharmony_ci group("static_modules") { 105e41f4b71Sopenharmony_ci if (!defined(ohos_lite)) { 106e41f4b71Sopenharmony_ci deps = [ ":libbootchart_static" ] 107e41f4b71Sopenharmony_ci } 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci ``` 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci3. Initialize the bootchart plug-in. 112e41f4b71Sopenharmony_ci ```c 113e41f4b71Sopenharmony_ci static int BootchartInit(void) 114e41f4b71Sopenharmony_ci { 115e41f4b71Sopenharmony_ci if (g_executorId == -1) { 116e41f4b71Sopenharmony_ci g_executorId = AddCmdExecutor("bootchart", DoBootchartCmd); 117e41f4b71Sopenharmony_ci PLUGIN_LOGI("BootchartInit executorId %d", g_executorId); 118e41f4b71Sopenharmony_ci } 119e41f4b71Sopenharmony_ci return 0; 120e41f4b71Sopenharmony_ci } 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci MODULE_CONSTRUCTOR(void) 123e41f4b71Sopenharmony_ci { 124e41f4b71Sopenharmony_ci PLUGIN_LOGI("DoBootchartStart now ..."); 125e41f4b71Sopenharmony_ci BootchartInit(); 126e41f4b71Sopenharmony_ci } 127e41f4b71Sopenharmony_ci ``` 128e41f4b71Sopenharmony_ci4. Exit the bootchart plug-in. 129e41f4b71Sopenharmony_ci ```c 130e41f4b71Sopenharmony_ci MODULE_DESTRUCTOR(void) 131e41f4b71Sopenharmony_ci { 132e41f4b71Sopenharmony_ci PLUGIN_LOGI("DoBootchartStop now ..."); 133e41f4b71Sopenharmony_ci DoBootchartStop(); 134e41f4b71Sopenharmony_ci BootchartExit(); 135e41f4b71Sopenharmony_ci } 136e41f4b71Sopenharmony_ci ``` 137e41f4b71Sopenharmony_ci5. Run the bootchart command. 138e41f4b71Sopenharmony_ci ```c 139e41f4b71Sopenharmony_ci static int DoBootchartCmd(int id, const char *name, int argc, const char **argv) 140e41f4b71Sopenharmony_ci { 141e41f4b71Sopenharmony_ci PLUGIN_LOGI("DoBootchartCmd argc %d %s", argc, name); 142e41f4b71Sopenharmony_ci ... 143e41f4b71Sopenharmony_ci return 0; 144e41f4b71Sopenharmony_ci } 145e41f4b71Sopenharmony_ci ``` 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci### Development Example 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci#### Bootchart 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci Prerequisites 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci 1. Prepare the bootchart test environment. Specifically, install Python and pycairo by running **pip install pycairo** on Linux. 154e41f4b71Sopenharmony_ci 2. Decompress **bootchart-master.tar**. 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci tar -zxvf bootchart-master.tar 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci Procedure 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci 1. Start the system. 161e41f4b71Sopenharmony_ci 2. Run the **begetctl bootchart enable** command. 162e41f4b71Sopenharmony_ci 3. Restart the system. 163e41f4b71Sopenharmony_ci 4. Run the **begetctl bootchart stop** command. 164e41f4b71Sopenharmony_ci 5. Run the **begetctl bootchart disable** command. 165e41f4b71Sopenharmony_ci 6. Export the following files from the **/data/service/el0/startup/init/** directory and save them to the **bootchart** folder:<br> 166e41f4b71Sopenharmony_ci header<br> 167e41f4b71Sopenharmony_ci proc_diskstats.log<br> 168e41f4b71Sopenharmony_ci proc_ps.log<br> 169e41f4b71Sopenharmony_ci proc_stat.log<br> 170e41f4b71Sopenharmony_ci 7. Run the **tar -zcvf bootchart.tgz *** command to compress the **bootchart.tgz** file (available only for Linux) and copy the compressed file to the **linux:bootchart-master** directory. 171e41f4b71Sopenharmony_ci 8. Run the following command in the **bootchart-master** directory: 172e41f4b71Sopenharmony_ci ``` 173e41f4b71Sopenharmony_ci python3 pybootchartgui.py -f pdf bootchart.tgz 174e41f4b71Sopenharmony_ci ``` 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci Expected result: 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci A **bootchart.pdf** file is generated in the **bootchart-master** directory. 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci#### bootevent 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci1. Configure one or more boot events in the **.cfg** file. 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci Configure a single boot event. 185e41f4b71Sopenharmony_ci ```json 186e41f4b71Sopenharmony_ci bootevents : "bootevent.xxxbootevent", 187e41f4b71Sopenharmony_ci ``` 188e41f4b71Sopenharmony_ci Configure multiple boot events. 189e41f4b71Sopenharmony_ci ```json 190e41f4b71Sopenharmony_ci bootevents : ["bootevent.xxxbootevent1", "bootevent.xxxbootevent2.xxx"], 191e41f4b71Sopenharmony_ci ``` 192e41f4b71Sopenharmony_ci> **NOTE** 193e41f4b71Sopenharmony_ci> 194e41f4b71Sopenharmony_ci> The configured event must start with **bootevent**. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci2. Send the boot events. 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci Call the **SetParameter** API provided by init process to send the boot events. For example, to send the XXXbootevent1 event configured in the previous step, use the following code: 199e41f4b71Sopenharmony_ci ```c 200e41f4b71Sopenharmony_ci SetParameter("bootevent.XXXbootevent1", "true"); 201e41f4b71Sopenharmony_ci ``` 202e41f4b71Sopenharmony_ci3. Enable the bootevent function by running the **begetctl bootevent enable** command. 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci To disable the bootevent function, run the **begetctl bootevent disable** command and restart the system. 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci4. Use the exported bootevent file for trace analysis. 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci - The exported bootevent file is stored in the **/data/service/el0/startup/init/** directory. 209e41f4b71Sopenharmony_ci - It is named in the format of *timestamp***.bootevent**. 210e41f4b71Sopenharmony_ci - You can import the file to the trace analysis tool for visual analysis. 211