OpenHarmony南向开发实战bootchart 插件

185 篇文章 0 订阅
181 篇文章 0 订阅

基本概念

  • begetctl介绍

    具体参考begetctl命令。

  • bootchart 插件

    bootchart是一个用于linux启动过程性能分析的开源工具软件,在系统中自动收集CPU占用率、磁盘吞吐率、进程等信息,并以图形方式显示分析结果,可用作指导优化系统启动过程。begetctl命令参考:begetctl命令。

  • bootevent 插件

    bootevent是一个记录init进程及各个服务的启动关键事件的插件,记录内容包括事件名称,关联事件的服务的启动时间,事件发生时间。导出文件支持tracing解析,可用作指导优化系统启动过程。

约束与限制

bootchart和bootevent只支持标准系统, begetctl 支持小型系统和标准系统。

点击领取→【纯血版鸿蒙全套最新学习资料】(安全链接,放心点击)希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源~

参数说明

表1 begetctl 命令说明

命令命令格式和示例说明
init group test [stage]init group teststage参见ServiceStatus。
param ls [-r] [name]显示系统参数,例如:
查看USB系统参数:begetctl param ls persist.sys.usb
param get [name]获取系统参数信息,例如:
begetctl param get 或 param get
param set name value设置系统参数,例如:
begetctl param set ohos.servicectrl.display 1 或 param set ohos.servicectrl.display 1
param wait name [value] [timeout]等待系统参数,例如:
begetctl param wait persist.sys.usb.config hdc 或 param wait persist.sys.usb.config hdc
timeout默认值:30秒
param dump [verbose]dump 系统参数信息,例如:
begetctl param dump 或 param dump
param shell [name]进入Parameter shell,例如:
begetctl param shell 或 param shell
timer_stop servicename停止服务计时器,例如:
begetctl timer_stop appspawn
servicename长度不超过96字符
timer_start servicename timeout启动服务计时器,例如:
begetctl timer_start appspawn
servicename长度不超过96;timeout默认值:10毫秒
start_service servicename启动服务,例如:
begetctl start_service appspawn 或 start_service appspawn
stop_service servicename停止服务,例如:
begetctl stop_service appspawn 或 stop_service appspawn
service_control start servicename启动服务,例如:
begetctl service_control start appspawn 或 service_control start appspawn
service_control stop servicename停止服务,例如:
begetctl service_control stop appspawn 或 service_control stop appspawn
misc_daemon --write_logo xxx.rgb写入开机logo,例如:
begetctl misc_daemon --write_logo logo.rgb 或 misc_daemon --write_logo logo.rgb
rgb文件最大不超过1024*2038,仅支持hi3516dv300
reboot重启系统,例如:
begetctl reboot 或 reboot
reboot shutdown关闭系统,例如:
begetctl reboot shutdown 或 reboot shutdown
reboot suspend暂停系统,例如:
begetctl reboot suspend 或 reboot suspend
reboot updater重新启动并进入updater,例如:
begetctl reboot updater 或 reboot updater
reboot updater[:options]重新启动并进入updater,例如:
begetctl reboot updater 或 reboot updater
reboot flashd重新启动并进入flashd,例如:
begetctl reboot flashd 或 reboot flashd
reboot flashd[:options]重新启动并进入flashd,例如:
begetctl reboot flashd 或 reboot flashd
reboot charge重新启动并进入charge,例如:
begetctl reboot charge 或 reboot charge
reboot loader重新启动并进入烧写模式,例如:
begetctl reboot loader 或 reboot loader
bootchart stop停止图形分析,例如:
begetctl bootchart stop
仅支持rk3568
bootchart start开始图形分析,例如:
begetctl bootchart start
bootchart disable图形分析不使能,例如:
begetctl bootchart disable
bootchart enable图形分析使能,例如:
begetctl bootchart enable
sandbox -s service_name服务进沙盒,例如:
sandbox -s foundation
sandbox -p process_name进程进沙盒,例如:
sandbox -p /bin/sh
sandbox -n sandbox_name进入配置的system或者chipset沙盒,例如:
sandbox -n system
sandbox -hsandbox command help
partitionslot getslot获取当前活动slot,例如:
begetctl partitionslot getslot 或 partitionslot getslot
partitionslot getsuffix slot获取当前匹配slot,例如:
begetctl partitionslot getsuffix 1 或 partitionslot getsuffix 1
partitionslot setactive slot设置活动slot,例如:
begetctl partitionslot setactive 1 或 partitionslot setactive 1
partitionslot setunboot slot设置非活动slot,例如:
begetctl partitionslot setunboot 1 或 partitionslot setunboot 1
modulectl uninstall moduleName卸载动态插件,例如:
modulectl uninstall bootchart
modulectl install moduleName安装动态插件,例如:
modulectl install bootchart
modulectl list动态插件列表,例如:
begetctl modulectl list
setloglevel level设置log等级为info,例如:
begetctl setloglevel 1
log等级设置范围0~4
getloglevel获取当前init的log等级,例如:
begetctl getloglevel
bootevent disable关闭bootevent插件功能,例如:
bootevent disable
bootevent enable开启bootevent插件功能,例如:
begetctl 关闭bootevent插件功能
dump_service parameter_service trigger命令行展示所有trigger信息,例如:
begetctl dump_service parameter_service trigger
dump_service all命令行展示所有服务的信息,例如:
begetctl dump_service all
dump_service serviceName命令行展示单个服务信息,例如:
begetctl dump_service param_watcher
dump api命令行展示init接口信息,例如:
begetctl dump api

