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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 2528033003: MetricsService: ensure in-memory/pref execution phase are in sync (Closed)
Patch Set: Address comments Created 4 years 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return BAD_REQUEST; 215 return BAD_REQUEST;
216 default: 216 default:
217 return UNKNOWN_FAILURE; 217 return UNKNOWN_FAILURE;
218 } 218 }
219 } 219 }
220 220
221 #if defined(OS_ANDROID) || defined(OS_IOS) 221 #if defined(OS_ANDROID) || defined(OS_IOS)
222 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, 222 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon,
223 PrefService* local_state) { 223 PrefService* local_state) {
224 clean_exit_beacon->WriteBeaconValue(true); 224 clean_exit_beacon->WriteBeaconValue(true);
225 // Note: the in-memory MetricsService::execution_phase_ is not updated.
225 local_state->SetInteger(prefs::kStabilityExecutionPhase, 226 local_state->SetInteger(prefs::kStabilityExecutionPhase,
226 MetricsService::SHUTDOWN_COMPLETE); 227 MetricsService::SHUTDOWN_COMPLETE);
227 // Start writing right away (write happens on a different thread). 228 // Start writing right away (write happens on a different thread).
228 local_state->CommitPendingWrite(); 229 local_state->CommitPendingWrite();
229 } 230 }
230 #endif // defined(OS_ANDROID) || defined(OS_IOS) 231 #endif // defined(OS_ANDROID) || defined(OS_IOS)
231 232
232 } // namespace 233 } // namespace
233 234
234 // static 235 // static
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 PushPendingLogsToPersistentStorage(); 474 PushPendingLogsToPersistentStorage();
474 // Persisting logs closes the current log, so start recording a new log 475 // Persisting logs closes the current log, so start recording a new log
475 // immediately to capture any background work that might be done before the 476 // immediately to capture any background work that might be done before the
476 // process is killed. 477 // process is killed.
477 OpenNewLog(); 478 OpenNewLog();
478 } 479 }
479 } 480 }
480 481
481 void MetricsService::OnAppEnterForeground() { 482 void MetricsService::OnAppEnterForeground() {
482 clean_exit_beacon_.WriteBeaconValue(false); 483 clean_exit_beacon_.WriteBeaconValue(false);
484 // Restore the execution phase stored in prefs. It was altered in
485 // OnAppEnterBackground by a call to MarkAppCleanShutdownAndCommit.
486 local_state_->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_);
483 StartSchedulerIfNecessary(); 487 StartSchedulerIfNecessary();
484 } 488 }
485 #else 489 #else
486 void MetricsService::LogNeedForCleanShutdown() { 490 void MetricsService::LogNeedForCleanShutdown() {
487 clean_exit_beacon_.WriteBeaconValue(false); 491 clean_exit_beacon_.WriteBeaconValue(false);
488 // Redundant setting to be sure we call for a clean shutdown. 492 // Redundant setting to be sure we call for a clean shutdown.
489 clean_shutdown_status_ = NEED_TO_SHUTDOWN; 493 clean_shutdown_status_ = NEED_TO_SHUTDOWN;
490 } 494 }
491 #endif // defined(OS_ANDROID) || defined(OS_IOS) 495 #endif // defined(OS_ANDROID) || defined(OS_IOS)
492 496
(...skipping 21 matching lines...) Expand all
514 void MetricsService::ClearSavedStabilityMetrics() { 518 void MetricsService::ClearSavedStabilityMetrics() {
515 for (MetricsProvider* provider : metrics_providers_) 519 for (MetricsProvider* provider : metrics_providers_)
516 provider->ClearSavedStabilityMetrics(); 520 provider->ClearSavedStabilityMetrics();
517 521
518 // Reset the prefs that are managed by MetricsService/MetricsLog directly. 522 // Reset the prefs that are managed by MetricsService/MetricsLog directly.
519 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 523 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
520 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 524 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
521 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); 525 local_state_->SetInteger(prefs::kStabilityCrashCount, 0);
522 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0); 526 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0);
523 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 527 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
524 local_state_->SetInteger(prefs::kStabilityExecutionPhase,
525 UNINITIALIZED_PHASE);
526 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 528 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
527 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); 529 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0);
528 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); 530 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
529 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); 531 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0);
530 // Note: kStabilityDiscardCount is not cleared as its intent is to measure 532 // Note: kStabilityDiscardCount is not cleared as its intent is to measure
531 // the number of times data is discarded, even across versions. 533 // the number of times data is discarded, even across versions.
532 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); 534 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0);
533 } 535 }
534 536
535 void MetricsService::PushExternalLog(const std::string& log) { 537 void MetricsService::PushExternalLog(const std::string& log) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 577
576 log_manager_.LoadPersistedUnsentLogs(); 578 log_manager_.LoadPersistedUnsentLogs();
577 579
578 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); 580 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID);
579 581
580 if (!clean_exit_beacon_.exited_cleanly()) { 582 if (!clean_exit_beacon_.exited_cleanly()) {
581 IncrementPrefValue(prefs::kStabilityCrashCount); 583 IncrementPrefValue(prefs::kStabilityCrashCount);
582 // Reset flag, and wait until we call LogNeedForCleanShutdown() before 584 // Reset flag, and wait until we call LogNeedForCleanShutdown() before
583 // monitoring. 585 // monitoring.
584 clean_exit_beacon_.WriteBeaconValue(true); 586 clean_exit_beacon_.WriteBeaconValue(true);
587 // TODO(rtenneti): On windows, consider saving/getting execution_phase from
588 // the registry.
589 int execution_phase =
590 local_state_->GetInteger(prefs::kStabilityExecutionPhase);
591 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase",
592 execution_phase);
593 SetExecutionPhase(UNINITIALIZED_PHASE, local_state_);
manzagop (departed) 2016/11/24 22:40:42 I moved this here, because is should only be sent
585 } 594 }
586 595
587 // ProvidersHaveInitialStabilityMetrics is called first to ensure it is never 596 // ProvidersHaveInitialStabilityMetrics is called first to ensure it is never
588 // bypassed. 597 // bypassed.
589 const bool is_initial_stability_log_required = 598 const bool is_initial_stability_log_required =
590 ProvidersHaveInitialStabilityMetrics() || 599 ProvidersHaveInitialStabilityMetrics() ||
591 !clean_exit_beacon_.exited_cleanly(); 600 !clean_exit_beacon_.exited_cleanly();
592 bool has_initial_stability_log = false; 601 bool has_initial_stability_log = false;
593 if (is_initial_stability_log_required) { 602 if (is_initial_stability_log_required) {
594 // TODO(rtenneti): On windows, consider saving/getting execution_phase from
595 // the registry.
596 int execution_phase =
597 local_state_->GetInteger(prefs::kStabilityExecutionPhase);
598 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase",
599 execution_phase);
600
601 // If the previous session didn't exit cleanly, or if any provider 603 // If the previous session didn't exit cleanly, or if any provider
602 // explicitly requests it, prepare an initial stability log - 604 // explicitly requests it, prepare an initial stability log -
603 // provided UMA is enabled. 605 // provided UMA is enabled.
604 if (state_manager_->IsMetricsReportingEnabled()) { 606 if (state_manager_->IsMetricsReportingEnabled()) {
605 has_initial_stability_log = PrepareInitialStabilityLog(previous_version); 607 has_initial_stability_log = PrepareInitialStabilityLog(previous_version);
606 if (!has_initial_stability_log) 608 if (!has_initial_stability_log)
607 IncrementPrefValue(prefs::kStabilityDeferredCount); 609 IncrementPrefValue(prefs::kStabilityDeferredCount);
608 } 610 }
609 } 611 }
610 612
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 provider->RecordInitialHistogramSnapshots(&histogram_snapshot_manager_); 1206 provider->RecordInitialHistogramSnapshots(&histogram_snapshot_manager_);
1205 } 1207 }
1206 1208
1207 void MetricsService::LogCleanShutdown() { 1209 void MetricsService::LogCleanShutdown() {
1208 // Redundant setting to assure that we always reset this value at shutdown 1210 // Redundant setting to assure that we always reset this value at shutdown
1209 // (and that we don't use some alternate path, and not call LogCleanShutdown). 1211 // (and that we don't use some alternate path, and not call LogCleanShutdown).
1210 clean_shutdown_status_ = CLEANLY_SHUTDOWN; 1212 clean_shutdown_status_ = CLEANLY_SHUTDOWN;
1211 client_->OnLogCleanShutdown(); 1213 client_->OnLogCleanShutdown();
1212 clean_exit_beacon_.WriteBeaconValue(true); 1214 clean_exit_beacon_.WriteBeaconValue(true);
1213 RecordCurrentState(local_state_); 1215 RecordCurrentState(local_state_);
1214 local_state_->SetInteger(prefs::kStabilityExecutionPhase, 1216 SetExecutionPhase(MetricsService::SHUTDOWN_COMPLETE, local_state_);
1215 MetricsService::SHUTDOWN_COMPLETE);
1216 } 1217 }
1217 1218
1218 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { 1219 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) {
1219 DCHECK(IsSingleThreaded()); 1220 DCHECK(IsSingleThreaded());
1220 local_state_->SetBoolean(path, value); 1221 local_state_->SetBoolean(path, value);
1221 RecordCurrentState(local_state_); 1222 RecordCurrentState(local_state_);
1222 } 1223 }
1223 1224
1224 void MetricsService::RecordCurrentState(PrefService* pref) { 1225 void MetricsService::RecordCurrentState(PrefService* pref) {
1225 pref->SetInt64(prefs::kStabilityLastTimestampSec, 1226 pref->SetInt64(prefs::kStabilityLastTimestampSec,
1226 base::Time::Now().ToTimeT()); 1227 base::Time::Now().ToTimeT());
1227 } 1228 }
1228 1229
1229 void MetricsService::SkipAndDiscardUpload() { 1230 void MetricsService::SkipAndDiscardUpload() {
1230 log_manager_.DiscardStagedLog(); 1231 log_manager_.DiscardStagedLog();
1231 scheduler_->UploadCancelled(); 1232 scheduler_->UploadCancelled();
1232 log_upload_in_progress_ = false; 1233 log_upload_in_progress_ = false;
1233 } 1234 }
1234 1235
1235 } // namespace metrics 1236 } // namespace metrics
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698