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

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

Issue 296483004: Introduce a MetricsDataProvider interface. (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 21 matching lines...) Expand all
32 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/google/google_util.h" 33 #include "chrome/browser/google/google_util.h"
34 #include "chrome/browser/metrics/extension_metrics.h" 34 #include "chrome/browser/metrics/extension_metrics.h"
35 #include "chrome/browser/omnibox/omnibox_log.h" 35 #include "chrome/browser/omnibox/omnibox_log.h"
36 #include "chrome/browser/plugins/plugin_prefs.h" 36 #include "chrome/browser/plugins/plugin_prefs.h"
37 #include "chrome/browser/profiles/profile_manager.h" 37 #include "chrome/browser/profiles/profile_manager.h"
38 #include "chrome/common/chrome_version_info.h" 38 #include "chrome/common/chrome_version_info.h"
39 #include "chrome/common/metrics/variations/variations_util.h" 39 #include "chrome/common/metrics/variations/variations_util.h"
40 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
41 #include "chrome/installer/util/google_update_settings.h" 41 #include "chrome/installer/util/google_update_settings.h"
42 #include "components/metrics/metrics_data_provider.h"
42 #include "components/metrics/proto/omnibox_event.pb.h" 43 #include "components/metrics/proto/omnibox_event.pb.h"
43 #include "components/metrics/proto/profiler_event.pb.h" 44 #include "components/metrics/proto/profiler_event.pb.h"
44 #include "components/metrics/proto/system_profile.pb.h" 45 #include "components/metrics/proto/system_profile.pb.h"
45 #include "components/nacl/common/nacl_process_type.h" 46 #include "components/nacl/common/nacl_process_type.h"
46 #include "content/public/browser/gpu_data_manager.h" 47 #include "content/public/browser/gpu_data_manager.h"
47 #include "content/public/common/content_client.h" 48 #include "content/public/common/content_client.h"
48 #include "content/public/common/webplugininfo.h" 49 #include "content/public/common/webplugininfo.h"
49 #include "gpu/config/gpu_info.h" 50 #include "gpu/config/gpu_info.h"
50 #include "ui/gfx/screen.h" 51 #include "ui/gfx/screen.h"
51 #include "url/gurl.h" 52 #include "url/gurl.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // static 442 // static
442 void MetricsLog::set_version_extension(const std::string& extension) { 443 void MetricsLog::set_version_extension(const std::string& extension) {
443 g_version_extension.Get() = extension; 444 g_version_extension.Get() = extension;
444 } 445 }
445 446
446 // static 447 // static
447 const std::string& MetricsLog::version_extension() { 448 const std::string& MetricsLog::version_extension() {
448 return g_version_extension.Get(); 449 return g_version_extension.Get();
449 } 450 }
450 451
451 void MetricsLog::RecordStabilityMetrics(base::TimeDelta incremental_uptime, 452 void MetricsLog::RecordStabilityMetrics(
452 base::TimeDelta uptime) { 453 const ScopedVector<metrics::MetricsDataProvider>& data_providers,
454 base::TimeDelta incremental_uptime,
455 base::TimeDelta uptime) {
453 DCHECK(!locked()); 456 DCHECK(!locked());
454 DCHECK(HasEnvironment()); 457 DCHECK(HasEnvironment());
455 DCHECK(!HasStabilityMetrics()); 458 DCHECK(!HasStabilityMetrics());
456 459
457 PrefService* pref = GetPrefService(); 460 PrefService* pref = GetPrefService();
458 DCHECK(pref); 461 DCHECK(pref);
459 462
460 // Get stability attributes out of Local State, zeroing out stored values. 463 // Get stability attributes out of Local State, zeroing out stored values.
461 // NOTE: This could lead to some data loss if this report isn't successfully 464 // NOTE: This could lead to some data loss if this report isn't successfully
462 // sent, but that's true for all the metrics. 465 // sent, but that's true for all the metrics.
463 466
464 WriteRequiredStabilityAttributes(pref); 467 WriteRequiredStabilityAttributes(pref);
465 WritePluginStabilityElements(pref); 468 WritePluginStabilityElements(pref);
466 469
467 // Record recent delta for critical stability metrics. We can't wait for a 470 // Record recent delta for critical stability metrics. We can't wait for a
468 // restart to gather these, as that delay biases our observation away from 471 // restart to gather these, as that delay biases our observation away from
469 // users that run happily for a looooong time. We send increments with each 472 // users that run happily for a looooong time. We send increments with each
470 // uma log upload, just as we send histogram data. 473 // uma log upload, just as we send histogram data.
471 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); 474 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
472 475
476 SystemProfileProto::Stability* stability =
477 uma_proto()->mutable_system_profile()->mutable_stability();
478 for (size_t i = 0; i < data_providers.size(); ++i)
479 data_providers[i]->ProvideStabilityMetrics(stability);
480
473 // Omit some stats unless this is the initial stability log. 481 // Omit some stats unless this is the initial stability log.
474 if (log_type() != INITIAL_STABILITY_LOG) 482 if (log_type() != INITIAL_STABILITY_LOG)
475 return; 483 return;
476 484
477 int incomplete_shutdown_count = 485 int incomplete_shutdown_count =
478 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); 486 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
479 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 487 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
480 int breakpad_registration_success_count = 488 int breakpad_registration_success_count =
481 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); 489 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
482 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 490 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
483 int breakpad_registration_failure_count = 491 int breakpad_registration_failure_count =
484 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); 492 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
485 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 493 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
486 int debugger_present_count = 494 int debugger_present_count =
487 pref->GetInteger(prefs::kStabilityDebuggerPresent); 495 pref->GetInteger(prefs::kStabilityDebuggerPresent);
488 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); 496 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
489 int debugger_not_present_count = 497 int debugger_not_present_count =
490 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); 498 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
491 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 499 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
492 500
493 // TODO(jar): The following are all optional, so we *could* optimize them for 501 // TODO(jar): The following are all optional, so we *could* optimize them for
494 // values of zero (and not include them). 502 // values of zero (and not include them).
495 SystemProfileProto::Stability* stability =
496 uma_proto()->mutable_system_profile()->mutable_stability();
497 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); 503 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
498 stability->set_breakpad_registration_success_count( 504 stability->set_breakpad_registration_success_count(
499 breakpad_registration_success_count); 505 breakpad_registration_success_count);
500 stability->set_breakpad_registration_failure_count( 506 stability->set_breakpad_registration_failure_count(
501 breakpad_registration_failure_count); 507 breakpad_registration_failure_count);
502 stability->set_debugger_present_count(debugger_present_count); 508 stability->set_debugger_present_count(debugger_present_count);
503 stability->set_debugger_not_present_count(debugger_not_present_count); 509 stability->set_debugger_not_present_count(debugger_not_present_count);
504 } 510 }
505 511
512
Ilya Sherman 2014/05/19 14:45:00 nit: Spurious newline.
Alexei Svitkine (slow) 2014/05/19 15:23:02 Done.
513 void MetricsLog::RecordGeneralMetrics(
514 const ScopedVector<metrics::MetricsDataProvider>& data_providers) {
515 for (size_t i = 0; i < data_providers.size(); ++i)
516 data_providers[i]->ProvideGeneralMetrics(uma_proto());
517 }
518
506 PrefService* MetricsLog::GetPrefService() { 519 PrefService* MetricsLog::GetPrefService() {
507 return g_browser_process->local_state(); 520 return g_browser_process->local_state();
508 } 521 }
509 522
510 gfx::Size MetricsLog::GetScreenSize() const { 523 gfx::Size MetricsLog::GetScreenSize() const {
511 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); 524 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
512 } 525 }
513 526
514 float MetricsLog::GetScreenDeviceScaleFactor() const { 527 float MetricsLog::GetScreenDeviceScaleFactor() const {
515 return gfx::Screen::GetNativeScreen()-> 528 return gfx::Screen::GetNativeScreen()->
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 for (std::vector<content::WebPluginInfo>::const_iterator iter = 695 for (std::vector<content::WebPluginInfo>::const_iterator iter =
683 plugin_list.begin(); 696 plugin_list.begin();
684 iter != plugin_list.end(); ++iter) { 697 iter != plugin_list.end(); ++iter) {
685 SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); 698 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
686 SetPluginInfo(*iter, plugin_prefs, plugin); 699 SetPluginInfo(*iter, plugin_prefs, plugin);
687 } 700 }
688 #endif // defined(ENABLE_PLUGINS) 701 #endif // defined(ENABLE_PLUGINS)
689 } 702 }
690 703
691 void MetricsLog::RecordEnvironment( 704 void MetricsLog::RecordEnvironment(
705 const ScopedVector<metrics::MetricsDataProvider>& data_providers,
692 const std::vector<content::WebPluginInfo>& plugin_list, 706 const std::vector<content::WebPluginInfo>& plugin_list,
693 const GoogleUpdateMetrics& google_update_metrics, 707 const GoogleUpdateMetrics& google_update_metrics,
694 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials) { 708 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials) {
695 DCHECK(!HasEnvironment()); 709 DCHECK(!HasEnvironment());
696 710
697 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 711 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
698 712
699 std::string brand_code; 713 std::string brand_code;
700 if (google_util::GetBrand(&brand_code)) 714 if (google_util::GetBrand(&brand_code))
701 system_profile->set_brand_code(brand_code); 715 system_profile->set_brand_code(brand_code);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 802
789 std::vector<ActiveGroupId> field_trial_ids; 803 std::vector<ActiveGroupId> field_trial_ids;
790 GetFieldTrialIds(&field_trial_ids); 804 GetFieldTrialIds(&field_trial_ids);
791 WriteFieldTrials(field_trial_ids, system_profile); 805 WriteFieldTrials(field_trial_ids, system_profile);
792 WriteFieldTrials(synthetic_trials, system_profile); 806 WriteFieldTrials(synthetic_trials, system_profile);
793 807
794 #if defined(OS_CHROMEOS) 808 #if defined(OS_CHROMEOS)
795 metrics_log_chromeos_->LogChromeOSMetrics(); 809 metrics_log_chromeos_->LogChromeOSMetrics();
796 #endif // OS_CHROMEOS 810 #endif // OS_CHROMEOS
797 811
812 for (size_t i = 0; i < data_providers.size(); ++i)
813 data_providers[i]->ProvideSystemProfileMetrics(system_profile);
814
798 std::string serialied_system_profile; 815 std::string serialied_system_profile;
799 std::string base64_system_profile; 816 std::string base64_system_profile;
800 if (system_profile->SerializeToString(&serialied_system_profile)) { 817 if (system_profile->SerializeToString(&serialied_system_profile)) {
801 base::Base64Encode(serialied_system_profile, &base64_system_profile); 818 base::Base64Encode(serialied_system_profile, &base64_system_profile);
802 PrefService* local_state = GetPrefService(); 819 PrefService* local_state = GetPrefService();
803 local_state->SetString(prefs::kStabilitySavedSystemProfile, 820 local_state->SetString(prefs::kStabilitySavedSystemProfile,
804 base64_system_profile); 821 base64_system_profile);
805 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, 822 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
806 ComputeSHA1(serialied_system_profile)); 823 ComputeSHA1(serialied_system_profile));
807 } 824 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 ProductDataToProto(google_update_metrics.google_update_data, 957 ProductDataToProto(google_update_metrics.google_update_data,
941 google_update->mutable_google_update_status()); 958 google_update->mutable_google_update_status());
942 } 959 }
943 960
944 if (!google_update_metrics.product_data.version.empty()) { 961 if (!google_update_metrics.product_data.version.empty()) {
945 ProductDataToProto(google_update_metrics.product_data, 962 ProductDataToProto(google_update_metrics.product_data,
946 google_update->mutable_client_status()); 963 google_update->mutable_client_status());
947 } 964 }
948 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) 965 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
949 } 966 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698