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

Side by Side Diff: chrome/browser/metrics/metrics_log.cc

Issue 299783004: Create PluginMetricsProvider class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/metrics/metrics_log.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/sys_info.h" 24 #include "base/sys_info.h"
25 #include "base/third_party/nspr/prtime.h" 25 #include "base/third_party/nspr/prtime.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "base/tracked_objects.h" 27 #include "base/tracked_objects.h"
28 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/google/google_util.h" 29 #include "chrome/browser/google/google_util.h"
30 #include "chrome/browser/metrics/extension_metrics.h" 30 #include "chrome/browser/metrics/extension_metrics.h"
31 #include "chrome/browser/plugins/plugin_prefs.h"
32 #include "chrome/browser/profiles/profile_manager.h"
33 #include "chrome/common/chrome_version_info.h" 31 #include "chrome/common/chrome_version_info.h"
34 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
35 #include "components/metrics/metrics_provider.h" 33 #include "components/metrics/metrics_provider.h"
36 #include "components/metrics/proto/profiler_event.pb.h" 34 #include "components/metrics/proto/profiler_event.pb.h"
37 #include "components/metrics/proto/system_profile.pb.h" 35 #include "components/metrics/proto/system_profile.pb.h"
38 #include "components/nacl/common/nacl_process_type.h" 36 #include "components/nacl/common/nacl_process_type.h"
39 #include "components/variations/active_field_trials.h" 37 #include "components/variations/active_field_trials.h"
40 #include "content/public/browser/gpu_data_manager.h" 38 #include "content/public/browser/gpu_data_manager.h"
41 #include "content/public/common/content_client.h" 39 #include "content/public/common/content_client.h"
42 #include "content/public/common/webplugininfo.h"
43 #include "gpu/config/gpu_info.h" 40 #include "gpu/config/gpu_info.h"
44 #include "ui/gfx/screen.h" 41 #include "ui/gfx/screen.h"
45 #include "url/gurl.h" 42 #include "url/gurl.h"
46 43
47 #if defined(OS_ANDROID) 44 #if defined(OS_ANDROID)
48 #include "base/android/build_info.h" 45 #include "base/android/build_info.h"
49 #endif 46 #endif
50 47
51 #if defined(OS_WIN) 48 #if defined(OS_WIN)
52 #include "base/win/metro.h" 49 #include "base/win/metro.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return SystemProfileProto::CHANNEL_UNKNOWN; 127 return SystemProfileProto::CHANNEL_UNKNOWN;
131 } 128 }
132 } 129 }
133 130
134 // Computes a SHA-1 hash of |data| and returns it as a hex string. 131 // Computes a SHA-1 hash of |data| and returns it as a hex string.
135 std::string ComputeSHA1(const std::string& data) { 132 std::string ComputeSHA1(const std::string& data) {
136 const std::string sha1 = base::SHA1HashString(data); 133 const std::string sha1 = base::SHA1HashString(data);
137 return base::HexEncode(sha1.data(), sha1.size()); 134 return base::HexEncode(sha1.data(), sha1.size());
138 } 135 }
139 136
140 #if defined(ENABLE_PLUGINS)
141 // Returns the plugin preferences corresponding for this user, if available.
142 // If multiple user profiles are loaded, returns the preferences corresponding
143 // to an arbitrary one of the profiles.
144 PluginPrefs* GetPluginPrefs() {
145 ProfileManager* profile_manager = g_browser_process->profile_manager();
146
147 if (!profile_manager) {
148 // The profile manager can be NULL when testing.
149 return NULL;
150 }
151
152 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
153 if (profiles.empty())
154 return NULL;
155
156 return PluginPrefs::GetForProfile(profiles.front()).get();
157 }
158
159 // Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|.
160 void SetPluginInfo(const content::WebPluginInfo& plugin_info,
161 const PluginPrefs* plugin_prefs,
162 SystemProfileProto::Plugin* plugin) {
163 plugin->set_name(base::UTF16ToUTF8(plugin_info.name));
164 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
165 plugin->set_version(base::UTF16ToUTF8(plugin_info.version));
166 plugin->set_is_pepper(plugin_info.is_pepper_plugin());
167 if (plugin_prefs)
168 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
169 }
170 #endif // defined(ENABLE_PLUGINS)
171
172 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, 137 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
173 SystemProfileProto* system_profile) { 138 SystemProfileProto* system_profile) {
174 for (std::vector<ActiveGroupId>::const_iterator it = 139 for (std::vector<ActiveGroupId>::const_iterator it =
175 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { 140 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
176 SystemProfileProto::FieldTrial* field_trial = 141 SystemProfileProto::FieldTrial* field_trial =
177 system_profile->add_field_trial(); 142 system_profile->add_field_trial();
178 field_trial->set_name_id(it->name); 143 field_trial->set_name_id(it->name);
179 field_trial->set_group_id(it->group); 144 field_trial->set_group_id(it->group);
180 } 145 }
181 } 146 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 AsProtobufChannel(chrome::VersionInfo::GetChannel())); 260 AsProtobufChannel(chrome::VersionInfo::GetChannel()));
296 261
297 #if defined(OS_CHROMEOS) 262 #if defined(OS_CHROMEOS)
298 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); 263 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto()));
299 #endif // OS_CHROMEOS 264 #endif // OS_CHROMEOS
300 } 265 }
301 266
302 MetricsLog::~MetricsLog() {} 267 MetricsLog::~MetricsLog() {}
303 268
304 // static 269 // static
305 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
306 registry->RegisterListPref(prefs::kStabilityPluginStats);
307 }
308
309 // static
310 std::string MetricsLog::GetVersionString() { 270 std::string MetricsLog::GetVersionString() {
311 chrome::VersionInfo version_info; 271 chrome::VersionInfo version_info;
312 if (!version_info.is_valid()) { 272 if (!version_info.is_valid()) {
313 NOTREACHED() << "Unable to retrieve version info."; 273 NOTREACHED() << "Unable to retrieve version info.";
314 return std::string(); 274 return std::string();
315 } 275 }
316 276
317 std::string version = version_info.Version(); 277 std::string version = version_info.Version();
318 if (!version_extension().empty()) 278 if (!version_extension().empty())
319 version += version_extension(); 279 version += version_extension();
(...skipping 21 matching lines...) Expand all
341 DCHECK(!HasStabilityMetrics()); 301 DCHECK(!HasStabilityMetrics());
342 302
343 PrefService* pref = GetPrefService(); 303 PrefService* pref = GetPrefService();
344 DCHECK(pref); 304 DCHECK(pref);
345 305
346 // Get stability attributes out of Local State, zeroing out stored values. 306 // Get stability attributes out of Local State, zeroing out stored values.
347 // NOTE: This could lead to some data loss if this report isn't successfully 307 // NOTE: This could lead to some data loss if this report isn't successfully
348 // sent, but that's true for all the metrics. 308 // sent, but that's true for all the metrics.
349 309
350 WriteRequiredStabilityAttributes(pref); 310 WriteRequiredStabilityAttributes(pref);
351 WritePluginStabilityElements(pref);
352 311
353 // Record recent delta for critical stability metrics. We can't wait for a 312 // Record recent delta for critical stability metrics. We can't wait for a
354 // restart to gather these, as that delay biases our observation away from 313 // restart to gather these, as that delay biases our observation away from
355 // users that run happily for a looooong time. We send increments with each 314 // users that run happily for a looooong time. We send increments with each
356 // uma log upload, just as we send histogram data. 315 // uma log upload, just as we send histogram data.
357 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); 316 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
358 317
359 SystemProfileProto::Stability* stability = 318 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
360 uma_proto()->mutable_system_profile()->mutable_stability();
361 for (size_t i = 0; i < metrics_providers.size(); ++i) 319 for (size_t i = 0; i < metrics_providers.size(); ++i)
362 metrics_providers[i]->ProvideStabilityMetrics(stability); 320 metrics_providers[i]->ProvideStabilityMetrics(system_profile);
363 321
364 // Omit some stats unless this is the initial stability log. 322 // Omit some stats unless this is the initial stability log.
365 if (log_type() != INITIAL_STABILITY_LOG) 323 if (log_type() != INITIAL_STABILITY_LOG)
366 return; 324 return;
367 325
368 int incomplete_shutdown_count = 326 int incomplete_shutdown_count =
369 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); 327 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
370 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 328 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
371 int breakpad_registration_success_count = 329 int breakpad_registration_success_count =
372 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); 330 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
373 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 331 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
374 int breakpad_registration_failure_count = 332 int breakpad_registration_failure_count =
375 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); 333 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
376 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 334 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
377 int debugger_present_count = 335 int debugger_present_count =
378 pref->GetInteger(prefs::kStabilityDebuggerPresent); 336 pref->GetInteger(prefs::kStabilityDebuggerPresent);
379 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); 337 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
380 int debugger_not_present_count = 338 int debugger_not_present_count =
381 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); 339 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
382 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 340 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
383 341
384 // TODO(jar): The following are all optional, so we *could* optimize them for 342 // TODO(jar): The following are all optional, so we *could* optimize them for
385 // values of zero (and not include them). 343 // values of zero (and not include them).
344 SystemProfileProto::Stability* stability =
345 system_profile->mutable_stability();
386 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); 346 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
387 stability->set_breakpad_registration_success_count( 347 stability->set_breakpad_registration_success_count(
388 breakpad_registration_success_count); 348 breakpad_registration_success_count);
389 stability->set_breakpad_registration_failure_count( 349 stability->set_breakpad_registration_failure_count(
390 breakpad_registration_failure_count); 350 breakpad_registration_failure_count);
391 stability->set_debugger_present_count(debugger_present_count); 351 stability->set_debugger_present_count(debugger_present_count);
392 stability->set_debugger_not_present_count(debugger_not_present_count); 352 stability->set_debugger_not_present_count(debugger_not_present_count);
393 } 353 }
394 354
395 void MetricsLog::RecordGeneralMetrics( 355 void MetricsLog::RecordGeneralMetrics(
(...skipping 26 matching lines...) Expand all
422 } 382 }
423 383
424 bool MetricsLog::HasEnvironment() const { 384 bool MetricsLog::HasEnvironment() const {
425 return uma_proto()->system_profile().has_uma_enabled_date(); 385 return uma_proto()->system_profile().has_uma_enabled_date();
426 } 386 }
427 387
428 bool MetricsLog::HasStabilityMetrics() const { 388 bool MetricsLog::HasStabilityMetrics() const {
429 return uma_proto()->system_profile().stability().has_launch_count(); 389 return uma_proto()->system_profile().stability().has_launch_count();
430 } 390 }
431 391
432 void MetricsLog::WritePluginStabilityElements(PrefService* pref) {
433 // Now log plugin stability info.
434 const base::ListValue* plugin_stats_list = pref->GetList(
435 prefs::kStabilityPluginStats);
436 if (!plugin_stats_list)
437 return;
438
439 #if defined(ENABLE_PLUGINS)
440 SystemProfileProto::Stability* stability =
441 uma_proto()->mutable_system_profile()->mutable_stability();
442 for (base::ListValue::const_iterator iter = plugin_stats_list->begin();
443 iter != plugin_stats_list->end(); ++iter) {
444 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) {
445 NOTREACHED();
446 continue;
447 }
448 base::DictionaryValue* plugin_dict =
449 static_cast<base::DictionaryValue*>(*iter);
450
451 // Note that this search is potentially a quadratic operation, but given the
452 // low number of plugins installed on a "reasonable" setup, this should be
453 // fine.
454 // TODO(isherman): Verify that this does not show up as a hotspot in
455 // profiler runs.
456 const SystemProfileProto::Plugin* system_profile_plugin = NULL;
457 std::string plugin_name;
458 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name);
459 const SystemProfileProto& system_profile = uma_proto()->system_profile();
460 for (int i = 0; i < system_profile.plugin_size(); ++i) {
461 if (system_profile.plugin(i).name() == plugin_name) {
462 system_profile_plugin = &system_profile.plugin(i);
463 break;
464 }
465 }
466
467 if (!system_profile_plugin) {
468 NOTREACHED();
469 continue;
470 }
471
472 SystemProfileProto::Stability::PluginStability* plugin_stability =
473 stability->add_plugin_stability();
474 *plugin_stability->mutable_plugin() = *system_profile_plugin;
475
476 int launches = 0;
477 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches);
478 if (launches > 0)
479 plugin_stability->set_launch_count(launches);
480
481 int instances = 0;
482 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances);
483 if (instances > 0)
484 plugin_stability->set_instance_count(instances);
485
486 int crashes = 0;
487 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes);
488 if (crashes > 0)
489 plugin_stability->set_crash_count(crashes);
490
491 int loading_errors = 0;
492 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors,
493 &loading_errors);
494 if (loading_errors > 0)
495 plugin_stability->set_loading_error_count(loading_errors);
496 }
497 #endif // defined(ENABLE_PLUGINS)
498
499 pref->ClearPref(prefs::kStabilityPluginStats);
500 }
501
502 // The server refuses data that doesn't have certain values. crashcount and 392 // The server refuses data that doesn't have certain values. crashcount and
503 // launchcount are currently "required" in the "stability" group. 393 // launchcount are currently "required" in the "stability" group.
504 // TODO(isherman): Stop writing these attributes specially once the migration to 394 // TODO(isherman): Stop writing these attributes specially once the migration to
505 // protobufs is complete. 395 // protobufs is complete.
506 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { 396 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
507 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); 397 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
508 pref->SetInteger(prefs::kStabilityLaunchCount, 0); 398 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
509 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); 399 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
510 pref->SetInteger(prefs::kStabilityCrashCount, 0); 400 pref->SetInteger(prefs::kStabilityCrashCount, 0);
511 401
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 #endif // OS_CHROMEOS 450 #endif // OS_CHROMEOS
561 451
562 const uint64 incremental_uptime_sec = incremental_uptime.InSeconds(); 452 const uint64 incremental_uptime_sec = incremental_uptime.InSeconds();
563 if (incremental_uptime_sec) 453 if (incremental_uptime_sec)
564 stability->set_incremental_uptime_sec(incremental_uptime_sec); 454 stability->set_incremental_uptime_sec(incremental_uptime_sec);
565 const uint64 uptime_sec = uptime.InSeconds(); 455 const uint64 uptime_sec = uptime.InSeconds();
566 if (uptime_sec) 456 if (uptime_sec)
567 stability->set_uptime_sec(uptime_sec); 457 stability->set_uptime_sec(uptime_sec);
568 } 458 }
569 459
570 void MetricsLog::WritePluginList(
571 const std::vector<content::WebPluginInfo>& plugin_list) {
572 DCHECK(!locked());
573
574 #if defined(ENABLE_PLUGINS)
575 PluginPrefs* plugin_prefs = GetPluginPrefs();
576 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
577 for (std::vector<content::WebPluginInfo>::const_iterator iter =
578 plugin_list.begin();
579 iter != plugin_list.end(); ++iter) {
580 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
581 SetPluginInfo(*iter, plugin_prefs, plugin);
582 }
583 #endif // defined(ENABLE_PLUGINS)
584 }
585
586 void MetricsLog::RecordEnvironment( 460 void MetricsLog::RecordEnvironment(
587 const std::vector<metrics::MetricsProvider*>& metrics_providers, 461 const std::vector<metrics::MetricsProvider*>& metrics_providers,
588 const std::vector<content::WebPluginInfo>& plugin_list,
589 const std::vector<variations::ActiveGroupId>& synthetic_trials) { 462 const std::vector<variations::ActiveGroupId>& synthetic_trials) {
590 DCHECK(!HasEnvironment()); 463 DCHECK(!HasEnvironment());
591 464
592 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 465 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
593 466
594 std::string brand_code; 467 std::string brand_code;
595 if (google_util::GetBrand(&brand_code)) 468 if (google_util::GetBrand(&brand_code))
596 system_profile->set_brand_code(brand_code); 469 system_profile->set_brand_code(brand_code);
597 470
598 int enabled_date; 471 int enabled_date;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 const gfx::Size display_size = GetScreenSize(); 542 const gfx::Size display_size = GetScreenSize();
670 hardware->set_primary_screen_width(display_size.width()); 543 hardware->set_primary_screen_width(display_size.width());
671 hardware->set_primary_screen_height(display_size.height()); 544 hardware->set_primary_screen_height(display_size.height());
672 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); 545 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
673 hardware->set_screen_count(GetScreenCount()); 546 hardware->set_screen_count(GetScreenCount());
674 547
675 #if defined(OS_WIN) 548 #if defined(OS_WIN)
676 WriteScreenDPIInformationProto(hardware); 549 WriteScreenDPIInformationProto(hardware);
677 #endif 550 #endif
678 551
679 WritePluginList(plugin_list);
680 extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile()); 552 extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile());
681 553
682 std::vector<ActiveGroupId> field_trial_ids; 554 std::vector<ActiveGroupId> field_trial_ids;
683 GetFieldTrialIds(&field_trial_ids); 555 GetFieldTrialIds(&field_trial_ids);
684 WriteFieldTrials(field_trial_ids, system_profile); 556 WriteFieldTrials(field_trial_ids, system_profile);
685 WriteFieldTrials(synthetic_trials, system_profile); 557 WriteFieldTrials(synthetic_trials, system_profile);
686 558
687 #if defined(OS_CHROMEOS) 559 #if defined(OS_CHROMEOS)
688 metrics_log_chromeos_->LogChromeOSMetrics(); 560 metrics_log_chromeos_->LogChromeOSMetrics();
689 #endif // OS_CHROMEOS 561 #endif // OS_CHROMEOS
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 profile = uma_proto()->add_profiler_event(); 611 profile = uma_proto()->add_profiler_event();
740 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE); 612 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
741 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); 613 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
742 } else { 614 } else {
743 // For the remaining calls, re-use the existing field. 615 // For the remaining calls, re-use the existing field.
744 profile = uma_proto()->mutable_profiler_event(0); 616 profile = uma_proto()->mutable_profiler_event(0);
745 } 617 }
746 618
747 WriteProfilerData(process_data, process_type, profile); 619 WriteProfilerData(process_data, process_type, profile);
748 } 620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698