• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Plug-in Management
2
3## Overview
4### Basic Concepts
5 - Introduction to begetctl
6
7   begetctl is a CLI-based management tool. For details about this functions, see [Description of begetctl Commands](#table14737791480).
8 - bootchart plug-in
9
10   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](#table14737791480).
11 - bootevent plug-in
12
13   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.
14
15### Constraints
16
17bootchart and bootevent are available only for the standard system, and begetctl is available for both the small system and the standard system.
18
19## How to Develop
20### Parameters
21 **Table 1** Description of begetctl commands<a name="table14737791480"></a>
22| Command| Description| Format and Example|
23| :----------  |  :----------  |:-------------- |
24| init group test [stage] | Applies to init module test.| For details about **stage**, see [ServiceStatus](#section001).|
25| param ls [-r] [name] | Displays system parameters **dac** and **selinux**.<br> -r: Displays information about all parameters.<br> name: Displays information about specified parameters.| begetctl param ls xxx.xxx or<br>param ls xxx.xxx<br>Example:<br>begetctl param ls persist.sys.usb |
26| param get [name] | Obtains system parameter values.| begetctl param get xxxx.xxx or<br>param get xxxx.xxx<br>Example:<br>param get const.product.name|
27| param set name value| Sets system parameter values.|begetctl param set xxxx.xxx value or<br> param set xxxx.xxx value <br>Example:<br>begetctl param set ohos.servicectrl.display 1 |
28| param wait name [value] [timeout] | Waits for the parameter to be set to a specific value.<br> The default value of **timeout** is **30**.| begetctl param wait xxx.xxx value or<br> wait xxx.xxx value <br>Example:<br>param wait xx.sss 1 |
29| param dump [verbose] | Dumps system parameter information.|begetctl param dump <br>or param dump|
30| param shell [name] | Enters the parameter shell.|begetctl param shell <br>or param shell|
31| param save | Persistently stores all parameters marked with a persistency flag in the workspace.|begetctl param save <br>or param save|
32| dump api | Displays information about APIs of the init process.|begetctl dump api |
33| getloglevel | Obtains the log level of the init process from<br>**persist.init.debug.loglevel**.<br>0: debug<br> 1: info<br> 2: warning<br> 3: err<br> 4: fatal|begetctl getloglevel |
34| setloglevel level | Sets the log level to **info**.<br>The log level ranges from **0** to **4**.<br> 0: debug<br>1: info<br> 2: warning<br> 3: err<br>4: fatal|begetctl setloglevel 1 |
35| timer_stop servicename | Stops a service timer.<br>The value of **servicename** can contain a maximum of 96 characters.|begetctl timer_stop servicename | begetctl timer_stop appspawn |
36| timer_start servicename timeout | Starts the service timer.<br>The value of **servicename** can contain a maximum of 96 characters.<br>The default value of **timeout** is 10 ms.|begetctl timer_start servicename | begetctl timer_start appspawn|
37| start_service servicename | Starts a service.| begetctl start_service servicename or<br>start_service servicename|begetctl start_service appspawn |
38| stop_service servicename | Stops a service.|begetctl stop_service servicename or<br> stop_service servicename|begetctl stop_service appspawn |
39| service_control start servicename | Starts a service.|begetctl service_control start servicename or<br> service_control start servicename|begetctl service_control start appspawn |
40| service_control stop servicename | Stops a service.|begetctl service_control stop servicename or<br> service_control stop servicename|begetctl service_control stop appspawn |
41| sandbox -b pid | Accesses the native application sandbox.| begetctl sandbox -b pid|
42| sandbox -p process_name | Moves a process into the sandbox.| begetctl sandbox -p /bin/sh |
43| sandbox -n sandbox_name | Moves a process into the configured **system** or **chipset** sandbox.| begetctl sandbox -n system|
44| sandbox -s service_name | Moves a service into the sandbox.| begetctl sandbox -s service_name |
45| sandbox -h | Displays the help information about the sandbox.| begetctl sandbox -h |
46| modulectl uninstall moduleName | Uninstalls a dynamic plug-in.| begetctl modulectl uninstall moduleName <br>Example:<br>Uninstall the bootchart:<br> begetctl modulectl uninstall bootchart |
47| modulectl install moduleName | Installs a dynamic plug-in.|begetctl modulectl install moduleName <br>Example:<br>Install the bootchart:<br>begetctl modulectl install bootchart |
48| modulectl list | Obtains the list of dynamic plug-ins.|begetctl modulectl list |
49| misc_daemon --write_logo xxx.rgb | Writes the startup logo.<br>The maximum size of an RGB file is **1024*2038**. Only Hi3516D V300 is supported.|begetctl misc_daemon --write_logo logo.rgb or<br> misc_daemon --write_logo logo.rgb|
50| reboot | Restarts the system.|begetctl reboot or<br> reboot|
51| reboot shutdown[:options] | Shuts down the system.|begetctl reboot shutdown or<br> reboot shutdown |
52| reboot suspend | Suspends a system.|begetctl reboot suspend or<br> reboot suspend |
53| reboot updater | Restarts and enters updater.|begetctl reboot updater or<br> reboot updater |
54| reboot updater[:options] | Restarts and enters updater.|begetctl reboot updater or<br> reboot updater |
55| reboot flashd | Restarts and enters flashd.|begetctl reboot flashd or<br> reboot flashd |
56| reboot flashd[:options] | Restarts and enters flashd.|begetctl reboot flashd or<br> reboot flashd |
57| reboot charge | Restarts and enters charge.|begetctl reboot charge or<br> reboot charge |
58| reboot loader | Restarts and enters loader.|begetctl reboot loader or<br> reboot loader |
59| bootevent disable | Disables the bootevent plug-in.|begetctl bootevent disable |
60| bootevent enable | Enables the bootevent plug-in.|begetctl bootevent enable |
61| dump_service parameter_service trigger | Displays information about all triggers.|begetctl dump_service parameter_service trigger |
62| dump_service all | Displays information about all services.|begetctl dump_service all |
63| dump_service serviceName | Displays information about a service.|begetctl dump_service param_watcher |
64| dump_service loop | Dumps fd information in the service loop.|begetctl dump_service loop|
65| bootchart stop | Stops graphics analysis. Only RK3568 is supported.|begetctl bootchart stop |
66| bootchart start | Starts graphics analysis.|begetctl bootchart start |
67| bootchart disable | Disables graphics analysis.|begetctl bootchart disable |
68| bootchart enable | Enables graphics analysis.|begetctl bootchart enable |
69| dac uid username | Obtains the UID corresponding to the specified **username**.|begetctl dac uid username <br>Example:<br>begetctl dac uid root|
70| dac gid groupname | Obtains the GID corresponding to the specified **groupname** and group members.|begetctl dac gid groupname <br>Example:<br> begetctl dac gid shell |
71| get log level | Obtains the log level of the init process from<br>**persist.init.debug.loglevel**.<br>0: debug<br> 1: info<br> 2: warning<br> 3: err<br> 4: fatal|begetctl get log level |
72| set log level | Set the log level to **info**.<br>The log level ranges from **0** to **4**.<br> 0: debug<br>1: info<br> 2: warning<br> 3: err<br>4: fatal|begetctl set log level 1 |
73| appspawn_time | Obtains the maximum and minimum time for application spawning.| begetctl appspawn_time <br>Example:<br>begetctl appspawn_time|
74| dump_nwebspawn | Dumps information about the nwebspawn application.|begetctl dump_nwebspawn <br>Example:<br>Opens Notepad.<br>begetctl dump_nwebspawn |
75| dump_appspawn | Dumps information about the appspawn application.|begetctl dump_appspawn<br>Example:<br>begetctl dump_appspawn|
76
77- <a name = "section001"> **ServiceStatus**
78```
79typedef enum {
80    SERVICE_IDLE = 0, // service add
81    SERVICE_STARTING, // service start
82    SERVICE_STARTED, // 2 service ok running
83    SERVICE_READY, // 3 service ok running
84    SERVICE_STOPPING,
85    SERVICE_STOPPED, // 5
86    SERVICE_ERROR,
87    SERVICE_SUSPENDED,
88    SERVICE_FREEZED,
89    SERVICE_DISABLED,
90    SERVICE_CRITICAL
91} ServiceStatus;
92```
93### Development Procedure
94  Add a plug-in. The following uses bootchart as an example:
951. Install the **.so** file and define an independent file to implement the following functions:
96      ```c
97      static int bootchartEarlyHook(int stage, int prio, void *cookie)
98      {
99          char enable[4] = {}; // 4 enable size
100          uint32_t size = sizeof(enable);
101          SystemReadParam("persist.init.bootchart.enabled", enable, &size);
102          if (strcmp(enable, "1") != 0) {
103              PLUGIN_LOGI("bootchart disabled.");
104              return 0;
105          }
106          InitModuleMgrInstall("libbootchart");
107          PLUGIN_LOGI("bootchart enabled.");
108          return 0;
109      }
110
111      MODULE_CONSTRUCTOR(void)
112      {
113          // Depends on parameter service
114          InitAddPostPersistParamLoadHook(0, bootchartEarlyHook);
115      }
116      ```
1172. Compile the static library **libbootchart\_static** and add it to the **static\_modules** group.
118      ```
119      group("static_modules") {
120        if (!defined(ohos_lite)) {
121          deps = [ ":libbootchart_static" ]
122        }
123      }
124      ```
125
1263. Initialize the bootchart plug-in.
127      ```c
128      static int BootchartInit(void)
129      {
130          if (g_executorId == -1) {
131              g_executorId = AddCmdExecutor("bootchart", DoBootchartCmd);
132              PLUGIN_LOGI("BootchartInit executorId %d", g_executorId);
133          }
134          return 0;
135      }
136
137      MODULE_CONSTRUCTOR(void)
138      {
139          PLUGIN_LOGI("DoBootchartStart now ...");
140          BootchartInit();
141      }
142      ```
1434. Exit the bootchart plug-in.
144      ```c
145      MODULE_DESTRUCTOR(void)
146      {
147          PLUGIN_LOGI("DoBootchartStop now ...");
148          DoBootchartStop();
149          BootchartExit();
150      }
151      ```
1525. Run the bootchart command.
153    ```c
154    static int DoBootchartCmd(int id, const char *name, int argc, const char **argv)
155    {
156        PLUGIN_LOGI("DoBootchartCmd argc %d %s", argc, name);
157        ...
158        return 0;
159    }
160    ```
161
162### Development Example
163#### Bootchart
164  Prerequisites
165  1. Prepare the bootchart test environment. Specifically, install Python and pycairo by running **pip install pycairo** on Linux.
166  2. Decompress **bootchart-master.tar**.
167
168     tar -zxvf  bootchart-master.tar
169
170  Procedure
171  1. Start the system.
172  2. Run the **begetctl bootchart enable** command.
173  3. Restart the system.
174  4. Run the **begetctl bootchart stop** command.
175  5. Run the **begetctl bootchart disable** command.
176  6. Export the following files from the **/data/service/el0/startup/init/** directory and save them to the **bootchart** folder:<br>
177        header<br>
178        proc_diskstats.log<br>
179        proc_ps.log<br>
180        proc_stat.log<br>
181  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.
182  8. Run the following command in the **bootchart-master** directory:
183      ```
184      python3 pybootchartgui.py -f pdf bootchart.tgz
185      ```
186
187  Expected Result
188        <br>A **bootchart.pdf** file is generated in the **bootchart-master** directory.
189#### bootevent
1901. Configure one or more boot events in the **.cfg** file.
191
192    Configure a single boot event.
193    ```json
194    bootevents : "bootevent.xxxbootevent",
195    ```
196    Configure multiple boot events.
197    ```json
198    bootevents : ["bootevent.xxxbootevent1", "bootevent.xxxbootevent2.xxx"],
199    ```
200> **Note:** The configured event must start with **bootevent**.
2012. Send the boot events.
202
203    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:
204    ```c
205    SetParameter("bootevent.XXXbootevent1", "true");
206    ```
2073. Enable the bootevent function by running the **begetctl bootevent enable** command.
208
209    - To enable the bootevent function, run the **begetctl bootevent enable** command and restart the system.
210    - To disable the bootevent function, run the **begetctl bootevent disable** command and restart the system.
2114. Use the exported bootevent file for trace analysis.
212
213    - The exported bootevent file is stored in the **/data/service/el0/startup/init/** directory.
214    - It is named in the format of *timestamp***.bootevent**.
215    - You can import the file to the trace analysis tool for visual analysis.
216