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

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

Issue 2528033003: MetricsService: ensure in-memory/pref execution phase are in sync (Closed)
Patch Set: Add metric owner 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.
Alexei Svitkine (slow) 2016/11/24 21:20:20 Nit: Mention MarkAppCleanShutdownAndCommit() here.
manzagop (departed) 2016/11/24 22:40:42 Done.
485 local_state_->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_);
483 StartSchedulerIfNecessary(); 486 StartSchedulerIfNecessary();
484 } 487 }
485 #else 488 #else
486 void MetricsService::LogNeedForCleanShutdown() { 489 void MetricsService::LogNeedForCleanShutdown() {
487 clean_exit_beacon_.WriteBeaconValue(false); 490 clean_exit_beacon_.WriteBeaconValue(false);
488 // Redundant setting to be sure we call for a clean shutdown. 491 // Redundant setting to be sure we call for a clean shutdown.
489 clean_shutdown_status_ = NEED_TO_SHUTDOWN; 492 clean_shutdown_status_ = NEED_TO_SHUTDOWN;
490 } 493 }
491 #endif // defined(OS_ANDROID) || defined(OS_IOS) 494 #endif // defined(OS_ANDROID) || defined(OS_IOS)
492 495
(...skipping 21 matching lines...) Expand all
514 void MetricsService::ClearSavedStabilityMetrics() { 517 void MetricsService::ClearSavedStabilityMetrics() {
515 for (MetricsProvider* provider : metrics_providers_) 518 for (MetricsProvider* provider : metrics_providers_)
516 provider->ClearSavedStabilityMetrics(); 519 provider->ClearSavedStabilityMetrics();
517 520
518 // Reset the prefs that are managed by MetricsService/MetricsLog directly. 521 // Reset the prefs that are managed by MetricsService/MetricsLog directly.
519 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 522 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
520 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 523 local_state_->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
521 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); 524 local_state_->SetInteger(prefs::kStabilityCrashCount, 0);
522 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0); 525 local_state_->SetInteger(prefs::kStabilityDebuggerPresent, 0);
523 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 526 local_state_->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
524 local_state_->SetInteger(prefs::kStabilityExecutionPhase, 527 local_state_->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_);
Alexei Svitkine (slow) 2016/11/24 21:20:20 I'm not sure this makes sense. Maybe better to jus
manzagop (departed) 2016/11/24 22:40:42 Done. The value needs to be preserved up to when
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 668 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