Loading metrics/constants.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events"; static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsServer[] = "http://clients4.google.com/uma/v2"; static const char kMetricsServer[] = "http://clients4.google.com/uma/v2"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; static const char kDefaultVersion[] = "0.0.0.0"; } // namespace metrics } // namespace metrics #endif // METRICS_CONSTANTS_H_ #endif // METRICS_CONSTANTS_H_ metrics/metrics_daemon.cc +11 −25 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <base/sys_info.h> #include <base/sys_info.h> #include <dbus/dbus.h> #include <dbus/dbus.h> #include <dbus/message.h> #include <dbus/message.h> #include "constants.h" #include "uploader/upload_service.h" #include "uploader/upload_service.h" using base::FilePath; using base::FilePath; Loading @@ -44,10 +46,6 @@ const char kCrashReporterUserCrashSignal[] = "UserCrash"; const char kCrashReporterMatchRule[] = const char kCrashReporterMatchRule[] = "type='signal',interface='%s',path='/',member='%s'"; "type='signal',interface='%s',path='/',member='%s'"; // Build type of an official build. // See src/third_party/chromiumos-overlay/chromeos/scripts/cros_set_lsb_release. const char kOfficialBuild[] = "Official Build"; const int kSecondsPerMinute = 60; const int kSecondsPerMinute = 60; const int kMinutesPerHour = 60; const int kMinutesPerHour = 60; const int kHoursPerDay = 24; const int kHoursPerDay = 24; Loading Loading @@ -199,24 +197,17 @@ uint32_t MetricsDaemon::GetOsVersionHash() { if (version_hash_is_cached) if (version_hash_is_cached) return cached_version_hash; return cached_version_hash; version_hash_is_cached = true; version_hash_is_cached = true; std::string version; std::string version = metrics::kDefaultVersion; if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) { // The version might not be set for development devices. In this case, use the // zero version. base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version); cached_version_hash = base::Hash(version); cached_version_hash = base::Hash(version); } else if (testing_) { if (testing_) { cached_version_hash = 42; // return any plausible value for the hash cached_version_hash = 42; // return any plausible value for the hash } else { LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION"; } } return cached_version_hash; return cached_version_hash; } } bool MetricsDaemon::IsOnOfficialBuild() const { std::string build_type; return (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE", &build_type) && build_type == kOfficialBuild); } void MetricsDaemon::Init(bool testing, void MetricsDaemon::Init(bool testing, bool uploader_active, bool uploader_active, MetricsLibraryInterface* metrics_lib, MetricsLibraryInterface* metrics_lib, Loading Loading @@ -317,14 +308,9 @@ int MetricsDaemon::OnInit() { } } if (uploader_active_) { if (uploader_active_) { if (IsOnOfficialBuild()) { LOG(INFO) << "uploader enabled"; upload_service_.reset( upload_service_.reset( new UploadService(new SystemProfileCache(), metrics_lib_, server_)); new UploadService(new SystemProfileCache(), metrics_lib_, server_)); upload_service_->Init(upload_interval_, metrics_file_); upload_service_->Init(upload_interval_, metrics_file_); } else { LOG(INFO) << "uploader disabled on non-official build"; } } } return EX_OK; return EX_OK; Loading metrics/metrics_daemon.h +0 −3 Original line number Original line Diff line number Diff line Loading @@ -268,9 +268,6 @@ class MetricsDaemon : public chromeos::DBusDaemon { // to a unsigned 32-bit int. // to a unsigned 32-bit int. uint32_t GetOsVersionHash(); uint32_t GetOsVersionHash(); // Returns true if the system is using an official build. bool IsOnOfficialBuild() const; // Updates stats, additionally sending them to UMA if enough time has elapsed // Updates stats, additionally sending them to UMA if enough time has elapsed // since the last report. // since the last report. void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time); void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time); Loading metrics/uploader/system_profile_cache.cc +11 −4 Original line number Original line Diff line number Diff line Loading @@ -61,15 +61,22 @@ bool SystemProfileCache::Initialize() { CHECK(!initialized_) CHECK(!initialized_) << "this should be called only once in the metrics_daemon lifetime."; << "this should be called only once in the metrics_daemon lifetime."; std::string channel; if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version) || !base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", &profile_.build_target_id)) { &profile_.build_target_id)) { LOG(ERROR) << "Could not initialize system profile."; LOG(ERROR) << "Could not initialize system profile."; return false; return false; } } std::string channel; if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version)) { // If the channel or version is missing, the image is not official. // In this case, set the channel to unknown and the version to 0.0.0.0 to // avoid polluting the production data. channel = ""; profile_.version = metrics::kDefaultVersion; } profile_.client_id = profile_.client_id = testing_ ? "client_id_test" : testing_ ? "client_id_test" : GetPersistentGUID(metrics::kMetricsGUIDFilePath); GetPersistentGUID(metrics::kMetricsGUIDFilePath); Loading Loading
metrics/constants.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events"; static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsServer[] = "http://clients4.google.com/uma/v2"; static const char kMetricsServer[] = "http://clients4.google.com/uma/v2"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; static const char kDefaultVersion[] = "0.0.0.0"; } // namespace metrics } // namespace metrics #endif // METRICS_CONSTANTS_H_ #endif // METRICS_CONSTANTS_H_
metrics/metrics_daemon.cc +11 −25 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <base/sys_info.h> #include <base/sys_info.h> #include <dbus/dbus.h> #include <dbus/dbus.h> #include <dbus/message.h> #include <dbus/message.h> #include "constants.h" #include "uploader/upload_service.h" #include "uploader/upload_service.h" using base::FilePath; using base::FilePath; Loading @@ -44,10 +46,6 @@ const char kCrashReporterUserCrashSignal[] = "UserCrash"; const char kCrashReporterMatchRule[] = const char kCrashReporterMatchRule[] = "type='signal',interface='%s',path='/',member='%s'"; "type='signal',interface='%s',path='/',member='%s'"; // Build type of an official build. // See src/third_party/chromiumos-overlay/chromeos/scripts/cros_set_lsb_release. const char kOfficialBuild[] = "Official Build"; const int kSecondsPerMinute = 60; const int kSecondsPerMinute = 60; const int kMinutesPerHour = 60; const int kMinutesPerHour = 60; const int kHoursPerDay = 24; const int kHoursPerDay = 24; Loading Loading @@ -199,24 +197,17 @@ uint32_t MetricsDaemon::GetOsVersionHash() { if (version_hash_is_cached) if (version_hash_is_cached) return cached_version_hash; return cached_version_hash; version_hash_is_cached = true; version_hash_is_cached = true; std::string version; std::string version = metrics::kDefaultVersion; if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) { // The version might not be set for development devices. In this case, use the // zero version. base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version); cached_version_hash = base::Hash(version); cached_version_hash = base::Hash(version); } else if (testing_) { if (testing_) { cached_version_hash = 42; // return any plausible value for the hash cached_version_hash = 42; // return any plausible value for the hash } else { LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION"; } } return cached_version_hash; return cached_version_hash; } } bool MetricsDaemon::IsOnOfficialBuild() const { std::string build_type; return (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE", &build_type) && build_type == kOfficialBuild); } void MetricsDaemon::Init(bool testing, void MetricsDaemon::Init(bool testing, bool uploader_active, bool uploader_active, MetricsLibraryInterface* metrics_lib, MetricsLibraryInterface* metrics_lib, Loading Loading @@ -317,14 +308,9 @@ int MetricsDaemon::OnInit() { } } if (uploader_active_) { if (uploader_active_) { if (IsOnOfficialBuild()) { LOG(INFO) << "uploader enabled"; upload_service_.reset( upload_service_.reset( new UploadService(new SystemProfileCache(), metrics_lib_, server_)); new UploadService(new SystemProfileCache(), metrics_lib_, server_)); upload_service_->Init(upload_interval_, metrics_file_); upload_service_->Init(upload_interval_, metrics_file_); } else { LOG(INFO) << "uploader disabled on non-official build"; } } } return EX_OK; return EX_OK; Loading
metrics/metrics_daemon.h +0 −3 Original line number Original line Diff line number Diff line Loading @@ -268,9 +268,6 @@ class MetricsDaemon : public chromeos::DBusDaemon { // to a unsigned 32-bit int. // to a unsigned 32-bit int. uint32_t GetOsVersionHash(); uint32_t GetOsVersionHash(); // Returns true if the system is using an official build. bool IsOnOfficialBuild() const; // Updates stats, additionally sending them to UMA if enough time has elapsed // Updates stats, additionally sending them to UMA if enough time has elapsed // since the last report. // since the last report. void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time); void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time); Loading
metrics/uploader/system_profile_cache.cc +11 −4 Original line number Original line Diff line number Diff line Loading @@ -61,15 +61,22 @@ bool SystemProfileCache::Initialize() { CHECK(!initialized_) CHECK(!initialized_) << "this should be called only once in the metrics_daemon lifetime."; << "this should be called only once in the metrics_daemon lifetime."; std::string channel; if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version) || !base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", &profile_.build_target_id)) { &profile_.build_target_id)) { LOG(ERROR) << "Could not initialize system profile."; LOG(ERROR) << "Could not initialize system profile."; return false; return false; } } std::string channel; if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version)) { // If the channel or version is missing, the image is not official. // In this case, set the channel to unknown and the version to 0.0.0.0 to // avoid polluting the production data. channel = ""; profile_.version = metrics::kDefaultVersion; } profile_.client_id = profile_.client_id = testing_ ? "client_id_test" : testing_ ? "client_id_test" : GetPersistentGUID(metrics::kMetricsGUIDFilePath); GetPersistentGUID(metrics::kMetricsGUIDFilePath); Loading