Merge "Use the timeout stack dump functions."

This commit is contained in:
Christopher Ferris 2015-01-15 23:40:39 +00:00 committed by Gerrit Code Review
commit 1d4638838a

View File

@ -619,20 +619,28 @@ const char *dump_traces() {
if (lseek(fd, 0, SEEK_END) < 0) { if (lseek(fd, 0, SEEK_END) < 0) {
fprintf(stderr, "lseek: %s\n", strerror(errno)); fprintf(stderr, "lseek: %s\n", strerror(errno));
} else { } else {
snprintf(data, sizeof(data), "[dump dalvik stack %d: %.3fs elapsed]\n", dprintf(fd, "[dump dalvik stack %d: %.3fs elapsed]\n",
pid, (float)(nanotime() - start) / NANOS_PER_SEC); pid, (float)(nanotime() - start) / NANOS_PER_SEC);
write(fd, data, strlen(data));
} }
} else if (should_dump_native_traces(data)) { } else if (should_dump_native_traces(data)) {
/* dump native process if appropriate */ /* dump native process if appropriate */
if (lseek(fd, 0, SEEK_END) < 0) { if (lseek(fd, 0, SEEK_END) < 0) {
fprintf(stderr, "lseek: %s\n", strerror(errno)); fprintf(stderr, "lseek: %s\n", strerror(errno));
} else { } else {
static uint16_t timeout_failures = 0;
int64_t start = nanotime(); int64_t start = nanotime();
dump_backtrace_to_file(pid, fd);
snprintf(data, sizeof(data), "[dump native stack %d: %.3fs elapsed]\n", /* If 3 backtrace dumps fail in a row, consider debuggerd dead. */
if (timeout_failures == 3) {
dprintf(fd, "too many stack dump failures, skipping...\n");
} else if (dump_backtrace_to_file_timeout(pid, fd, 20) == -1) {
dprintf(fd, "dumping failed, likely due to a timeout\n");
timeout_failures++;
} else {
timeout_failures = 0;
}
dprintf(fd, "[dump native stack %d: %.3fs elapsed]\n",
pid, (float)(nanotime() - start) / NANOS_PER_SEC); pid, (float)(nanotime() - start) / NANOS_PER_SEC);
write(fd, data, strlen(data));
} }
} }
} }