Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: chromecast/crash/breakpad_util.cc

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: Corrected version hack in breakpad_util. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromecast/crash/breakpad_util.cc
diff --git a/chromecast/crash/breakpad_util.cc b/chromecast/crash/breakpad_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1b9bcadfe4d23debf1e07abf9ef24fd3e09a05ac
--- /dev/null
+++ b/chromecast/crash/breakpad_util.cc
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromecast/crash/breakpad_util.h"
gunsch 2015/06/09 18:46:18 naming: "breakpad_util" --> "crash_util"
slan 2015/06/10 01:49:13 Done.
+
+#include <stdlib.h>
+
+#include "base/files/file_path.h"
+#include "base/time/time.h"
+#include "chromecast/base/path_utils.h"
+#include "chromecast/base/version.h"
+#include "chromecast/crash/app_state_tracker.h"
+#include "chromecast/crash/dummy_minidump_generator.h"
+#include "chromecast/crash/minidump_writer.h"
+
+namespace chromecast {
+
+namespace {
+
+// CAST_BUILD_REVISION is in the format of "1.15.20150520.120651
+// Returns "1.15".
+std::string GetReleaseVersion() {
gunsch 2015/06/09 18:46:19 Oof, don't do this parsing. We can just add anothe
slan 2015/06/10 01:49:13 Done.
+ const std::string& revision(CAST_BUILD_REVISION);
+
+ std::size_t pos = revision.find('.');
+ if (pos == std::string::npos)
+ return "";
+ pos = revision.find('.', pos + 1);
+ if (pos == std::string::npos)
+ return "";
+
+ return revision.substr(0, pos);
+}
+
+} // namespace
+
+// static
+uint64_t BreakpadUtil::GetCurrentTimeMs() {
+ return (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
+}
+
+// static
+void BreakpadUtil::RequestUploadCrashDump(
+ const std::string& existing_minidump_path,
+ const std::string& crashed_process_name,
+ uint64_t crashed_process_start_time_ms) {
+ LOG(INFO) << "Request to upload crash dump " << existing_minidump_path
+ << " for process " << crashed_process_name;
+ // Note: Do not use Chromium IO methods in this function. When cast_shell
+ // crashes, this function can be called by any thread, which may not allow IO.
+ // Use stdlib system calls for IO instead.
+ uint64_t uptime_ms = GetCurrentTimeMs() - crashed_process_start_time_ms;
+ MinidumpParams params(crashed_process_name,
+ uptime_ms,
+ "", // suffix
+ AppStateTracker::GetPreviousApp(),
+ AppStateTracker::GetCurrentApp(),
+ AppStateTracker::GetLastLaunchedApp(),
+ GetReleaseVersion(),
+ CAST_BUILD_INCREMENTAL);
+ DummyMinidumpGenerator minidump_generator(existing_minidump_path);
+
+ // TODO(slan): Use FilePath and file_utils instead of string manipulation.
+ // Moving minidump file from /tmp/xxxxxxxxxx to $HOME/minidumps/xxxxxxxx
+ // Get filename only.
+ const size_t separator_idx = existing_minidump_path.find_last_of('/');
+ const std::string filename =
+ (separator_idx != std::string::npos)
+ ? existing_minidump_path.substr(separator_idx + 1)
+ : existing_minidump_path;
+ const std::string dump_path = GetHomePathASCII("minidumps").value();
+ const std::string target_minidump_path =
+ dump_path + std::string("/") + filename;
+ MinidumpWriter writer(&minidump_generator, target_minidump_path, params);
+ writer.DoWorkLocked(); // error already logged.
+
+ // Still delete /tmp file to free memory, in case anything wrong in
+ // DummyMinidumpGenerator.
+ if (0 != remove(existing_minidump_path.c_str())) {
+ // According to base/files/file_util.h, it is considered successful
+ // to delete a file that does not exist.
+ LOG(ERROR) << "Unable to delete temp minidump file "
+ << existing_minidump_path;
+ }
+
+ // Use std::endl to flush the log stream in case this process exits.
+ LOG(INFO) << "Request to upload crash dump finished. "
+ << "Exit now if it is main process that crashed." << std::endl;
+}
+
+} // namespace chromecast

Powered by Google App Engine
This is Rietveld 408576698