From 608385dd151e36a93f3e3f4a7514b1e720d20ae9 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 1 Feb 2016 10:35:38 -0800 Subject: Redirect output to file ASAP, otherwise printf() calls might be missed. Also removed the duraction reporter on add_zip_entry_from_fd - since it was spamming the report and the timing could be infered by calculating the delta between each ALOGD entry anyways - and logged PID and statistics. BUG: 26885492 Change-Id: Iadb00957daac68b7a40b0e36ee5cce2b82264588 --- cmds/dumpstate/utils.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'cmds/dumpstate/utils.cpp') diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp index 3f2d126071..ee60f57f83 100644 --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@ -60,19 +60,26 @@ static const char* native_processes_to_dump[] = { NULL, }; -DurationReporter::DurationReporter(const char *title) { +DurationReporter::DurationReporter(const char *title) : DurationReporter(title, stdout) {} + +DurationReporter::DurationReporter(const char *title, FILE *out) { title_ = title; if (title) { started_ = DurationReporter::nanotime(); } + out_ = out; } DurationReporter::~DurationReporter() { if (title_) { uint64_t elapsed = DurationReporter::nanotime() - started_; // Use "Yoda grammar" to make it easier to grep|sort sections. - printf("------ %.3fs was the duration of '%s' ------\n", - (float) elapsed / NANOS_PER_SEC, title_); + if (out_) { + fprintf(out_, "------ %.3fs was the duration of '%s' ------\n", + (float) elapsed / NANOS_PER_SEC, title_); + } else { + ALOGD("Duration of '%s': %.3fs\n", title_, (float) elapsed / NANOS_PER_SEC); + } } } @@ -668,7 +675,7 @@ void redirect_to_file(FILE *redirect, char *path) { } } - int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, + int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)); if (fd < 0) { fprintf(stderr, "%s: %s\n", path, strerror(errno)); @@ -690,7 +697,7 @@ static bool should_dump_native_traces(const char* path) { /* dump Dalvik and native stack traces, return the trace file location (NULL if none) */ const char *dump_traces() { - DurationReporter duration_reporter("DUMP TRACES"); + DurationReporter duration_reporter("DUMP TRACES", NULL); ON_DRY_RUN_RETURN(NULL); const char* result = NULL; -- cgit v1.2.3-59-g8ed1b