blob: fdc5d5d63ecfa845c918ccb11365dd6d4ccce999 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Command that dumps interesting system state to the log.
3 *
4 */
5
6#define LOG_TAG "dumpsys"
7
8#include <utils/Log.h>
Mathias Agopian07952722009-05-19 19:08:10 -07009#include <binder/Parcel.h>
10#include <binder/ProcessState.h>
11#include <binder/IServiceManager.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012#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
Dianne Hackbornc59411b2009-12-21 20:10:14 -080054 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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 }
64 }
65
66 for (size_t i=0; i<N; i++) {
67 sp<IBinder> service = sm->checkService(services[i]);
68 if (service != NULL) {
Dianne Hackbornc59411b2009-12-21 20:10:14 -080069 if (N > 1) {
70 aout << "------------------------------------------------------------"
71 "-------------------" << endl;
72 aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
73 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 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}