The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 17 | #include <errno.h> |
| 18 | #include <fcntl.h> |
| 19 | #include <limits.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <sys/resource.h> |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 24 | #include <sys/stat.h> |
| 25 | #include <sys/time.h> |
Dan Egnor | efd1393 | 2010-03-08 13:04:13 -0800 | [diff] [blame] | 26 | #include <sys/wait.h> |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 27 | #include <unistd.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 29 | #include <cutils/properties.h> |
| 30 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include "private/android_filesystem_config.h" |
| 32 | |
Mike Lockwood | bb6fa17 | 2009-10-05 23:23:40 -0400 | [diff] [blame] | 33 | #define LOG_TAG "dumpstate" |
| 34 | #include <utils/Log.h> |
| 35 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include "dumpstate.h" |
| 37 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 38 | /* read before root is shed */ |
| 39 | static char cmdline_buf[16384] = "(unknown)"; |
| 40 | static const char *dump_traces_path = NULL; |
San Mehat | 30b9f57 | 2009-09-01 13:27:20 -0700 | [diff] [blame] | 41 | |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 42 | static char screenshot_path[PATH_MAX] = ""; |
| 43 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | /* dumps the current system state to stdout */ |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 45 | static void dumpstate() { |
| 46 | time_t now = time(NULL); |
| 47 | char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX]; |
| 48 | char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX]; |
| 49 | char network[PROPERTY_VALUE_MAX], date[80]; |
John Michelau | 790d2e4 | 2011-07-05 15:20:03 -0500 | [diff] [blame] | 50 | char build_type[PROPERTY_VALUE_MAX]; |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 51 | |
| 52 | property_get("ro.build.display.id", build, "(unknown)"); |
| 53 | property_get("ro.build.fingerprint", fingerprint, "(unknown)"); |
John Michelau | 790d2e4 | 2011-07-05 15:20:03 -0500 | [diff] [blame] | 54 | property_get("ro.build.type", build_type, "(unknown)"); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 55 | property_get("ro.baseband", radio, "(unknown)"); |
| 56 | property_get("ro.bootloader", bootloader, "(unknown)"); |
| 57 | property_get("gsm.operator.alpha", network, "(unknown)"); |
| 58 | strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now)); |
| 59 | |
| 60 | printf("========================================================\n"); |
| 61 | printf("== dumpstate: %s\n", date); |
| 62 | printf("========================================================\n"); |
| 63 | |
| 64 | printf("\n"); |
| 65 | printf("Build: %s\n", build); |
| 66 | printf("Bootloader: %s\n", bootloader); |
| 67 | printf("Radio: %s\n", radio); |
| 68 | printf("Network: %s\n", network); |
| 69 | |
| 70 | printf("Kernel: "); |
| 71 | dump_file(NULL, "/proc/version"); |
| 72 | printf("Command line: %s\n", strtok(cmdline_buf, "\n")); |
| 73 | printf("\n"); |
| 74 | |
Colin Cross | 5965ba3 | 2011-09-20 15:49:14 -0700 | [diff] [blame] | 75 | run_command("UPTIME", 10, "uptime", NULL); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 76 | dump_file("MEMORY INFO", "/proc/meminfo"); |
| 77 | run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-t", NULL); |
| 78 | run_command("PROCRANK", 20, "procrank", NULL); |
| 79 | dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat"); |
| 80 | dump_file("VMALLOC INFO", "/proc/vmallocinfo"); |
| 81 | dump_file("SLAB INFO", "/proc/slabinfo"); |
| 82 | dump_file("ZONEINFO", "/proc/zoneinfo"); |
Arve Hjønnevåg | 351e74de1 | 2011-08-15 19:43:35 -0700 | [diff] [blame] | 83 | dump_file("PAGETYPEINFO", "/proc/pagetypeinfo"); |
JP Abgrall | 2eb8e36 | 2011-08-24 11:24:33 -0700 | [diff] [blame] | 84 | dump_file("BUDDYINFO", "/proc/buddyinfo"); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 85 | |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 86 | if (screenshot_path[0]) { |
Steve Block | 933e856 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 87 | ALOGI("taking screenshot\n"); |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 88 | run_command(NULL, 5, "su", "root", "screenshot", screenshot_path, NULL); |
Steve Block | 933e856 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 89 | ALOGI("wrote screenshot: %s\n", screenshot_path); |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Wink Saville | 2f791fd | 2010-10-07 13:38:09 -0700 | [diff] [blame] | 92 | run_command("SYSTEM LOG", 20, "logcat", "-v", "threadtime", "-d", "*:v", NULL); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 93 | |
| 94 | /* show the traces we collected in main(), if that was done */ |
| 95 | if (dump_traces_path != NULL) { |
| 96 | dump_file("VM TRACES JUST NOW", dump_traces_path); |
| 97 | } |
| 98 | |
| 99 | /* only show ANR traces if they're less than 15 minutes old */ |
| 100 | struct stat st; |
| 101 | char anr_traces_path[PATH_MAX]; |
| 102 | property_get("dalvik.vm.stack-trace-file", anr_traces_path, ""); |
Dan Egnor | efd1393 | 2010-03-08 13:04:13 -0800 | [diff] [blame] | 103 | if (!anr_traces_path[0]) { |
| 104 | printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); |
| 105 | } else if (stat(anr_traces_path, &st)) { |
| 106 | printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno)); |
| 107 | } else { |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 108 | dump_file("VM TRACES AT LAST ANR", anr_traces_path); |
| 109 | } |
| 110 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 111 | /* slow traces for slow operations */ |
| 112 | if (anr_traces_path[0] != 0) { |
| 113 | int tail = strlen(anr_traces_path)-1; |
| 114 | while (tail > 0 && anr_traces_path[tail] != '/') { |
| 115 | tail--; |
| 116 | } |
| 117 | int i = 0; |
| 118 | while (1) { |
| 119 | sprintf(anr_traces_path+tail+1, "slow%02d.txt", i); |
| 120 | if (stat(anr_traces_path, &st)) { |
| 121 | // No traces file at this index, done with the files. |
| 122 | break; |
| 123 | } |
| 124 | dump_file("VM TRACES WHEN SLOW", anr_traces_path); |
| 125 | i++; |
| 126 | } |
| 127 | } |
| 128 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 129 | // dump_file("EVENT LOG TAGS", "/etc/event-log-tags"); |
Wink Saville | 2f791fd | 2010-10-07 13:38:09 -0700 | [diff] [blame] | 130 | run_command("EVENT LOG", 20, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL); |
| 131 | run_command("RADIO LOG", 20, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 132 | |
Dmitry Shmidt | 2c3197b | 2010-11-03 16:59:47 -0700 | [diff] [blame] | 133 | run_command("NETWORK INTERFACES", 10, "su", "root", "netcfg", NULL); |
JP Abgrall | 20e93c0 | 2011-09-19 22:29:18 -0700 | [diff] [blame] | 134 | dump_file("NETWORK DEV INFO", "/proc/net/dev"); |
| 135 | dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all"); |
| 136 | dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl"); |
| 137 | run_command("QTAGUID STATS INFO", 10, "su", "root", "cat", "/proc/net/xt_qtaguid/stats", NULL); |
| 138 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 139 | dump_file("NETWORK ROUTES", "/proc/net/route"); |
Robert Greenwalt | 5f2ff42 | 2011-04-28 17:10:23 -0700 | [diff] [blame] | 140 | dump_file("NETWORK ROUTES IPV6", "/proc/net/ipv6_route"); |
Robert Greenwalt | e83d181 | 2011-11-21 14:44:39 -0800 | [diff] [blame] | 141 | run_command("IP RULES", 10, "ip", "rule", "show", NULL); |
| 142 | run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL); |
| 143 | run_command("ROUTE TABLE 60", 10, "ip", "route", "show", "table", "60", NULL); |
| 144 | run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "60", NULL); |
| 145 | run_command("ROUTE TABLE 61", 10, "ip", "route", "show", "table", "61", NULL); |
| 146 | run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "61", NULL); |
Dmitry Shmidt | 84b72ec | 2010-02-23 15:21:11 -0800 | [diff] [blame] | 147 | dump_file("ARP CACHE", "/proc/net/arp"); |
JP Abgrall | 2eb8e36 | 2011-08-24 11:24:33 -0700 | [diff] [blame] | 148 | run_command("IPTABLES", 10, "su", "root", "iptables", "-L", "-nvx", NULL); |
| 149 | run_command("IP6TABLES", 10, "su", "root", "ip6tables", "-L", "-nvx", NULL); |
John Michelau | ac74551 | 2011-07-25 20:42:50 -0500 | [diff] [blame] | 150 | run_command("IPTABLE NAT", 10, "su", "root", "iptables", "-t", "nat", "-L", "-n", NULL); |
JP Abgrall | 2eb8e36 | 2011-08-24 11:24:33 -0700 | [diff] [blame] | 151 | run_command("IPT6ABLE NAT", 10, "su", "root", "ip6tables", "-t", "nat", "-L", "-n", NULL); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 152 | |
Dmitry Shmidt | 631e0f1 | 2010-05-26 10:57:11 -0700 | [diff] [blame] | 153 | run_command("WIFI NETWORKS", 20, |
| 154 | "su", "root", "wpa_cli", "list_networks", NULL); |
| 155 | |
Dmitry Shmidt | 9abfeb4 | 2011-03-28 13:45:21 -0700 | [diff] [blame] | 156 | property_get("dhcp.wlan0.gateway", network, ""); |
| 157 | if (network[0]) |
| 158 | run_command("PING GATEWAY", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL); |
| 159 | property_get("dhcp.wlan0.dns1", network, ""); |
| 160 | if (network[0]) |
| 161 | run_command("PING DNS1", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL); |
| 162 | property_get("dhcp.wlan0.dns2", network, ""); |
| 163 | if (network[0]) |
| 164 | run_command("PING DNS2", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL); |
Dmitry Shmidt | 64bf3d5 | 2009-12-16 16:05:08 -0800 | [diff] [blame] | 165 | #ifdef FWDUMP_bcm4329 |
Dmitry Shmidt | 5500c4f | 2010-09-01 16:18:14 -0700 | [diff] [blame] | 166 | run_command("DUMP WIFI STATUS", 20, |
Dmitry Shmidt | 285a8f5 | 2011-02-14 11:08:01 -0800 | [diff] [blame] | 167 | "su", "root", "dhdutil", "-i", "wlan0", "dump", NULL); |
Dmitry Shmidt | 2b79919 | 2010-11-04 14:39:24 -0700 | [diff] [blame] | 168 | run_command("DUMP WIFI INTERNAL COUNTERS", 20, |
| 169 | "su", "root", "wlutil", "counters", NULL); |
Dmitry Shmidt | 64bf3d5 | 2009-12-16 16:05:08 -0800 | [diff] [blame] | 170 | #endif |
San Mehat | 30b9f57 | 2009-09-01 13:27:20 -0700 | [diff] [blame] | 171 | |
Jake Hamby | 9c27e36 | 2011-11-17 13:20:35 -0800 | [diff] [blame] | 172 | char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0}; |
John Michelau | 71bbe7a | 2010-09-22 16:49:19 -0500 | [diff] [blame] | 173 | property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30"); |
John Michelau | 790d2e4 | 2011-07-05 15:20:03 -0500 | [diff] [blame] | 174 | if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) { |
| 175 | if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) { |
| 176 | // su does not exist on user builds, so try running without it. |
| 177 | // This way any implementations of vril-dump that do not require |
| 178 | // root can run on user builds. |
| 179 | run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout), |
| 180 | "vril-dump", NULL); |
| 181 | } else { |
| 182 | run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout), |
| 183 | "su", "root", "vril-dump", NULL); |
| 184 | } |
John Michelau | 71bbe7a | 2010-09-22 16:49:19 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 187 | print_properties(); |
Iliyan Malchev | 326e3e2 | 2009-11-15 18:28:06 -0800 | [diff] [blame] | 188 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 189 | run_command("KERNEL LOG", 20, "dmesg", NULL); |
Iliyan Malchev | 326e3e2 | 2009-11-15 18:28:06 -0800 | [diff] [blame] | 190 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 191 | dump_file("KERNEL WAKELOCKS", "/proc/wakelocks"); |
| 192 | dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state"); |
Mike Lockwood | 2ecf3f5e0 | 2009-10-04 17:21:05 -0400 | [diff] [blame] | 193 | |
San Mehat | 9e3f8c6 | 2010-03-17 09:50:25 -0700 | [diff] [blame] | 194 | run_command("VOLD DUMP", 10, "vdc", "dump", NULL); |
San Mehat | 54aa577 | 2010-03-08 08:58:03 -0800 | [diff] [blame] | 195 | run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL); |
San Mehat | 54aa577 | 2010-03-08 08:58:03 -0800 | [diff] [blame] | 196 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 197 | run_command("PROCESSES", 10, "ps", "-P", NULL); |
| 198 | run_command("PROCESSES AND THREADS", 10, "ps", "-t", "-p", "-P", NULL); |
| 199 | run_command("LIBRANK", 10, "librank", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 201 | dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log"); |
| 202 | dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log"); |
| 203 | dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions"); |
| 204 | dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats"); |
| 205 | dump_file("BINDER STATE", "/sys/kernel/debug/binder/state"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | |
JP Abgrall | 8935bca | 2011-01-21 22:32:00 -0800 | [diff] [blame] | 207 | run_command("FILESYSTEMS & FREE SPACE", 10, "su", "root", "df", NULL); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 208 | |
| 209 | dump_file("PACKAGE SETTINGS", "/data/system/packages.xml"); |
| 210 | dump_file("PACKAGE UID ERRORS", "/data/system/uiderrors.txt"); |
| 211 | |
| 212 | dump_file("LAST KMSG", "/proc/last_kmsg"); |
| 213 | run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL); |
| 214 | dump_file("LAST PANIC CONSOLE", "/data/dontpanic/apanic_console"); |
| 215 | dump_file("LAST PANIC THREADS", "/data/dontpanic/apanic_threads"); |
| 216 | |
San Mehat | 57fff78 | 2010-04-27 10:53:35 -0700 | [diff] [blame] | 217 | for_each_pid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS"); |
| 218 | |
Dan Egnor | ea11654 | 2010-01-26 17:04:26 -0800 | [diff] [blame] | 219 | printf("------ BACKLIGHTS ------\n"); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 220 | printf("LCD brightness="); |
| 221 | dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness"); |
| 222 | printf("Button brightness="); |
| 223 | dump_file(NULL, "/sys/class/leds/button-backlight/brightness"); |
| 224 | printf("Keyboard brightness="); |
| 225 | dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness"); |
| 226 | printf("ALS mode="); |
| 227 | dump_file(NULL, "/sys/class/leds/lcd-backlight/als"); |
| 228 | printf("LCD driver registers:\n"); |
| 229 | dump_file(NULL, "/sys/class/leds/lcd-backlight/registers"); |
| 230 | printf("\n"); |
| 231 | |
Jeff Brown | c74a028 | 2011-08-11 20:07:39 -0700 | [diff] [blame] | 232 | run_command("LIST OF OPEN FILES", 10, "su", "root", "lsof", NULL); |
| 233 | |
Dianne Hackborn | 5123468 | 2011-11-03 19:19:28 -0700 | [diff] [blame] | 234 | for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES"); |
| 235 | |
Colin Cross | 1e9f56c | 2011-07-18 16:56:35 -0700 | [diff] [blame] | 236 | #ifdef BOARD_HAS_DUMPSTATE |
| 237 | printf("========================================================\n"); |
| 238 | printf("== Board\n"); |
| 239 | printf("========================================================\n"); |
| 240 | |
| 241 | dumpstate_board(); |
| 242 | printf("\n"); |
| 243 | #endif |
| 244 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 245 | printf("========================================================\n"); |
| 246 | printf("== Android Framework Services\n"); |
| 247 | printf("========================================================\n"); |
| 248 | |
| 249 | /* the full dumpsys is starting to take a long time, so we need |
| 250 | to increase its timeout. we really need to do the timeouts in |
| 251 | dumpsys itself... */ |
| 252 | run_command("DUMPSYS", 60, "dumpsys", NULL); |
Joe Onorato | eb95b08 | 2010-10-21 14:54:19 -0400 | [diff] [blame] | 253 | |
| 254 | printf("========================================================\n"); |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 255 | printf("== Running Application Activities\n"); |
Joe Onorato | eb95b08 | 2010-10-21 14:54:19 -0400 | [diff] [blame] | 256 | printf("========================================================\n"); |
| 257 | |
Dianne Hackborn | e17aeb3 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 258 | run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL); |
| 259 | |
| 260 | printf("========================================================\n"); |
| 261 | printf("== Running Application Services\n"); |
| 262 | printf("========================================================\n"); |
| 263 | |
| 264 | run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL); |
Joe Onorato | eb95b08 | 2010-10-21 14:54:19 -0400 | [diff] [blame] | 265 | |
Colin Cross | 1e9f56c | 2011-07-18 16:56:35 -0700 | [diff] [blame] | 266 | printf("========================================================\n"); |
| 267 | printf("== dumpstate: done\n"); |
| 268 | printf("========================================================\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 271 | static void usage() { |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 272 | fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s]\n" |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 273 | " -o: write to file (instead of stdout)\n" |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 274 | " -d: append date to filename (requires -o)\n" |
| 275 | " -z: gzip output (requires -o)\n" |
| 276 | " -p: capture screenshot to filename.png (requires -o)\n" |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 277 | " -s: write output to control socket (for init)\n" |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 278 | " -b: play sound file instead of vibrate, at beginning of job\n" |
| 279 | " -e: play sound file instead of vibrate, at end of job\n" |
| 280 | ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | int main(int argc, char *argv[]) { |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 284 | int do_add_date = 0; |
| 285 | int do_compress = 0; |
| 286 | char* use_outfile = 0; |
Paul Eastham | bfb071d | 2010-08-06 14:11:55 -0700 | [diff] [blame] | 287 | char* begin_sound = 0; |
| 288 | char* end_sound = 0; |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 289 | int use_socket = 0; |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 290 | int do_fb = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | |
Steve Block | 933e856 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 292 | ALOGI("begin\n"); |
Mike Lockwood | bb6fa17 | 2009-10-05 23:23:40 -0400 | [diff] [blame] | 293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /* set as high priority, and protect from OOM killer */ |
| 295 | setpriority(PRIO_PROCESS, 0, -20); |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 296 | FILE *oom_adj = fopen("/proc/self/oom_adj", "w"); |
| 297 | if (oom_adj) { |
| 298 | fputs("-17", oom_adj); |
| 299 | fclose(oom_adj); |
| 300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 302 | /* very first thing, collect VM traces from Dalvik (needs root) */ |
| 303 | dump_traces_path = dump_vm_traces(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 305 | int c; |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 306 | while ((c = getopt(argc, argv, "b:de:ho:svzp")) != -1) { |
Mike Lockwood | 8d53373 | 2009-09-02 18:01:05 -0400 | [diff] [blame] | 307 | switch (c) { |
Paul Eastham | bfb071d | 2010-08-06 14:11:55 -0700 | [diff] [blame] | 308 | case 'b': begin_sound = optarg; break; |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 309 | case 'd': do_add_date = 1; break; |
Paul Eastham | bfb071d | 2010-08-06 14:11:55 -0700 | [diff] [blame] | 310 | case 'e': end_sound = optarg; break; |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 311 | case 'o': use_outfile = optarg; break; |
| 312 | case 's': use_socket = 1; break; |
| 313 | case 'v': break; // compatibility no-op |
| 314 | case 'z': do_compress = 6; break; |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 315 | case 'p': do_fb = 1; break; |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 316 | case '?': printf("\n"); |
| 317 | case 'h': |
| 318 | usage(); |
Mike Lockwood | 8d53373 | 2009-09-02 18:01:05 -0400 | [diff] [blame] | 319 | exit(1); |
| 320 | } |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 321 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 323 | /* open the vibrator before dropping root */ |
| 324 | FILE *vibrator = fopen("/sys/class/timed_output/vibrator/enable", "w"); |
| 325 | if (vibrator) fcntl(fileno(vibrator), F_SETFD, FD_CLOEXEC); |
| 326 | |
| 327 | /* read /proc/cmdline before dropping root */ |
| 328 | FILE *cmdline = fopen("/proc/cmdline", "r"); |
| 329 | if (cmdline != NULL) { |
| 330 | fgets(cmdline_buf, sizeof(cmdline_buf), cmdline); |
| 331 | fclose(cmdline); |
| 332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
Nick Kralevich | 77d87aa | 2010-10-21 09:14:14 -0700 | [diff] [blame] | 334 | if (getuid() == 0) { |
| 335 | /* switch to non-root user and group */ |
John Michelau | 790d2e4 | 2011-07-05 15:20:03 -0500 | [diff] [blame] | 336 | gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT, AID_INET }; |
Nick Kralevich | 77d87aa | 2010-10-21 09:14:14 -0700 | [diff] [blame] | 337 | if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 338 | ALOGE("Unable to setgroups, aborting: %s\n", strerror(errno)); |
Nick Kralevich | 77d87aa | 2010-10-21 09:14:14 -0700 | [diff] [blame] | 339 | return -1; |
| 340 | } |
| 341 | if (setgid(AID_SHELL) != 0) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 342 | ALOGE("Unable to setgid, aborting: %s\n", strerror(errno)); |
Nick Kralevich | 77d87aa | 2010-10-21 09:14:14 -0700 | [diff] [blame] | 343 | return -1; |
| 344 | } |
| 345 | if (setuid(AID_SHELL) != 0) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 346 | ALOGE("Unable to setuid, aborting: %s\n", strerror(errno)); |
Nick Kralevich | 77d87aa | 2010-10-21 09:14:14 -0700 | [diff] [blame] | 347 | return -1; |
| 348 | } |
Nick Kralevich | 05f0382 | 2010-08-31 18:17:31 -0700 | [diff] [blame] | 349 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 351 | char path[PATH_MAX], tmp_path[PATH_MAX]; |
| 352 | pid_t gzip_pid = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 354 | if (use_socket) { |
| 355 | redirect_to_socket(stdout, "dumpstate"); |
| 356 | } else if (use_outfile) { |
| 357 | strlcpy(path, use_outfile, sizeof(path)); |
| 358 | if (do_add_date) { |
| 359 | char date[80]; |
| 360 | time_t now = time(NULL); |
| 361 | strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", localtime(&now)); |
| 362 | strlcat(path, date, sizeof(path)); |
Mike Lockwood | 8d53373 | 2009-09-02 18:01:05 -0400 | [diff] [blame] | 363 | } |
Daniel Sandler | 27e1a79 | 2010-07-27 14:46:34 -0400 | [diff] [blame] | 364 | if (do_fb) { |
| 365 | strlcpy(screenshot_path, path, sizeof(screenshot_path)); |
| 366 | strlcat(screenshot_path, ".png", sizeof(screenshot_path)); |
| 367 | } |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 368 | strlcat(path, ".txt", sizeof(path)); |
| 369 | if (do_compress) strlcat(path, ".gz", sizeof(path)); |
| 370 | strlcpy(tmp_path, path, sizeof(tmp_path)); |
| 371 | strlcat(tmp_path, ".tmp", sizeof(tmp_path)); |
| 372 | gzip_pid = redirect_to_file(stdout, tmp_path, do_compress); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Paul Eastham | bfb071d | 2010-08-06 14:11:55 -0700 | [diff] [blame] | 375 | if (begin_sound) { |
| 376 | play_sound(begin_sound); |
| 377 | } else if (vibrator) { |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 378 | fputs("150", vibrator); |
| 379 | fflush(vibrator); |
| 380 | } |
| 381 | |
| 382 | dumpstate(); |
| 383 | |
Paul Eastham | bfb071d | 2010-08-06 14:11:55 -0700 | [diff] [blame] | 384 | if (end_sound) { |
| 385 | play_sound(end_sound); |
| 386 | } else if (vibrator) { |
Dan Egnor | 52952b1 | 2010-01-13 12:27:50 -0800 | [diff] [blame] | 387 | int i; |
| 388 | for (i = 0; i < 3; i++) { |
| 389 | fputs("75\n", vibrator); |
| 390 | fflush(vibrator); |
| 391 | usleep((75 + 50) * 1000); |
| 392 | } |
| 393 | fclose(vibrator); |
| 394 | } |
| 395 | |
| 396 | /* wait for gzip to finish, otherwise it might get killed when we exit */ |
| 397 | if (gzip_pid > 0) { |
| 398 | fclose(stdout); |
| 399 | waitpid(gzip_pid, NULL, 0); |
| 400 | } |
| 401 | |
| 402 | /* rename the (now complete) .tmp file to its final location */ |
| 403 | if (use_outfile && rename(tmp_path, path)) { |
| 404 | fprintf(stderr, "rename(%s, %s): %s\n", tmp_path, path, strerror(errno)); |
| 405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
Steve Block | 933e856 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 407 | ALOGI("done\n"); |
Mike Lockwood | bb6fa17 | 2009-10-05 23:23:40 -0400 | [diff] [blame] | 408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | return 0; |
| 410 | } |