开发步骤

新增一个插件, 以bootchart为例:

  1. 安装so文件, 定义单独文件,实现下面函数。

    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);
    }
  2. 编译成静态库libbootchart_static,并加入static_modules组。

    group("static_modules") {
      if (!defined(ohos_lite)) {
        deps = [ ":libbootchart_static" ]
      }
    }
  3. 初始化bootchart插件, 可以安装插件命令。

    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();
    }
  4. 退出bootchart插件。

    MODULE_DESTRUCTOR(void)
    {
        PLUGIN_LOGI("DoBootchartStop now ...");
        DoBootchartStop();
        BootchartExit();
    }
  5. 执行bootchart命令。

    static int DoBootchartCmd(int id, const char *name, int argc, const char **argv)
    {
        PLUGIN_LOGI("DoBootchartCmd argc %d %s", argc, name);
        ...
        return 0;
    }

开发实例

bootchart 使用示例

预制条件:

  1. 准备bootchart测试环境:linux操作系统下安装python及pycairo pip install pycairo

  2. 在linux解压bootchart-master.tar

    tar -zxvf bootchart-master.tar

执行步骤:

  1. 启动系统。
  2. 执行命令行:begetctl bootchart enable
  3. 重启系统。
  4. 执行命令行:begetctl bootchart stop
  5. 执行命令行:begetctl bootchart disable
  6. 在/data/service/el0/startup/init/目录下导出如下文件并存放在bootchart文件夹:
    header
    proc_diskstats.log
    proc_ps.log
    proc_stat.log
  7. 使用tar -zcvf bootchart.tgz * 命令进行打包(只支持linux版本)并将该打包文件拷贝到linux:bootchart-master目录下。
  8. 在bootchart-master目录下运行命令:
    python3 pybootchartgui.py -f pdf bootchart.tgz

预期结果:
        在bootchart-master目录下生成bootchart.pdf。

bootevent 使用示例
  1. 在服务的cfg文件中配置bootevent事件,支持配置一个或多个bootevent事件。

    配置单个bootevent事件:

    bootevents : "bootevent.xxxbootevent",

    配置多个bootevent事件:

    bootevents : ["bootevent.xxxbootevent1", "bootevent.xxxbootevent2.xxx"],

注意: 配置的bootevent事件必须以“bootevent.”开始。

  1. 服务代码中发送bootevent事件。

    服务自身代码中调用init提供的SetParameter接口发送bootevent事件,例如发送上一步骤中设置的XXXbootevent1事件:

    SetParameter("bootevent.XXXbootevent1", "true");
  2. 命令行启用bootevent功能。

    • 执行begetctl bootevent enable命令后再次启动系统,bootevent功能开启。
    • 执行begetctl bootevent disable命令后再次启动系统,bootevent功能关闭。
  3. 导出文件支持trace分析。

    • 导出的bootevent文件目录:/data/service/el0/startup/init/。
    • 导出文件命名规则:“时间戳.bootevent”。
    • 导出的bootevent信息文件可以通过trace分析工具进行可视化展示。

最后

有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。 

点击领取→【纯血版鸿蒙全套最新学习资料】(安全链接,放心点击希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!

这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、(南向驱动、嵌入式等)鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。


 鸿蒙(HarmonyOS NEXT)最新学习路线

有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开发入门教学视频,内容包含:ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。

获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料

HarmonyOS Next 最新全套视频教程

 《鸿蒙 (OpenHarmony)开发基础到实战手册》

OpenHarmony北向、南向开发环境搭建

《鸿蒙开发基础》

  • ArkTS语言
  • 安装DevEco Studio
  • 运用你的第一个ArkTS应用
  • ArkUI声明式UI开发
  • .……

《鸿蒙开发进阶》

  • Stage模型入门
  • 网络管理
  • 数据管理
  • 电话服务
  • 分布式应用开发
  • 通知与窗口管理
  • 多媒体技术
  • 安全技能
  • 任务管理
  • WebGL
  • 国际化开发
  • 应用测试
  • DFX面向未来设计
  • 鸿蒙系统移植和裁剪定制
  • ……

《鸿蒙进阶实战》

  • ArkTS实践
  • UIAbility应用
  • 网络案例
  • ……

大厂面试必问面试题

鸿蒙南向开发技术

鸿蒙APP开发必备

鸿蒙生态应用开发白皮书V2.0PDF


请点击→纯血版全套鸿蒙HarmonyOS学习资料

总结
总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个挑战,也是一个机会。只有积极应对变化,不断学习和提升自己,他们才能在这个变革的时代中立于不败之地。 

                   

  • 18
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值