Plug-in Management
Overview
Basic Concepts
-
Introduction to begetctl
begetctl is a CLI-based management tool. For details about this functions, see Description of begetctl Commands.
-
bootchart plug-in
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. For details about this functions, see Description of begetctl Commands.
-
bootevent plug-in
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.
Constraints
bootchart and bootevent are available only for the standard system, and begetctl is available for both the small system and the standard system.
How to Develop
Parameters
Table 1 Description of begetctl commands
| Command | Description | Format and Example |
|---|---|---|
| init group test [stage] | Applies to init module test. | For details about stage, see ServiceStatus. |
| param ls [-r] [name] | Displays system parameters dac and selinux. -r: Displays information about all parameters. name: Displays information about specified parameters. |
begetctl param ls xxx.xxx or param ls xxx.xxx Example: begetctl param ls persist.sys.usb |
| param get [name] | Obtains system parameter values. | begetctl param get xxxx.xxx or param get xxxx.xxx Example: param get const.product.name |
| param set name value | Sets system parameter values. | begetctl param set xxxx.xxx value or param set xxxx.xxx value Example: begetctl param set ohos.servicectrl.display 1 |
| param wait name [value] [timeout] | Waits for the parameter to be set to a specific value. The default value of timeout is 30. |
begetctl param wait xxx.xxx value or wait xxx.xxx value Example: param wait xx.sss 1 |
| param dump [verbose] | Dumps system parameter information. | begetctl param dump or param dump |
| param shell [name] | Enters the parameter shell. | begetctl param shell or param shell |
| param save | Persistently stores all parameters marked with a persistency flag in the workspace. | begetctl param save or param save |
| dump api | Displays information about APIs of the init process. | begetctl dump api |
| getloglevel | Obtains the log level of the init process from persist.init.debug.loglevel. 0: debug 1: info 2: warning 3: err 4: fatal |
begetctl getloglevel |
| setloglevel level | Sets the log level to info. The log level ranges from 0 to 4. 0: debug 1: info 2: warning 3: err 4: fatal |
begetctl setloglevel 1 |
| timer_stop servicename | Stops a service timer. The value of servicename can contain a maximum of 96 characters. |
begetctl timer_stop servicename |
| timer_start servicename timeout | Starts the service timer. The value of servicename can contain a maximum of 96 characters. The default value of timeout is 10 ms. |
begetctl timer_start servicename |
| start_service servicename | Starts a service. | begetctl start_service servicename or start_service servicename |
| stop_service servicename | Stops a service. | begetctl stop_service servicename or stop_service servicename |
| service_control start servicename | Starts a service. | begetctl service_control start servicename or service_control start servicename |
| service_control stop servicename | Stops a service. | begetctl service_control stop servicename or service_control stop servicename |
| sandbox -b pid | Accesses the native application sandbox. | begetctl sandbox -b pid |
| sandbox -p process_name | Moves a process into the sandbox. | begetctl sandbox -p /bin/sh |
| sandbox -n sandbox_name | Moves a process into the configured system or chipset sandbox. | begetctl sandbox -n system |
| sandbox -s service_name | Moves a service into the sandbox. | begetctl sandbox -s service_name |
| sandbox -h | Displays the help information about the sandbox. | begetctl sandbox -h |
| modulectl uninstall moduleName | Uninstalls a dynamic plug-in. | begetctl modulectl uninstall moduleName Example: Uninstall the bootchart: begetctl modulectl uninstall bootchart |
| modulectl install moduleName | Installs a dynamic plug-in. | begetctl modulectl install moduleName Example: Install the bootchart: begetctl modulectl install bootchart |
| modulectl list | Obtains the list of dynamic plug-ins. | begetctl modulectl list |
| misc_daemon --write_logo xxx.rgb | Writes the startup logo. The maximum size of an RGB file is 1024*2038. Only Hi3516D V300 is supported. |
begetctl misc_daemon --write_logo logo.rgb or misc_daemon --write_logo logo.rgb |
| reboot | Restarts the system. | begetctl reboot or reboot |
| reboot shutdown[:options] | Shuts down the system. | begetctl reboot shutdown or reboot shutdown |
| reboot suspend | Suspends a system. | begetctl reboot suspend or reboot suspend |
| reboot updater | Restarts and enters updater. | begetctl reboot updater or reboot updater |
| reboot updater[:options] | Restarts and enters updater. | begetctl reboot updater or reboot updater |
| reboot flashd | Restarts and enters flashd. | begetctl reboot flashd or reboot flashd |
| reboot flashd[:options] | Restarts and enters flashd. | begetctl reboot flashd or reboot flashd |
| reboot charge | Restarts and enters charge. | begetctl reboot charge or reboot charge |
| reboot loader | Restarts and enters loader. | begetctl reboot loader or reboot loader |
| bootevent disable | Disables the bootevent plug-in. | begetctl bootevent disable |
| bootevent enable | Enables the bootevent plug-in. | begetctl bootevent enable |
| dump_service parameter_service trigger | Displays information about all triggers. | begetctl dump_service parameter_service trigger |
| dump_service all | Displays information about all services. | begetctl dump_service all |
| dump_service serviceName | Displays information about a service. | begetctl dump_service param_watcher |
| dump_service loop | Dumps fd information in the service loop. | begetctl dump_service loop |
| bootchart stop | Stops graphics analysis. Only RK3568 is supported. | begetctl bootchart stop |
| bootchart start | Starts graphics analysis. | begetctl bootchart start |
| bootchart disable | Disables graphics analysis. | begetctl bootchart disable |
| bootchart enable | Enables graphics analysis. | begetctl bootchart enable |
| dac uid username | Obtains the UID corresponding to the specified username. | begetctl dac uid username Example: begetctl dac uid root |
| dac gid groupname | Obtains the GID corresponding to the specified groupname and group members. | begetctl dac gid groupname Example: begetctl dac gid shell |
| get log level | Obtains the log level of the init process from persist.init.debug.loglevel. 0: debug 1: info 2: warning 3: err 4: fatal |
begetctl get log level |
| set log level | Set the log level to info. The log level ranges from 0 to 4. 0: debug 1: info 2: warning 3: err 4: fatal |
begetctl set log level 1 |
| appspawn_time | Obtains the maximum and minimum time for application spawning. | begetctl appspawn_time Example: begetctl appspawn_time |
| dump_nwebspawn | Dumps information about the nwebspawn application. | begetctl dump_nwebspawn Example: Opens Notepad. begetctl dump_nwebspawn |
| dump_appspawn | Dumps information about the appspawn application. | begetctl dump_appspawn Example: begetctl dump_appspawn |
typedef enum {
SERVICE_IDLE = 0, // service add
SERVICE_STARTING, // service start
SERVICE_STARTED, // 2 service ok running
SERVICE_READY, // 3 service ok running
SERVICE_STOPPING,
SERVICE_STOPPED, // 5
SERVICE_ERROR,
SERVICE_SUSPENDED,
SERVICE_FREEZED,
SERVICE_DISABLED,
SERVICE_CRITICAL
} ServiceStatus;
Development Procedure
Add a plug-in. The following uses bootchart as an example:
-
Install the .so file and define an independent file to implement the following functions:
static int bootchartEarlyHook(int stage, int prio, void *cookie) { char enable[4] = {}; // 4 enable size uint32_t size = sizeof(enable); SystemReadParam("persist.init.bootchart.enabled", enable, &size); if (strcmp(enable, "1") != 0) { PLUGIN_LOGI("bootchart disabled."); return 0; } InitModuleMgrInstall("libbootchart"); PLUGIN_LOGI("bootchart enabled."); return 0; } MODULE_CONSTRUCTOR(void) { // Depends on parameter service InitAddPostPersistParamLoadHook(0, bootchartEarlyHook); } -
Compile the static library libbootchart_static and add it to the static_modules group.
group("static_modules") { if (!defined(ohos_lite)) { deps = [ ":libbootchart_static" ] } } -
Initialize the bootchart plug-in.
static int BootchartInit(void) { if (g_executorId == -1) { g_executorId = AddCmdExecutor("bootchart", DoBootchartCmd); PLUGIN_LOGI("BootchartInit executorId %d", g_executorId); } return 0; } MODULE_CONSTRUCTOR(void) { PLUGIN_LOGI("DoBootchartStart now ..."); BootchartInit(); } -
Exit the bootchart plug-in.
MODULE_DESTRUCTOR(void) { PLUGIN_LOGI("DoBootchartStop now ..."); DoBootchartStop(); BootchartExit(); } -
Run the bootchart command.
static int DoBootchartCmd(int id, const char *name, int argc, const char **argv) { PLUGIN_LOGI("DoBootchartCmd argc %d %s", argc, name); ... return 0; }
Development Example
Bootchart
Prerequisites
-
Prepare the bootchart test environment. Specifically, install Python and pycairo by running pip install pycairo on Linux.
-
Decompress bootchart-master.tar.
tar -zxvf bootchart-master.tar
Procedure
- Start the system.
- Run the begetctl bootchart enable command.
- Restart the system.
- Run the begetctl bootchart stop command.
- Run the begetctl bootchart disable command.
- Export the following files from the /data/service/el0/startup/init/ directory and save them to the bootchart folder:
header
proc_diskstats.log
proc_ps.log
proc_stat.log - 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.
- Run the following command in the bootchart-master directory:
python3 pybootchartgui.py -f pdf bootchart.tgz
Expected Result
A bootchart.pdf file is generated in the bootchart-master directory.
bootevent
-
Configure one or more boot events in the .cfg file.
Configure a single boot event.
bootevents : "bootevent.xxxbootevent",Configure multiple boot events.
bootevents : ["bootevent.xxxbootevent1", "bootevent.xxxbootevent2.xxx"],
Note: The configured event must start with bootevent.
-
Send the boot events.
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:
SetParameter("bootevent.XXXbootevent1", "true"); -
Enable the bootevent function by running the begetctl bootevent enable command.
- To enable the bootevent function, run the begetctl bootevent enable command and restart the system.
- To disable the bootevent function, run the begetctl bootevent disable command and restart the system.
-
Use the exported bootevent file for trace analysis.
- The exported bootevent file is stored in the /data/service/el0/startup/init/ directory.
- It is named in the format of timestamp**.bootevent**.
- You can import the file to the trace analysis tool for visual analysis.