1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <errno.h>
16 #include <stdio.h>
17 #include <string.h>
18 
19 #include "begetctl.h"
20 #include "init_param.h"
21 
bootchartCmdEnable(BShellHandle shell,int argc,char ** argv)22 static int bootchartCmdEnable(BShellHandle shell, int argc, char **argv)
23 {
24     SystemSetParameter("persist.init.bootchart.enabled", "1");
25     return 0;
26 }
27 
bootchartCmdDisable(BShellHandle shell,int argc,char ** argv)28 static int bootchartCmdDisable(BShellHandle shell, int argc, char **argv)
29 {
30     SystemSetParameter("persist.init.bootchart.enabled", "0");
31     return 0;
32 }
33 
bootchartCmdStart(BShellHandle shell,int argc,char ** argv)34 static int bootchartCmdStart(BShellHandle shell, int argc, char **argv)
35 {
36     char enable[4] = {}; // 4 enable size
37     uint32_t size = sizeof(enable);
38     int ret = SystemGetParameter("persist.init.bootchart.enabled", enable, &size);
39     if (ret != 0 || strcmp(enable, "1") != 0) {
40         BShellEnvOutput(shell, "Not bootcharting\r\n");
41         return 0;
42     }
43     SystemSetParameter("ohos.servicectrl.bootchart", "start");
44     return 0;
45 }
46 
bootchartCmdStop(BShellHandle shell,int argc,char ** argv)47 static int bootchartCmdStop(BShellHandle shell, int argc, char **argv)
48 {
49     SystemSetParameter("ohos.servicectrl.bootchart", "stop");
50     return 0;
51 }
52 
MODULE_CONSTRUCTOR(void)53 MODULE_CONSTRUCTOR(void)
54 {
55     const CmdInfo infos[] = {
56         {"bootchart", bootchartCmdEnable, "bootchart enable", "bootchart enable", "bootchart enable"},
57         {"bootchart", bootchartCmdDisable, "bootchart disable", "bootchart disable", "bootchart disable"},
58         {"bootchart", bootchartCmdStart, "bootchart start", "bootchart start", "bootchart start"},
59         {"bootchart", bootchartCmdStop, "bootchart stop", "bootchart stop", "bootchart stop"},
60     };
61     for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) {
62         BShellEnvRegisterCmd(GetShellHandle(), &infos[i]);
63     }
64 }
65