Chromium Code Reviews| 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/breakpad_util.h" | |
|
gunsch
2015/06/09 18:46:18
naming: "breakpad_util" --> "crash_util"
slan
2015/06/10 01:49:13
Done.
| |
| 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/dummy_minidump_generator.h" | |
| 15 #include "chromecast/crash/minidump_writer.h" | |
| 16 | |
| 17 namespace chromecast { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // CAST_BUILD_REVISION is in the format of "1.15.20150520.120651 | |
| 22 // Returns "1.15". | |
| 23 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.
| |
| 24 const std::string& revision(CAST_BUILD_REVISION); | |
| 25 | |
| 26 std::size_t pos = revision.find('.'); | |
| 27 if (pos == std::string::npos) | |
| 28 return ""; | |
| 29 pos = revision.find('.', pos + 1); | |
| 30 if (pos == std::string::npos) | |
| 31 return ""; | |
| 32 | |
| 33 return revision.substr(0, pos); | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 // static | |
| 39 uint64_t BreakpadUtil::GetCurrentTimeMs() { | |
| 40 return (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); | |
| 41 } | |
| 42 | |
| 43 // static | |
| 44 void BreakpadUtil::RequestUploadCrashDump( | |
| 45 const std::string& existing_minidump_path, | |
| 46 const std::string& crashed_process_name, | |
| 47 uint64_t crashed_process_start_time_ms) { | |
| 48 LOG(INFO) << "Request to upload crash dump " << existing_minidump_path | |
| 49 << " for process " << crashed_process_name; | |
| 50 // Note: Do not use Chromium IO methods in this function. When cast_shell | |
| 51 // crashes, this function can be called by any thread, which may not allow IO. | |
| 52 // Use stdlib system calls for IO instead. | |
| 53 uint64_t uptime_ms = GetCurrentTimeMs() - crashed_process_start_time_ms; | |
| 54 MinidumpParams params(crashed_process_name, | |
| 55 uptime_ms, | |
| 56 "", // suffix | |
| 57 AppStateTracker::GetPreviousApp(), | |
| 58 AppStateTracker::GetCurrentApp(), | |
| 59 AppStateTracker::GetLastLaunchedApp(), | |
| 60 GetReleaseVersion(), | |
| 61 CAST_BUILD_INCREMENTAL); | |
| 62 DummyMinidumpGenerator minidump_generator(existing_minidump_path); | |
| 63 | |
| 64 // TODO(slan): Use FilePath and file_utils instead of string manipulation. | |
| 65 // Moving minidump file from /tmp/xxxxxxxxxx to $HOME/minidumps/xxxxxxxx | |
| 66 // Get filename only. | |
| 67 const size_t separator_idx = existing_minidump_path.find_last_of('/'); | |
| 68 const std::string filename = | |
| 69 (separator_idx != std::string::npos) | |
| 70 ? existing_minidump_path.substr(separator_idx + 1) | |
| 71 : existing_minidump_path; | |
| 72 const std::string dump_path = GetHomePathASCII("minidumps").value(); | |
| 73 const std::string target_minidump_path = | |
| 74 dump_path + std::string("/") + filename; | |
| 75 MinidumpWriter writer(&minidump_generator, target_minidump_path, params); | |
| 76 writer.DoWorkLocked(); // error already logged. | |
| 77 | |
| 78 // Still delete /tmp file to free memory, in case anything wrong in | |
| 79 // DummyMinidumpGenerator. | |
| 80 if (0 != remove(existing_minidump_path.c_str())) { | |
| 81 // According to base/files/file_util.h, it is considered successful | |
| 82 // to delete a file that does not exist. | |
| 83 LOG(ERROR) << "Unable to delete temp minidump file " | |
| 84 << existing_minidump_path; | |
| 85 } | |
| 86 | |
| 87 // Use std::endl to flush the log stream in case this process exits. | |
| 88 LOG(INFO) << "Request to upload crash dump finished. " | |
| 89 << "Exit now if it is main process that crashed." << std::endl; | |
| 90 } | |
| 91 | |
| 92 } // namespace chromecast | |
| OLD | NEW |