鸿蒙Harmony南向开发:性能分析插件-bootchart

 基本概念

  • 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)最新学习路线

该路线图包含基础技能、就业必备技能、多媒体技术、六大电商APP、进阶高级技能、实战就业级设备开发,不仅补充了华为官网未涉及的解决方案

路线图适合人群:

IT开发人员:想要拓展职业边界
零基础小白:鸿蒙爱好者,希望从0到1学习,增加一项技能。
技术提升/进阶跳槽:发展瓶颈期,提升职场竞争力,快速掌握鸿蒙技术

2.视频学习资料+学习PDF文档

(鸿蒙语法ArkTS、TypeScript、ArkUI教程……)

 纯血版鸿蒙全套学习资料(面试、文档、全套视频等)

                   

鸿蒙APP开发必备

​​

总结

参与鸿蒙开发,你要先认清适合你的方向,如果是想从事鸿蒙应用开发方向的话,可以参考本文的学习路径,简单来说就是:为了确保高效学习,建议规划清晰的学习路线

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值