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

Side by Side Diff: components/browser_watcher/stability_debugging_win.cc

Issue 2128683002: Collect unclean shutdown debug information (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tracker
Patch Set: Merge Created 4 years, 3 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 (c) 2016 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 "components/browser_watcher/stability_debugging_win.h"
6
7 #include <string>
8
9 #include "base/metrics/persistent_memory_allocator.h"
10 #include "base/path_service.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/time/time.h"
13
14 namespace browser_watcher {
15
16 namespace {
17
18 bool GetCreationTime(const base::Process& process, base::Time* time) {
19 DCHECK(time);
20
21 FILETIME creation_time = {};
22 FILETIME ignore1 = {};
23 FILETIME ignore2 = {};
24 FILETIME ignore3 = {};
25 if (!::GetProcessTimes(process.Handle(), &creation_time, &ignore1, &ignore2,
26 &ignore3)) {
27 return false;
28 }
29 *time = base::Time::FromFileTime(creation_time);
30 return true;
31 }
32
33 } // namespace
34
35 // static
36 base::FilePath StabilityDebugging::GetDir(const base::FilePath& user_data_dir) {
37 return user_data_dir.AppendASCII("Stability");
38 }
39
40 // static
41 bool StabilityDebugging::GetFileForProcess(const base::Process& process,
42 const base::FilePath& user_data_dir,
43 base::FilePath* file_path) {
44 DCHECK(file_path);
45 base::FilePath stability_dir = GetDir(user_data_dir);
46
47 // Build the name using the pid and creation time. On windows, this is unique
48 // even after the process exits.
49 base::Time creation_time;
50 if (!GetCreationTime(process, &creation_time))
51 return false;
52
53 std::string file_name =
54 base::StringPrintf("%u-%llu", process.Pid(), creation_time.ToJavaTime());
55 *file_path = stability_dir.AppendASCII(file_name).AddExtension(
56 base::PersistentMemoryAllocator::kFileExtension);
57 return true;
58 }
59
60 // static
61 base::FilePath::StringType StabilityDebugging::GetFilePattern() {
62 return base::FilePath::StringType(FILE_PATH_LITERAL("*-*")) +
63 base::PersistentMemoryAllocator::kFileExtension;
64 }
65
66 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/stability_debugging_win.h ('k') | components/browser_watcher/stability_debugging_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698