Loading cmds/dumpstate/dumpstate.cpp +59 −60 Original line number Original line Diff line number Diff line Loading @@ -602,7 +602,7 @@ static int dump_stat_from_fd(const char *title __unused, const char *path, int f path += sizeof(mmcblk0) - 1; path += sizeof(mmcblk0) - 1; } } dprintf(STDOUT_FILENO, "%s: %s\n", path, buffer); printf("%s: %s\n", path, buffer); free(buffer); free(buffer); if (fields[__STAT_IO_TICKS]) { if (fields[__STAT_IO_TICKS]) { Loading Loading @@ -639,11 +639,10 @@ static int dump_stat_from_fd(const char *title __unused, const char *path, int f / fields[__STAT_IO_TICKS]; / fields[__STAT_IO_TICKS]; if (!write_perf && !write_ios) { if (!write_perf && !write_ios) { dprintf(STDOUT_FILENO, "%s: perf(ios) rd: %luKB/s(%lu/s) q: %u\n", path, read_perf, printf("%s: perf(ios) rd: %luKB/s(%lu/s) q: %u\n", path, read_perf, read_ios, queue); read_ios, queue); } else { } else { dprintf(STDOUT_FILENO, "%s: perf(ios) rd: %luKB/s(%lu/s) wr: %luKB/s(%lu/s) q: %u\n", printf("%s: perf(ios) rd: %luKB/s(%lu/s) wr: %luKB/s(%lu/s) q: %u\n", path, read_perf, path, read_perf, read_ios, write_perf, write_ios, queue); read_ios, write_perf, write_ios, queue); } } /* bugreport timeout factor adjustment */ /* bugreport timeout factor adjustment */ Loading Loading @@ -673,27 +672,25 @@ void Dumpstate::PrintHeader() const { network = android::base::GetProperty("gsm.operator.alpha", "(unknown)"); network = android::base::GetProperty("gsm.operator.alpha", "(unknown)"); strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now_)); strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now_)); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== dumpstate: %s\n", date); printf("== dumpstate: %s\n", date); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "\n"); printf("\n"); dprintf(STDOUT_FILENO, "Build: %s\n", build.c_str()); printf("Build: %s\n", build.c_str()); // NOTE: fingerprint entry format is important for other tools. // NOTE: fingerprint entry format is important for other tools. dprintf(STDOUT_FILENO, "Build fingerprint: '%s'\n", fingerprint.c_str()); printf("Build fingerprint: '%s'\n", fingerprint.c_str()); dprintf(STDOUT_FILENO, "Bootloader: %s\n", bootloader.c_str()); printf("Bootloader: %s\n", bootloader.c_str()); dprintf(STDOUT_FILENO, "Radio: %s\n", radio.c_str()); printf("Radio: %s\n", radio.c_str()); dprintf(STDOUT_FILENO, "Network: %s\n", network.c_str()); printf("Network: %s\n", network.c_str()); dprintf(STDOUT_FILENO, "Kernel: "); printf("Kernel: "); fsync(STDOUT_FILENO); DumpFileToFd(STDOUT_FILENO, "", "/proc/version"); DumpFileToFd(STDOUT_FILENO, "", "/proc/version"); dprintf(STDOUT_FILENO, "Command line: %s\n", strtok(cmdline_buf, "\n")); printf("Command line: %s\n", strtok(cmdline_buf, "\n")); dprintf(STDOUT_FILENO, "Bugreport format version: %s\n", version_.c_str()); printf("Bugreport format version: %s\n", version_.c_str()); dprintf(STDOUT_FILENO, "Dumpstate info: id=%d pid=%d dry_run=%d args=%s extra_options=%s\n", printf("Dumpstate info: id=%d pid=%d dry_run=%d args=%s extra_options=%s\n", id_, pid_, id_, pid_, PropertiesHelper::IsDryRun(), args_.c_str(), extra_options_.c_str()); PropertiesHelper::IsDryRun(), args_.c_str(), extra_options_.c_str()); dprintf(STDOUT_FILENO, "\n"); printf("\n"); fsync(STDOUT_FILENO); } } // List of file extensions that can cause a zip file attachment to be rejected by some email // List of file extensions that can cause a zip file attachment to be rejected by some email Loading Loading @@ -857,13 +854,13 @@ static void AddAnrTraceFiles() { dump_traces_dir.c_str(), anr_traces_dir.c_str(), already_dumped); dump_traces_dir.c_str(), anr_traces_dir.c_str(), already_dumped); if (anr_traces_path.empty()) { if (anr_traces_path.empty()) { dprintf(STDOUT_FILENO, "*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); } else { } else { int fd = TEMP_FAILURE_RETRY( int fd = TEMP_FAILURE_RETRY( open(anr_traces_path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)); open(anr_traces_path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)); if (fd < 0) { if (fd < 0) { dprintf(STDOUT_FILENO, "*** NO ANR VM TRACES FILE (%s): %s\n\n", printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path.c_str(), anr_traces_path.c_str(), strerror(errno)); strerror(errno)); } else { } else { if (add_to_zip) { if (add_to_zip) { if (!already_dumped) { if (!already_dumped) { Loading Loading @@ -1003,7 +1000,7 @@ static void dumpstate() { } } } } if (!dumped) { if (!dumped) { dprintf(STDOUT_FILENO, "*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR); printf("*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR); } } DumpFile("NETWORK DEV INFO", "/proc/net/dev"); DumpFile("NETWORK DEV INFO", "/proc/net/dev"); Loading Loading @@ -1076,18 +1073,18 @@ static void dumpstate() { RunCommand("LAST RADIO LOG", {"parse_radio_log", "/proc/last_radio_log"}); RunCommand("LAST RADIO LOG", {"parse_radio_log", "/proc/last_radio_log"}); dprintf(STDOUT_FILENO, "------ BACKLIGHTS ------\n"); printf("------ BACKLIGHTS ------\n"); dprintf(STDOUT_FILENO, "LCD brightness="); printf("LCD brightness="); DumpFile("", "/sys/class/leds/lcd-backlight/brightness"); DumpFile("", "/sys/class/leds/lcd-backlight/brightness"); dprintf(STDOUT_FILENO, "Button brightness="); printf("Button brightness="); DumpFile("", "/sys/class/leds/button-backlight/brightness"); DumpFile("", "/sys/class/leds/button-backlight/brightness"); dprintf(STDOUT_FILENO, "Keyboard brightness="); printf("Keyboard brightness="); DumpFile("", "/sys/class/leds/keyboard-backlight/brightness"); DumpFile("", "/sys/class/leds/keyboard-backlight/brightness"); dprintf(STDOUT_FILENO, "ALS mode="); printf("ALS mode="); DumpFile("", "/sys/class/leds/lcd-backlight/als"); DumpFile("", "/sys/class/leds/lcd-backlight/als"); dprintf(STDOUT_FILENO, "LCD driver registers:\n"); printf("LCD driver registers:\n"); DumpFile("", "/sys/class/leds/lcd-backlight/registers"); DumpFile("", "/sys/class/leds/lcd-backlight/registers"); dprintf(STDOUT_FILENO, "\n"); printf("\n"); /* Binder state is expensive to look at as it uses a lot of memory. */ /* Binder state is expensive to look at as it uses a lot of memory. */ DumpFile("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log"); DumpFile("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log"); Loading @@ -1112,16 +1109,16 @@ static void dumpstate() { RunCommand("DUMP VENDOR RIL LOGS", {"vril-dump"}, options.Build()); RunCommand("DUMP VENDOR RIL LOGS", {"vril-dump"}, options.Build()); } } dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Android Framework Services\n"); printf("== Android Framework Services\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("DUMPSYS", {"--skip", "meminfo", "cpuinfo"}, CommandOptions::WithTimeout(90).Build(), RunDumpsys("DUMPSYS", {"--skip", "meminfo", "cpuinfo"}, CommandOptions::WithTimeout(90).Build(), 10); 10); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Checkins\n"); printf("== Checkins\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); RunDumpsys("CHECKIN MEMINFO", {"meminfo", "--checkin"}); RunDumpsys("CHECKIN MEMINFO", {"meminfo", "--checkin"}); Loading @@ -1130,21 +1127,21 @@ static void dumpstate() { RunDumpsys("CHECKIN USAGESTATS", {"usagestats", "-c"}); RunDumpsys("CHECKIN USAGESTATS", {"usagestats", "-c"}); RunDumpsys("CHECKIN PACKAGE", {"package", "--checkin"}); RunDumpsys("CHECKIN PACKAGE", {"package", "--checkin"}); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Running Application Activities\n"); printf("== Running Application Activities\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("APP ACTIVITIES", {"activity", "all"}); RunDumpsys("APP ACTIVITIES", {"activity", "all"}); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Running Application Services\n"); printf("== Running Application Services\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("APP SERVICES", {"activity", "service", "all"}); RunDumpsys("APP SERVICES", {"activity", "service", "all"}); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Running Application Providers\n"); printf("== Running Application Providers\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("APP PROVIDERS", {"activity", "provider", "all"}); RunDumpsys("APP PROVIDERS", {"activity", "provider", "all"}); Loading @@ -1153,20 +1150,19 @@ static void dumpstate() { // collected. // collected. DumpModemLogs(); DumpModemLogs(); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Final progress (pid %d): %d/%d (estimated %d)\n", ds.pid_, printf("== Final progress (pid %d): %d/%d (estimated %d)\n", ds.pid_, ds.progress_->Get(), ds.progress_->Get(), ds.progress_->GetMax(), ds.progress_->GetInitialMax()); ds.progress_->GetMax(), ds.progress_->GetInitialMax()); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== dumpstate: done (id %d)\n", ds.id_); printf("== dumpstate: done (id %d)\n", ds.id_); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); } } void Dumpstate::DumpstateBoard() { void Dumpstate::DumpstateBoard() { DurationReporter duration_reporter("dumpstate_board()"); DurationReporter duration_reporter("dumpstate_board()"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Board\n"); printf("== Board\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); fsync(STDOUT_FILENO); android::sp<android::hardware::dumpstate::V1_0::IDumpstateDevice> dumpstate_device( android::sp<android::hardware::dumpstate::V1_0::IDumpstateDevice> dumpstate_device( android::hardware::dumpstate::V1_0::IDumpstateDevice::getService("DumpstateDevice")); android::hardware::dumpstate::V1_0::IDumpstateDevice::getService("DumpstateDevice")); Loading Loading @@ -1204,8 +1200,7 @@ void Dumpstate::DumpstateBoard() { dumpstate_device->dumpstateBoard(handle); dumpstate_device->dumpstateBoard(handle); AddZipEntry("dumpstate-board.txt", path); AddZipEntry("dumpstate-board.txt", path); dprintf(STDOUT_FILENO, "*** See dumpstate-board.txt entry ***\n"); printf("*** See dumpstate-board.txt entry ***\n"); fsync(STDOUT_FILENO); native_handle_close(handle); native_handle_close(handle); native_handle_delete(handle); native_handle_delete(handle); Loading Loading @@ -1632,6 +1627,10 @@ int main(int argc, char *argv[]) { ds.tmp_path_.c_str(), strerror(errno)); ds.tmp_path_.c_str(), strerror(errno)); } } } } // Don't buffer stdout setvbuf(stdout, nullptr, _IONBF, 0); // NOTE: there should be no stdout output until now, otherwise it would break the header. // NOTE: there should be no stdout output until now, otherwise it would break the header. // In particular, DurationReport objects should be created passing 'title, NULL', so their // In particular, DurationReport objects should be created passing 'title, NULL', so their // duration is logged into MYLOG instead. // duration is logged into MYLOG instead. Loading cmds/dumpstate/utils.cpp +49 −57 Original line number Original line Diff line number Diff line Loading @@ -97,9 +97,8 @@ DurationReporter::~DurationReporter() { MYLOGD("Duration of '%s': %.3fs\n", title_.c_str(), (float)elapsed / NANOS_PER_SEC); MYLOGD("Duration of '%s': %.3fs\n", title_.c_str(), (float)elapsed / NANOS_PER_SEC); } else { } else { // Use "Yoda grammar" to make it easier to grep|sort sections. // Use "Yoda grammar" to make it easier to grep|sort sections. dprintf(STDOUT_FILENO, "------ %.3fs was the duration of '%s' ------\n", printf("------ %.3fs was the duration of '%s' ------\n", (float)elapsed / NANOS_PER_SEC, (float)elapsed / NANOS_PER_SEC, title_.c_str()); title_.c_str()); fsync(STDOUT_FILENO); } } } } } } Loading Loading @@ -235,11 +234,11 @@ void for_each_userid(void (*func)(int), const char *header) { DIR *d; DIR *d; struct dirent *de; struct dirent *de; if (header) dprintf(STDOUT_FILENO, "\n------ %s ------\n", header); if (header) printf("\n------ %s ------\n", header); func(0); func(0); if (!(d = opendir("/data/system/users"))) { if (!(d = opendir("/data/system/users"))) { dprintf(STDOUT_FILENO, "Failed to open /data/system/users (%s)\n", strerror(errno)); printf("Failed to open /data/system/users (%s)\n", strerror(errno)); return; return; } } Loading @@ -259,11 +258,11 @@ static void __for_each_pid(void (*helper)(int, const char *, void *), const char struct dirent *de; struct dirent *de; if (!(d = opendir("/proc"))) { if (!(d = opendir("/proc"))) { dprintf(STDOUT_FILENO, "Failed to open /proc (%s)\n", strerror(errno)); printf("Failed to open /proc (%s)\n", strerror(errno)); return; return; } } if (header) dprintf(STDOUT_FILENO, "\n------ %s ------\n", header); if (header) printf("\n------ %s ------\n", header); while ((de = readdir(d))) { while ((de = readdir(d))) { int pid; int pid; int fd; int fd; Loading Loading @@ -330,7 +329,7 @@ static void for_each_tid_helper(int pid, const char *cmdline, void *arg) { snprintf(taskpath, sizeof(taskpath), "/proc/%d/task", pid); snprintf(taskpath, sizeof(taskpath), "/proc/%d/task", pid); if (!(d = opendir(taskpath))) { if (!(d = opendir(taskpath))) { dprintf(STDOUT_FILENO, "Failed to open %s (%s)\n", taskpath, strerror(errno)); printf("Failed to open %s (%s)\n", taskpath, strerror(errno)); return; return; } } Loading Loading @@ -373,6 +372,7 @@ void for_each_tid(for_each_tid_func func, const char *header) { std::string title = header == nullptr ? "for_each_tid" std::string title = header == nullptr ? "for_each_tid" : android::base::StringPrintf("for_each_tid(%s)", header); : android::base::StringPrintf("for_each_tid(%s)", header); DurationReporter duration_reporter(title); DurationReporter duration_reporter(title); if (PropertiesHelper::IsDryRun()) return; if (PropertiesHelper::IsDryRun()) return; __for_each_pid(for_each_tid_helper, header, (void *) func); __for_each_pid(for_each_tid_helper, header, (void *) func); Loading @@ -390,7 +390,7 @@ void show_wchan(int pid, int tid, const char *name) { snprintf(path, sizeof(path), "/proc/%d/wchan", tid); snprintf(path, sizeof(path), "/proc/%d/wchan", tid); if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { dprintf(STDOUT_FILENO, "Failed to open '%s' (%s)\n", path, strerror(errno)); printf("Failed to open '%s' (%s)\n", path, strerror(errno)); return; return; } } Loading @@ -399,14 +399,14 @@ void show_wchan(int pid, int tid, const char *name) { close(fd); close(fd); if (ret < 0) { if (ret < 0) { dprintf(STDOUT_FILENO, "Failed to read '%s' (%s)\n", path, strerror(save_errno)); printf("Failed to read '%s' (%s)\n", path, strerror(save_errno)); return; return; } } snprintf(name_buffer, sizeof(name_buffer), "%*s%s", snprintf(name_buffer, sizeof(name_buffer), "%*s%s", pid == tid ? 0 : 3, "", name); pid == tid ? 0 : 3, "", name); dprintf(STDOUT_FILENO, "%-7d %-32s %s\n", tid, name_buffer, buffer); printf("%-7d %-32s %s\n", tid, name_buffer, buffer); return; return; } } Loading Loading @@ -456,7 +456,7 @@ void show_showtime(int pid, const char *name) { snprintf(path, sizeof(path), "/proc/%d/stat", pid); snprintf(path, sizeof(path), "/proc/%d/stat", pid); if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { dprintf(STDOUT_FILENO, "Failed to open '%s' (%s)\n", path, strerror(errno)); printf("Failed to open '%s' (%s)\n", path, strerror(errno)); return; return; } } Loading @@ -465,7 +465,7 @@ void show_showtime(int pid, const char *name) { close(fd); close(fd); if (ret < 0) { if (ret < 0) { dprintf(STDOUT_FILENO, "Failed to read '%s' (%s)\n", path, strerror(save_errno)); printf("Failed to read '%s' (%s)\n", path, strerror(save_errno)); return; return; } } Loading Loading @@ -504,7 +504,7 @@ void show_showtime(int pid, const char *name) { if (iotime) { if (iotime) { snprdec(buffer, sizeof(buffer), 79, permille); snprdec(buffer, sizeof(buffer), 79, permille); } } dprintf(STDOUT_FILENO, "%s\n", buffer); puts(buffer); // adds a trailing newline return; return; } } Loading @@ -512,29 +512,29 @@ void show_showtime(int pid, const char *name) { void do_dmesg() { void do_dmesg() { const char *title = "KERNEL LOG (dmesg)"; const char *title = "KERNEL LOG (dmesg)"; DurationReporter duration_reporter(title); DurationReporter duration_reporter(title); dprintf(STDOUT_FILENO, "------ %s ------\n", title); printf("------ %s ------\n", title); if (PropertiesHelper::IsDryRun()) return; if (PropertiesHelper::IsDryRun()) return; /* Get size of kernel buffer */ /* Get size of kernel buffer */ int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0); int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0); if (size <= 0) { if (size <= 0) { dprintf(STDOUT_FILENO, "Unexpected klogctl return value: %d\n\n", size); printf("Unexpected klogctl return value: %d\n\n", size); return; return; } } char *buf = (char *) malloc(size + 1); char *buf = (char *) malloc(size + 1); if (buf == NULL) { if (buf == NULL) { dprintf(STDOUT_FILENO, "memory allocation failed\n\n"); printf("memory allocation failed\n\n"); return; return; } } int retval = klogctl(KLOG_READ_ALL, buf, size); int retval = klogctl(KLOG_READ_ALL, buf, size); if (retval < 0) { if (retval < 0) { dprintf(STDOUT_FILENO, "klogctl failure\n\n"); printf("klogctl failure\n\n"); free(buf); free(buf); return; return; } } buf[retval] = '\0'; buf[retval] = '\0'; dprintf(STDOUT_FILENO, "%s\n\n", buf); printf("%s\n\n", buf); free(buf); free(buf); return; return; } } Loading @@ -555,8 +555,6 @@ int Dumpstate::DumpFile(const std::string& title, const std::string& path) { UpdateProgress(WEIGHT_FILE); UpdateProgress(WEIGHT_FILE); fsync(STDOUT_FILENO); return status; return status; } } Loading Loading @@ -597,7 +595,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha int fd, retval = 0; int fd, retval = 0; if (!title.empty()) { if (!title.empty()) { dprintf(STDOUT_FILENO, "------ %s (%s) ------\n", title.c_str(), dir); printf("------ %s (%s) ------\n", title.c_str(), dir); } } if (PropertiesHelper::IsDryRun()) return 0; if (PropertiesHelper::IsDryRun()) return 0; Loading Loading @@ -639,14 +637,14 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha fd = TEMP_FAILURE_RETRY(open(newpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC)); fd = TEMP_FAILURE_RETRY(open(newpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC)); if (fd < 0) { if (fd < 0) { retval = fd; retval = fd; dprintf(STDOUT_FILENO, "*** %s: %s\n", newpath, strerror(errno)); printf("*** %s: %s\n", newpath, strerror(errno)); continue; continue; } } (*dump_from_fd)(NULL, newpath, fd); (*dump_from_fd)(NULL, newpath, fd); } } closedir(dirp); closedir(dirp); if (!title.empty()) { if (!title.empty()) { dprintf(STDOUT_FILENO, "\n"); printf("\n"); } } return retval; return retval; } } Loading @@ -660,12 +658,11 @@ int dump_file_from_fd(const char *title, const char *path, int fd) { int flags = fcntl(fd, F_GETFL); int flags = fcntl(fd, F_GETFL); if (flags == -1) { if (flags == -1) { dprintf(STDOUT_FILENO, "*** %s: failed to get flags on fd %d: %s\n", path, fd, printf("*** %s: failed to get flags on fd %d: %s\n", path, fd, strerror(errno)); strerror(errno)); close(fd); close(fd); return -1; return -1; } else if (!(flags & O_NONBLOCK)) { } else if (!(flags & O_NONBLOCK)) { dprintf(STDOUT_FILENO, "*** %s: fd must have O_NONBLOCK set.\n", path); printf("*** %s: fd must have O_NONBLOCK set.\n", path); close(fd); close(fd); return -1; return -1; } } Loading @@ -684,8 +681,6 @@ int Dumpstate::RunCommand(const std::string& title, const std::vector<std::strin * Ideally, it should use a options.EstimatedDuration() instead...*/ * Ideally, it should use a options.EstimatedDuration() instead...*/ UpdateProgress(options.Timeout()); UpdateProgress(options.Timeout()); fsync(STDOUT_FILENO); return status; return status; } } Loading Loading @@ -730,7 +725,7 @@ static int compare_prop(const void *a, const void *b) { void print_properties() { void print_properties() { const char* title = "SYSTEM PROPERTIES"; const char* title = "SYSTEM PROPERTIES"; DurationReporter duration_reporter(title); DurationReporter duration_reporter(title); dprintf(STDOUT_FILENO, "------ %s ------\n", title); printf("------ %s ------\n", title); if (PropertiesHelper::IsDryRun()) return; if (PropertiesHelper::IsDryRun()) return; size_t i; size_t i; num_props = 0; num_props = 0; Loading @@ -741,7 +736,7 @@ void print_properties() { fputs(props[i], stdout); fputs(props[i], stdout); free(props[i]); free(props[i]); } } dprintf(STDOUT_FILENO, "\n"); printf("\n"); } } int open_socket(const char *service) { int open_socket(const char *service) { Loading Loading @@ -995,7 +990,7 @@ void dump_route_tables() { ds.DumpFile("RT_TABLES", RT_TABLES_PATH); ds.DumpFile("RT_TABLES", RT_TABLES_PATH); FILE* fp = fopen(RT_TABLES_PATH, "re"); FILE* fp = fopen(RT_TABLES_PATH, "re"); if (!fp) { if (!fp) { dprintf(STDOUT_FILENO, "*** %s: %s\n", RT_TABLES_PATH, strerror(errno)); printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno)); return; return; } } char table[16]; char table[16]; Loading Loading @@ -1102,42 +1097,40 @@ void dump_emmc_ecsd(const char *ext_csd_path) { return; return; } } dprintf(STDOUT_FILENO, "------ %s Extended CSD ------\n", ext_csd_path); printf("------ %s Extended CSD ------\n", ext_csd_path); if (buffer.length() < (EXT_CSD_REV + sizeof(hex))) { if (buffer.length() < (EXT_CSD_REV + sizeof(hex))) { dprintf(STDOUT_FILENO, "*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); printf("*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); return; return; } } int ext_csd_rev = 0; int ext_csd_rev = 0; std::string sub = buffer.substr(EXT_CSD_REV, sizeof(hex)); std::string sub = buffer.substr(EXT_CSD_REV, sizeof(hex)); if (sscanf(sub.c_str(), "%2x", &ext_csd_rev) != 1) { if (sscanf(sub.c_str(), "%2x", &ext_csd_rev) != 1) { dprintf(STDOUT_FILENO, "*** %s: EXT_CSD_REV parse error \"%s\"\n\n", ext_csd_path, printf("*** %s: EXT_CSD_REV parse error \"%s\"\n\n", ext_csd_path, sub.c_str()); sub.c_str()); return; return; } } static const char *ver_str[] = { static const char *ver_str[] = { "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" }; }; dprintf(STDOUT_FILENO, "rev 1.%d (MMC %s)\n", ext_csd_rev, printf("rev 1.%d (MMC %s)\n", ext_csd_rev, (ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ? ver_str[ext_csd_rev] (ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ? ver_str[ext_csd_rev] : "Unknown"); : "Unknown"); if (ext_csd_rev < 7) { if (ext_csd_rev < 7) { dprintf(STDOUT_FILENO, "\n"); printf("\n"); return; return; } } if (buffer.length() < (EXT_PRE_EOL_INFO + sizeof(hex))) { if (buffer.length() < (EXT_PRE_EOL_INFO + sizeof(hex))) { dprintf(STDOUT_FILENO, "*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); printf("*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); return; return; } } int ext_pre_eol_info = 0; int ext_pre_eol_info = 0; sub = buffer.substr(EXT_PRE_EOL_INFO, sizeof(hex)); sub = buffer.substr(EXT_PRE_EOL_INFO, sizeof(hex)); if (sscanf(sub.c_str(), "%2x", &ext_pre_eol_info) != 1) { if (sscanf(sub.c_str(), "%2x", &ext_pre_eol_info) != 1) { dprintf(STDOUT_FILENO, "*** %s: PRE_EOL_INFO parse error \"%s\"\n\n", ext_csd_path, printf("*** %s: PRE_EOL_INFO parse error \"%s\"\n\n", ext_csd_path, sub.c_str()); sub.c_str()); return; return; } } Loading @@ -1147,8 +1140,8 @@ void dump_emmc_ecsd(const char *ext_csd_path) { "Warning (consumed 80% of reserve)", "Warning (consumed 80% of reserve)", "Urgent (consumed 90% of reserve)" "Urgent (consumed 90% of reserve)" }; }; dprintf( printf( STDOUT_FILENO, "PRE_EOL_INFO %d (MMC %s)\n", ext_pre_eol_info, "PRE_EOL_INFO %d (MMC %s)\n", ext_pre_eol_info, eol_str[(ext_pre_eol_info < (int)(sizeof(eol_str) / sizeof(eol_str[0]))) ? ext_pre_eol_info eol_str[(ext_pre_eol_info < (int)(sizeof(eol_str) / sizeof(eol_str[0]))) ? ext_pre_eol_info : 0]); : 0]); Loading @@ -1172,20 +1165,19 @@ void dump_emmc_ecsd(const char *ext_csd_path) { }; }; if (buffer.length() < (lifetime + sizeof(hex))) { if (buffer.length() < (lifetime + sizeof(hex))) { dprintf(STDOUT_FILENO, "*** %s: truncated content %zu\n", ext_csd_path, buffer.length()); printf("*** %s: truncated content %zu\n", ext_csd_path, buffer.length()); break; break; } } ext_device_life_time_est = 0; ext_device_life_time_est = 0; sub = buffer.substr(lifetime, sizeof(hex)); sub = buffer.substr(lifetime, sizeof(hex)); if (sscanf(sub.c_str(), "%2x", &ext_device_life_time_est) != 1) { if (sscanf(sub.c_str(), "%2x", &ext_device_life_time_est) != 1) { dprintf(STDOUT_FILENO, "*** %s: DEVICE_LIFE_TIME_EST_TYP_%c parse error \"%s\"\n", printf("*** %s: DEVICE_LIFE_TIME_EST_TYP_%c parse error \"%s\"\n", ext_csd_path, ext_csd_path, (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', sub.c_str()); sub.c_str()); continue; continue; } } dprintf(STDOUT_FILENO, "DEVICE_LIFE_TIME_EST_TYP_%c %d (MMC %s)\n", printf("DEVICE_LIFE_TIME_EST_TYP_%c %d (MMC %s)\n", (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', ext_device_life_time_est, ext_device_life_time_est, est_str[(ext_device_life_time_est < (int)(sizeof(est_str) / sizeof(est_str[0]))) est_str[(ext_device_life_time_est < (int)(sizeof(est_str) / sizeof(est_str[0]))) Loading @@ -1193,5 +1185,5 @@ void dump_emmc_ecsd(const char *ext_csd_path) { : 0]); : 0]); } } dprintf(STDOUT_FILENO, "\n"); printf("\n"); } } Loading
cmds/dumpstate/dumpstate.cpp +59 −60 Original line number Original line Diff line number Diff line Loading @@ -602,7 +602,7 @@ static int dump_stat_from_fd(const char *title __unused, const char *path, int f path += sizeof(mmcblk0) - 1; path += sizeof(mmcblk0) - 1; } } dprintf(STDOUT_FILENO, "%s: %s\n", path, buffer); printf("%s: %s\n", path, buffer); free(buffer); free(buffer); if (fields[__STAT_IO_TICKS]) { if (fields[__STAT_IO_TICKS]) { Loading Loading @@ -639,11 +639,10 @@ static int dump_stat_from_fd(const char *title __unused, const char *path, int f / fields[__STAT_IO_TICKS]; / fields[__STAT_IO_TICKS]; if (!write_perf && !write_ios) { if (!write_perf && !write_ios) { dprintf(STDOUT_FILENO, "%s: perf(ios) rd: %luKB/s(%lu/s) q: %u\n", path, read_perf, printf("%s: perf(ios) rd: %luKB/s(%lu/s) q: %u\n", path, read_perf, read_ios, queue); read_ios, queue); } else { } else { dprintf(STDOUT_FILENO, "%s: perf(ios) rd: %luKB/s(%lu/s) wr: %luKB/s(%lu/s) q: %u\n", printf("%s: perf(ios) rd: %luKB/s(%lu/s) wr: %luKB/s(%lu/s) q: %u\n", path, read_perf, path, read_perf, read_ios, write_perf, write_ios, queue); read_ios, write_perf, write_ios, queue); } } /* bugreport timeout factor adjustment */ /* bugreport timeout factor adjustment */ Loading Loading @@ -673,27 +672,25 @@ void Dumpstate::PrintHeader() const { network = android::base::GetProperty("gsm.operator.alpha", "(unknown)"); network = android::base::GetProperty("gsm.operator.alpha", "(unknown)"); strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now_)); strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now_)); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== dumpstate: %s\n", date); printf("== dumpstate: %s\n", date); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "\n"); printf("\n"); dprintf(STDOUT_FILENO, "Build: %s\n", build.c_str()); printf("Build: %s\n", build.c_str()); // NOTE: fingerprint entry format is important for other tools. // NOTE: fingerprint entry format is important for other tools. dprintf(STDOUT_FILENO, "Build fingerprint: '%s'\n", fingerprint.c_str()); printf("Build fingerprint: '%s'\n", fingerprint.c_str()); dprintf(STDOUT_FILENO, "Bootloader: %s\n", bootloader.c_str()); printf("Bootloader: %s\n", bootloader.c_str()); dprintf(STDOUT_FILENO, "Radio: %s\n", radio.c_str()); printf("Radio: %s\n", radio.c_str()); dprintf(STDOUT_FILENO, "Network: %s\n", network.c_str()); printf("Network: %s\n", network.c_str()); dprintf(STDOUT_FILENO, "Kernel: "); printf("Kernel: "); fsync(STDOUT_FILENO); DumpFileToFd(STDOUT_FILENO, "", "/proc/version"); DumpFileToFd(STDOUT_FILENO, "", "/proc/version"); dprintf(STDOUT_FILENO, "Command line: %s\n", strtok(cmdline_buf, "\n")); printf("Command line: %s\n", strtok(cmdline_buf, "\n")); dprintf(STDOUT_FILENO, "Bugreport format version: %s\n", version_.c_str()); printf("Bugreport format version: %s\n", version_.c_str()); dprintf(STDOUT_FILENO, "Dumpstate info: id=%d pid=%d dry_run=%d args=%s extra_options=%s\n", printf("Dumpstate info: id=%d pid=%d dry_run=%d args=%s extra_options=%s\n", id_, pid_, id_, pid_, PropertiesHelper::IsDryRun(), args_.c_str(), extra_options_.c_str()); PropertiesHelper::IsDryRun(), args_.c_str(), extra_options_.c_str()); dprintf(STDOUT_FILENO, "\n"); printf("\n"); fsync(STDOUT_FILENO); } } // List of file extensions that can cause a zip file attachment to be rejected by some email // List of file extensions that can cause a zip file attachment to be rejected by some email Loading Loading @@ -857,13 +854,13 @@ static void AddAnrTraceFiles() { dump_traces_dir.c_str(), anr_traces_dir.c_str(), already_dumped); dump_traces_dir.c_str(), anr_traces_dir.c_str(), already_dumped); if (anr_traces_path.empty()) { if (anr_traces_path.empty()) { dprintf(STDOUT_FILENO, "*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); } else { } else { int fd = TEMP_FAILURE_RETRY( int fd = TEMP_FAILURE_RETRY( open(anr_traces_path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)); open(anr_traces_path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)); if (fd < 0) { if (fd < 0) { dprintf(STDOUT_FILENO, "*** NO ANR VM TRACES FILE (%s): %s\n\n", printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path.c_str(), anr_traces_path.c_str(), strerror(errno)); strerror(errno)); } else { } else { if (add_to_zip) { if (add_to_zip) { if (!already_dumped) { if (!already_dumped) { Loading Loading @@ -1003,7 +1000,7 @@ static void dumpstate() { } } } } if (!dumped) { if (!dumped) { dprintf(STDOUT_FILENO, "*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR); printf("*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR); } } DumpFile("NETWORK DEV INFO", "/proc/net/dev"); DumpFile("NETWORK DEV INFO", "/proc/net/dev"); Loading Loading @@ -1076,18 +1073,18 @@ static void dumpstate() { RunCommand("LAST RADIO LOG", {"parse_radio_log", "/proc/last_radio_log"}); RunCommand("LAST RADIO LOG", {"parse_radio_log", "/proc/last_radio_log"}); dprintf(STDOUT_FILENO, "------ BACKLIGHTS ------\n"); printf("------ BACKLIGHTS ------\n"); dprintf(STDOUT_FILENO, "LCD brightness="); printf("LCD brightness="); DumpFile("", "/sys/class/leds/lcd-backlight/brightness"); DumpFile("", "/sys/class/leds/lcd-backlight/brightness"); dprintf(STDOUT_FILENO, "Button brightness="); printf("Button brightness="); DumpFile("", "/sys/class/leds/button-backlight/brightness"); DumpFile("", "/sys/class/leds/button-backlight/brightness"); dprintf(STDOUT_FILENO, "Keyboard brightness="); printf("Keyboard brightness="); DumpFile("", "/sys/class/leds/keyboard-backlight/brightness"); DumpFile("", "/sys/class/leds/keyboard-backlight/brightness"); dprintf(STDOUT_FILENO, "ALS mode="); printf("ALS mode="); DumpFile("", "/sys/class/leds/lcd-backlight/als"); DumpFile("", "/sys/class/leds/lcd-backlight/als"); dprintf(STDOUT_FILENO, "LCD driver registers:\n"); printf("LCD driver registers:\n"); DumpFile("", "/sys/class/leds/lcd-backlight/registers"); DumpFile("", "/sys/class/leds/lcd-backlight/registers"); dprintf(STDOUT_FILENO, "\n"); printf("\n"); /* Binder state is expensive to look at as it uses a lot of memory. */ /* Binder state is expensive to look at as it uses a lot of memory. */ DumpFile("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log"); DumpFile("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log"); Loading @@ -1112,16 +1109,16 @@ static void dumpstate() { RunCommand("DUMP VENDOR RIL LOGS", {"vril-dump"}, options.Build()); RunCommand("DUMP VENDOR RIL LOGS", {"vril-dump"}, options.Build()); } } dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Android Framework Services\n"); printf("== Android Framework Services\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("DUMPSYS", {"--skip", "meminfo", "cpuinfo"}, CommandOptions::WithTimeout(90).Build(), RunDumpsys("DUMPSYS", {"--skip", "meminfo", "cpuinfo"}, CommandOptions::WithTimeout(90).Build(), 10); 10); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Checkins\n"); printf("== Checkins\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); RunDumpsys("CHECKIN MEMINFO", {"meminfo", "--checkin"}); RunDumpsys("CHECKIN MEMINFO", {"meminfo", "--checkin"}); Loading @@ -1130,21 +1127,21 @@ static void dumpstate() { RunDumpsys("CHECKIN USAGESTATS", {"usagestats", "-c"}); RunDumpsys("CHECKIN USAGESTATS", {"usagestats", "-c"}); RunDumpsys("CHECKIN PACKAGE", {"package", "--checkin"}); RunDumpsys("CHECKIN PACKAGE", {"package", "--checkin"}); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Running Application Activities\n"); printf("== Running Application Activities\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("APP ACTIVITIES", {"activity", "all"}); RunDumpsys("APP ACTIVITIES", {"activity", "all"}); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Running Application Services\n"); printf("== Running Application Services\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("APP SERVICES", {"activity", "service", "all"}); RunDumpsys("APP SERVICES", {"activity", "service", "all"}); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Running Application Providers\n"); printf("== Running Application Providers\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); RunDumpsys("APP PROVIDERS", {"activity", "provider", "all"}); RunDumpsys("APP PROVIDERS", {"activity", "provider", "all"}); Loading @@ -1153,20 +1150,19 @@ static void dumpstate() { // collected. // collected. DumpModemLogs(); DumpModemLogs(); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Final progress (pid %d): %d/%d (estimated %d)\n", ds.pid_, printf("== Final progress (pid %d): %d/%d (estimated %d)\n", ds.pid_, ds.progress_->Get(), ds.progress_->Get(), ds.progress_->GetMax(), ds.progress_->GetInitialMax()); ds.progress_->GetMax(), ds.progress_->GetInitialMax()); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== dumpstate: done (id %d)\n", ds.id_); printf("== dumpstate: done (id %d)\n", ds.id_); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); } } void Dumpstate::DumpstateBoard() { void Dumpstate::DumpstateBoard() { DurationReporter duration_reporter("dumpstate_board()"); DurationReporter duration_reporter("dumpstate_board()"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); dprintf(STDOUT_FILENO, "== Board\n"); printf("== Board\n"); dprintf(STDOUT_FILENO, "========================================================\n"); printf("========================================================\n"); fsync(STDOUT_FILENO); android::sp<android::hardware::dumpstate::V1_0::IDumpstateDevice> dumpstate_device( android::sp<android::hardware::dumpstate::V1_0::IDumpstateDevice> dumpstate_device( android::hardware::dumpstate::V1_0::IDumpstateDevice::getService("DumpstateDevice")); android::hardware::dumpstate::V1_0::IDumpstateDevice::getService("DumpstateDevice")); Loading Loading @@ -1204,8 +1200,7 @@ void Dumpstate::DumpstateBoard() { dumpstate_device->dumpstateBoard(handle); dumpstate_device->dumpstateBoard(handle); AddZipEntry("dumpstate-board.txt", path); AddZipEntry("dumpstate-board.txt", path); dprintf(STDOUT_FILENO, "*** See dumpstate-board.txt entry ***\n"); printf("*** See dumpstate-board.txt entry ***\n"); fsync(STDOUT_FILENO); native_handle_close(handle); native_handle_close(handle); native_handle_delete(handle); native_handle_delete(handle); Loading Loading @@ -1632,6 +1627,10 @@ int main(int argc, char *argv[]) { ds.tmp_path_.c_str(), strerror(errno)); ds.tmp_path_.c_str(), strerror(errno)); } } } } // Don't buffer stdout setvbuf(stdout, nullptr, _IONBF, 0); // NOTE: there should be no stdout output until now, otherwise it would break the header. // NOTE: there should be no stdout output until now, otherwise it would break the header. // In particular, DurationReport objects should be created passing 'title, NULL', so their // In particular, DurationReport objects should be created passing 'title, NULL', so their // duration is logged into MYLOG instead. // duration is logged into MYLOG instead. Loading
cmds/dumpstate/utils.cpp +49 −57 Original line number Original line Diff line number Diff line Loading @@ -97,9 +97,8 @@ DurationReporter::~DurationReporter() { MYLOGD("Duration of '%s': %.3fs\n", title_.c_str(), (float)elapsed / NANOS_PER_SEC); MYLOGD("Duration of '%s': %.3fs\n", title_.c_str(), (float)elapsed / NANOS_PER_SEC); } else { } else { // Use "Yoda grammar" to make it easier to grep|sort sections. // Use "Yoda grammar" to make it easier to grep|sort sections. dprintf(STDOUT_FILENO, "------ %.3fs was the duration of '%s' ------\n", printf("------ %.3fs was the duration of '%s' ------\n", (float)elapsed / NANOS_PER_SEC, (float)elapsed / NANOS_PER_SEC, title_.c_str()); title_.c_str()); fsync(STDOUT_FILENO); } } } } } } Loading Loading @@ -235,11 +234,11 @@ void for_each_userid(void (*func)(int), const char *header) { DIR *d; DIR *d; struct dirent *de; struct dirent *de; if (header) dprintf(STDOUT_FILENO, "\n------ %s ------\n", header); if (header) printf("\n------ %s ------\n", header); func(0); func(0); if (!(d = opendir("/data/system/users"))) { if (!(d = opendir("/data/system/users"))) { dprintf(STDOUT_FILENO, "Failed to open /data/system/users (%s)\n", strerror(errno)); printf("Failed to open /data/system/users (%s)\n", strerror(errno)); return; return; } } Loading @@ -259,11 +258,11 @@ static void __for_each_pid(void (*helper)(int, const char *, void *), const char struct dirent *de; struct dirent *de; if (!(d = opendir("/proc"))) { if (!(d = opendir("/proc"))) { dprintf(STDOUT_FILENO, "Failed to open /proc (%s)\n", strerror(errno)); printf("Failed to open /proc (%s)\n", strerror(errno)); return; return; } } if (header) dprintf(STDOUT_FILENO, "\n------ %s ------\n", header); if (header) printf("\n------ %s ------\n", header); while ((de = readdir(d))) { while ((de = readdir(d))) { int pid; int pid; int fd; int fd; Loading Loading @@ -330,7 +329,7 @@ static void for_each_tid_helper(int pid, const char *cmdline, void *arg) { snprintf(taskpath, sizeof(taskpath), "/proc/%d/task", pid); snprintf(taskpath, sizeof(taskpath), "/proc/%d/task", pid); if (!(d = opendir(taskpath))) { if (!(d = opendir(taskpath))) { dprintf(STDOUT_FILENO, "Failed to open %s (%s)\n", taskpath, strerror(errno)); printf("Failed to open %s (%s)\n", taskpath, strerror(errno)); return; return; } } Loading Loading @@ -373,6 +372,7 @@ void for_each_tid(for_each_tid_func func, const char *header) { std::string title = header == nullptr ? "for_each_tid" std::string title = header == nullptr ? "for_each_tid" : android::base::StringPrintf("for_each_tid(%s)", header); : android::base::StringPrintf("for_each_tid(%s)", header); DurationReporter duration_reporter(title); DurationReporter duration_reporter(title); if (PropertiesHelper::IsDryRun()) return; if (PropertiesHelper::IsDryRun()) return; __for_each_pid(for_each_tid_helper, header, (void *) func); __for_each_pid(for_each_tid_helper, header, (void *) func); Loading @@ -390,7 +390,7 @@ void show_wchan(int pid, int tid, const char *name) { snprintf(path, sizeof(path), "/proc/%d/wchan", tid); snprintf(path, sizeof(path), "/proc/%d/wchan", tid); if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { dprintf(STDOUT_FILENO, "Failed to open '%s' (%s)\n", path, strerror(errno)); printf("Failed to open '%s' (%s)\n", path, strerror(errno)); return; return; } } Loading @@ -399,14 +399,14 @@ void show_wchan(int pid, int tid, const char *name) { close(fd); close(fd); if (ret < 0) { if (ret < 0) { dprintf(STDOUT_FILENO, "Failed to read '%s' (%s)\n", path, strerror(save_errno)); printf("Failed to read '%s' (%s)\n", path, strerror(save_errno)); return; return; } } snprintf(name_buffer, sizeof(name_buffer), "%*s%s", snprintf(name_buffer, sizeof(name_buffer), "%*s%s", pid == tid ? 0 : 3, "", name); pid == tid ? 0 : 3, "", name); dprintf(STDOUT_FILENO, "%-7d %-32s %s\n", tid, name_buffer, buffer); printf("%-7d %-32s %s\n", tid, name_buffer, buffer); return; return; } } Loading Loading @@ -456,7 +456,7 @@ void show_showtime(int pid, const char *name) { snprintf(path, sizeof(path), "/proc/%d/stat", pid); snprintf(path, sizeof(path), "/proc/%d/stat", pid); if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) { dprintf(STDOUT_FILENO, "Failed to open '%s' (%s)\n", path, strerror(errno)); printf("Failed to open '%s' (%s)\n", path, strerror(errno)); return; return; } } Loading @@ -465,7 +465,7 @@ void show_showtime(int pid, const char *name) { close(fd); close(fd); if (ret < 0) { if (ret < 0) { dprintf(STDOUT_FILENO, "Failed to read '%s' (%s)\n", path, strerror(save_errno)); printf("Failed to read '%s' (%s)\n", path, strerror(save_errno)); return; return; } } Loading Loading @@ -504,7 +504,7 @@ void show_showtime(int pid, const char *name) { if (iotime) { if (iotime) { snprdec(buffer, sizeof(buffer), 79, permille); snprdec(buffer, sizeof(buffer), 79, permille); } } dprintf(STDOUT_FILENO, "%s\n", buffer); puts(buffer); // adds a trailing newline return; return; } } Loading @@ -512,29 +512,29 @@ void show_showtime(int pid, const char *name) { void do_dmesg() { void do_dmesg() { const char *title = "KERNEL LOG (dmesg)"; const char *title = "KERNEL LOG (dmesg)"; DurationReporter duration_reporter(title); DurationReporter duration_reporter(title); dprintf(STDOUT_FILENO, "------ %s ------\n", title); printf("------ %s ------\n", title); if (PropertiesHelper::IsDryRun()) return; if (PropertiesHelper::IsDryRun()) return; /* Get size of kernel buffer */ /* Get size of kernel buffer */ int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0); int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0); if (size <= 0) { if (size <= 0) { dprintf(STDOUT_FILENO, "Unexpected klogctl return value: %d\n\n", size); printf("Unexpected klogctl return value: %d\n\n", size); return; return; } } char *buf = (char *) malloc(size + 1); char *buf = (char *) malloc(size + 1); if (buf == NULL) { if (buf == NULL) { dprintf(STDOUT_FILENO, "memory allocation failed\n\n"); printf("memory allocation failed\n\n"); return; return; } } int retval = klogctl(KLOG_READ_ALL, buf, size); int retval = klogctl(KLOG_READ_ALL, buf, size); if (retval < 0) { if (retval < 0) { dprintf(STDOUT_FILENO, "klogctl failure\n\n"); printf("klogctl failure\n\n"); free(buf); free(buf); return; return; } } buf[retval] = '\0'; buf[retval] = '\0'; dprintf(STDOUT_FILENO, "%s\n\n", buf); printf("%s\n\n", buf); free(buf); free(buf); return; return; } } Loading @@ -555,8 +555,6 @@ int Dumpstate::DumpFile(const std::string& title, const std::string& path) { UpdateProgress(WEIGHT_FILE); UpdateProgress(WEIGHT_FILE); fsync(STDOUT_FILENO); return status; return status; } } Loading Loading @@ -597,7 +595,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha int fd, retval = 0; int fd, retval = 0; if (!title.empty()) { if (!title.empty()) { dprintf(STDOUT_FILENO, "------ %s (%s) ------\n", title.c_str(), dir); printf("------ %s (%s) ------\n", title.c_str(), dir); } } if (PropertiesHelper::IsDryRun()) return 0; if (PropertiesHelper::IsDryRun()) return 0; Loading Loading @@ -639,14 +637,14 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha fd = TEMP_FAILURE_RETRY(open(newpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC)); fd = TEMP_FAILURE_RETRY(open(newpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC)); if (fd < 0) { if (fd < 0) { retval = fd; retval = fd; dprintf(STDOUT_FILENO, "*** %s: %s\n", newpath, strerror(errno)); printf("*** %s: %s\n", newpath, strerror(errno)); continue; continue; } } (*dump_from_fd)(NULL, newpath, fd); (*dump_from_fd)(NULL, newpath, fd); } } closedir(dirp); closedir(dirp); if (!title.empty()) { if (!title.empty()) { dprintf(STDOUT_FILENO, "\n"); printf("\n"); } } return retval; return retval; } } Loading @@ -660,12 +658,11 @@ int dump_file_from_fd(const char *title, const char *path, int fd) { int flags = fcntl(fd, F_GETFL); int flags = fcntl(fd, F_GETFL); if (flags == -1) { if (flags == -1) { dprintf(STDOUT_FILENO, "*** %s: failed to get flags on fd %d: %s\n", path, fd, printf("*** %s: failed to get flags on fd %d: %s\n", path, fd, strerror(errno)); strerror(errno)); close(fd); close(fd); return -1; return -1; } else if (!(flags & O_NONBLOCK)) { } else if (!(flags & O_NONBLOCK)) { dprintf(STDOUT_FILENO, "*** %s: fd must have O_NONBLOCK set.\n", path); printf("*** %s: fd must have O_NONBLOCK set.\n", path); close(fd); close(fd); return -1; return -1; } } Loading @@ -684,8 +681,6 @@ int Dumpstate::RunCommand(const std::string& title, const std::vector<std::strin * Ideally, it should use a options.EstimatedDuration() instead...*/ * Ideally, it should use a options.EstimatedDuration() instead...*/ UpdateProgress(options.Timeout()); UpdateProgress(options.Timeout()); fsync(STDOUT_FILENO); return status; return status; } } Loading Loading @@ -730,7 +725,7 @@ static int compare_prop(const void *a, const void *b) { void print_properties() { void print_properties() { const char* title = "SYSTEM PROPERTIES"; const char* title = "SYSTEM PROPERTIES"; DurationReporter duration_reporter(title); DurationReporter duration_reporter(title); dprintf(STDOUT_FILENO, "------ %s ------\n", title); printf("------ %s ------\n", title); if (PropertiesHelper::IsDryRun()) return; if (PropertiesHelper::IsDryRun()) return; size_t i; size_t i; num_props = 0; num_props = 0; Loading @@ -741,7 +736,7 @@ void print_properties() { fputs(props[i], stdout); fputs(props[i], stdout); free(props[i]); free(props[i]); } } dprintf(STDOUT_FILENO, "\n"); printf("\n"); } } int open_socket(const char *service) { int open_socket(const char *service) { Loading Loading @@ -995,7 +990,7 @@ void dump_route_tables() { ds.DumpFile("RT_TABLES", RT_TABLES_PATH); ds.DumpFile("RT_TABLES", RT_TABLES_PATH); FILE* fp = fopen(RT_TABLES_PATH, "re"); FILE* fp = fopen(RT_TABLES_PATH, "re"); if (!fp) { if (!fp) { dprintf(STDOUT_FILENO, "*** %s: %s\n", RT_TABLES_PATH, strerror(errno)); printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno)); return; return; } } char table[16]; char table[16]; Loading Loading @@ -1102,42 +1097,40 @@ void dump_emmc_ecsd(const char *ext_csd_path) { return; return; } } dprintf(STDOUT_FILENO, "------ %s Extended CSD ------\n", ext_csd_path); printf("------ %s Extended CSD ------\n", ext_csd_path); if (buffer.length() < (EXT_CSD_REV + sizeof(hex))) { if (buffer.length() < (EXT_CSD_REV + sizeof(hex))) { dprintf(STDOUT_FILENO, "*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); printf("*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); return; return; } } int ext_csd_rev = 0; int ext_csd_rev = 0; std::string sub = buffer.substr(EXT_CSD_REV, sizeof(hex)); std::string sub = buffer.substr(EXT_CSD_REV, sizeof(hex)); if (sscanf(sub.c_str(), "%2x", &ext_csd_rev) != 1) { if (sscanf(sub.c_str(), "%2x", &ext_csd_rev) != 1) { dprintf(STDOUT_FILENO, "*** %s: EXT_CSD_REV parse error \"%s\"\n\n", ext_csd_path, printf("*** %s: EXT_CSD_REV parse error \"%s\"\n\n", ext_csd_path, sub.c_str()); sub.c_str()); return; return; } } static const char *ver_str[] = { static const char *ver_str[] = { "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" }; }; dprintf(STDOUT_FILENO, "rev 1.%d (MMC %s)\n", ext_csd_rev, printf("rev 1.%d (MMC %s)\n", ext_csd_rev, (ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ? ver_str[ext_csd_rev] (ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ? ver_str[ext_csd_rev] : "Unknown"); : "Unknown"); if (ext_csd_rev < 7) { if (ext_csd_rev < 7) { dprintf(STDOUT_FILENO, "\n"); printf("\n"); return; return; } } if (buffer.length() < (EXT_PRE_EOL_INFO + sizeof(hex))) { if (buffer.length() < (EXT_PRE_EOL_INFO + sizeof(hex))) { dprintf(STDOUT_FILENO, "*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); printf("*** %s: truncated content %zu\n\n", ext_csd_path, buffer.length()); return; return; } } int ext_pre_eol_info = 0; int ext_pre_eol_info = 0; sub = buffer.substr(EXT_PRE_EOL_INFO, sizeof(hex)); sub = buffer.substr(EXT_PRE_EOL_INFO, sizeof(hex)); if (sscanf(sub.c_str(), "%2x", &ext_pre_eol_info) != 1) { if (sscanf(sub.c_str(), "%2x", &ext_pre_eol_info) != 1) { dprintf(STDOUT_FILENO, "*** %s: PRE_EOL_INFO parse error \"%s\"\n\n", ext_csd_path, printf("*** %s: PRE_EOL_INFO parse error \"%s\"\n\n", ext_csd_path, sub.c_str()); sub.c_str()); return; return; } } Loading @@ -1147,8 +1140,8 @@ void dump_emmc_ecsd(const char *ext_csd_path) { "Warning (consumed 80% of reserve)", "Warning (consumed 80% of reserve)", "Urgent (consumed 90% of reserve)" "Urgent (consumed 90% of reserve)" }; }; dprintf( printf( STDOUT_FILENO, "PRE_EOL_INFO %d (MMC %s)\n", ext_pre_eol_info, "PRE_EOL_INFO %d (MMC %s)\n", ext_pre_eol_info, eol_str[(ext_pre_eol_info < (int)(sizeof(eol_str) / sizeof(eol_str[0]))) ? ext_pre_eol_info eol_str[(ext_pre_eol_info < (int)(sizeof(eol_str) / sizeof(eol_str[0]))) ? ext_pre_eol_info : 0]); : 0]); Loading @@ -1172,20 +1165,19 @@ void dump_emmc_ecsd(const char *ext_csd_path) { }; }; if (buffer.length() < (lifetime + sizeof(hex))) { if (buffer.length() < (lifetime + sizeof(hex))) { dprintf(STDOUT_FILENO, "*** %s: truncated content %zu\n", ext_csd_path, buffer.length()); printf("*** %s: truncated content %zu\n", ext_csd_path, buffer.length()); break; break; } } ext_device_life_time_est = 0; ext_device_life_time_est = 0; sub = buffer.substr(lifetime, sizeof(hex)); sub = buffer.substr(lifetime, sizeof(hex)); if (sscanf(sub.c_str(), "%2x", &ext_device_life_time_est) != 1) { if (sscanf(sub.c_str(), "%2x", &ext_device_life_time_est) != 1) { dprintf(STDOUT_FILENO, "*** %s: DEVICE_LIFE_TIME_EST_TYP_%c parse error \"%s\"\n", printf("*** %s: DEVICE_LIFE_TIME_EST_TYP_%c parse error \"%s\"\n", ext_csd_path, ext_csd_path, (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', sub.c_str()); sub.c_str()); continue; continue; } } dprintf(STDOUT_FILENO, "DEVICE_LIFE_TIME_EST_TYP_%c %d (MMC %s)\n", printf("DEVICE_LIFE_TIME_EST_TYP_%c %d (MMC %s)\n", (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', (unsigned)((lifetime - EXT_DEVICE_LIFE_TIME_EST_TYP_A) / sizeof(hex)) + 'A', ext_device_life_time_est, ext_device_life_time_est, est_str[(ext_device_life_time_est < (int)(sizeof(est_str) / sizeof(est_str[0]))) est_str[(ext_device_life_time_est < (int)(sizeof(est_str) / sizeof(est_str[0]))) Loading @@ -1193,5 +1185,5 @@ void dump_emmc_ecsd(const char *ext_csd_path) { : 0]); : 0]); } } dprintf(STDOUT_FILENO, "\n"); printf("\n"); } }