龙空技术网

鸿蒙宝藏小工具:HiDumper

51CTO 187

前言:

眼前看官们对“js pagehide”大约比较关怀,小伙伴们都想要分析一些“js pagehide”的相关文章。那么小编同时在网上搜集了一些有关“js pagehide””的相关知识,希望各位老铁们能喜欢,你们快快来学习一下吧!

HiDumper 是 OpenHarmony 中为开发、测试人员,IDE 工具提供统一的系统信息获取工具,帮助使用者分析,定位问题。

HiDumper 主要包括以下几个主要模块:

hidumper:可执行程序,工具入口,在板上可通过 hidumper 执行对应命令hidumperclient:动态库,提供 framework 层接口lib_dump_usage:动态库,提供 framework 层功能实现hidumperservice:动态库,sa 服务,提供 service 层功能实现结构分析:

.├── BUILD.gn├── bundle.json├── client│   └── native│       ├── dump_client_main.cpp    │       └── main.cpp                //可执行文件入口├── figures├── frameworks                        //框架实现│   └── native│       ├── BUILD.gn│       ├── common.h│       ├── dump_controller.h│       ├── dump_utils.cpp│       ├── dump_utils.h│       ├── include│       └── src├── hidumper.gni├── interfaces│   ├── innerkits│   │   ├── BUILD.gn│   │   ├── dump_usage.cpp│   │   └── include│   └── native│       └── innerkits├── LICENSE├── OAT.xml├── README.md├── README_zh.md├── sa_profile├── services                        //服务实现│   ├── BUILD.gn│   ├── hidumper.map│   ├── native│   │   ├── etc│   │   ├── include│   │   └── src│   └── zidl│       ├── include│       └── src├── test└── utils

usage:

"usage:\n"        "  -h                          |help text for the tool\n"        "  -lc                         |a list of system information clusters\n"        "  -ls                         |a list of system abilities\n"        "  -c                          |all system information clusters\n"        "  -c [base system]            |system information clusters labeled \"base\" and \"system\"\n"        "  -s                          |all system abilities\n"        "  -s [SA0 SA1]                |system abilities labeled \"SA0\" and \"SA1\"\n"        "  -s [SA] -a ['-h']           |system ability labeled \"SA\" with arguments \"-h\" specified\n"        "  -e                          |faultlogs of crash history\n"        "  --net                       |dump network information\n"        "  --storage                   |dump storage information\n"        "  -p                          |processes information, include list and infromation of processes"        " and threads\n"        "  -p [pid]                    |dump threads under pid, includes smap, block channel,"        " execute time, mountinfo\n"        "  --cpuusage [pid]            |dump cpu usage by processes and category; if PID is specified,"        " dump category usage of specified pid\n"        "  --cpufreq                   |dump real CPU frequency of each core\n"        "  --mem [pid]                 |dump memory usage of total; dump memory usage of specified"        " pid if pid was specified\n"        "  --zip                       |compress output to /data/log/hidumper\n";

如上,我们可以看出hidumper能查看几乎OpenHarmony里内的所有信息,比如:

查看系统 ability 信息,其中也包括 HiDumperService:

# hidumper -lsSystem ability list:RenderService                    AbilityManagerService            DataObserverMgrUriPermissionMgr                 AccountMgr                       BundleMgrFormMgr                          ApplicationManagerService        InstalldAccessibilityManagerService      UserIdmService                   UserAuthServiceAuthExecutorMgrService           PinAuthService                   FaceAuthServiceWifiDevice                       WifiHotspot                      WifiP2pWifiScan                         BluetoothHost                    NetConnManagerNetPolicyManager                 NetStatsManager                  NetTetheringManagerEthernetManager                  NetsysNative                     HiviewServiceHiviewFaultLogger                HiviewSysEventService            HiDumperServiceDistributedKvData                DistributedSched                 EnterpriseDeviceManagerServiceResourceSched                    BackgroundTaskManager            WorkScheduleSocPerfService                   DeviceUsageStatistics            MemoryManagerServiceLocationGeoConvert               LocationLocator                  LocationGnssLocationNetworkLocating          LocationNopowerLocating          DeviceStatusServiceAudioDistributed                 PlayerDistributedService         CameraServiceAudioPolicyService               AVSessionService                 MultimodalInputDistributedNotificationService   CommonEventService               PowerManagerServiceBatteryService                   ThermalService                   BatteryStatisticsServiceDisplayPowerManagerService       AccessTokenManagerService        PrivacyManagerServiceKeystoreService                  CertManagerService               SensorServiceMiscDeviceService                PasteboardService                TimeServiceInputMethodService               ScreenlockService                WallpaperManagerServiceParamWatcher                     SysParamDevice                   TelephonyCellularCallTelephonyCellularData            TelephonySmsMms                  TelephonyStateRegistryTelephonyCoreService             UsbService                       WindowManagerServiceDisplayManagerService            DSoftbus                         DeviceAuthServiceDeviceManagerService             StorageDaemon                    StorageManagerHdfDeviceServiceManager          DistributedFileDaemon            devattest_serviceDistributedDeviceProfile         UiService

