首页 > 代码库 > dumpsys工作原理初探
dumpsys工作原理初探
dumpsys用来dump某系统组件的信息:
*./frameworks/av/native/cmds/dumpsys/dumpsys.cpp* ``` sp<IServiceManager> sm = defaultServiceManager(); //... for (size_t i=0; i<N; i++) { sp<IBinder> service = sm->checkService(services[i]); if (service != NULL) { //... int err = service->dump(STDOUT_FILENO, args); } } ```
从上面实现代码得知,dumpsys特指dump注册在ServiceManager里的`Service`, 每个`Service`都可以通过实现`dump`接口来说明自己的信息
以media.player为例:
*./frameworks/av/media/mediaserver/main_mediaserver.cpp* ``` int main(int argc, char** argv) { MediaPlayerService::instatiate(); } ``` *./frameworks/av/media/libmediaplayerservice/MediaPlayerService.cpp* ``` void MediaPlayerService::instantiate() { defaultServiceManager()->addService( String16("media.player"), new MediaPlayerService()); } ```
mediaserver进程在ServiceManager里注册了`Service`,名字叫做"media.player",最终dump实现:
``` status_t MediaPlayerService::Client::dump(...) const { String8 result; result.append(" Client\n"); snprintf(buffer, 255, " pid(%d), connId(%d), status(%d), looping(%s)\n", mPid, mConnId, mStatus, mLoop?"true": "false"); result.append(buffer); write(fd, result.string(), result.size()); if (mPlayer != NULL) { mPlayer->dump(fd, args); } if (mAudioOutput != 0) { mAudioOutput->dump(fd, args); } write(fd, "\n", 1); } ```
当有视频播放的时候,敲入`dumpsys media.player`命令,可以输出:
``` ? ~ adb shell dumpsys media.player Client pid(17882), connId(5), status(0), looping(false) AwesomePlayer URI(suppressed), flags(0x00000008) Track 1 MIME(video/avc) videoDimensions(-1 x -1), numVideoFramesDecoded(0), numVideoFramesDropped(0) Track 2 MIME(audio/mp4a-latm) AudioOutput stream type(3), left - right volume(1.000000, 1.000000) msec per frame(0.000000), latency (-1) aux effect id(0), send level (0.000000) No media recorder client Files opened and/or mapped: ```
扩展阅读:
利用`dumpsys statusbar`做一个寻找statusbar所属包名的应用
android中dumpsys函数介绍与使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。