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

Side by Side Diff: chromecast/crash/linux/crash_util.cc

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: 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 unified diff | Download patch
OLDNEW
(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/bind.h"
10 #include "base/files/file_path.h"
11 #include "base/time/time.h"
12 #include "chromecast/base/path_utils.h"
13 #include "chromecast/base/version.h"
14 #include "chromecast/crash/app_state_tracker.h"
15 #include "chromecast/crash/linux/dummy_minidump_generator.h"
16 #include "chromecast/crash/linux/minidump_writer.h"
17
18 namespace chromecast {
19
20 namespace {
21
22 // This can be set to a callback for testing. This allows us to inject a fake
23 // dumpstate routine to avoid calling an executable during an automated test.
24 // This value should not be mutated through any other function except
25 // CrashUtil::SetDumpStateCbForTest().
26 static base::Callback<int(const std::string&)>* g_dumpstate_cb = nullptr;
27
28 } // namespace
alokp 2015/06/15 17:51:48 nit: space
slan 2015/06/16 14:57:49 Done.
29 // static
30 uint64_t CrashUtil::GetCurrentTimeMs() {
31 return (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
32 }
33
34 // static
35 void CrashUtil::RequestUploadCrashDump(
36 const std::string& existing_minidump_path,
37 const std::string& crashed_process_name,
38 uint64_t crashed_process_start_time_ms) {
39 LOG(INFO) << "Request to upload crash dump " << existing_minidump_path
40 << " for process " << crashed_process_name;
41
42 // Note: Do not use Chromium IO methods in this function. When cast_shell
43 // crashes, this function can be called by any thread, which may not allow IO.
44 // Use stdlib system calls for IO instead.
45 uint64_t uptime_ms = GetCurrentTimeMs() - crashed_process_start_time_ms;
46 MinidumpParams params(crashed_process_name,
47 uptime_ms,
48 "", // suffix
49 AppStateTracker::GetPreviousApp(),
50 AppStateTracker::GetCurrentApp(),
51 AppStateTracker::GetLastLaunchedApp(),
52 CAST_BUILD_RELEASE,
53 CAST_BUILD_INCREMENTAL);
54 DummyMinidumpGenerator minidump_generator(existing_minidump_path);
55
56 base::FilePath filename = base::FilePath(existing_minidump_path).BaseName();
57
58 scoped_ptr<MinidumpWriter> writer;
59 if (g_dumpstate_cb) {
60 writer.reset(new MinidumpWriter(
61 &minidump_generator, filename.value(), params, *g_dumpstate_cb));
62 } else {
63 writer.reset(
64 new MinidumpWriter(&minidump_generator, filename.value(), params));
65 }
66 writer->DoWorkLocked(); // error already logged.
67
68 // In case the file is still in $TEMP, remove it.
69 if (remove(existing_minidump_path.c_str()) < 0 && errno != ENOENT) {
70 LOG(ERROR) << "Unable to delete temp minidump file "
71 << existing_minidump_path << ": " << strerror(errno);
72 }
73
74 // Use std::endl to flush the log stream in case this process exits.
75 LOG(INFO) << "Request to upload crash dump finished. "
76 << "Exit now if it is main process that crashed." << std::endl;
77 }
78
79 void CrashUtil::SetDumpStateCbForTest(
80 const base::Callback<int(const std::string&)>& cb) {
81 DCHECK(!g_dumpstate_cb);
82 g_dumpstate_cb = new base::Callback<int(const std::string&)>(cb);
83 }
84
85 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698