android 中的dumpsys

文章出处:http://blog.csdn.net/shift_wwx

请转载的朋友标明出处~~


首先来看一下dumpsys的source code:

path:frameworks/native/cmds/dumpsys

#define LOG_TAG "dumpsys"

#include <utils/Log.h>
#include <binder/Parcel.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/TextOutput.h>
#include <utils/Vector.h>

#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>

using namespace android;

static int sort_func(const String16* lhs, const String16* rhs)
{
    return lhs->compare(*rhs);
}

int main(int argc, char* const argv[])
{
    signal(SIGPIPE, SIG_IGN);
    sp<IServiceManager> sm = defaultServiceManager();
    fflush(stdout);
    if (sm == NULL) {
		ALOGE("Unable to get default service manager!");
        aerr << "dumpsys: Unable to get default service manager!" << endl;
        return 20;
    }

    Vector<String16> services;
    Vector<String16> args;
    bool showListOnly = false;
    if ((argc == 2) && (strcmp(argv[1], "-l") == 0)) {
        showListOnly = true;
    }
    if ((argc == 1) || showListOnly) {
        services = sm->listServices();
        services.sort(sort_func);
        args.add(String16("-a"));
    } else {
    	 if((argc == 2) && 0 == strcmp(argv[1], "list")){
	 	services = sm->listServices();
		services.sort(sort_func);
		const size_t N = services.size();
	       aout << "Currently running services:" << endl;
    
		for (size_t i=0; i<N; i++) {
		     aout << "  " << services[i] << endl;
		}
		return 0;
	  }
	 else{
	        services.add(String16(argv[1]));
	        for (int i=2; i<argc; i++) {
	            args.add(String16(argv[i]));
	        }
	 }
    }

    const size_t N = services.size();

    if (N > 1) {
        // first print a list of the current services
        aout << "Currently running services:" << endl;
    
        for (size_t i=0; i<N; i++) {
            sp<IBinder> service = sm->checkService(services[i]);
            if (service != NULL) {
                aout << "  " << services[i] << endl;
            }
        }
    }

    if (showListOnly) {
        return 0;
    }

    for (size_t i=0; i<N; i++) {
        sp<IBinder> service = sm->checkService(services[i]);
        if (service != NULL) {
            if (N > 1) {
                aout << "------------------------------------------------------------"
                        "-------------------" << endl;
                aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
            }
            int err = service->dump(STDOUT_FILENO, args);
            if (err != 0) {
                aerr << "Error dumping service info: (" << strerror(err)
                        << ") " << services[i] << endl;
            }
        } else {
            aerr << "Can't find service: " << services[i] << endl;
        }
    }

    return 0;
}

从code中可以看到对参数的要求:

1. 当没有参数的时候会,list出所有的services,然后dump出来信息

2. 当参数是-l 或者是list的时候,只会list出所有的services

3. 当参数后面是service name的时候,会dump出service的信息


dumpsys -l:

  SurfaceFlinger
  accessibility
  account
  activity
  alarm
  android.security.keystore
  appops
  appwidget
  audio
  backup
  battery
  batterypropreg
  batterystats
  clipboard
  commontime_management
  connectivity
  consumer_ir
  content
  country_detector
  cpuinfo
  dbinfo
  device_policy
  devicestoragemonitor
  diskstats
  display
  dreams
  drm.drmManager
  dropbox
  entropy
  ethernet
  gfxinfo
  hardware
  image.player
  input
  input_method
  iphonesubinfo
  isms
  location
  lock_settings
  mbox_outputmode_service
  media.audio_flinger
  media.audio_policy
  media.camera
  media.player
  media_router
  meminfo
  mount
  netpolicy
  netstats
  network_management
  notification
  package
  permission
  phone
  power
  pppoe
  print
  procstats
  samplingprofiler
  scheduling_policy
  search
  sensorservice
  serial
  servicediscovery
  simphonebook
  sip
  statusbar
  subtitle_service
  system_write
  telephony.registry
  textservices
  uimode
  updatelock
  usagestats
  usb
  user
  vibrator
  wallpaper
  wifi
  wifip2p
  window

从code中,可以看出,

         else{
	        services.add(String16(argv[1]));
	        for (int i=2; i<argc; i++) {
	            args.add(String16(argv[i]));
	        }
	 }

 
 

将命令的第二个参数add到services,然后后面的都作为services的参数。

所以后面有点没看懂,为什么N会大于1?

最终所有的dump信息都是通过函数:

int err = service->dump(STDOUT_FILENO, args);

而这个service对象,是Ibinder类,所以其实可以看出来最终调用的是Ibinder类里面的dump函数,那么接下来就好办了。详细的binder机制,这里不再多说明。


下面来详细说明一下这个service。

1. meminfo

这个是比较常用的service,可以看一下:android 查看内存使用情况


2. cpuinfo

可以看一下:dumpsys cpuinfo


3. window


4. surfaceflinger



你可能感兴趣的:(android,window,dumpsys,meminfo,surfaceflinger)