查看系统 ability 信息,其中也包括 HiDumperService:

-------------------------------[ability]-----------------------------------------------------------------RenderService---------------------------------------Graphic2D--RenderSerice ------Usage: h                             |help text for the toolscreen                         |dump all screen infomation in the systemsurface                        |dump all surface informationcomposer fps                   |dump the fps info of composer[surface name] fps             |dump the fps info of surfacecomposer fpsClear                   |clear the fps info of composer[surface name] fpsClear             |clear the fps info of surfacenodeNotOnTree                  |dump nodeNotOnTree infoallSurfacesMem                 |dump surface mem infoRSTree                         |dump RSTree infoEventParamList                 |dump EventParamList infoallInfo                        |dump all info...后面有好多

查看系统网络信息:

#hidumper --net-------------------------------[net]-------------------------------cmd is: netstat -nWActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address                                       Foreign Address                                     State      udp        0      0 127.0.0.1:44451                                     127.0.0.1:9877                                      ESTABLISHEDudp        0      0 127.0.0.1:37649                                     127.0.0.1:9877                                      ESTABLISHEDActive UNIX domain sockets (w/o servers)Proto RefCnt Flags     Type       State       I-Node Pathunix  2      [ ]         DGRAM                        1675 /dev/unix/socket/fd_holderunix  74     [ ]         DGRAM                         344 /dev/unix/socket/hilogInputunix  2      [ ]         DGRAM                        1719 /dev/unix/socket/hisyseventunix  2      [ ]         SEQPACKET                   24844 /dev/unix/socket/hdcd...后面还有好多

查看系统进程信息:

#hidumper -p-------------------------------[processes]-------------------------------cmd is: ps -efTUID            PID   TID  PPID TCNT STIME TTY          TIME CMDroot             1     1     0    1 15:55:05 ?     00:00:03 init --second-stageroot             2     2     0    1 15:55:05 ?     00:00:00 [kthreadd]root             3     3     2    1 15:55:05 ?     00:00:00 [rcu_gp]root             4     4     2    1 15:55:05 ?     00:00:00 [rcu_par_gp]root             8     8     2    1 15:55:05 ?     00:00:00 [mm_percpu_wq]root             9     9     2    1 15:55:05 ?     00:00:00 [rcu_tasks_rude_]...后面还有好多

查看系统内存信息:

#hidumper --mem-------------------------------[memory]-------------------------------Total Memory Usage by PID:PID  Name                Total Pss(xxx in SwapPss)   Total Vss   Total Rss   Total Uss          GL       Graph1        init               1217(0 in SwapPss) kB     4612 kB     3600 kB      828 kB        0 kB        0 kB241      watchdog_servic    260(0 in SwapPss) kB     3160 kB     2320 kB      232 kB        0 kB        0 kB253      hilogd             2414(0 in SwapPss) kB     5968 kB     4576 kB     2252 kB        0 kB        0 kB254      hdf_devmgr         600(0 in SwapPss) kB     6440 kB     3320 kB      496 kB        0 kB        0 kB255      hiview             4780(0 in SwapPss) kB    79168 kB    14752 kB     3148 kB        0 kB        0 kB256      storage_daemon     1539(0 in SwapPss) kB    11404 kB     7024 kB      932 kB        0 kB        0 kB...后面有好多

查看系统错误:

