| Index: chromecast/crash/linux/crash_util.cc
|
| diff --git a/chromecast/crash/linux/crash_util.cc b/chromecast/crash/linux/crash_util.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ce127b508cac3511789439e940c3cc6e087405a9
|
| --- /dev/null
|
| +++ b/chromecast/crash/linux/crash_util.cc
|
| @@ -0,0 +1,73 @@
|
| +// 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/linux/crash_util.h"
|
| +
|
| +#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/linux/dummy_minidump_generator.h"
|
| +#include "chromecast/crash/linux/minidump_writer.h"
|
| +
|
| +namespace chromecast {
|
| +
|
| +// static
|
| +uint64_t CrashUtil::GetCurrentTimeMs() {
|
| + return (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
|
| +}
|
| +
|
| +// static
|
| +void CrashUtil::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(),
|
| + CAST_BUILD_RELEASE,
|
| + 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
|
|
|