Dumpsys is used to dump the information of a system component:
*./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); } } ```
The above implementation code shows that dumpsys refers to the 'service' registered by dump in servicemanager. Each 'service' can describe its own information through the 'dump 'interface.
Take media. player as an example:
*./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());}```
The mediaserver process registers a 'service' in servicemanager and the name is "media. player". Finally, dump is implemented:
```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);}```
When a video is played, run the 'dumpsys media. play' command to output the following information:
```? ~ 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:```
Additional reading: