blob: ce8993d6e93f7cdc0ae1a36dad3654b1c97143c1 [file] [log] [blame]
Colin Crossf45fa6b2012-03-26 12:38:26 -07001/*
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 <binder/Parcel.h>
10#include <binder/ProcessState.h>
11#include <binder/IServiceManager.h>
Mathias Agopian002e1e52013-05-06 20:20:50 -070012#include <binder/TextOutput.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070013#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{
JP Abgrall3e03d3f2012-05-11 14:14:09 -070031 signal(SIGPIPE, SIG_IGN);
Colin Crossf45fa6b2012-03-26 12:38:26 -070032 sp<IServiceManager> sm = defaultServiceManager();
33 fflush(stdout);
34 if (sm == NULL) {
35 ALOGE("Unable to get default service manager!");
36 aerr << "dumpsys: Unable to get default service manager!" << endl;
37 return 20;
38 }
39
40 Vector<String16> services;
41 Vector<String16> args;
keunyoungcaad5552013-06-13 15:08:51 -070042 bool showListOnly = false;
43 if ((argc == 2) && (strcmp(argv[1], "-l") == 0)) {
44 showListOnly = true;
45 }
46 if ((argc == 1) || showListOnly) {
Colin Crossf45fa6b2012-03-26 12:38:26 -070047 services = sm->listServices();
48 services.sort(sort_func);
49 args.add(String16("-a"));
50 } else {
51 services.add(String16(argv[1]));
52 for (int i=2; i<argc; i++) {
53 args.add(String16(argv[i]));
54 }
55 }
56
57 const size_t N = services.size();
58
59 if (N > 1) {
60 // first print a list of the current services
61 aout << "Currently running services:" << endl;
62
63 for (size_t i=0; i<N; i++) {
64 sp<IBinder> service = sm->checkService(services[i]);
65 if (service != NULL) {
66 aout << " " << services[i] << endl;
67 }
68 }
69 }
70
keunyoungcaad5552013-06-13 15:08:51 -070071 if (showListOnly) {
72 return 0;
73 }
74
Colin Crossf45fa6b2012-03-26 12:38:26 -070075 for (size_t i=0; i<N; i++) {
76 sp<IBinder> service = sm->checkService(services[i]);
77 if (service != NULL) {
78 if (N > 1) {
79 aout << "------------------------------------------------------------"
80 "-------------------" << endl;
81 aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
82 }
83 int err = service->dump(STDOUT_FILENO, args);
84 if (err != 0) {
85 aerr << "Error dumping service info: (" << strerror(err)
86 << ") " << services[i] << endl;
87 }
88 } else {
89 aerr << "Can't find service: " << services[i] << endl;
90 }
91 }
92
93 return 0;
94}