OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
7 // | 7 // |
8 // OVERVIEW | 8 // OVERVIEW |
9 // | 9 // |
10 // A MetricsService instance is typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 return NO_RESPONSE; | 247 return NO_RESPONSE; |
248 case 200: | 248 case 200: |
249 return SUCCESS; | 249 return SUCCESS; |
250 case 400: | 250 case 400: |
251 return BAD_REQUEST; | 251 return BAD_REQUEST; |
252 default: | 252 default: |
253 return UNKNOWN_FAILURE; | 253 return UNKNOWN_FAILURE; |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 void MarkAppCleanShutdownAndCommit(PrefService* local_state) { | 257 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, |
258 local_state->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); | 258 PrefService* local_state) { |
259 clean_exit_beacon->WriteBeaconValue(true); | |
259 local_state->SetInteger(metrics::prefs::kStabilityExecutionPhase, | 260 local_state->SetInteger(metrics::prefs::kStabilityExecutionPhase, |
260 MetricsService::SHUTDOWN_COMPLETE); | 261 MetricsService::SHUTDOWN_COMPLETE); |
261 // Start writing right away (write happens on a different thread). | 262 // Start writing right away (write happens on a different thread). |
262 local_state->CommitPendingWrite(); | 263 local_state->CommitPendingWrite(); |
263 } | 264 } |
264 | 265 |
265 } // namespace | 266 } // namespace |
266 | 267 |
267 | 268 |
268 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { | 269 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { |
269 id.name = trial; | 270 id.name = trial; |
270 id.group = group; | 271 id.group = group; |
271 } | 272 } |
272 | 273 |
273 SyntheticTrialGroup::~SyntheticTrialGroup() { | 274 SyntheticTrialGroup::~SyntheticTrialGroup() { |
274 } | 275 } |
275 | 276 |
276 // static | 277 // static |
277 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = | 278 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = |
278 MetricsService::CLEANLY_SHUTDOWN; | 279 MetricsService::CLEANLY_SHUTDOWN; |
279 | 280 |
280 MetricsService::ExecutionPhase MetricsService::execution_phase_ = | 281 MetricsService::ExecutionPhase MetricsService::execution_phase_ = |
281 MetricsService::UNINITIALIZED_PHASE; | 282 MetricsService::UNINITIALIZED_PHASE; |
282 | 283 |
283 // static | 284 // static |
284 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { | 285 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { |
285 DCHECK(IsSingleThreaded()); | 286 DCHECK(IsSingleThreaded()); |
286 metrics::MetricsStateManager::RegisterPrefs(registry); | 287 metrics::MetricsStateManager::RegisterPrefs(registry); |
287 MetricsLog::RegisterPrefs(registry); | 288 MetricsLog::RegisterPrefs(registry); |
289 CleanExitBeacon::RegisterPrefs(registry); | |
288 | 290 |
289 registry->RegisterInt64Pref(metrics::prefs::kInstallDate, 0); | 291 registry->RegisterInt64Pref(metrics::prefs::kInstallDate, 0); |
290 | 292 |
291 registry->RegisterInt64Pref(metrics::prefs::kStabilityLaunchTimeSec, 0); | 293 registry->RegisterInt64Pref(metrics::prefs::kStabilityLaunchTimeSec, 0); |
292 registry->RegisterInt64Pref(metrics::prefs::kStabilityLastTimestampSec, 0); | 294 registry->RegisterInt64Pref(metrics::prefs::kStabilityLastTimestampSec, 0); |
293 registry->RegisterStringPref(metrics::prefs::kStabilityStatsVersion, | 295 registry->RegisterStringPref(metrics::prefs::kStabilityStatsVersion, |
294 std::string()); | 296 std::string()); |
295 registry->RegisterInt64Pref(metrics::prefs::kStabilityStatsBuildTime, 0); | 297 registry->RegisterInt64Pref(metrics::prefs::kStabilityStatsBuildTime, 0); |
296 registry->RegisterBooleanPref(metrics::prefs::kStabilityExitedCleanly, true); | |
297 registry->RegisterIntegerPref(metrics::prefs::kStabilityExecutionPhase, | 298 registry->RegisterIntegerPref(metrics::prefs::kStabilityExecutionPhase, |
298 UNINITIALIZED_PHASE); | 299 UNINITIALIZED_PHASE); |
299 registry->RegisterBooleanPref(metrics::prefs::kStabilitySessionEndCompleted, | 300 registry->RegisterBooleanPref(metrics::prefs::kStabilitySessionEndCompleted, |
300 true); | 301 true); |
301 registry->RegisterIntegerPref(metrics::prefs::kMetricsSessionID, -1); | 302 registry->RegisterIntegerPref(metrics::prefs::kMetricsSessionID, -1); |
302 | 303 |
303 registry->RegisterListPref(metrics::prefs::kMetricsInitialLogs); | 304 registry->RegisterListPref(metrics::prefs::kMetricsInitialLogs); |
304 registry->RegisterListPref(metrics::prefs::kMetricsOngoingLogs); | 305 registry->RegisterListPref(metrics::prefs::kMetricsOngoingLogs); |
305 | 306 |
306 registry->RegisterInt64Pref(metrics::prefs::kUninstallLaunchCount, 0); | 307 registry->RegisterInt64Pref(metrics::prefs::kUninstallLaunchCount, 0); |
307 registry->RegisterInt64Pref(metrics::prefs::kUninstallMetricsUptimeSec, 0); | 308 registry->RegisterInt64Pref(metrics::prefs::kUninstallMetricsUptimeSec, 0); |
308 } | 309 } |
309 | 310 |
310 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, | 311 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
311 metrics::MetricsServiceClient* client, | 312 metrics::MetricsServiceClient* client, |
312 PrefService* local_state) | 313 PrefService* local_state) |
313 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), | 314 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), |
314 histogram_snapshot_manager_(this), | 315 histogram_snapshot_manager_(this), |
315 state_manager_(state_manager), | 316 state_manager_(state_manager), |
316 client_(client), | 317 client_(client), |
317 local_state_(local_state), | 318 local_state_(local_state), |
319 #if defined(OS_WIN) | |
320 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), | |
321 #else | |
322 clean_exit_beacon_(local_state), | |
323 #endif | |
318 recording_active_(false), | 324 recording_active_(false), |
319 reporting_active_(false), | 325 reporting_active_(false), |
320 test_mode_active_(false), | 326 test_mode_active_(false), |
321 state_(INITIALIZED), | 327 state_(INITIALIZED), |
322 has_initial_stability_log_(false), | 328 has_initial_stability_log_(false), |
323 log_upload_in_progress_(false), | 329 log_upload_in_progress_(false), |
324 idle_since_last_transmission_(false), | 330 idle_since_last_transmission_(false), |
325 session_id_(-1), | 331 session_id_(-1), |
326 self_ptr_factory_(this), | 332 self_ptr_factory_(this), |
327 state_saver_factory_(this) { | 333 state_saver_factory_(this) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 | 497 |
492 void MetricsService::RecordCompletedSessionEnd() { | 498 void MetricsService::RecordCompletedSessionEnd() { |
493 LogCleanShutdown(); | 499 LogCleanShutdown(); |
494 RecordBooleanPrefValue(metrics::prefs::kStabilitySessionEndCompleted, true); | 500 RecordBooleanPrefValue(metrics::prefs::kStabilitySessionEndCompleted, true); |
495 } | 501 } |
496 | 502 |
497 #if defined(OS_ANDROID) || defined(OS_IOS) | 503 #if defined(OS_ANDROID) || defined(OS_IOS) |
498 void MetricsService::OnAppEnterBackground() { | 504 void MetricsService::OnAppEnterBackground() { |
499 scheduler_->Stop(); | 505 scheduler_->Stop(); |
500 | 506 |
501 MarkAppCleanShutdownAndCommit(local_state_); | 507 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); |
502 | 508 |
503 // At this point, there's no way of knowing when the process will be | 509 // At this point, there's no way of knowing when the process will be |
504 // killed, so this has to be treated similar to a shutdown, closing and | 510 // killed, so this has to be treated similar to a shutdown, closing and |
505 // persisting all logs. Unlinke a shutdown, the state is primed to be ready | 511 // persisting all logs. Unlinke a shutdown, the state is primed to be ready |
506 // to continue logging and uploading if the process does return. | 512 // to continue logging and uploading if the process does return. |
507 if (recording_active() && state_ >= SENDING_INITIAL_STABILITY_LOG) { | 513 if (recording_active() && state_ >= SENDING_INITIAL_STABILITY_LOG) { |
508 PushPendingLogsToPersistentStorage(); | 514 PushPendingLogsToPersistentStorage(); |
509 // Persisting logs closes the current log, so start recording a new log | 515 // Persisting logs closes the current log, so start recording a new log |
510 // immediately to capture any background work that might be done before the | 516 // immediately to capture any background work that might be done before the |
511 // process is killed. | 517 // process is killed. |
512 OpenNewLog(); | 518 OpenNewLog(); |
513 } | 519 } |
514 } | 520 } |
515 | 521 |
516 void MetricsService::OnAppEnterForeground() { | 522 void MetricsService::OnAppEnterForeground() { |
517 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, false); | 523 clean_exit_beacon_->WriteBeaconValue(false); |
Alexei Svitkine (slow)
2014/09/11 15:23:28
Shouldn't this be . instead of ->?
erikwright (departed)
2014/09/11 19:00:29
Done.
| |
518 StartSchedulerIfNecessary(); | 524 StartSchedulerIfNecessary(); |
519 } | 525 } |
520 #else | 526 #else |
521 void MetricsService::LogNeedForCleanShutdown() { | 527 void MetricsService::LogNeedForCleanShutdown() { |
522 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, false); | 528 clean_exit_beacon_.WriteBeaconValue(false); |
523 // Redundant setting to be sure we call for a clean shutdown. | 529 // Redundant setting to be sure we call for a clean shutdown. |
524 clean_shutdown_status_ = NEED_TO_SHUTDOWN; | 530 clean_shutdown_status_ = NEED_TO_SHUTDOWN; |
525 } | 531 } |
526 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 532 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
527 | 533 |
528 // static | 534 // static |
529 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase, | 535 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase, |
530 PrefService* local_state) { | 536 PrefService* local_state) { |
531 execution_phase_ = execution_phase; | 537 execution_phase_ = execution_phase; |
532 local_state->SetInteger(metrics::prefs::kStabilityExecutionPhase, | 538 local_state->SetInteger(metrics::prefs::kStabilityExecutionPhase, |
(...skipping 25 matching lines...) Expand all Loading... | |
558 void MetricsService::InitializeMetricsState() { | 564 void MetricsService::InitializeMetricsState() { |
559 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, | 565 local_state_->SetString(metrics::prefs::kStabilityStatsVersion, |
560 client_->GetVersionString()); | 566 client_->GetVersionString()); |
561 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, | 567 local_state_->SetInt64(metrics::prefs::kStabilityStatsBuildTime, |
562 MetricsLog::GetBuildTime()); | 568 MetricsLog::GetBuildTime()); |
563 | 569 |
564 log_manager_.LoadPersistedUnsentLogs(); | 570 log_manager_.LoadPersistedUnsentLogs(); |
565 | 571 |
566 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); | 572 session_id_ = local_state_->GetInteger(metrics::prefs::kMetricsSessionID); |
567 | 573 |
568 if (!local_state_->GetBoolean(metrics::prefs::kStabilityExitedCleanly)) { | 574 if (!clean_exit_beacon_.exited_cleanly()) { |
Alexei Svitkine (slow)
2014/09/11 15:23:28
Note: You need to sync/rebase on top of siggi's ch
erikwright (departed)
2014/09/11 19:00:29
Done.
| |
569 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); | 575 IncrementPrefValue(metrics::prefs::kStabilityCrashCount); |
570 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 576 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
571 // monitoring. | 577 // monitoring. |
572 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); | 578 clean_exit_beacon_.WriteBeaconValue(true); |
573 | 579 |
574 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 580 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
575 // the registry. | 581 // the registry. |
576 int execution_phase = | 582 int execution_phase = |
577 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); | 583 local_state_->GetInteger(metrics::prefs::kStabilityExecutionPhase); |
578 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 584 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
579 execution_phase); | 585 execution_phase); |
580 | 586 |
581 // If the previous session didn't exit cleanly, then prepare an initial | 587 // If the previous session didn't exit cleanly, then prepare an initial |
582 // stability log if UMA is enabled. | 588 // stability log if UMA is enabled. |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 } | 1152 } |
1147 | 1153 |
1148 void MetricsService::RecordCurrentStabilityHistograms() { | 1154 void MetricsService::RecordCurrentStabilityHistograms() { |
1149 DCHECK(log_manager_.current_log()); | 1155 DCHECK(log_manager_.current_log()); |
1150 histogram_snapshot_manager_.PrepareDeltas( | 1156 histogram_snapshot_manager_.PrepareDeltas( |
1151 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1157 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
1152 } | 1158 } |
1153 | 1159 |
1154 void MetricsService::LogCleanShutdown() { | 1160 void MetricsService::LogCleanShutdown() { |
1155 // Redundant hack to write pref ASAP. | 1161 // Redundant hack to write pref ASAP. |
1156 MarkAppCleanShutdownAndCommit(local_state_); | 1162 MarkAppCleanShutdownAndCommit(&clean_exit_beacon_, local_state_); |
1157 | 1163 |
1158 // Redundant setting to assure that we always reset this value at shutdown | 1164 // Redundant setting to assure that we always reset this value at shutdown |
1159 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1165 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1160 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1166 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1161 | 1167 |
1162 RecordBooleanPrefValue(metrics::prefs::kStabilityExitedCleanly, true); | 1168 clean_exit_beacon_.WriteBeaconValue(true); |
1169 RecordCurrentState(local_state_); | |
1163 local_state_->SetInteger(metrics::prefs::kStabilityExecutionPhase, | 1170 local_state_->SetInteger(metrics::prefs::kStabilityExecutionPhase, |
1164 MetricsService::SHUTDOWN_COMPLETE); | 1171 MetricsService::SHUTDOWN_COMPLETE); |
1165 } | 1172 } |
1166 | 1173 |
1167 bool MetricsService::ShouldLogEvents() { | 1174 bool MetricsService::ShouldLogEvents() { |
1168 // We simply don't log events to UMA if there is a single incognito | 1175 // We simply don't log events to UMA if there is a single incognito |
1169 // session visible. The problem is that we always notify using the orginal | 1176 // session visible. The problem is that we always notify using the orginal |
1170 // profile in order to simplify notification processing. | 1177 // profile in order to simplify notification processing. |
1171 return !client_->IsOffTheRecordSessionActive(); | 1178 return !client_->IsOffTheRecordSessionActive(); |
1172 } | 1179 } |
1173 | 1180 |
1174 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1181 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1175 DCHECK(IsSingleThreaded()); | 1182 DCHECK(IsSingleThreaded()); |
1176 local_state_->SetBoolean(path, value); | 1183 local_state_->SetBoolean(path, value); |
1177 RecordCurrentState(local_state_); | 1184 RecordCurrentState(local_state_); |
1178 } | 1185 } |
1179 | 1186 |
1180 void MetricsService::RecordCurrentState(PrefService* pref) { | 1187 void MetricsService::RecordCurrentState(PrefService* pref) { |
1181 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, | 1188 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, |
1182 base::Time::Now().ToTimeT()); | 1189 base::Time::Now().ToTimeT()); |
1183 } | 1190 } |
1184 | 1191 |
1185 } // namespace metrics | 1192 } // namespace metrics |
OLD | NEW |