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

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

Issue 2296543002: Quantify initial stability report edge cases. (Closed)
Patch Set: Change a metric's name Created 4 years, 3 months 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 | « components/metrics/metrics_log.h ('k') | components/metrics/metrics_log_unittest.cc » ('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 #include "components/metrics/metrics_log.h" 5 #include "components/metrics/metrics_log.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 #if defined(SYZYASAN) 110 #if defined(SYZYASAN)
111 system_profile->set_is_asan_build(true); 111 system_profile->set_is_asan_build(true);
112 #endif 112 #endif
113 } 113 }
114 114
115 MetricsLog::~MetricsLog() { 115 MetricsLog::~MetricsLog() {
116 } 116 }
117 117
118 // static 118 // static
119 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { 119 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
120 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
121 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); 120 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0);
122 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); 121 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0);
122 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
123 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); 123 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0);
124 registry->RegisterIntegerPref( 124 registry->RegisterIntegerPref(
125 prefs::kStabilityBreakpadRegistrationSuccess, 0); 125 prefs::kStabilityBreakpadRegistrationSuccess, 0);
126 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); 126 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0);
127 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); 127 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0);
128 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile, 128 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile,
129 std::string()); 129 std::string());
130 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash, 130 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash,
131 std::string()); 131 std::string());
132 registry->RegisterIntegerPref(prefs::kStabilityDeferredCount, 0);
133 registry->RegisterIntegerPref(prefs::kStabilityDiscardCount, 0);
134 registry->RegisterIntegerPref(prefs::kStabilityVersionMismatchCount, 0);
132 } 135 }
133 136
134 // static 137 // static
135 uint64_t MetricsLog::Hash(const std::string& value) { 138 uint64_t MetricsLog::Hash(const std::string& value) {
136 uint64_t hash = base::HashMetricName(value); 139 uint64_t hash = base::HashMetricName(value);
137 140
138 // The following log is VERY helpful when folks add some named histogram into 141 // The following log is VERY helpful when folks add some named histogram into
139 // the code, but forgot to update the descriptive list of histograms. When 142 // the code, but forgot to update the descriptive list of histograms. When
140 // that happens, all we get to see (server side) is a hash of the histogram 143 // that happens, all we get to see (server side) is a hash of the histogram
141 // name. We can then use this logging to find out what histogram name was 144 // name. We can then use this logging to find out what histogram name was
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); 238 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
236 stability->set_debugger_present_count(debugger_present_count); 239 stability->set_debugger_present_count(debugger_present_count);
237 } 240 }
238 241
239 int debugger_not_present_count = 242 int debugger_not_present_count =
240 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); 243 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
241 if (debugger_not_present_count) { 244 if (debugger_not_present_count) {
242 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 245 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
243 stability->set_debugger_not_present_count(debugger_not_present_count); 246 stability->set_debugger_not_present_count(debugger_not_present_count);
244 } 247 }
248
249 // Note: only logging the following histograms for non-zero values.
250
251 int deferred_count = pref->GetInteger(prefs::kStabilityDeferredCount);
252 if (deferred_count) {
253 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0);
254 UMA_STABILITY_HISTOGRAM_COUNTS_100(
255 "Stability.Internals.InitialStabilityLogDeferredCount", deferred_count);
256 }
257
258 int discard_count = local_state_->GetInteger(prefs::kStabilityDiscardCount);
259 if (discard_count) {
260 local_state_->SetInteger(prefs::kStabilityDiscardCount, 0);
261 UMA_STABILITY_HISTOGRAM_COUNTS_100("Stability.Internals.DataDiscardCount",
262 discard_count);
263 }
264
265 int version_mismatch_count =
266 local_state_->GetInteger(prefs::kStabilityVersionMismatchCount);
267 if (version_mismatch_count) {
268 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0);
269 UMA_STABILITY_HISTOGRAM_COUNTS_100(
270 "Stability.Internals.VersionMismatchCount",
271 version_mismatch_count);
272 }
245 } 273 }
246 274
247 void MetricsLog::RecordGeneralMetrics( 275 void MetricsLog::RecordGeneralMetrics(
248 const std::vector<MetricsProvider*>& metrics_providers) { 276 const std::vector<MetricsProvider*>& metrics_providers) {
249 for (size_t i = 0; i < metrics_providers.size(); ++i) 277 for (size_t i = 0; i < metrics_providers.size(); ++i)
250 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); 278 metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
251 } 279 }
252 280
253 void MetricsLog::GetFieldTrialIds( 281 void MetricsLog::GetFieldTrialIds(
254 std::vector<ActiveGroupId>* field_trial_ids) const { 282 std::vector<ActiveGroupId>* field_trial_ids) const {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (system_profile->SerializeToString(&serialized_system_profile)) { 422 if (system_profile->SerializeToString(&serialized_system_profile)) {
395 base::Base64Encode(serialized_system_profile, &base64_system_profile); 423 base::Base64Encode(serialized_system_profile, &base64_system_profile);
396 PrefService* local_state = local_state_; 424 PrefService* local_state = local_state_;
397 local_state->SetString(prefs::kStabilitySavedSystemProfile, 425 local_state->SetString(prefs::kStabilitySavedSystemProfile,
398 base64_system_profile); 426 base64_system_profile);
399 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, 427 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
400 ComputeSHA1(serialized_system_profile)); 428 ComputeSHA1(serialized_system_profile));
401 } 429 }
402 } 430 }
403 431
404 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { 432 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) {
433 DCHECK(app_version);
434 app_version->clear();
435
405 PrefService* local_state = local_state_; 436 PrefService* local_state = local_state_;
406 const std::string base64_system_profile = 437 const std::string base64_system_profile =
407 local_state->GetString(prefs::kStabilitySavedSystemProfile); 438 local_state->GetString(prefs::kStabilitySavedSystemProfile);
408 if (base64_system_profile.empty()) 439 if (base64_system_profile.empty())
409 return false; 440 return false;
410 441
411 const std::string system_profile_hash = 442 const std::string system_profile_hash =
412 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); 443 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
413 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); 444 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
414 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); 445 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
415 446
416 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 447 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
417 std::string serialized_system_profile; 448 std::string serialized_system_profile;
418 return base::Base64Decode(base64_system_profile, 449
419 &serialized_system_profile) && 450 bool success =
420 ComputeSHA1(serialized_system_profile) == system_profile_hash && 451 base::Base64Decode(base64_system_profile, &serialized_system_profile) &&
421 system_profile->ParseFromString(serialized_system_profile); 452 ComputeSHA1(serialized_system_profile) == system_profile_hash &&
453 system_profile->ParseFromString(serialized_system_profile);
454 if (success)
455 *app_version = system_profile->app_version();
456 return success;
422 } 457 }
423 458
424 void MetricsLog::CloseLog() { 459 void MetricsLog::CloseLog() {
425 DCHECK(!closed_); 460 DCHECK(!closed_);
426 closed_ = true; 461 closed_ = true;
427 } 462 }
428 463
429 void MetricsLog::GetEncodedLog(std::string* encoded_log) { 464 void MetricsLog::GetEncodedLog(std::string* encoded_log) {
430 DCHECK(closed_); 465 DCHECK(closed_);
431 uma_proto_.SerializeToString(encoded_log); 466 uma_proto_.SerializeToString(encoded_log);
432 } 467 }
433 468
434 } // namespace metrics 469 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log.h ('k') | components/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698