1/* 2 * Command that dumps interesting system state to the log. 3 * 4 */ 5 6#define LOG_TAG "dumpsys" 7 8#include <utils/Log.h> 9#include <utils/Parcel.h> 10#include <utils/ProcessState.h> 11#include <utils/IServiceManager.h> 12#include <utils/TextOutput.h> 13#include <utils/Vector.h> 14 15#include <getopt.h> 16#include <stdlib.h> 17#include <stdio.h> 18#include <string.h> 19#include <unistd.h> 20#include <sys/time.h> 21 22using namespace android; 23 24static int sort_func(const String16* lhs, const String16* rhs) 25{ 26 return lhs->compare(*rhs); 27} 28 29int main(int argc, char* const argv[]) 30{ 31 sp<IServiceManager> sm = defaultServiceManager(); 32 fflush(stdout); 33 if (sm == NULL) { 34 LOGE("Unable to get default service manager!"); 35 aerr << "dumpsys: Unable to get default service manager!" << endl; 36 return 20; 37 } 38 39 Vector<String16> services; 40 Vector<String16> args; 41 if (argc == 1) { 42 services = sm->listServices(); 43 services.sort(sort_func); 44 args.add(String16("-a")); 45 } else { 46 services.add(String16(argv[1])); 47 for (int i=2; i<argc; i++) { 48 args.add(String16(argv[i])); 49 } 50 } 51 52 const size_t N = services.size(); 53 54 // first print a list of the current services 55 aout << "Currently running services:" << endl; 56 57 for (size_t i=0; i<N; i++) { 58 sp<IBinder> service = sm->checkService(services[i]); 59 if (service != NULL) { 60 aout << " " << services[i] << endl; 61 } 62 } 63 64 for (size_t i=0; i<N; i++) { 65 sp<IBinder> service = sm->checkService(services[i]); 66 if (service != NULL) { 67 aout << "------------------------------------------------------------" 68 "-------------------" << endl; 69 aout << "DUMP OF SERVICE " << services[i] << ":" << endl; 70 int err = service->dump(STDOUT_FILENO, args); 71 if (err != 0) { 72 aerr << "Error dumping service info: (" << strerror(err) 73 << ") " << services[i] << endl; 74 } 75 } else { 76 aerr << "Can't find service: " << services[i] << endl; 77 } 78 } 79 80 return 0; 81} 82