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

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

Issue 2294323002: Avoid some pref writes in MetricsLog. Ensure some stability metrics are cleared. (Closed)
Patch Set: 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 | « no previous file | no next file » | 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); 197 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
198 198
199 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 199 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
200 for (size_t i = 0; i < metrics_providers.size(); ++i) { 200 for (size_t i = 0; i < metrics_providers.size(); ++i) {
201 if (log_type() == INITIAL_STABILITY_LOG) 201 if (log_type() == INITIAL_STABILITY_LOG)
202 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile); 202 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile);
203 metrics_providers[i]->ProvideStabilityMetrics(system_profile); 203 metrics_providers[i]->ProvideStabilityMetrics(system_profile);
204 } 204 }
205 205
206 // Omit some stats unless this is the initial stability log. 206 // Omit some stats unless this is the initial stability log.
207 if (log_type() != INITIAL_STABILITY_LOG) 207 if (log_type() != INITIAL_STABILITY_LOG)
manzagop (departed) 2016/08/31 16:20:47 What is the reason for skipping these stats? Is it
Alexei Svitkine (slow) 2016/08/31 16:40:00 I think the logic was that it was not necessary to
manzagop (departed) 2016/08/31 19:26:52 Ok, removing. Won't cause a storage size increase
208 return; 208 return;
209 209
210 SystemProfileProto::Stability* stability =
211 system_profile->mutable_stability();
212
213 // TODO(jar): The following are all optional in SystemProfileProto::Stability,
manzagop (departed) 2016/08/31 16:20:47 This todo is still valid because it's about not se
Alexei Svitkine (slow) 2016/08/31 16:40:00 No server-side change is needed, so the TODO can b
manzagop (departed) 2016/08/31 19:26:51 Great! Done.
214 // so we *could* optimize them for values of zero (and not include them).
215
210 int incomplete_shutdown_count = 216 int incomplete_shutdown_count =
211 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); 217 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
212 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 218 if (incomplete_shutdown_count)
219 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
220 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
221
213 int breakpad_registration_success_count = 222 int breakpad_registration_success_count =
manzagop (departed) 2016/08/31 16:20:47 These last 4 metrics are never cleared. Should the
Alexei Svitkine (slow) 2016/08/31 16:40:00 Yes, I think so. Although, I wonder if anyone eve
manzagop (departed) 2016/08/31 19:26:52 Not feeling comfortable making that call / do the
214 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); 223 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
215 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 224 if (breakpad_registration_success_count)
225 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
226 stability->set_breakpad_registration_success_count(
227 breakpad_registration_success_count);
228
216 int breakpad_registration_failure_count = 229 int breakpad_registration_failure_count =
217 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); 230 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
218 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 231 if (breakpad_registration_failure_count)
232 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
233 stability->set_breakpad_registration_failure_count(
234 breakpad_registration_failure_count);
235
219 int debugger_present_count = 236 int debugger_present_count =
220 pref->GetInteger(prefs::kStabilityDebuggerPresent); 237 pref->GetInteger(prefs::kStabilityDebuggerPresent);
221 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); 238 if (debugger_present_count)
239 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
240 stability->set_debugger_present_count(debugger_present_count);
241
222 int debugger_not_present_count = 242 int debugger_not_present_count =
223 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); 243 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
224 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 244 if (debugger_not_present_count)
225 245 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
226 // TODO(jar): The following are all optional, so we *could* optimize them for
227 // values of zero (and not include them).
228 SystemProfileProto::Stability* stability =
229 system_profile->mutable_stability();
230 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
231 stability->set_breakpad_registration_success_count(
232 breakpad_registration_success_count);
233 stability->set_breakpad_registration_failure_count(
234 breakpad_registration_failure_count);
235 stability->set_debugger_present_count(debugger_present_count);
236 stability->set_debugger_not_present_count(debugger_not_present_count); 246 stability->set_debugger_not_present_count(debugger_not_present_count);
237 } 247 }
238 248
239 void MetricsLog::RecordGeneralMetrics( 249 void MetricsLog::RecordGeneralMetrics(
240 const std::vector<MetricsProvider*>& metrics_providers) { 250 const std::vector<MetricsProvider*>& metrics_providers) {
241 for (size_t i = 0; i < metrics_providers.size(); ++i) 251 for (size_t i = 0; i < metrics_providers.size(); ++i)
242 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); 252 metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
243 } 253 }
244 254
245 void MetricsLog::GetFieldTrialIds( 255 void MetricsLog::GetFieldTrialIds(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 bool MetricsLog::HasStabilityMetrics() const { 288 bool MetricsLog::HasStabilityMetrics() const {
279 return uma_proto()->system_profile().stability().has_launch_count(); 289 return uma_proto()->system_profile().stability().has_launch_count();
280 } 290 }
281 291
282 // The server refuses data that doesn't have certain values. crashcount and 292 // The server refuses data that doesn't have certain values. crashcount and
283 // launchcount are currently "required" in the "stability" group. 293 // launchcount are currently "required" in the "stability" group.
284 // TODO(isherman): Stop writing these attributes specially once the migration to 294 // TODO(isherman): Stop writing these attributes specially once the migration to
285 // protobufs is complete. 295 // protobufs is complete.
286 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { 296 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
287 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); 297 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
288 pref->SetInteger(prefs::kStabilityLaunchCount, 0); 298 if (launch_count)
299 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
289 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); 300 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
290 pref->SetInteger(prefs::kStabilityCrashCount, 0); 301 if (crash_count)
302 pref->SetInteger(prefs::kStabilityCrashCount, 0);
291 303
292 SystemProfileProto::Stability* stability = 304 SystemProfileProto::Stability* stability =
293 uma_proto()->mutable_system_profile()->mutable_stability(); 305 uma_proto()->mutable_system_profile()->mutable_stability();
294 stability->set_launch_count(launch_count); 306 stability->set_launch_count(launch_count);
295 stability->set_crash_count(crash_count); 307 stability->set_crash_count(crash_count);
296 } 308 }
297 309
298 void MetricsLog::WriteRealtimeStabilityAttributes( 310 void MetricsLog::WriteRealtimeStabilityAttributes(
299 PrefService* pref, 311 PrefService* pref,
300 base::TimeDelta incremental_uptime, 312 base::TimeDelta incremental_uptime,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); 384 cpu->set_num_cores(base::SysInfo::NumberOfProcessors());
373 385
374 std::vector<ActiveGroupId> field_trial_ids; 386 std::vector<ActiveGroupId> field_trial_ids;
375 GetFieldTrialIds(&field_trial_ids); 387 GetFieldTrialIds(&field_trial_ids);
376 WriteFieldTrials(field_trial_ids, system_profile); 388 WriteFieldTrials(field_trial_ids, system_profile);
377 WriteFieldTrials(synthetic_trials, system_profile); 389 WriteFieldTrials(synthetic_trials, system_profile);
378 390
379 for (size_t i = 0; i < metrics_providers.size(); ++i) 391 for (size_t i = 0; i < metrics_providers.size(); ++i)
380 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); 392 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
381 393
382 std::string serialied_system_profile; 394 std::string serialized_system_profile;
383 std::string base64_system_profile; 395 std::string base64_system_profile;
384 if (system_profile->SerializeToString(&serialied_system_profile)) { 396 if (system_profile->SerializeToString(&serialized_system_profile)) {
385 base::Base64Encode(serialied_system_profile, &base64_system_profile); 397 base::Base64Encode(serialized_system_profile, &base64_system_profile);
386 PrefService* local_state = local_state_; 398 PrefService* local_state = local_state_;
387 local_state->SetString(prefs::kStabilitySavedSystemProfile, 399 local_state->SetString(prefs::kStabilitySavedSystemProfile,
388 base64_system_profile); 400 base64_system_profile);
389 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, 401 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
390 ComputeSHA1(serialied_system_profile)); 402 ComputeSHA1(serialized_system_profile));
391 } 403 }
392 } 404 }
393 405
394 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { 406 bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
395 PrefService* local_state = local_state_; 407 PrefService* local_state = local_state_;
396 const std::string base64_system_profile = 408 const std::string base64_system_profile =
397 local_state->GetString(prefs::kStabilitySavedSystemProfile); 409 local_state->GetString(prefs::kStabilitySavedSystemProfile);
398 if (base64_system_profile.empty()) 410 if (base64_system_profile.empty())
399 return false; 411 return false;
400 412
401 const std::string system_profile_hash = 413 const std::string system_profile_hash =
402 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); 414 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
403 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); 415 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
404 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); 416 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
405 417
406 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 418 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
407 std::string serialied_system_profile; 419 std::string serialized_system_profile;
408 return base::Base64Decode(base64_system_profile, &serialied_system_profile) && 420 return base::Base64Decode(base64_system_profile,
409 ComputeSHA1(serialied_system_profile) == system_profile_hash && 421 &serialized_system_profile) &&
410 system_profile->ParseFromString(serialied_system_profile); 422 ComputeSHA1(serialized_system_profile) == system_profile_hash &&
423 system_profile->ParseFromString(serialized_system_profile);
411 } 424 }
412 425
413 void MetricsLog::CloseLog() { 426 void MetricsLog::CloseLog() {
414 DCHECK(!closed_); 427 DCHECK(!closed_);
415 closed_ = true; 428 closed_ = true;
416 } 429 }
417 430
418 void MetricsLog::GetEncodedLog(std::string* encoded_log) { 431 void MetricsLog::GetEncodedLog(std::string* encoded_log) {
419 DCHECK(closed_); 432 DCHECK(closed_);
420 uma_proto_.SerializeToString(encoded_log); 433 uma_proto_.SerializeToString(encoded_log);
421 } 434 }
422 435
423 } // namespace metrics 436 } // namespace metrics
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698