OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromecast/crash/linux/crash_util.h" |
| 6 |
| 7 #include <stdlib.h> |
| 8 |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/time/time.h" |
| 11 #include "chromecast/base/path_utils.h" |
| 12 #include "chromecast/base/version.h" |
| 13 #include "chromecast/crash/app_state_tracker.h" |
| 14 #include "chromecast/crash/linux/dummy_minidump_generator.h" |
| 15 #include "chromecast/crash/linux/minidump_writer.h" |
| 16 |
| 17 namespace chromecast { |
| 18 |
| 19 // static |
| 20 uint64_t CrashUtil::GetCurrentTimeMs() { |
| 21 return (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); |
| 22 } |
| 23 |
| 24 // static |
| 25 void CrashUtil::RequestUploadCrashDump( |
| 26 const std::string& existing_minidump_path, |
| 27 const std::string& crashed_process_name, |
| 28 uint64_t crashed_process_start_time_ms) { |
| 29 LOG(INFO) << "Request to upload crash dump " << existing_minidump_path |
| 30 << " for process " << crashed_process_name; |
| 31 // Note: Do not use Chromium IO methods in this function. When cast_shell |
| 32 // crashes, this function can be called by any thread, which may not allow IO. |
| 33 // Use stdlib system calls for IO instead. |
| 34 uint64_t uptime_ms = GetCurrentTimeMs() - crashed_process_start_time_ms; |
| 35 MinidumpParams params(crashed_process_name, |
| 36 uptime_ms, |
| 37 "", // suffix |
| 38 AppStateTracker::GetPreviousApp(), |
| 39 AppStateTracker::GetCurrentApp(), |
| 40 AppStateTracker::GetLastLaunchedApp(), |
| 41 CAST_BUILD_RELEASE, |
| 42 CAST_BUILD_INCREMENTAL); |
| 43 DummyMinidumpGenerator minidump_generator(existing_minidump_path); |
| 44 |
| 45 // TODO(slan): Use FilePath and file_utils instead of string manipulation. |
| 46 // Moving minidump file from /tmp/xxxxxxxxxx to $HOME/minidumps/xxxxxxxx |
| 47 // Get filename only. |
| 48 const size_t separator_idx = existing_minidump_path.find_last_of('/'); |
| 49 const std::string filename = |
| 50 (separator_idx != std::string::npos) |
| 51 ? existing_minidump_path.substr(separator_idx + 1) |
| 52 : existing_minidump_path; |
| 53 const std::string dump_path = GetHomePathASCII("minidumps").value(); |
| 54 const std::string target_minidump_path = |
| 55 dump_path + std::string("/") + filename; |
| 56 MinidumpWriter writer(&minidump_generator, target_minidump_path, params); |
| 57 writer.DoWorkLocked(); // error already logged. |
| 58 |
| 59 // Still delete /tmp file to free memory, in case anything wrong in |
| 60 // DummyMinidumpGenerator. |
| 61 if (0 != remove(existing_minidump_path.c_str())) { |
| 62 // According to base/files/file_util.h, it is considered successful |
| 63 // to delete a file that does not exist. |
| 64 LOG(ERROR) << "Unable to delete temp minidump file " |
| 65 << existing_minidump_path; |
| 66 } |
| 67 |
| 68 // Use std::endl to flush the log stream in case this process exits. |
| 69 LOG(INFO) << "Request to upload crash dump finished. " |
| 70 << "Exit now if it is main process that crashed." << std::endl; |
| 71 } |
| 72 |
| 73 } // namespace chromecast |
OLD | NEW |