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

Side by Side Diff: unclean_shutdown_collector.cc

Issue 3644007: Crash reporter: collect suspend and resume info from power manager (Closed) Base URL: http://git.chromium.org/git/crash-reporter.git
Patch Set: Code cleanup, comments end with period, interpretation of events Created 10 years, 1 month 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 | Annotate | Revision Log
« unclean_shutdown_collector.h ('K') | « unclean_shutdown_collector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "crash-reporter/unclean_shutdown_collector.h" 5 #include "crash-reporter/unclean_shutdown_collector.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "crash-reporter/system_logging.h" 9 #include "crash-reporter/system_logging.h"
10 10
11 static const char kUncleanShutdownFile[] = 11 static const char kUncleanShutdownFile[] =
12 "/var/lib/crash_reporter/pending_clean_shutdown"; 12 "/var/lib/crash_reporter/pending_clean_shutdown";
13 13
14 // Files created by power manager used for crash reporting.
15 static const FilePath kPowerdTracePath = FilePath("/var/lib/power_manager");
tfarina 2010/11/19 15:35:43 Please, don't do this. See http://groups.google.co
tfarina 2010/11/19 15:35:43 Can you use FILE_PATH_LITERAL instead?
kmixter1 2010/11/19 20:02:02 Fair enough, I retract my statement about doing th
16 // File with timestamp of last suspend.
17 static const char kPowerdSuspendFile[] = "powerd_suspending";
18 // File with timestamp of last resume.
19 static const char kPowerdResumeFile[] = "powerd_resuming";
20 // Presence of this file indicates that the battery is critically low.
21 static const char kPowerdLowBatteryFile[] = "powerd_low_battery";
22
14 UncleanShutdownCollector::UncleanShutdownCollector() 23 UncleanShutdownCollector::UncleanShutdownCollector()
15 : unclean_shutdown_file_(kUncleanShutdownFile) { 24 : unclean_shutdown_file_(kUncleanShutdownFile) {
16 } 25 }
17 26
18 UncleanShutdownCollector::~UncleanShutdownCollector() { 27 UncleanShutdownCollector::~UncleanShutdownCollector() {
19 } 28 }
20 29
21 bool UncleanShutdownCollector::Enable() { 30 bool UncleanShutdownCollector::Enable() {
22 FilePath file_path(unclean_shutdown_file_); 31 FilePath file_path(unclean_shutdown_file_);
23 file_util::CreateDirectory(file_path.DirName()); 32 file_util::CreateDirectory(file_path.DirName());
(...skipping 14 matching lines...) Expand all
38 } 47 }
39 48
40 bool UncleanShutdownCollector::Collect() { 49 bool UncleanShutdownCollector::Collect() {
41 FilePath unclean_file_path(unclean_shutdown_file_); 50 FilePath unclean_file_path(unclean_shutdown_file_);
42 if (!file_util::PathExists(unclean_file_path)) { 51 if (!file_util::PathExists(unclean_file_path)) {
43 return false; 52 return false;
44 } 53 }
45 logger_->LogWarning("Last shutdown was not clean"); 54 logger_->LogWarning("Last shutdown was not clean");
46 DeleteUncleanShutdownFile(); 55 DeleteUncleanShutdownFile();
47 56
57 // Check for unclean shutdown due to battery running out.
tfarina 2010/11/19 15:35:43 This comment is good. I'd add it in the header fil
kmixter1 2010/11/19 20:02:02 I'd name the function to indicate this: CheckForDe
58 CheckPowerdFiles();
59
48 if (is_feedback_allowed_function_()) { 60 if (is_feedback_allowed_function_()) {
49 count_crash_function_(); 61 count_crash_function_();
50 } 62 }
51 return true; 63 return true;
52 } 64 }
53 65
54 bool UncleanShutdownCollector::Disable() { 66 bool UncleanShutdownCollector::Disable() {
55 logger_->LogInfo("Clean shutdown signalled"); 67 logger_->LogInfo("Clean shutdown signalled");
68 file_util::Delete(kPowerdTracePath.Append(kPowerdSuspendFile), false);
69 file_util::Delete(kPowerdTracePath.Append(kPowerdResumeFile), false);
70 file_util::Delete(kPowerdTracePath.Append(kPowerdLowBatteryFile), false);
56 return DeleteUncleanShutdownFile(); 71 return DeleteUncleanShutdownFile();
57 } 72 }
73
74 bool UncleanShutdownCollector::ReadModificationTime(const FilePath &file_path,
75 base::Time *mod_time)
76 {
tfarina 2010/11/19 15:35:43 the { should be in the end of the previous line.
77 file_util::FileInfo file_info;
tfarina 2010/11/19 15:35:43 Please, move this inside the first if, close where
78 base::Time::Exploded timestamp;
tfarina 2010/11/19 15:35:43 Please, move this inside the if too.
79 // Initialize timestamp fields to prevent warnings during print.
80 timestamp.hour = -1;
81 timestamp.minute = -1;
82 timestamp.second = -1;
83 // Log the file modification time if it exists.
84 if (file_util::PathExists(file_path)) {
tfarina 2010/11/19 15:35:43 You can return early. I think it's better. if (!f
85 if (!GetFileInfo(file_path, &file_info))
86 return false;
87 file_info.last_modified.LocalExplode(&timestamp);
88 logger_->LogInfo("%s modified at %02d:%02d:%02d", file_path.value().c_str(),
89 timestamp.hour, timestamp.minute, timestamp.second);
90 // Return the timestamp.
91 if (mod_time != NULL)
92 *mod_time = base::Time::FromLocalExploded(timestamp);
93 return true;
94 }
95 return false;
96 }
97
98 bool UncleanShutdownCollector::CheckPowerdFiles()
99 {
tfarina 2010/11/19 15:35:43 the { should be on the previous line.
100 logger_->LogInfo("Checking for Power Daemon files");
kmixter1 2010/11/19 20:02:02 This seems pretty chatty as we already emit a few
101
102 base::Time suspend_time, resume_time, low_battery_time;
103 bool was_suspended = ReadModificationTime(kPowerdTracePath.
104 Append(kPowerdSuspendFile), &suspend_time);
tfarina 2010/11/19 15:35:43 wrong indentation. Indent 4 spaces. Better, if pos
105 bool was_resumed = ReadModificationTime(kPowerdTracePath.
kmixter1 2010/11/19 20:02:02 I would move these down to where they're actually
106 Append(kPowerdResumeFile), &resume_time);
107 bool running_on_low_battery = ReadModificationTime(kPowerdTracePath.
108 Append(kPowerdLowBatteryFile), &low_battery_time);
109 bool battery_ran_out = false;
110
111 if (was_suspended) {
kmixter1 2010/11/19 20:02:02 Once the Delete calls are factored out you can mak
112 // Check for case of battery running out while suspended.
113 if (!was_resumed || (was_resumed && resume_time < suspend_time)) {
114 logger_->LogInfo("Unclean shutdown occurred while suspended. The battery "
115 "probably ran out.");
116 battery_ran_out = true;
117 // Check for case of battery running out after resuming from a low-battery
118 // suspend.
119 } else if (was_suspended && was_resumed && resume_time > suspend_time &&
kmixter1 2010/11/19 20:02:02 I think the whole first line of this is redundant.
120 running_on_low_battery && low_battery_time <= suspend_time) {
121
tfarina 2010/11/19 15:35:43 remove this blank line.
122 logger_->LogInfo("Unclean shutdown occurred while resumed after battery "
123 "was critically low. The battery probably ran out.");
124 battery_ran_out = true;
125 }
126 }
127
128 file_util::Delete(kPowerdTracePath.Append(kPowerdSuspendFile), false);
kmixter1 2010/11/19 20:02:02 Please separate this out into a function with a na
129 file_util::Delete(kPowerdTracePath.Append(kPowerdResumeFile), false);
130 file_util::Delete(kPowerdTracePath.Append(kPowerdLowBatteryFile), false);
131
132 return battery_ran_out;
133 }
OLDNEW
« unclean_shutdown_collector.h ('K') | « unclean_shutdown_collector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698