#hidumper -e-------------------------------[faultlog]-------------------------------/data/log/faultlog/faultlogger/jscrash-ohos.samples.videoplayer-20010040-20230328160126Generated by HiviewDFX@OpenHarmony================================================================Device info:OpenHarmony 3.2Build info:OpenHarmony 3.2.11.2Module name:ohos.samples.videoplayerVersion:1.0.0Pid:1763Uid:20010040Lifetime: 0.000000sJs-Engine: arkpage: pages/Player.jsError message: assertion (false) failed: type mismatchStacktrace:    at clearVideoPlayer (/ets/pages/Player.ets:213:7)    at onPageHide (/ets/pages/Player.ets:200:5)...后面还有好多

从上面列举的一些命令可以看出 hidumper 是个集成入口,有些用了 Linux 下的常规命令,如 ps,netstat,有些用 OH 内特制的内容,如 systemability,faultlog。

基本原理

hidumper 同 OHOS 里的其他服务一样都提供 framework 和 service 架构,通过 IPC 方式通过 hidumperservice 服务执行具体命令。

功能定义:在下面的问题提供三部分内容:

base/hiviewdfx/hidumper/frameworks/native/src/util/config_data.cpp1. 功能定义const std::string ConfigData::CONFIG_NAME_SPLIT = "_";const std::string ConfigData::CONFIG_GROUP = "group";...const std::string ConfigData::CONFIG_DUMPER_LIST_SYSTEM_ABILITY = ConfigData::CONFIG_DUMPER_LIST_ + "system_ability";...const std::string ConfigData::STR_ABILITY = "ability";const std::string ConfigData::STR_BASE = "base";const std::string ConfigData::STR_SERVICE = "service";const std::string ConfigData::STR_SYSTEM = "system";2. dumper方法const ConfigData::ItemCfg ConfigData::baseInfoDumper_[] = {    {        .name_ = "dumper_base_info",        .desc_ = "Base Information",        .target_ = "",        .section_ = "",        .class_ = DumperConstant::API_DUMPER,        .level_ = DumperConstant::NONE,        .loop_ = DumperConstant::NONE,        .filterCfg_ = "",    },    {        .name_ = "",        .desc_ = "",        .target_ = "",        .section_ = "",        .class_ = DumperConstant::FD_OUTPUT,        .level_ = DumperConstant::NONE,        .loop_ = DumperConstant::NONE,        .filterCfg_ = "",    },};3. 功能组定义...const std::string ConfigData::testGroup_[] = {    "dumper_test",};const ConfigData::GroupCfg ConfigData::groups_[] = {    {        .name_ = ConfigData::CONFIG_GROUP_CPU_FREQ,        .desc_ = "group of cpu freq dumper",        .list_ = cpuFreqGroup_,        .size_ = ARRAY_SIZE(cpuFreqGroup_),        .type_ = DumperConstant::GROUPTYPE_CPUID,        .expand_ = true,    },...

简单调用流程:

graph LRmain --> DumpManagerClient --> DumpManagerService --> DumpImplement

功能实现流程:

graph LRCmdParse --> GetDumperConfigs --> GetExecutorConfigList --> setExecutorList --> SetProgressEnabled --> DumpDatas

如下:

CmdParse: 解析命令GetDumperConfigs: 获取配置GetExecutorConfigList: 根据配置获取执行命令setExecutorList: 生成执行命令列表,通过 ptrExecutorFactoryMap_ 获得对应 executorSetProgressEnabled: 设置执行开关DumpDatas: 执行命令,获取输出信息

executor 实现:

//命令调用popen 对应 dumper里.class_ = DumperConstant::CMD_DUMPER,//文件读取fdopen 对应 dumper里 .class_ = DumperConstant::FILE_DUMPER,//api接口读取提供对应的API调用,如GetDisplayVersion, 对应 dumper里 .class_ = DumperConstant::API_DUMPER,

小结

本章我们讲了 hidumper,作为开发者的查询工具,通过此工具可以查询系统信息,服务信息,进程栈等信息。

通过此工具可以协助开发者发现一些系统运行信息,比如进程,线程,内存,CPU 等信息;当然也可自己根据具体内容实现实现自己的对应查看工具。

标签: #js pagehide