Commit 20b64020 authored by Eugene But's avatar Eugene But Committed by Commit Bot

[ios] Add process uptime to synthetic crash reports

The uptime is only estimate and updated when app gets backgrounded,
battery level changes or similar system notification is posted.

It might be useful to add a timer, which updates up time every few
seconds, but that change will be done in a separate CL.

Bug: 1103752
Change-Id: Ie12af0a259f915181199bd58aa1dbc57758ab60b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459307
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815350}
parent 5a86ed7c
...@@ -101,6 +101,13 @@ void CreateSyntheticCrashReportForUte( ...@@ -101,6 +101,13 @@ void CreateSyntheticCrashReportForUte(
base::SysNSStringToUTF8(previous_session.reportParameterURLs[key])); base::SysNSStringToUTF8(previous_session.reportParameterURLs[key]));
} }
if (previous_session.sessionStartTime && previous_session.sessionEndTime) {
NSTimeInterval uptime = [previous_session.sessionEndTime
timeIntervalSinceDate:previous_session.sessionStartTime];
AppendConfig(config, "BreakpadProcessUpTime",
base::NumberToString(static_cast<long>(uptime * 1000)));
}
// Write empty minidump file, as Breakpad can't upload config without the // Write empty minidump file, as Breakpad can't upload config without the
// minidump. // minidump.
base::File minidump_file( base::File minidump_file(
......
...@@ -42,6 +42,10 @@ TEST_F(SyntheticCrashReportUtilTest, CreateSyntheticCrashReportForUte) { ...@@ -42,6 +42,10 @@ TEST_F(SyntheticCrashReportUtilTest, CreateSyntheticCrashReportForUte) {
previous_session.terminatedDuringSessionRestoration = YES; previous_session.terminatedDuringSessionRestoration = YES;
NSString* const kURL = @"URL"; NSString* const kURL = @"URL";
previous_session.reportParameterURLs = @{@"url" : kURL}; previous_session.reportParameterURLs = @{@"url" : kURL};
previous_session.sessionStartTime = [NSDate date];
const NSTimeInterval kUptimeMs = 5000;
previous_session.sessionEndTime = [previous_session.sessionStartTime
dateByAddingTimeInterval:kUptimeMs / 1000];
// Create crash report. // Create crash report.
base::ScopedTempDir temp_dir; base::ScopedTempDir temp_dir;
...@@ -98,7 +102,7 @@ TEST_F(SyntheticCrashReportUtilTest, CreateSyntheticCrashReportForUte) { ...@@ -98,7 +102,7 @@ TEST_F(SyntheticCrashReportUtilTest, CreateSyntheticCrashReportForUte) {
// Verify config file content. Config file has the following format: // Verify config file content. Config file has the following format:
// <Key1>\n<Value1Length>\n<Value1>\n...<KeyN>\n<ValueNLength>\n<ValueN> // <Key1>\n<Value1Length>\n<Value1>\n...<KeyN>\n<ValueNLength>\n<ValueN>
ASSERT_EQ(42U, config_lines.size()) ASSERT_EQ(45U, config_lines.size())
<< "<content>" << config_content << "</content>"; << "<content>" << config_content << "</content>";
EXPECT_EQ("MinidumpDir", config_lines[0]); EXPECT_EQ("MinidumpDir", config_lines[0]);
...@@ -167,6 +171,11 @@ TEST_F(SyntheticCrashReportUtilTest, CreateSyntheticCrashReportForUte) { ...@@ -167,6 +171,11 @@ TEST_F(SyntheticCrashReportUtilTest, CreateSyntheticCrashReportForUte) {
EXPECT_EQ(base::NumberToString(kURL.length), config_lines[40]); EXPECT_EQ(base::NumberToString(kURL.length), config_lines[40]);
EXPECT_EQ(base::SysNSStringToUTF8(kURL), config_lines[41]); EXPECT_EQ(base::SysNSStringToUTF8(kURL), config_lines[41]);
EXPECT_EQ("BreakpadProcessUpTime", config_lines[42]);
EXPECT_EQ(base::NumberToString(base::NumberToString(kUptimeMs).size()),
config_lines[43]);
EXPECT_EQ(base::NumberToString(kUptimeMs), config_lines[44]);
// Read minidump file. It must be empty as there is no stack trace, but // Read minidump file. It must be empty as there is no stack trace, but
// Breakpad will not upload config without minidump file. // Breakpad will not upload config without minidump file.
base::File minidump_file(minidump_file_path, base::File minidump_file(minidump_file_path,
......
...@@ -110,6 +110,11 @@ enum class DeviceBatteryState { ...@@ -110,6 +110,11 @@ enum class DeviceBatteryState {
// is available. // is available.
@property(nonatomic, strong, readonly) NSString* OSVersion; @property(nonatomic, strong, readonly) NSString* OSVersion;
// The date time at which recording for the previous sesion has started. Note
// that recording usually starts soon after startup, but not exactly at the
// startup.
@property(nonatomic, strong, readonly) NSDate* sessionStartTime;
// The time at which the previous sesion ended. Note that this is only an // The time at which the previous sesion ended. Note that this is only an
// estimate and is updated whenever another value of the receiver is updated. // estimate and is updated whenever another value of the receiver is updated.
@property(nonatomic, strong, readonly) NSDate* sessionEndTime; @property(nonatomic, strong, readonly) NSDate* sessionEndTime;
......
...@@ -76,6 +76,8 @@ NSString* const kPreviousSessionInfoBatteryLevel = ...@@ -76,6 +76,8 @@ NSString* const kPreviousSessionInfoBatteryLevel =
// the device battery state. // the device battery state.
NSString* const kPreviousSessionInfoBatteryState = NSString* const kPreviousSessionInfoBatteryState =
@"PreviousSessionInfoBatteryState"; @"PreviousSessionInfoBatteryState";
// - The (Date) of the recording start.
NSString* const kPreviousSessionInfoStartTime = @"PreviousSessionInfoStartTime";
// - The (Date) of the estimated end of the session. // - The (Date) of the estimated end of the session.
NSString* const kPreviousSessionInfoEndTime = @"PreviousSessionInfoEndTime"; NSString* const kPreviousSessionInfoEndTime = @"PreviousSessionInfoEndTime";
// - The (string) OS version. // - The (string) OS version.
...@@ -130,6 +132,7 @@ NSString* const kPreviousSessionInfoURLs = @"PreviousSessionInfoURLs"; ...@@ -130,6 +132,7 @@ NSString* const kPreviousSessionInfoURLs = @"PreviousSessionInfoURLs";
@property(nonatomic, assign) BOOL isMultiWindowEnabledSession; @property(nonatomic, assign) BOOL isMultiWindowEnabledSession;
@property(nonatomic, assign) BOOL OSRestartedAfterPreviousSession; @property(nonatomic, assign) BOOL OSRestartedAfterPreviousSession;
@property(nonatomic, strong) NSString* OSVersion; @property(nonatomic, strong) NSString* OSVersion;
@property(nonatomic, strong) NSDate* sessionStartTime;
@property(nonatomic, strong) NSDate* sessionEndTime; @property(nonatomic, strong) NSDate* sessionEndTime;
@property(nonatomic, assign) BOOL terminatedDuringSessionRestoration; @property(nonatomic, assign) BOOL terminatedDuringSessionRestoration;
@property(nonatomic, strong) NSMutableSet<NSString*>* connectedSceneSessionsIDs; @property(nonatomic, strong) NSMutableSet<NSString*>* connectedSceneSessionsIDs;
...@@ -177,6 +180,8 @@ static PreviousSessionInfo* gSharedInstance = nil; ...@@ -177,6 +180,8 @@ static PreviousSessionInfo* gSharedInstance = nil;
[defaults floatForKey:kPreviousSessionInfoBatteryLevel]; [defaults floatForKey:kPreviousSessionInfoBatteryLevel];
gSharedInstance.deviceThermalState = static_cast<DeviceThermalState>( gSharedInstance.deviceThermalState = static_cast<DeviceThermalState>(
[defaults integerForKey:kPreviousSessionInfoThermalState]); [defaults integerForKey:kPreviousSessionInfoThermalState]);
gSharedInstance.sessionStartTime =
[defaults objectForKey:kPreviousSessionInfoStartTime];
gSharedInstance.sessionEndTime = gSharedInstance.sessionEndTime =
[defaults objectForKey:kPreviousSessionInfoEndTime]; [defaults objectForKey:kPreviousSessionInfoEndTime];
...@@ -266,6 +271,8 @@ static PreviousSessionInfo* gSharedInstance = nil; ...@@ -266,6 +271,8 @@ static PreviousSessionInfo* gSharedInstance = nil;
removeObjectForKey:previous_session_info_constants:: removeObjectForKey:previous_session_info_constants::
kDidSeeMemoryWarningShortlyBeforeTerminating]; kDidSeeMemoryWarningShortlyBeforeTerminating];
[defaults setObject:[NSDate date] forKey:kPreviousSessionInfoStartTime];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver:self addObserver:self
selector:@selector(updateApplicationState) selector:@selector(updateApplicationState)
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
previous_session_info_constants::DeviceBatteryState deviceBatteryState; previous_session_info_constants::DeviceBatteryState deviceBatteryState;
@property(nonatomic, assign) BOOL OSRestartedAfterPreviousSession; @property(nonatomic, assign) BOOL OSRestartedAfterPreviousSession;
@property(nonatomic, copy) NSString* OSVersion; @property(nonatomic, copy) NSString* OSVersion;
@property(nonatomic, strong) NSDate* sessionStartTime;
@property(nonatomic, strong) NSDate* sessionEndTime;
@property(nonatomic, assign) BOOL terminatedDuringSessionRestoration; @property(nonatomic, assign) BOOL terminatedDuringSessionRestoration;
@property(nonatomic, strong) NSMutableSet<NSString*>* connectedSceneSessionsIDs; @property(nonatomic, strong) NSMutableSet<NSString*>* connectedSceneSessionsIDs;
@property(nonatomic, copy) @property(nonatomic, copy)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment