blob: 7dad6b625b6a998056b351e96aa3ebbc436b23f1 [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>
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 ALOGE("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 if (N > 1) {
55 // first print a list of the current services
56 aout << "Currently running services:" << endl;
57
58 for (size_t i=0; i<N; i++) {
59 sp<IBinder> service = sm->checkService(services[i]);
60 if (service != NULL) {
61 aout << " " << services[i] << endl;
62 }
63 }
64 }
65
66 for (size_t i=0; i<N; i++) {
67 sp<IBinder> service = sm->checkService(services[i]);
68 if (service != NULL) {
69 if (N > 1) {
70 aout << "------------------------------------------------------------"
71 "-------------------" << endl;
72 aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
73 }
74 int err = service->dump(STDOUT_FILENO, args);
75 if (err != 0) {
76 aerr << "Error dumping service info: (" << strerror(err)
77 << ") " << services[i] << endl;
78 }
79 } else {
80 aerr << "Can't find service: " << services[i] << endl;
81 }
82 }
83
84 return 0;
85}