打开/关闭搜索
搜索
打开/关闭菜单
通知
打开/关闭个人菜单
查看“HDC命令”的源代码
来自Uotan Wiki · 刷机百科
查看
阅读
查看源代码
查看历史
associated-pages
页面
讨论
更多操作
←
HDC命令
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
= HDC是什么 = HDC(OpenHarmony Device Connector) 是为鸿蒙开发/测试人员提供的用于设备调试的命令行工具,类似Android端的ADB工具。 HDC主要有三部分组成: 1. <code>hdc client</code>:运行于电脑上的客户端,用户可以在电脑命令终端(windows cmd/linux shell)下请求执行相应的hdc命令。 2. <code>hdc server</code>:作为后台进程也运行于电脑上,server管理client和设备端daemon之间通信包括连接的复用、数据通信包的收发,以及个别本地命令的直接处理。 3. <code>hdc daemon</code>:daemon部署于OpenHarmony设备端作为守护进程按需运行,负责处理来自client端请求。 整体架构和Android系统的ADB架构非常类似。 = HDC安装 = * 下载 [https://developer.huawei.com/consumer/cn/download/ Command Line Tools] 并解压 * <code>hdc</code>文件在<code>command-line-tools/sdk/HarmonyOS-NEXT-DB2/openharmony/toolchains</code>目录下 * 配置电脑环境变量,以macOS为例,在<code>~/.bash_profile</code> 或者 <code>~/.zshrc</code>文件中添加如下内容: <pre>export HM_SDK_HOME="/Users/develop/command-line-tools/sdk/HarmonyOS-NEXT-DB2" //请以sdk实际安装目录为准 export PATH=$PATH:$HM_SDK_HOME/hms/toolchains:$HM_SDK_HOME/openharmony/toolchains export HDC_SERVER_PORT=7035</pre> 也可以自行编译安装:参考鸿蒙官方gitree文档 = 基本用法 = == 基本语法 == <pre>hdc -t <connectKey> <command></pre> 如果只有一个设备/模拟器连接时,可以省略掉<code>-t <connectKey></code> 这一部分,直接使用<code>hdc <command></code>。在多个设备/模拟器连接的情况下需要指定<code>-t</code> 参数, <code>connectKey</code>可以通过<code>hdc list targets</code>命令获取,对应Android里的<code>adb devices</code>获取的<code>serialNumber</code>。 <pre>$ hdc list targets 127.0.0.1:5555 //<IP>:<Port>形式的connectKey ,一般为无线连接的设备或模拟器 FMR0223C13000649</pre> 比如给<code>FMR0223C13000649</code> 这个设备安装应用: <pre>$ hdc -t FMR0223C13000649 install entry-default-signed.hap [Info]App install path:/Users/develop/entry-default-signed.hap, queuesize:0, msg:install bundle successfully. AppMod finish</pre> '''注意事项''' * 使用<code>hdc</code>,如果出现异常,可以尝试通过<code>hdc kill -r</code>命令杀掉并重启hdc服务。 * 如果出现<code>hdc list targets</code>获取不到设备信息的情况,可以通过任务管理器查看是否有hdc进程存在。若进程存在,则通过<code>hdc kill -r</code>命令杀掉该进程。 = 设备连接管理 = <span id="查看hdc版本"></span> == 查看HDC版本 == <pre>$ hdc -v Ver: 2.0.0a</pre> <span id="启动停止-hdc-server"></span> == 启动/停止 HDC Server == 停止 <pre>$ hdc kill Kill server finish</pre> 重启 <pre>$ hdc start -r</pre> == 查询设备列表 == <pre>$ hdc list targets 127.0.0.1:5555 FMR0223C13000649</pre> <code>-v</code> 选项 显示详细信息 <pre>$ hdc list targets -v 127.0.0.1:5555 TCP Connected localhost FMR0223C13000649 USB Connected unknown...</pre> 输出的内容第一列为设备的<code>connectKey</code>, 第二列是设备<code>连接方式</code>,第三列为设备<code>连接状态</code>,第四列暂时未知 <span id="查询设备udid"></span> == 查询设备UDID == <pre>$ hdc shell bm get --udid udid of current device is : C46284C052AE01BBD2358FE44B279524B508FC959AAB5F4B0B74E42A06569B7E</pre> 这个<code>udid</code>在用开发者账号打包时,需要添加这个<code>udid</code>到对应的<code>profile</code>文件中 == 重启手机 == <pre>$ hdc target boot </pre> = 应用管理 = == 安装应用 == <pre>$ hdc app install entry-default-signed.hap [Info]App install path:/Users/develop/entry-default-signed.hap, queuesize:0, msg:install bundle successfully. AppMod finish</pre> 或者 <pre>$ hdc install entry-default-signed.hap [Info]App install path:/Users/develop/entry-default-signed.hap, queuesize:0, msg:install bundle successfully. AppMod finish</pre> == 卸载应用 == <pre>$ hdc app uninstall com.kk.hmscrcpy [Info]App uninstall path:, queuesize:0, msg:uninstall bundle successfully. AppMod finish</pre> 或者 <pre>$ hdc uninstall com.kk.hmscrcpy [Info]App uninstall path:, queuesize:0, msg:uninstall bundle successfully. AppMod finish</pre> == 获取应用列表 == <pre>$ hdc shell bm dump -a ID: 100: com.huawei.associateassistant com.huawei.batterycare com.huawei.hmos.AutoRegService com.huawei.hmos.advisor com.huawei.hmos.advsecmode com.huawei.hmos.aibase com.huawei.hmos.aidataservice com.huawei.hmos.aidispatchservice com.huawei.hmos.ailife com.huawei.hmos.ailifesvc com.huawei.hmos.audioaccessorymanager com.huawei.hmos.authcredmgr ...</pre> == 启动应用 == 通过启动<code>Ability</code>来拉起<code>APP</code> <pre>hdc shell aa start -a {abilityName} -b {bundleName} </pre> * 其中<code>bundleName</code>可以通过<code>hdc shell bm dump -a</code>获取 * 其中<code>abilityName</code>可以通过如下命令获取(查看当前任务栈的ability信息) <pre>$ hdc shell aa dump -l # 运行命令前需要手动打开app User ID #100 current mission lists:{ Mission ID #139 mission name #[#com.kuaishou.hmapp:kwai:EntryAbility] lockedState #0 mission affinity #[] AbilityRecord ID #55 app name [com.kuaishou.hmapp] main name [EntryAbility] bundle name [com.kuaishou.hmapp] ability type [PAGE] state #FOREGROUND start time [152523] app state #FOREGROUND ready #1 window attached #0 launcher #0 callee connections: isKeepAlive: false }</pre> 里面的EntryAbility就是你要打开app的Ability名称 == 退出应用 == 强制退出应用 <pre>hdc shell aa force-stop {bundleName} </pre> * 其中<code>bundleName</code>可以通过<code>hdc shell bm dump -a</code>获取 == 获取应用版本 == <pre>$ hdc shell bm dump -n {bundleName}</pre> 执行上述命令后,再解析json, 提取<code>versionName</code>字段即可 <span id="dump应用信息"></span> == Dump应用信息 == '''aa dump''' <pre>$ hdc shell aa dump -h usage: aa dump <options> options list: -h, --help list available commands -a, --all dump all abilities -l, --mission-list dump mission list -i, --ability dump abilityRecordId -e, --extension dump elementName (FA: serviceAbilityRecords,Stage: ExtensionRecords) -p, --pending dump pendingWantRecordId -r, --process dump process -d, --data dump the data abilities -u, --userId userId -c, --client client -c, -u are auxiliary parameters and cannot be used alone</pre> '''bm dump''' <pre>$ hdc shell bm dump -h usage: bm dump <options> options list: -h, --help list available commands -a, --all list all bundles in system -n, --bundle-name <bundle-name> list the bundle info by a bundle name -s, --shortcut-info list the shortcut info -d, --device-id <device-id> specify a device id -u, --user-id <user-id> specify a user id</pre> <span id="获取应用-ability信息"></span> === 获取应用 Ability信息 === <pre>$ hdc shell aa dump -l //运行命令前需要手动打开app User ID #100 current mission lists:{ Mission ID #139 mission name #[#com.kuaishou.hmapp:kwai:EntryAbility] lockedState #0 mission affinity #[] AbilityRecord ID #55 app name [com.kuaishou.hmapp] main name [EntryAbility] bundle name [com.kuaishou.hmapp] ability type [PAGE] state #FOREGROUND start time [152523] app state #FOREGROUND ready #1 window attached #0 launcher #0 callee connections: isKeepAlive: false }</pre> === 获取应用详情 === 查询该应用的详细信息 <pre>$ hdc shell bm dump -n com.kuaishou.hmapp com.kuaishou.hmapp: { "appId": "com.kuaishou.hmapp_BIS88rItfUAk+V9Y4WZp2HgIZ/JeOgvEBkwgB/YyrKiwrWhje9Xn2F6Q7WKFVM22RdIR4vFsG14A7ombgQmIIxU=", "appIdentifier": "5765880207853819885", "appIndex": 0, "applicationInfo": { ... "applicationReservedFlag": 0, "arkNativeFileAbi": "", "arkNativeFilePath": "", "asanEnabled": false, "asanLogPath": "", "associatedWakeUp": false, "bundleName": "com.kuaishou.hmapp", "bundleType": 0, "cacheDir": "", "codePath": "/data/app/el1/bundle/public/com.kuaishou.hmapp", "compileSdkType": "HarmonyOS", "compileSdkVersion": "4.1.0.73", "cpuAbi": "arm64-v8a", "crowdtestDeadline": -1, "dataBaseDir": "/data/app/el2/database/com.kuaishou.hmapp", "dataDir": "", "debug": true, "description": "", "descriptionId": 0, "descriptionResource": { "bundleName": "com.kuaishou.hmapp", "id": 0, "moduleName": "kwai" }, "deviceId": "PHONE-001", "distributedNotificationEnabled": true, "enabled": true, "entityType": "unspecified", "entryDir": "", "entryModuleName": "", "fingerprint": "96C4B0B051421A56EC9117BC6E3CF093C428B6B6D59DA13205C29C9BDD39AE7C", ... "minCompatibleVersionCode": 999999, "moduleInfos": [ { "moduleName": "kwai", "moduleSourceDir": "", "preloads": [] } ], ... "userDataClearable": true, "vendor": "快手", "versionCode": 999999, "versionName": "12.2.40" }, "compatibleVersion": 40100011, "cpuAbi": "", "defPermissions": [], "description": "", "entryInstallationFree": false, "entryModuleName": "kwai", "gid": 20020014, "hapModuleInfos": [ ... ], "reqPermissions": [ "ohos.permission.ACCELEROMETER", "ohos.permission.GET_NETWORK_INFO", "ohos.permission.GET_WIFI_INFO", "ohos.permission.INTERNET", "ohos.permission.SET_NETWORK_INFO", "ohos.permission.STORE_PERSISTENT_DATA" ], ... "vendor": "快手", "versionCode": 999999, "versionName": "12.2.40" }</pre> 通过这个命令可以获取到很多应用的关键信息,比如<code>reqPermissions</code>,<code>version</code>,<code>abilities</code>等等 == 清除应用数据 == <pre>$ hdc shell bm clean -h usage: bm clean <options> options list: -h, --help list available commands -n, --bundle-name <bundle-name> bundle name -c, --cache clean bundle cache files by bundle name -d, --data clean bundle data files by bundle name -u, --user-id <user-id> specify a user id</pre> === 清除应用缓存 === <pre>$ hdc shell bm clean -n {bundleName} -c clean bundle cache files successfully.</pre> 其中<code>bundleName</code>可以通过<code>hdc shell bm dump -a</code>获取, 比如<code>com.kuaishou.hmapp</code> <span id="清除应用数据-1"></span> === 清除应用数据 === <pre>$ hdc shell bm clean -n {bundleName} -d </pre> == 显示可调试应用列表 == <pre>$ hdc jpid 2571 2633 2638 2658 2666 2691 2825 3310 3804 3977 30178 $ hdc track-jpid 0000</pre> * <code>jpid</code>显示可调试应用列表 * <code>track-jpid</code>动态显示可调试应用列表。 = 查看设备信息 = == 名称 == <pre>$ hdc shell param get const.product.name HUAWEI Mate 60 Pro</pre> <span id="brand"></span> == Brand == <pre>$ hdc shell param get const.product.brand HUAWEI </pre> <span id="model"></span> == Model == <pre>$ hdc shell param get const.product.model ALN-AL00 </pre> == 系统版本 == <pre>$ hdc shell param get const.product.software.version ALN-AL00 5.0.0.22(SP35DEVC00E22R4P1log) </pre> <span id="os版本"></span> == OS版本 == <pre>$ hdc shell param get const.ohos.apiversion 12 </pre> <span id="cpu架构"></span> == CPU架构 == <pre>$ hdc shell param get const.product.cpu.abilist arm64-v8a </pre> == 分辩率 == <pre>$ hdc shell hidumper -s RenderService -a screen -------------------------------[ability]------------------------------- ----------------------------------RenderService--------------------------------- -- ScreenInfo screen[0]: id=0, powerstatus=POWER_STATUS_OFF, backlight=51, screenType=EXTERNAL_TYPE, render size: 1260x2720, physical screen resolution: 1260x2720, isvirtual=false, skipFrameInterval_:1 supportedMode[0]: 1260x2720, refreshrate=120 supportedMode[1]: 1260x2720, refreshrate=90 supportedMode[2]: 1260x2720, refreshrate=60 supportedMode[3]: 1260x2720, refreshrate=30 activeMode: 1260x2720, refreshrate=60 capability: name=, phywidth=72, phyheight=156,supportlayers=12, virtualDispCount=0, propCount=0, type=DISP_INTF_HDMI, supportWriteBack=false</pre> 执行上述命令后,解析返回内容,可以通过正则表达式提取<code>1260x2720</code> == wlanip == <pre>$ hdc shell ip address show</pre> 后来发现这个命令再最新的系统上实现,提示<code>Cannot open netlink socket: Permission denied</code>, 正在联系鸿蒙方,等待更新。 先记个TODO吧。 <span id="电量温度"></span> == 电量/温度 == <pre>$ hdc shell hidumper -s BatteryService -a -i -------------------------------[ability]------------------------------- ----------------------------------BatteryService--------------------------------- Current time: 2024-05-30 12:08:37.419 capacity: 100 batteryLevel: 1 chargingStatus: 3 healthState: 1 pluggedType: 1 voltage: 4496732 present: 1 technology: Li-poly nowCurrent: 123 currentAverage: 83 totalEnergy: 5203 remainingEnergy: 5207 remainingChargeTime: 0 temperature: 280 chargeType: 1 </pre> == 查看屏幕状态 == 可以通过如下命令判断屏幕是否点亮 <pre>$ hdc shell hidumper -s 3301 -a -a -------------------------------[ability]------------------------------- ----------------------------------PowerManagerService--------------------------------- POWER STATE DUMP: Current State: AWAKE Reason: 20 Time: 107537120 ScreenOffTime: Timeout=600000ms DUMP DETAILS: Last Screen On: 107573125 Last Screen Off: 103825347 Last SuspendDevice: 0 Last WakeupDevice: 100917510 Last Refresh: 107573125 DUMP EACH STATES: State: AWAKE Reason: POWER_KEY Time: 107537120 Failure: APPLICATION Reason: Already in the state From: AWAKE Time: 97916146 State: FREEZE Reason: INIT Time: 0 Failure: INIT Reason: From: AWAKE Time: 0 State: INACTIVE Reason: TIMEOUT Time: 103825357 Failure: INIT Reason: From: AWAKE Time: 0 State: STAND_BY Reason: UNKNOWN Time: 0 Failure: UNKNOWN Reason: From: UNKNOWN Time: 0 State: DOZE Reason: INIT Time: 0 Failure: INIT Reason: From: AWAKE Time: 0 State: SLEEP Reason: TIMEOUT Time: 103830359 Failure: INIT Reason: From: AWAKE Time: 0 State: HIBERNATE Reason: INIT Time: 0 Failure: INIT Reason: From: AWAKE Time: 0 State: SHUTDOWN Reason: INIT Time: 0 Failure: INIT Reason: From: AWAKE Time: 0 State: DIM Reason: INIT Time: 0 Failure: TIMEOUT Reason: Forbid transit From: SLEEP Time: 98317861 RUNNING LOCK DUMP: totalSize=15 validSize=0 Summary By Type: SCREEN: 0 BACKGROUND: 0 PROXIMITY_SCREEN_CONTROL: 0 RUNNINGLOCK_COORDINATION: 0 Dump Lock List: index=1 time=107569814 type=BACKGROUND_TASK name=PowerMgrWakeupLock uid=5555 pid=601 state=0 index=2 time=107569710 type=BACKGROUND_PHONE name=telRilAckRunningLock uid=1001 pid=966 state=0 index=3 time=107569709 type=BACKGROUND_PHONE name=telRilRequestRunningLock uid=1001 pid=966 state=0 index=4 time=107569669 type=BACKGROUND name=handleAckRunningLock uid=1001 pid=966 state=0 index=5 time=107569669 type=BACKGROUND name=handleRequestRunningLock uid=1001 pid=966 state=0 index=6 time=107569657 type=BACKGROUND name=telRilExtRequestRunningLock uid=1001 pid=966 state=0 index=7 time=107569657 type=BACKGROUND name=telRilExtAckRunningLock uid=1001 pid=966 state=0 index=8 time=107566014 type=SCREEN name=KeepScreenOn uid=20020108 pid=2666 state=0 index=9 time=107415510 type=BACKGROUND_AUDIO name=AudioOffloadBackgroudPlay uid=1041 pid=839 state=0 index=10 time=107569355 type=BACKGROUND_AUDIO name=AudioPrimaryBackgroundPlay uid=1041 pid=839 state=0 index=11 time=107569347 type=BACKGROUND_AUDIO name=AudioPrimaryBackgroundPlay uid=1041 pid=839 state=0 index=12 time=107569060 type=BACKGROUND name=StandbyRunningLock uid=0 pid=852 state=0 index=13 time=107549168 type=BACKGROUND_NOTIFICATION name=timeServiceRunningLock uid=3819 pid=1073 state=0 index=14 time=107568182 type=BACKGROUND name=BoosterNetAckRunningLock uid=1099 pid=958 state=0 index=15 time=107568182 type=BACKGROUND name=BoosterNetRequestRunningLock uid=1099 pid=958 state=0 Dump Proxy List: index=1 pid_uid=1073_3819 lock_cnt=1 proxy_cnt=0 index=2 pid_uid=2638_20001 lock_cnt=0 proxy_cnt=1 index=3 pid_uid=2666_20020108 lock_cnt=1 proxy_cnt=0 index=4 pid_uid=2691_20012 lock_cnt=0 proxy_cnt=1 index=5 pid_uid=3310_20020040 lock_cnt=0 proxy_cnt=1 index=6 pid_uid=601_5555 lock_cnt=1 proxy_cnt=0 index=7 pid_uid=839_1041 lock_cnt=3 proxy_cnt=0 index=8 pid_uid=852_0 lock_cnt=1 proxy_cnt=0 index=9 pid_uid=958_1099 lock_cnt=2 proxy_cnt=0 index=10 pid_uid=966_1001 lock_cnt=6 proxy_cnt=0 Peripherals Info: Proximity: Enabled=0 Status=0</pre> = 端口转发 = {| class="wikitable" |- ! 命令 ! 说明 |- | fport ls | 展示全部“端口转发主机端口转发数据到设备侧端口”的转发任务 |- | fport local remote | 端口转发主机端口转发数据到设备侧端口 |- | fport rm local remote | 删除指定“端口转发主机端口转发数据到设备侧端口”的转发任务 |- | rport ls | 展示全部“端口转发设备侧端口转发数据到主机端口”的转发任务 |- | rport local remote | 端口转发设备侧端口转发数据到主机端口 |- | rport rm local remote | 删除指定“端口转发设备侧端口转发数据到主机端口”的转发任务 |} == 显示端口转发列表 == 展示电脑端口转发到手机端口的列表 <pre>$ hdc fport ls FMR0223C13000649 tcp:7912 tcp:7912 [Forward]</pre> == 本地端口转发到手机 == 将本地电脑的<code>7913</code>端口转发到手机<code>7912</code>端口 <pre>$ hdc fport tcp:7913 tcp:7912 Forwardport result:OK</pre> 这个命令非常实用,比如我再手机上实现了一个 <code>http</code>服务,没有这个命令前需要通过手机<code>ip:port</code>来访问,这就需要提前知道手机的<code>wlanIP</code>,执行这个命令后可以直接通过<code>localhost:localPort</code>来访问手机里的服务。 == 删除端口转发任务 == <pre>$ hdc fport rm tcp:7913 tcp:7912 Remove forward ruler success, ruler:tcp:7913 tcp:7912 $ hdc fport ls [Empty]</pre> 同理,<code>rport</code>命令表示手机端口转发到电脑端口,我就不一一举例了. = 无线调试 = # 在手机上开启5555端口 <code>hdc -t {SERIAL} tmode port {PORT}</code> # 连接手机上的端口 <code>hdc -t {SERIAL} tconn {WLANIP}:{PORT}</code> # 恢复手机USB连接 <code>hdc -t {SERIAL} tmode usb</code> '''示例''' <pre>$ hdc tmode port 5555 $ hdc tconn 172.31.124.84:5555 Connect OK $ hdc list targets 172.31.124.84:5555 $ hdc tmode usb Set device run mode successful. </pre> 不过目前这个无线调试,会导致该手机USB连接方式断开,导致无法进行端口转发,每次进行无线调试时,需要知道手机的wlanip才行。 这个问题也在和鸿蒙方沟通,待解决。 记个TODO. = 文件传输 = {| class="wikitable" |- ! 命令 ! 说明 |- | file send local remote | 从本地发送文件至远端设备 |- | file recv remote local | 从远端设备发送文件至本地 |} == 从本地电脑发送文件至手机 == <pre>$ hdc file send ~/layout_407568854.json /data/local/tmp/layout_407568854.json FileTransfer finish, Size:71792, File count = 1, time:24ms rate:2991.33kB/s</pre> == 从手机拷贝文件至本地电脑 == <pre>$ hdc file recv /data/local/tmp/layout_407568854.json ~/layout_407568854.json [I][2024-05-28 20:15:45] HdcFile::TransferSummary success FileTransfer finish, Size:71792, File count = 1, time:12ms rate:5982.67kB/s</pre> = uitest工具 = <pre>$ hdc shell uitest help help, print help messages screenCap, dumpLayout, uiRecord record, wirte location coordinates of events into files uiRecord read, print file content to the console uiInput, --version, print current tool version</pre> <span id="ui模拟操作"></span> == UI模拟操作 == 支持操作类型:<code>点击</code> <code>双击</code> <code>长按</code> <code>慢滑</code> <code>快滑</code> <code>拖拽</code> <code>输入文字</code> <code>KeyEvent</code> | 配置参数名 | 配置参数含义 | 配置参数取值 | 示例 | |————-|——————————————-|——————————————————————————————————————————————————————–|————————————————————————————————–| | click | 模拟单击操作 | point_x (必选参数,点击x坐标点)<br>point_y (必选参数,点击y坐标点) | hdc shell uitest uiInput click point_x point_y | | doubleClick | 模拟双击操作 | point_x (必选参数,双击x坐标点)<br>point_y (必选参数,双击y坐标点) | hdc shell uitest uiInput doubleClick point_x point_y | | longClick | 模拟长按操作 | point_x (必选参数,长按x坐标点)<br>point_y (必选参数,长按y坐标点) | hdc shell uitest uiInput longClick point_x point_y | | fling | 模拟快滑操作 | from_x (必选参数,滑动起点x坐标)<br>from_y(必选参数,滑动起点y坐标)<br>to_x(必选参数,滑动终点x坐标)<br>to_y(必选参数,滑动终点y坐标)<br>swipeVelocityPps_ (可选参数,滑动速度,取值范围: 200-40000, 默认值: 600, 单位: px/s)<br>stepLength(可选参数,滑动步长,默认值:滑动距离/50, 单位: px) | hdc shell uitest uiInput fling from_x from_y to_x to_y swipeVelocityPps_ stepLength | | swipe | 模拟慢滑操作 | from_x (必选参数,滑动起点x坐标)<br>from_y(必选参数,滑动起点y坐标)<br>to_x(必选参数,滑动终点x坐标)<br>to_y(必选参数,滑动终点y坐标)<br>swipeVelocityPps_ (可选参数,滑动速度,取值范围: 200-40000, 默认值: 600, 单位: px/s) | hdc shell uitest uiInput swipe from_x from_y to_x to_y swipeVelocityPps_ | | drag | 模拟拖拽操作 | from_x (必选参数,拖拽起点x坐标)<br>from_y(必选参数,拖拽起点y坐标)<br>to_x(必选参数,拖拽终点x坐标)<br>to_y(必选参数,拖拽终点y坐标)<br>swipeVelocityPps_ (可选参数,滑动速度,取值范围: 200-40000, 默认值: 600, 单位: px/s) | hdc shell uitest uiInput drag from_x from_y to_x to_y swipeVelocityPps_ | | dircFling | 模拟指定方向滑动操作 | direction (可选参数,滑动方向,可选值: [0,1,2,3], 滑动方向: [左,右,上,下],默认值: 0)<br>swipeVelocityPps_ (可选参数,滑动速度,取值范围: 200-40000, 默认值: 600, 单位: px/s)<br>stepLength(可选参数,滑动步长,默认值:滑动距离/50, 单位: px) | hdc shell uitest uiInput dircFling direction swipeVelocityPps_ stepLength | | inputText | 模拟输入框输入文本操作 | point_x (必选参数,输入框x坐标点)<br>point_y (必选参数,输入框y坐标点)<br>input(输入文本) | hdc shell uitest uiInput inputText point_x point_y text | | keyEvent | 模拟实体按键事件(如:键盘,电源键,返回上一级,返回桌面等),以及组合按键操作 | keyID (必选参数,实体按键对应ID)<br>keyID2 (可选参数,实体按键对应ID) | hdc shell uitest uiInput keyEvent keyID | '''举例''' <pre>//点击 hdc shell uitest uiInput click 100 100 //双击 hdc shell uitest uiInput doubleClick 100 100 //长按 hdc shell uitest uiInput longClick 100 100 //快滑 hdc shell uitest uiInput fling 10 10 200 200 500 //慢滑 hdc shell uitest uiInput swipe 10 10 200 200 500 //拖拽 hdc shell uitest uiInput drag 10 10 100 100 500 //左滑 hdc shell uitest uiInput dircFling 0 500 //右滑 hdc shell uitest uiInput dircFling 1 600 //上滑 hdc shell uitest uiInput dircFling 2 //下滑 hdc shell uitest uiInput dircFling 3 //输入框输入 hdc shell uitest uiInput inputText 100 100 hello //返回主页 hdc shell uitest uiInput keyEvent Home //返回上一步 hdc shell uitest uiInput keyEvent Back //组合键粘贴操作 hdc shell uitest uiInput keyEvent 2072 2038</pre> <code>keyEvent</code>映射表可以参考这个文档:https://docs.openharmony.cn/pages/v4.1/en/application-dev/reference/apis-input-kit/js-apis-keycode.md <span id="获取页面布局信息控件树"></span> == 获取页面布局信息(控件树) == <pre>$ hdc shell uitest dumpLayout -p {saveDumpPath} # 运行命令前需要手动打开app,进入对应页面 DumpLayout saved to:/data/local/tmp/layout_407568854.json</pre> * <code>-p</code>表示控件树保存的目录,如果不指定,则默认保存在手机的<code>/data/local/tmp</code>目录 <code>/data/local/tmp/layout_407568854.json</code>文件内容如下: <pre>{ "attributes": { "accessibilityId": "", "bounds": "[0,0][1260,2720]", "checkable": "", "checked": "", "clickable": "", "description": "", "enabled": "", "focused": "", "hostWindowId": "", "id": "", "key": "", "longClickable": "", "origBounds": "", "scrollable": "", "selected": "", "text": "", "type": "" }, "children": [ ... ]</pre> == 录制用户操作 == 将当前界面操作记录到<code>/data/local/tmp/layout/record.csv</code>,结束录制操作使用<code>Ctrl+C</code>结束录制 <pre>$ hdc shell uitest uiRecord record windowBounds : (0,0,1260,2720) Current ForAbility :com.kuaishou.hmapp, EntryAbility The result will be written in csv file at location: /data/local/tmp/layout/record.csv Started Recording Successfully... click , fingerNumber:1 , finger1:click: at Point(x:557, y:1542) ; from Point(x:557, y:1542) to Point(x:557, y:1542) ; click , fingerNumber:1 , finger1:click: at Point(x:550, y:1638) ; from Point(x:550, y:1638) to Point(x:550, y:1638) ; fling , fingerNumber:1 , finger1:from Point(x:409, y:1916) to Point(x:370, y:1528) ; Off-hand speed:1415.42, Step length:34; fling , fingerNumber:1 , finger1:from Point(x:400, y:1886) to Point(x:389, y:1586) ; Off-hand speed:1995.97, Step length:31; home , fingerNumber:1 , finger1:from Widget(id: , type: Text, text: state: didAppear, feedId: 5218827670987295481, feedType: 3, ServerExpTag: feed_photo|5218827670987295481|1499501607|1_u/2003373606202106162_bs54357, ) ; to Point(x:615, y:2338) ;</pre> 支持两种方式查看数据: - <code>uiRecord record</code>, 将事件的位置坐标写入文件 - <code>uiRecord read</code>, 将文件内容打印到控制台 录制完成后,再将<code>csv</code>文件拷贝到电脑上 <pre>$ hdc file recv /data/local/tmp/layout/record.csv ~/record.csv</pre> <code>record</code>数据字段含义请参考如下示例数据 <pre>{ "ABILITY": "com.ohos.launcher.MainAbility", // 前台应用界面 "BUNDLE": "com.ohos.launcher", // 操作应用 "CENTER_X": "", // 模拟捏合中心X, pinch事件 "CENTER_Y": "", // 模拟捏合中心Y, pinch事件 "EVENT_TYPE": "pointer", // "LENGTH": "0", // 总体步长 "OP_TYPE": "click", //事件类型,当前支持点击、双击、长按、拖拽、捏合、滑动、抛滑动作录制 "VELO": "0.000000", // 离手速度 "direction.X": "0.000000",// 总体移动X方向 "direction.Y": "0.000000", // 总体移动Y方向 "duration": 33885000.0, // 手势操作持续时间 "fingerList": [{ "LENGTH": "0", // 总体步长 "MAX_VEL": "40000", // 最大速度 "VELO": "0.000000", // 离手速度 "W1_BOUNDS": "{"bottom":361,"left":37,"right":118,"top":280}", // 起点控件bounds "W1_HIER": "ROOT,3,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0", // 起点控件hierarchy "W1_ID": "", // 起点控件id "W1_Text": "", // 起点控件text "W1_Type": "Image", // 起点控件类型 "W2_BOUNDS": "{"bottom":361,"left":37,"right":118,"top":280}", // 终点控件bounds "W2_HIER": "ROOT,3,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0", // 终点控件hierarchy "W2_ID": "", // 终点控件id "W2_Text": "", // 终点控件text "W2_Type": "Image", // 终点控件类型 "X2_POSI": "47", // 终点X "X_POSI": "47", // 起点X "Y2_POSI": "301", // 终点Y "Y_POSI": "301", // 起点Y "direction.X": "0.000000", // x方向移动量 "direction.Y": "0.000000" // Y方向移动量 }], "fingerNumber": "1" //手指数量 }</pre> = 屏幕截图 = hdc提供了两种截图命令 方式一 <pre>$ hdc shell uitest screenCap // 默认存储路径:/data/local/tmp,文件名:时间戳 + .png。 $ hdc shell uitest screenCap -p /data/local/tmp/1.png // 指定存储路径和文件名。</pre> 【推荐】方式二 <pre>$ hdc shell snapshot_display -f /data/local/tmp/2.jpeg // 截图完成后可以通过 hdc file recv 命令导入到本地</pre> 方式二的截图性能效率远远高于方式一 = 屏幕录屏 = 相关hdc命令还未支持,官方在开发中。。。 我这边通过python脚本实现了录屏功能,使用方法如下 <pre>cd awesome-hdc/scripts pip3 install -r requirements.txt python3 screen_recroding.py</pre> <span id="点亮屏幕唤醒"></span> = 点亮屏幕(唤醒) = <pre>$ hdc shell power-shell wakeup WakeupDevice is called</pre> <span id="打开scheme-url"></span> = 打开Scheme (URL) = <pre>$ hdc shell aa start -U http://www.baidu.com start ability successfully. $ hdc shell aa start -U kwai://home </pre> = 收起键盘 = <pre>$ hdc shell uinput -K -d 2 -i 2 -u 2</pre> = hidumper工具 = <pre>$ hdc shell hidumper -h usage: -h |help text for the tool -lc |a list of system information clusters -ls |a list of system abilities -c |all system information clusters -c [base system] |system information clusters labeled "base" and "system" -s |all system abilities -s [SA0 SA1] |system abilities labeled "SA0" and "SA1" -s [SA] -a ['-h'] |system ability labeled "SA" with arguments "-h" specified -e |faultlogs of crash history --net [pid] |dump network information; if pid is specified, dump traffic usage of specified pid --storage [pid] |dump storage information; if pid is specified, dump /proc/pid/io -p |processes information, include list and information of processes and threads -p [pid] |dump threads under pid, includes smap, block channel, execute time, mountinfo --cpuusage [pid] |dump cpu usage by processes and category; if PID is specified, dump category usage of specified pid --cpufreq |dump real CPU frequency of each core --mem [pid] |dump memory usage of total; dump memory usage of specified pid if pid was specified --zip |compress output to /data/log/hidumper --mem-smaps pid [-v] |display statistic in /proc/pid/smaps, use -v specify more details --mem-jsheap pid [-T tid] [--gc] |triggerGC and dumpHeapSnapshot under pid and tid</pre> <span id="system-abilities"></span> == system abilities == <pre>$ hdc shell hidumper -ls System ability list: SystemAbilityManager RenderService AbilityManagerService DataObserverMgr UriPermissionMgr AccountMgr BundleMgr FormMgr ApplicationManagerService AccessibilityManagerService UserIdmService UserAuthService AuthExecutorMgrService PinAuthService FaceAuthService FingerprintAuthService WifiDevice WifiHotspot WifiP2p WifiScan 1125 1126 NetConnManager NetPolicyManager NetStatsManager NetTetheringManager VPNManager EthernetManager NetsysNative NetsysExtService DistributedNet 1181 HiviewService HiviewFaultLogger HiviewSysEventService 1204 XperfTraceService HiDumperService XpowerManager HiDumperCpuService DistributedKvData ContinuationManagerService ResourceSched BackgroundTaskManager WorkSchedule ComponentSchedServer SocPerfService DeviceUsageStatistics MemoryManagerService SuspendManager AbnormalEfficiencyManager ConcurrentTaskService ResourceQuotaControl DeviceStandbyService TaskHeartbeatMgrService 2901 DeviceStatusService 2903 2904 2908 AudioDistributed PlayerDistributedService CameraService AudioPolicyService AVSessionService AVCodecService MediaKeySystemService MultimodalInput DistributedNotificationService CommonEventService PowerManagerService BatteryService ThermalService BatteryStatisticsService DisplayPowerManagerService AccessTokenManagerService PrivacyManagerService KeystoreService DeviceThreatDetectionService RiskAnalysisManagerService DataCollectManagerService DlpCreService SensorService MiscDeviceService PasteboardService TimeService InputMethodService ScreenlockService WallpaperManagerService ParamWatcher TelephonyCallManager TelephonyCellularCall TelephonyCellularData TelephonySmsMms TelephonyStateRegistry TelephonyCoreService 4011 TelephonyIms ModuleUpdateService UsbService WindowManagerService DisplayManagerService DSoftbus DeviceAuthService DeviceManagerService StorageDaemon StorageManager HdfDeviceServiceManager CloudFileDaemonService EcologicalRuleManager UiService UiAppearanceService CaDaemon AssetService 9527 65537 65570 65728 65777 65830 65850 65888 65904 65926 65958 65962 66070 66090 70633 </pre> 获取到abilities后,就可以指定service获取相关的信息。 比如通过RenderService获取一些信息 <pre>$ hdc shell hidumper -s RenderService -------------------------------[ability]------------------------------- ----------------------------------RenderService--------------------------------- ------Graphic2D--RenderSerice ------ Usage: h |help text for the tool screen |dump all screen infomation in the system surface |dump all surface information composer fps |dump the fps info of composer [surface name] fps |dump the fps info of surface composer fpsClear |clear the fps info of composer [windowname] fps |dump the fps info of window [windowname] hitchs |dump the hitchs info of window [surface name] fpsClear |clear the fps info of surface nodeNotOnTree |dump nodeNotOnTree info allSurfacesMem |dump surface mem info RSTree |dump RSTree info EventParamList |dump EventParamList info allInfo |dump all info dumpMem |dump Cache trimMem cpu/gpu/shader |release Cache surfacenode [id] |dump node info fpsCount |dump the refresh rate counts info clearFpsCount |clear the refresh rate counts info</pre> '''获取分辩率''' <pre>$ hdc shell hidumper -s RenderService -a screen -------------------------------[ability]------------------------------- ----------------------------------RenderService--------------------------------- -- ScreenInfo screen[0]: id=0, powerstatus=POWER_STATUS_OFF, backlight=21, screenType=EXTERNAL_TYPE, render size: 1260x2720, physical screen resolution: 1260x2720, isvirtual=false, skipFrameInterval_:1 supportedMode[0]: 1260x2720, refreshrate=120 supportedMode[1]: 1260x2720, refreshrate=90 supportedMode[2]: 1260x2720, refreshrate=60 supportedMode[3]: 1260x2720, refreshrate=30 activeMode: 1260x2720, refreshrate=60 capability: name=, phywidth=72, phyheight=156,supportlayers=12, virtualDispCount=0, propCount=0, type=DISP_INTF_HDMI, supportWriteBack=false</pre> '''获取帧率''' 首先执行如下命令进入到shell环境 <pre>$ hdc shell</pre> 然后执行<code>hidumper [surface name] fps</code> , 例如<code>composer fps</code> <pre>$ hidumper -s RenderService -a "composer fps" -------------------------------[ability]------------------------------- ----------------------------------RenderService--------------------------------- -- The recently fps records info of screens: The fps of screen [Id:0] is: 107537646652857 107537663200253 107537679747128 107537696352336 107537712846086 107537729390357 107537745974211 107537762468482 107537779015357 107537795561190 107537812110148 107537828651815 107537845349732 ...</pre> = aa工具 = Ability assistant(Ability助手,简称为aa),是实现应用及测试用例启动功能的工具,为开发者提供基本的应用调试和测试能力,例如启动应用组件、强制停止进程、打印应用组件相关信息等。 <pre>$ hdc shell aa help usage: aa <command> <options> These are common aa commands list: help list available commands start start ability with options stop-service stop service with options dump dump the ability info force-stop <bundle-name> force stop the process with bundle name attach attach application to enter debug mdoe detach detach application to exit debug mode test start the test framework with options appdebug set / cancel / get waiting debug status</pre> 详细介绍请参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/tools/aa-tool.md = bm工具 = Bundle Manager(包管理工具,简称bm)是实现应用安装、卸载、更新、查询等功能的工具,bm为开发者提供基本的应用安装包的调试能力,例如:安装应用,卸载应用,查询安装包信息等。 <pre>$ hdc shell bm help usage: bm <command> <options> These are common bm commands list: help list available commands install install a bundle with options uninstall uninstall a bundle with options dump dump the bundle info get obtain device udid quickfix quick fix, including query and install compile Compile the software package dump-overlay dump overlay info of the specific overlay bundle dump-target-overlay dump overlay info of the specific target bundle dump-dependencies dump dependencies by given bundle name and module name dump-shared dump inter-application shared library information by bundle name clean clean the bundle data</pre> 详细介绍请参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/tools/bm-tool.md = param工具 = param是为开发人员提供用于操作系统参数的工具,该工具只支持标准系统。 <pre>$ hdc shell param Command list: param ls [-r] [name] --display system parameter param get [name] --get system parameter param set name value --set system parameter param wait name [value] [timeout] --wait system parameter param dump [verbose] --dump system parameter param shell [-p] [name] [-u] [username] [-g] [groupname] --shell system parameter param save </pre> 详细介绍请参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/tools/param-tool.md = 设备日志 = <pre>$ hdc hilog -h Usage: -h --help Show all help information. Show single help information with option: query/clear/buffer/stats/persist/private/kmsg/flowcontrol/baselevel/domain/combo Querying logs options: No option performs a blocking read and keeps printing. -x --exit Performs a non-blocking read and exits when all logs in buffer are printed. -a <n>, --head=<n> Show n lines logs on head of buffer. -z <n>, --tail=<n> Show n lines logs on tail of buffer. -t <type>, --type=<type> Show specific type/types logs with format: type1,type2,type3 Don't show specific type/types logs with format: ^type1,type2,type3 Type coule be: app/core/init/kmsg, kmsg can't combine with others. Default types are: app,core,init. -L <level>, --level=<level> Show specific level/levels logs with format: level1,level2,level3 Don't show specific level/levels logs with format: ^level1,level2,level3 Long and short level string are both accepted Long level string coule be: DEBUG/INFO/WARN/ERROR/FATAL. Short level string coule be: D/I/W/E/F. Default levels are all levels. -D <domain>, --domain=<domain> Show specific domain/domains logs with format: domain1,domain2,doman3 Don't show specific domain/domains logs with format: ^domain1,domain2,doman3 Max domain count is 5. See domain description at the end of this message. -T <tag>, --tag=<tag> Show specific tag/tags logs with format: tag1,tag2,tag3 Don't show specific tag/tags logs with format: ^tag1,tag2,tag3 Max tag count is 10. -P <pid>, --pid=<pid> Show specific pid/pids logs with format: pid1,pid2,pid3 Don't show specific domain/domains logs with format: ^pid1,pid2,pid3 Max pid count is 5. -e <expr>, --regex=<expr> Show the logs which match the regular expression <expr>. -v <format>, --format=<format> Show logs in different formats, options are: color or colour display colorful logs by log level.i.e. DEBUG INFO WARN ERROR FATAL time format options are(single accepted): time display local time, this is default. epoch display the time from 1970/1/1. monotonic display the cpu time from bootup. time accuracy format options are(single accepted): msec display time by millisecond, this is default. usec display time by microsecond. nsec display time by nanosecond. year display the year when -v time is specified. zone display the time zone when -v time is specified. Different types of formats can be combined, such as: -v color -v time -v msec -v year -v zone. -r Remove all logs in hilogd buffer, advanced option: -t <type>, --type=<type> Remove specific type/types logs in buffer with format: type1,type2,type3 Type coule be: app/core/init/kmsg. Default types are: app,core -g Query hilogd buffer size, advanced option: -t <type>, --type=<type> Query specific type/types buffer size with format: type1,type2,type3 Type coule be: app/core/init/kmsg. Default types are: app,core -G <size>, --buffer-size=<size> Set hilogd buffer size, <size> could be number or number with unit. Unit could be: B/K/M/G which represents Byte/Kilobyte/Megabyte/Gigabyte. <size> range: [64.0K,64.0K]. Advanced option: -t <type>, --type=<type> Set specific type/types log buffer size with format: type1,type2,type3 Type coule be: app/core/init/kmsg. Default types are: app,core **It's a persistant configuration** -s, --statistics Query log statistic information. Set param persist.sys.hilog.stats true to enable statistic. Set param persist.sys.hilog.stats.tag true to enable statistic of log tag. -S Clear hilogd statistic information. -w <control>,--write=<control> Log persistance task control, options are: query query tasks informations stop stop all tasks start start one task clear clear /data/log/hilog/hilog*.gz Persistance task is used for saving logs in files. The files are saved in directory: /data/log/hilog/ Advanced options: -f <filename>, --filename=<filename> Set log file name, name should be valid of Linux FS. -l <length>, --length=<length> Set single log file size. <length> could be number or number with unit. Unit could be: B/K/M/G which represents Byte/Kilobyte/Megabyte/Gigabyte. <length> range: [64.0K, 512.0M]. -n <number>, --number<number> Set max log file numbers, log file rotate when files count over this number. <number> range: [2, 1000]. -m <compress algorithm>,--stream=<compress algorithm> Set log file compressed algorithm, options are: none write file with non-compressed logs. zlib write file with zlib compressed logs. -j <jobid>, --jobid<jobid> Start/stop specific task of <jobid>. <jobid> range: [10, 0xffffffff). User can start task with options (t/L/D/T/P/e/v) as if using them when "Query logs" too. **It's a persistant configuration** -p <on/off>, --privacy <on/off> Set HILOG api privacy formatter feature on or off. **It's a temporary configuration, will be lost after reboot** -k <on/off>, --kmsg <on/off> Set hilogd storing kmsg log feature on or off **It's a persistant configuration** -Q <control-type> Set log flow-control feature on or off, options are: pidon process flow control on pidoff process flow control off domainon domain flow control on domainoff domain flow control off **It's a temporary configuration, will be lost after reboot** -b <loglevel>, --baselevel=<loglevel> Set global loggable level to <loglevel> Long and short level string are both accepted. Long level string coule be: DEBUG/INFO/WARN/ERROR/FATAL/X. Short level string coule be: D/I/W/E/F/X. X means that loggable level is higher than the max level, no log could be printed. Advanced options: -D <domain>, --domain=<domain> Set specific domain loggable level. See domain description at the end of this message. -T <tag>, --tag=<tag> Set specific tag loggable level. The priority is: tag level > domain level > global level. **It's a temporary configuration, will be lost after reboot** The first layer options can't be used in combination, ILLEGAL expamples: hilog -S -s; hilog -w start -r; hilog -p on -k on -b D Domain description: Log type "core" & "init" are used for OS subsystems, the range is [0xd000000, 0xd0fffff] Log type "app" is used for applications, the range is [0x0, 0xffff] To reduce redundant info when printing logs, only last five hex numbers of domain are printed So if user wants to use -D option to filter OS logs, user should add 0xD0 as prefix to the printed domain: Exapmle: hilog -D 0xD0xxxxx The xxxxx is the domain string printed in logs. Dictionary description: -d <path>, --dictionary=<path> Set elf file path, name should be valid of Linux FS. Rescan the elf file in the system to generate a full data dictionary file </pre> <span id="instrument-test"></span> = Instrument Test = 主要用来做APP 的UI自动化测试,将应用测试包安装到测试设备上,在cmd窗口中执行aa命令,完成对用例测试。 <code>aa test</code>命令执行配置参数 {| class="wikitable" |- ! 执行参数全写 ! 执行参数缩写 ! 执行参数含义 ! 执行参数示例 |- | –bundleName | -b | 应用 Bundle 名称 | -b com.test.example |- | –packageName | -p | 应用模块名,适用于 FA 模型应用 | -p com.test.example.entry |- | –moduleName | -m | 应用模块名,适用于 STAGE 模型应用 | -m entry |- | NA | -s | 特定参数,以 <key, value> 键值对方式传入 | -s unittest /ets/testrunner/OpenHarmonyTestRunner |} <pre>$ hdc shell aa test -h usage: aa test <options> options list: -h, --help list available commands -b <bundle-name> -s unittest <test-runner> start the test framework with options [-p <package-name>] the name of package with test-runner, required for the FA model [-m <module-name>] the name of module with test-runner, required for the STAGE model [-s class <test-class>] [-s level <test-level>] [-s size <test-size>] [-s testType <test-testType>] [-s timeout <test-timeout>] [-s <any-key> <any-value>] [-w <wait-time>] [-D]</pre> '''举例''' <pre>$ hdc shell aa test -b com.example.myapplication -m entry_test -s unittest /ets/testrunner/OpenHarmonyTestRunner -s class UiTestDemo timeout 15000</pre> 查看测试结果 cmd模式执行过程,会打印如下相关日志信息。 <pre>OHOS_REPORT_STATUS: class=testStop OHOS_REPORT_STATUS: current=1 OHOS_REPORT_STATUS: id=JS OHOS_REPORT_STATUS: numtests=447 OHOS_REPORT_STATUS: stream= OHOS_REPORT_STATUS: test=stop_0 OHOS_REPORT_STATUS_CODE: 1 OHOS_REPORT_STATUS: class=testStop OHOS_REPORT_STATUS: current=1 OHOS_REPORT_STATUS: id=JS OHOS_REPORT_STATUS: numtests=447 OHOS_REPORT_STATUS: stream= OHOS_REPORT_STATUS: test=stop_0 OHOS_REPORT_STATUS_CODE: 0 OHOS_REPORT_STATUS: consuming=4 OHOS_REPORT_RESULT: stream=Tests run: 447, Failure: 0, Error: 1, Pass: 201, Ignore: 245 OHOS_REPORT_CODE: 0 OHOS_REPORT_RESULT: breakOnError model, Stopping whole test suite if one specific test case failed or error OHOS_REPORT_STATUS: taskconsuming=16029</pre> = 性能工具 = <code>SmartPerf</code>是一款基于系统开发的性能功耗测试工具,操作简单易用。工具可以检测性能、功耗相关指标,包括<code>FPS</code>、<code>CPU</code>、<code>GPU</code>、<code>RAM</code>、<code>Temp</code>等,通过量化的指标项了解应用性能状况。在开发过程中,使用的可能是有屏或无屏设备,对此<code>SmartPerf</code>提供了两种方式:分别是<code>SmartPerf-Device</code>和<code>SmartPerf-Daemon</code>。<code>SmartPerf-Device</code>适用于有屏设备,支持可视化操作。测试时是通过悬浮窗的开始和暂停来实时展示性能指标数据,保存后可生成数据报告,在报告中可分析各指标数据详情。<code>SmartPerf-Daemon</code>支持<code>shell命令行</code>方式,同时适用于有屏和无屏设备。 * CPU:每秒读取一次设备节点下CPU大中小核的频点和各核使用率,衡量应用占用CPU资源的情况,占用过多的CPU资源会导致芯片发烫。 * GPU:每秒读取一次设备节点下GPU的频点和负载信息,衡量应用占用GPU资源的情况,当GPU占用过多时,会导致性能下降,应用程序的运行速度变慢。 * FPS:应用界面每秒刷新次数,衡量应用画面的流畅度,FPS越高表示图像流畅度越好,用户体验也越好。 * POWER:每秒读取一次设备节点下的电流及电压信息。 * TEMP:每秒读取一次设备节点下电池温度、系统芯片温度等信息。 * RAM:每秒读取一次应用进程的实际物理内存,衡量应用的内存占比情况。 * snapshot:每秒截取一张应用界面截图。 <pre>$ hdc shell # SP_daemon // 查看daemon进程是否存在 # ps -ef | grep SP_daemon root 1584 1 0 21:50:05 ? 00:00:00 SP_daemon root 1595 1574 3 21:51:02 pts/0 00:00:00 grep SP_daemon </pre> 执行查看帮助命令 <pre># SP_daemon --help OpenHarmony performance testing tool SmartPerf command-line version Usage: SP_daemon [options] [arguments] options: -N set the collection times(default value is 0) range[1,2147483647], for example: -N 10 -PKG set package name, must add, for example: -PKG ohos.samples.ecg -c get device CPU frequency and CPU usage, process CPU usage and CPU load .. -g get device GPU frequency and GPU load -f get app refresh fps(frames per second) and fps jitters and refreshrate -profilerfps get refresh fps and timestamp -sections set collection time period(using with profilerfps) -t get remaining battery power and temperature.. -p get battery power consumption and voltage -r get process memory and total memory -snapshot get screen capture -net get uplink and downlink traffic -start collection start command -stop collection stop command -VIEW set layler, for example: -VIEW DisplayNode -screen get screen resolution -OUT set csv output path. -d get device DDR information -m get other memory example: SP_daemon -N 20 -c -g -t -p -r -m -net -snapshot -d SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -m -net -snapshot -d SP_daemon -start -c SP_daemon -stop SP_daemon -screen</pre> 基于<code>hdc</code>命令行的<code>SmartPerf</code>性能工具使用详细文档参考这个:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/application-test/smartperf-guidelines.md = 参考链接 = * https://github.com/codematrixer/awesome-hdc * https://gitee.com/openharmony/developtools_hdc * https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V2/ide-command-line-hdc-0000001237908229-V2#section116322265308 * https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/application-test/smartperf-guidelines.md * https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/tools/aa-tool.md * https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/tools/bm-tool.md * https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/tools/param-tool.md * https://github.com/mzlogin/awesome-adb
返回
HDC命令
。