Merge "crash_reporter: Fix initial compile issues with Android toolchain"
diff --git a/metrics/uploader/system_profile_cache.cc b/metrics/uploader/system_profile_cache.cc
deleted file mode 100644
index ea4a38c..0000000
--- a/metrics/uploader/system_profile_cache.cc
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "metrics/uploader/system_profile_cache.h"
-
-#include <string>
-#include <vector>
-
-#include "base/files/file_util.h"
-#include "base/guid.h"
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/sys_info.h"
-#include "metrics/persistent_integer.h"
-#include "metrics/uploader/metrics_log_base.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
-#include "vboot/crossystem.h"
-
-namespace {
-
-const char kPersistentGUIDFile[] = "/var/lib/metrics/Sysinfo.GUID";
-const char kPersistentSessionIdFilename[] = "Sysinfo.SessionId";
-const char kProductIdFieldName[] = "GOOGLE_METRICS_PRODUCT_ID";
-
-} // namespace
-
-std::string ChannelToString(
- const metrics::SystemProfileProto_Channel& channel) {
- switch (channel) {
- case metrics::SystemProfileProto::CHANNEL_STABLE:
- return "STABLE";
- case metrics::SystemProfileProto::CHANNEL_DEV:
- return "DEV";
- case metrics::SystemProfileProto::CHANNEL_BETA:
- return "BETA";
- case metrics::SystemProfileProto::CHANNEL_CANARY:
- return "CANARY";
- default:
- return "UNKNOWN";
- }
-}
-
-SystemProfileCache::SystemProfileCache()
- : initialized_(false),
- testing_(false),
- config_root_("/"),
- session_id_(new chromeos_metrics::PersistentInteger(
- kPersistentSessionIdFilename)) {
-}
-
-SystemProfileCache::SystemProfileCache(bool testing,
- const std::string& config_root)
- : initialized_(false),
- testing_(testing),
- config_root_(config_root),
- session_id_(new chromeos_metrics::PersistentInteger(
- kPersistentSessionIdFilename)) {
-}
-
-bool SystemProfileCache::Initialize() {
- CHECK(!initialized_)
- << "this should be called only once in the metrics_daemon lifetime.";
-
- std::string chromeos_version;
- std::string board;
- std::string build_type;
- if (!base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_NAME",
- &profile_.os_name) ||
- !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION",
- &profile_.os_version) ||
- !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD", &board) ||
- !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE",
- &build_type) ||
- !GetChromeOSVersion(&chromeos_version) ||
- !GetHardwareId(&profile_.hardware_class)) {
- DLOG(ERROR) << "failing to initialize profile cache";
- return false;
- }
-
- std::string channel_string;
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &channel_string);
- profile_.channel = ProtoChannelFromString(channel_string);
-
- profile_.app_version = chromeos_version + " (" + build_type + ")" +
- ChannelToString(profile_.channel) + " " + board;
-
- // If the product id is not defined, use the default one from the protobuf.
- profile_.product_id = metrics::ChromeUserMetricsExtension::CHROME;
- if (GetProductId(&profile_.product_id)) {
- DLOG(INFO) << "Set the product id to " << profile_.product_id;
- }
-
- profile_.client_id =
- testing_ ? "client_id_test" : GetPersistentGUID(kPersistentGUIDFile);
-
- // Increment the session_id everytime we initialize this. If metrics_daemon
- // does not crash, this should correspond to the number of reboots of the
- // system.
- // TODO(bsimonnet): Change this to map to the number of time system-services
- // is started.
- session_id_->Add(1);
- profile_.session_id = static_cast<int32_t>(session_id_->Get());
-
- initialized_ = true;
- return initialized_;
-}
-
-bool SystemProfileCache::InitializeOrCheck() {
- return initialized_ || Initialize();
-}
-
-void SystemProfileCache::Populate(
- metrics::ChromeUserMetricsExtension* metrics_proto) {
- CHECK(metrics_proto);
- CHECK(InitializeOrCheck())
- << "failed to initialize system information.";
-
- // The client id is hashed before being sent.
- metrics_proto->set_client_id(
- metrics::MetricsLogBase::Hash(profile_.client_id));
- metrics_proto->set_session_id(profile_.session_id);
-
- // Sets the product id.
- metrics_proto->set_product(profile_.product_id);
-
- metrics::SystemProfileProto* profile_proto =
- metrics_proto->mutable_system_profile();
- profile_proto->mutable_hardware()->set_hardware_class(
- profile_.hardware_class);
- profile_proto->set_app_version(profile_.app_version);
- profile_proto->set_channel(profile_.channel);
-
- metrics::SystemProfileProto_OS* os = profile_proto->mutable_os();
- os->set_name(profile_.os_name);
- os->set_version(profile_.os_version);
-}
-
-std::string SystemProfileCache::GetPersistentGUID(const std::string& filename) {
- std::string guid;
- base::FilePath filepath(filename);
- if (!base::ReadFileToString(filepath, &guid)) {
- guid = base::GenerateGUID();
- // If we can't read or write the file, the guid will not be preserved during
- // the next reboot. Crash.
- CHECK(base::WriteFile(filepath, guid.c_str(), guid.size()));
- }
- return guid;
-}
-
-bool SystemProfileCache::GetChromeOSVersion(std::string* version) {
- if (testing_) {
- *version = "0.0.0.0";
- return true;
- }
-
- std::string milestone, build, branch, patch;
- unsigned tmp;
- if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_CHROME_MILESTONE",
- &milestone) &&
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_NUMBER",
- &build) &&
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BRANCH_NUMBER",
- &branch) &&
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_PATCH_NUMBER",
- &patch)) {
- // Convert to uint to ensure those fields are positive numbers.
- if (base::StringToUint(milestone, &tmp) &&
- base::StringToUint(build, &tmp) &&
- base::StringToUint(branch, &tmp) &&
- base::StringToUint(patch, &tmp)) {
- std::vector<std::string> parts = {milestone, build, branch, patch};
- *version = JoinString(parts, '.');
- return true;
- }
- DLOG(INFO) << "The milestone, build, branch or patch is not a positive "
- << "number.";
- return false;
- }
- DLOG(INFO) << "Field missing from /etc/lsb-release";
- return false;
-}
-
-bool SystemProfileCache::GetHardwareId(std::string* hwid) {
- CHECK(hwid);
-
- if (testing_) {
- // if we are in test mode, we do not call crossystem directly.
- DLOG(INFO) << "skipping hardware id";
- *hwid = "";
- return true;
- }
-
- char buffer[128];
- if (buffer != VbGetSystemPropertyString("hwid", buffer, sizeof(buffer))) {
- LOG(ERROR) << "error getting hwid";
- return false;
- }
-
- *hwid = std::string(buffer);
- return true;
-}
-
-bool SystemProfileCache::GetProductId(int* product_id) const {
- chromeos::OsReleaseReader reader;
- if (testing_) {
- base::FilePath root(config_root_);
- reader.LoadTestingOnly(root);
- } else {
- reader.Load();
- }
-
- std::string id;
- if (reader.GetString(kProductIdFieldName, &id)) {
- CHECK(base::StringToInt(id, product_id)) << "Failed to convert product_id "
- << id << " to int.";
- return true;
- }
- return false;
-}
-
-metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString(
- const std::string& channel) {
-
- if (channel == "stable-channel") {
- return metrics::SystemProfileProto::CHANNEL_STABLE;
- } else if (channel == "dev-channel") {
- return metrics::SystemProfileProto::CHANNEL_DEV;
- } else if (channel == "beta-channel") {
- return metrics::SystemProfileProto::CHANNEL_BETA;
- } else if (channel == "canary-channel") {
- return metrics::SystemProfileProto::CHANNEL_CANARY;
- }
-
- DLOG(INFO) << "unknown channel: " << channel;
- return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
-}
diff --git a/metrics/MODULE_LICENSE_BSD b/metricsd/MODULE_LICENSE_BSD
similarity index 100%
rename from metrics/MODULE_LICENSE_BSD
rename to metricsd/MODULE_LICENSE_BSD
diff --git a/metrics/NOTICE b/metricsd/NOTICE
similarity index 100%
rename from metrics/NOTICE
rename to metricsd/NOTICE
diff --git a/metrics/OWNERS b/metricsd/OWNERS
similarity index 100%
rename from metrics/OWNERS
rename to metricsd/OWNERS
diff --git a/metrics/README b/metricsd/README
similarity index 100%
rename from metrics/README
rename to metricsd/README
diff --git a/metrics/WATCHLISTS b/metricsd/WATCHLISTS
similarity index 100%
rename from metrics/WATCHLISTS
rename to metricsd/WATCHLISTS
diff --git a/metrics/c_metrics_library.cc b/metricsd/c_metrics_library.cc
similarity index 100%
rename from metrics/c_metrics_library.cc
rename to metricsd/c_metrics_library.cc
diff --git a/metricsd/constants.h b/metricsd/constants.h
new file mode 100644
index 0000000..d65e0e0
--- /dev/null
+++ b/metricsd/constants.h
@@ -0,0 +1,29 @@
+//
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef METRICS_CONSTANTS_H_
+#define METRICS_CONSTANTS_H_
+
+namespace metrics {
+static const char kMetricsDirectory[] = "/data/misc/metrics/";
+static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events";
+static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID";
+static const char kMetricsServer[] = "http://clients4.google.com/uma/v2";
+static const char kConsentFilePath[] = "/data/misc/metrics/enabled";
+static const char kDefaultVersion[] = "0.0.0.0";
+} // namespace metrics
+
+#endif // METRICS_CONSTANTS_H_
diff --git a/metrics/c_metrics_library.h b/metricsd/include/metrics/c_metrics_library.h
similarity index 100%
rename from metrics/c_metrics_library.h
rename to metricsd/include/metrics/c_metrics_library.h
diff --git a/metrics/metrics_library.h b/metricsd/include/metrics/metrics_library.h
similarity index 93%
rename from metrics/metrics_library.h
rename to metricsd/include/metrics/metrics_library.h
index a90f3e6..1c124d2 100644
--- a/metrics/metrics_library.h
+++ b/metricsd/include/metrics/metrics_library.h
@@ -14,8 +14,6 @@
#include <base/memory/scoped_ptr.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "policy/libpolicy.h"
-
class MetricsLibraryInterface {
public:
virtual void Init() = 0;
@@ -28,7 +26,7 @@
virtual ~MetricsLibraryInterface() {}
};
-// Library used to send metrics to both Autotest and Chrome/UMA.
+// Library used to send metrics to Chrome/UMA.
class MetricsLibrary : public MetricsLibraryInterface {
public:
MetricsLibrary();
@@ -109,9 +107,6 @@
// number in the histograms dashboard).
bool SendCrosEventToUMA(const std::string& event);
- // Sends to Autotest and returns true on success.
- static bool SendToAutotest(const std::string& name, int value);
-
private:
friend class CMetricsLibraryTest;
friend class MetricsLibraryTest;
@@ -130,9 +125,6 @@
char* buffer, int buffer_size,
bool* result);
- // This function is used by tests only to mock the device policies.
- void SetPolicyProvider(policy::PolicyProvider* provider);
-
// Time at which we last checked if metrics were enabled.
static time_t cached_enabled_time_;
@@ -142,8 +134,6 @@
std::string uma_events_file_;
std::string consent_file_;
- scoped_ptr<policy::PolicyProvider> policy_provider_;
-
DISALLOW_COPY_AND_ASSIGN(MetricsLibrary);
};
diff --git a/metrics/init/metrics_daemon.conf b/metricsd/init/metrics_daemon.conf
similarity index 100%
rename from metrics/init/metrics_daemon.conf
rename to metricsd/init/metrics_daemon.conf
diff --git a/metrics/init/metrics_library.conf b/metricsd/init/metrics_library.conf
similarity index 100%
rename from metrics/init/metrics_library.conf
rename to metricsd/init/metrics_library.conf
diff --git a/metrics/libmetrics-334380.gyp b/metricsd/libmetrics-334380.gyp
similarity index 100%
rename from metrics/libmetrics-334380.gyp
rename to metricsd/libmetrics-334380.gyp
diff --git a/metrics/libmetrics.gypi b/metricsd/libmetrics.gypi
similarity index 100%
rename from metrics/libmetrics.gypi
rename to metricsd/libmetrics.gypi
diff --git a/metrics/libmetrics.pc.in b/metricsd/libmetrics.pc.in
similarity index 100%
rename from metrics/libmetrics.pc.in
rename to metricsd/libmetrics.pc.in
diff --git a/metrics/make_tests.sh b/metricsd/make_tests.sh
similarity index 100%
rename from metrics/make_tests.sh
rename to metricsd/make_tests.sh
diff --git a/metrics/metrics.gyp b/metricsd/metrics.gyp
similarity index 100%
rename from metrics/metrics.gyp
rename to metricsd/metrics.gyp
diff --git a/metrics/metrics_client.cc b/metricsd/metrics_client.cc
similarity index 73%
rename from metrics/metrics_client.cc
rename to metricsd/metrics_client.cc
index bbe9dcd..b587e3a 100644
--- a/metrics/metrics_client.cc
+++ b/metricsd/metrics_client.cc
@@ -19,17 +19,15 @@
void ShowUsage() {
fprintf(stderr,
- "Usage: metrics_client [-ab] [-t] name sample min max nbuckets\n"
- " metrics_client [-ab] -e name sample max\n"
- " metrics_client [-ab] -s name sample\n"
- " metrics_client [-ab] -v event\n"
+ "Usage: metrics_client [-t] name sample min max nbuckets\n"
+ " metrics_client -e name sample max\n"
+ " metrics_client -s name sample\n"
+ " metrics_client -v event\n"
" metrics_client -u action\n"
" metrics_client [-cg]\n"
"\n"
- " default: send metric with integer values to Chrome only\n"
+ " default: send metric with integer values \n"
" |min| > 0, |min| <= sample < |max|\n"
- " -a: send metric (name/sample) to Autotest only\n"
- " -b: send metric to both Chrome and Autotest\n"
" -c: return exit status 0 if user consents to stats, 1 otherwise,\n"
" in guest mode always return 1\n"
" -e: send linear/enumeration histogram data\n"
@@ -64,9 +62,7 @@
static int SendStats(char* argv[],
int name_index,
enum Mode mode,
- bool secs_to_msecs,
- bool send_to_autotest,
- bool send_to_chrome) {
+ bool secs_to_msecs) {
const char* name = argv[name_index];
int sample;
if (secs_to_msecs) {
@@ -75,25 +71,18 @@
sample = ParseInt(argv[name_index + 1]);
}
- // Send metrics
- if (send_to_autotest) {
- MetricsLibrary::SendToAutotest(name, sample);
- }
-
- if (send_to_chrome) {
- MetricsLibrary metrics_lib;
- metrics_lib.Init();
- if (mode == kModeSendSparseSample) {
- metrics_lib.SendSparseToUMA(name, sample);
- } else if (mode == kModeSendEnumSample) {
- int max = ParseInt(argv[name_index + 2]);
- metrics_lib.SendEnumToUMA(name, sample, max);
- } else {
- int min = ParseInt(argv[name_index + 2]);
- int max = ParseInt(argv[name_index + 3]);
- int nbuckets = ParseInt(argv[name_index + 4]);
- metrics_lib.SendToUMA(name, sample, min, max, nbuckets);
- }
+ MetricsLibrary metrics_lib;
+ metrics_lib.Init();
+ if (mode == kModeSendSparseSample) {
+ metrics_lib.SendSparseToUMA(name, sample);
+ } else if (mode == kModeSendEnumSample) {
+ int max = ParseInt(argv[name_index + 2]);
+ metrics_lib.SendEnumToUMA(name, sample, max);
+ } else {
+ int min = ParseInt(argv[name_index + 2]);
+ int max = ParseInt(argv[name_index + 3]);
+ int nbuckets = ParseInt(argv[name_index + 4]);
+ metrics_lib.SendToUMA(name, sample, min, max, nbuckets);
}
return 0;
}
@@ -133,22 +122,12 @@
int main(int argc, char** argv) {
enum Mode mode = kModeSendSample;
- bool send_to_autotest = false;
- bool send_to_chrome = true;
bool secs_to_msecs = false;
// Parse arguments
int flag;
while ((flag = getopt(argc, argv, "abcegstuv")) != -1) {
switch (flag) {
- case 'a':
- send_to_autotest = true;
- send_to_chrome = false;
- break;
- case 'b':
- send_to_chrome = true;
- send_to_autotest = true;
- break;
case 'c':
mode = kModeHasConsent;
break;
@@ -203,9 +182,7 @@
return SendStats(argv,
arg_index,
mode,
- secs_to_msecs,
- send_to_autotest,
- send_to_chrome);
+ secs_to_msecs);
case kModeSendUserAction:
return SendUserAction(argv, arg_index);
case kModeSendCrosEvent:
diff --git a/metrics/metrics_daemon.cc b/metricsd/metrics_daemon.cc
similarity index 91%
rename from metrics/metrics_daemon.cc
rename to metricsd/metrics_daemon.cc
index 880e90c..f9061d5 100644
--- a/metrics/metrics_daemon.cc
+++ b/metricsd/metrics_daemon.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/metrics_daemon.h"
+#include "metrics_daemon.h"
#include <fcntl.h>
#include <inttypes.h>
@@ -11,6 +11,7 @@
#include <sysexits.h>
#include <time.h>
+#include <base/bind.h>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/hash.h>
@@ -20,9 +21,10 @@
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <base/sys_info.h>
-#include <chromeos/dbus/service_constants.h>
#include <dbus/dbus.h>
#include <dbus/message.h>
+
+#include "constants.h"
#include "uploader/upload_service.h"
using base::FilePath;
@@ -44,10 +46,6 @@
const char kCrashReporterMatchRule[] =
"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 kMinutesPerHour = 60;
const int kHoursPerDay = 24;
@@ -199,28 +197,21 @@
if (version_hash_is_cached)
return cached_version_hash;
version_hash_is_cached = true;
- std::string version;
- if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) {
- cached_version_hash = base::Hash(version);
- } else if (testing_) {
+ std::string version = metrics::kDefaultVersion;
+ // 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);
+ if (testing_) {
cached_version_hash = 42; // return any plausible value for the hash
- } else {
- LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION";
}
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,
bool uploader_active,
+ bool dbus_enabled,
MetricsLibraryInterface* metrics_lib,
- const string& diskstats_path,
const string& vmstats_path,
const string& scaling_max_freq_path,
const string& cpuinfo_max_freq_path,
@@ -230,6 +221,7 @@
const string& config_root) {
testing_ = testing;
uploader_active_ = uploader_active;
+ dbus_enabled_ = dbus_enabled;
config_root_ = config_root;
DCHECK(metrics_lib != nullptr);
metrics_lib_ = metrics_lib;
@@ -279,77 +271,58 @@
weekly_cycle_.reset(new PersistentInteger("weekly.cycle"));
version_cycle_.reset(new PersistentInteger("version.cycle"));
- diskstats_path_ = diskstats_path;
vmstats_path_ = vmstats_path;
scaling_max_freq_path_ = scaling_max_freq_path;
cpuinfo_max_freq_path_ = cpuinfo_max_freq_path;
-
- // If testing, initialize Stats Reporter without connecting DBus
- if (testing_)
- StatsReporterInit();
}
int MetricsDaemon::OnInit() {
- int return_code = chromeos::DBusDaemon::OnInit();
+ int return_code = dbus_enabled_ ? chromeos::DBusDaemon::OnInit() :
+ chromeos::Daemon::OnInit();
if (return_code != EX_OK)
return return_code;
- StatsReporterInit();
-
- // Start collecting meminfo stats.
- ScheduleMeminfoCallback(kMetricMeminfoInterval);
- memuse_final_time_ = GetActiveTime() + kMemuseIntervals[0];
- ScheduleMemuseCallback(kMemuseIntervals[0]);
-
if (testing_)
return EX_OK;
- bus_->AssertOnDBusThread();
- CHECK(bus_->SetUpAsyncOperations());
+ if (dbus_enabled_) {
+ bus_->AssertOnDBusThread();
+ CHECK(bus_->SetUpAsyncOperations());
- if (bus_->is_connected()) {
- const std::string match_rule =
- base::StringPrintf(kCrashReporterMatchRule,
- kCrashReporterInterface,
- kCrashReporterUserCrashSignal);
+ if (bus_->is_connected()) {
+ const std::string match_rule =
+ base::StringPrintf(kCrashReporterMatchRule,
+ kCrashReporterInterface,
+ kCrashReporterUserCrashSignal);
- bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
+ bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
- DBusError error;
- dbus_error_init(&error);
- bus_->AddMatch(match_rule, &error);
+ DBusError error;
+ dbus_error_init(&error);
+ bus_->AddMatch(match_rule, &error);
- if (dbus_error_is_set(&error)) {
- LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
- << error.name << ": " << error.message;
- return EX_SOFTWARE;
+ if (dbus_error_is_set(&error)) {
+ LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
+ << error.name << ": " << error.message;
+ return EX_SOFTWARE;
+ }
+ } else {
+ LOG(ERROR) << "DBus isn't connected.";
+ return EX_UNAVAILABLE;
}
- } else {
- LOG(ERROR) << "DBus isn't connected.";
- return EX_UNAVAILABLE;
}
- base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
- base::Bind(&MetricsDaemon::HandleUpdateStatsTimeout,
- base::Unretained(this)),
- base::TimeDelta::FromMilliseconds(kUpdateStatsIntervalMs));
-
if (uploader_active_) {
- if (IsOnOfficialBuild()) {
- LOG(INFO) << "uploader enabled";
- upload_service_.reset(
- new UploadService(new SystemProfileCache(), metrics_lib_, server_));
- upload_service_->Init(upload_interval_, metrics_file_);
- } else {
- LOG(INFO) << "uploader disabled on non-official build";
- }
+ upload_service_.reset(
+ new UploadService(new SystemProfileCache(), metrics_lib_, server_));
+ upload_service_->Init(upload_interval_, metrics_file_);
}
return EX_OK;
}
void MetricsDaemon::OnShutdown(int* return_code) {
- if (!testing_ && bus_->is_connected()) {
+ if (!testing_ && dbus_enabled_ && bus_->is_connected()) {
const std::string match_rule =
base::StringPrintf(kCrashReporterMatchRule,
kCrashReporterInterface,
@@ -520,41 +493,6 @@
base::TimeDelta::FromSeconds(wait));
}
-bool MetricsDaemon::DiskStatsReadStats(uint64_t* read_sectors,
- uint64_t* write_sectors) {
- int nchars;
- int nitems;
- bool success = false;
- char line[200];
- if (diskstats_path_.empty()) {
- return false;
- }
- int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY));
- if (file < 0) {
- PLOG(WARNING) << "cannot open " << diskstats_path_;
- return false;
- }
- nchars = HANDLE_EINTR(read(file, line, sizeof(line)));
- if (nchars < 0) {
- PLOG(WARNING) << "cannot read from " << diskstats_path_;
- return false;
- } else {
- LOG_IF(WARNING, nchars == sizeof(line))
- << "line too long in " << diskstats_path_;
- line[nchars] = '\0';
- nitems = sscanf(line, "%*d %*d %" PRIu64 " %*d %*d %*d %" PRIu64,
- read_sectors, write_sectors);
- if (nitems == 2) {
- success = true;
- } else {
- LOG(WARNING) << "found " << nitems << " items in "
- << diskstats_path_ << ", expected 2";
- }
- }
- IGNORE_EINTR(close(file));
- return success;
-}
-
bool MetricsDaemon::VmStatsParseStats(const char* stats,
struct VmstatRecord* record) {
// a mapping of string name to field in VmstatRecord and whether we found it
diff --git a/metrics/metrics_daemon.h b/metricsd/metrics_daemon.h
similarity index 98%
rename from metrics/metrics_daemon.h
rename to metricsd/metrics_daemon.h
index b1b2d11..ccac52a 100644
--- a/metrics/metrics_daemon.h
+++ b/metricsd/metrics_daemon.h
@@ -18,7 +18,7 @@
#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "metrics/metrics_library.h"
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
#include "uploader/upload_service.h"
using chromeos_metrics::PersistentInteger;
@@ -31,8 +31,8 @@
// Initializes metrics class variables.
void Init(bool testing,
bool uploader_active,
+ bool dbus_enabled,
MetricsLibraryInterface* metrics_lib,
- const std::string& diskstats_path,
const std::string& vmstats_path,
const std::string& cpuinfo_max_freq_path,
const std::string& scaling_max_freq_path,
@@ -269,9 +269,6 @@
// to a unsigned 32-bit int.
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
// since the last report.
void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time);
@@ -293,6 +290,10 @@
// Whether the uploader is enabled or disabled.
bool uploader_active_;
+ // Whether or not dbus should be used.
+ // If disabled, we will not collect the frequency of crashes.
+ bool dbus_enabled_;
+
// Root of the configuration files to use.
std::string config_root_;
@@ -356,7 +357,6 @@
scoped_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
scoped_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;
- std::string diskstats_path_;
std::string vmstats_path_;
std::string scaling_max_freq_path_;
std::string cpuinfo_max_freq_path_;
diff --git a/metrics/metrics_daemon_main.cc b/metricsd/metrics_daemon_main.cc
similarity index 69%
rename from metrics/metrics_daemon_main.cc
rename to metricsd/metrics_daemon_main.cc
index 1f64ef3..6c580ba 100644
--- a/metrics/metrics_daemon_main.cc
+++ b/metricsd/metrics_daemon_main.cc
@@ -8,40 +8,15 @@
#include <base/strings/string_util.h>
#include <chromeos/flag_helper.h>
#include <chromeos/syslog_logging.h>
-#include <rootdev/rootdev.h>
-#include "metrics/metrics_daemon.h"
+#include "constants.h"
+#include "metrics_daemon.h"
const char kScalingMaxFreqPath[] =
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq";
const char kCpuinfoMaxFreqPath[] =
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
-// Returns the path to the disk stats in the sysfs. Returns the null string if
-// it cannot find the disk stats file.
-static
-const std::string MetricsMainDiskStatsPath() {
- char dev_path_cstr[PATH_MAX];
- std::string dev_prefix = "/dev/";
- std::string dev_path;
- std::string dev_name;
-
- int ret = rootdev(dev_path_cstr, sizeof(dev_path_cstr), true, true);
- if (ret != 0) {
- LOG(WARNING) << "error " << ret << " determining root device";
- return "";
- }
- dev_path = dev_path_cstr;
- // Check that rootdev begins with "/dev/".
- if (!base::StartsWithASCII(dev_path, dev_prefix, false)) {
- LOG(WARNING) << "unexpected root device " << dev_path;
- return "";
- }
- // Get the device name, e.g. "sda" from "/dev/sda".
- dev_name = dev_path.substr(dev_prefix.length());
- return "/sys/class/block/" + dev_name + "/stat";
-}
-
int main(int argc, char** argv) {
DEFINE_bool(daemon, true, "run as daemon (use -nodaemon for debugging)");
@@ -54,16 +29,19 @@
false,
"run the uploader once and exit");
+ // Enable dbus.
+ DEFINE_bool(withdbus, true, "Enable dbus");
+
// Upload Service flags.
DEFINE_int32(upload_interval_secs,
1800,
"Interval at which metrics_daemon sends the metrics. (needs "
"-uploader)");
DEFINE_string(server,
- "https://clients4.google.com/uma/v2",
+ metrics::kMetricsServer,
"Server to upload the metrics to. (needs -uploader)");
DEFINE_string(metrics_file,
- "/var/lib/metrics/uma-events",
+ metrics::kMetricsEventsFilePath,
"File to use as a proxy for uploading the metrics");
DEFINE_string(config_root,
"/", "Root of the configuration files (testing only)");
@@ -83,8 +61,8 @@
MetricsDaemon daemon;
daemon.Init(FLAGS_uploader_test,
FLAGS_uploader | FLAGS_uploader_test,
+ FLAGS_withdbus,
&metrics_lib,
- MetricsMainDiskStatsPath(),
"/proc/vmstat",
kScalingMaxFreqPath,
kCpuinfoMaxFreqPath,
diff --git a/metrics/metrics_daemon_test.cc b/metricsd/metrics_daemon_test.cc
similarity index 98%
rename from metrics/metrics_daemon_test.cc
rename to metricsd/metrics_daemon_test.cc
index 7dafbd6..5aa7ab8 100644
--- a/metrics/metrics_daemon_test.cc
+++ b/metricsd/metrics_daemon_test.cc
@@ -15,9 +15,9 @@
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
-#include "metrics/metrics_daemon.h"
-#include "metrics/metrics_library_mock.h"
-#include "metrics/persistent_integer_mock.h"
+#include "metrics_daemon.h"
+#include "metrics_library_mock.h"
+#include "persistent_integer_mock.h"
using base::FilePath;
using base::StringPrintf;
@@ -44,8 +44,6 @@
static const char kFakeVmStatsName[] = "fake-vm-stats";
static const char kFakeScalingMaxFreqPath[] = "fake-scaling-max-freq";
static const char kFakeCpuinfoMaxFreqPath[] = "fake-cpuinfo-max-freq";
-static const char kMetricsServer[] = "https://clients4.google.com/uma/v2";
-static const char kMetricsFilePath[] = "/var/lib/metrics/uma-events";
class MetricsDaemonTest : public testing::Test {
protected:
diff --git a/metrics/metrics_library.cc b/metricsd/metrics_library.cc
similarity index 71%
rename from metrics/metrics_library.cc
rename to metricsd/metrics_library.cc
index 70c8eac..f777f28 100644
--- a/metrics/metrics_library.cc
+++ b/metricsd/metrics_library.cc
@@ -13,14 +13,10 @@
#include <cstdio>
#include <cstring>
-#include "metrics/serialization/metric_sample.h"
-#include "metrics/serialization/serialization_utils.h"
+#include "constants.h"
+#include "serialization/metric_sample.h"
+#include "serialization/serialization_utils.h"
-#include "policy/device_policy.h"
-
-static const char kAutotestPath[] = "/var/log/metrics/autotest-events";
-static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events";
-static const char kConsentFile[] = "/home/chronos/Consent To Send Stats";
static const char kCrosEventHistogramName[] = "Platform.CrOSEvent";
static const int kCrosEventHistogramMax = 100;
@@ -48,7 +44,7 @@
time_t MetricsLibrary::cached_enabled_time_ = 0;
bool MetricsLibrary::cached_enabled_ = false;
-MetricsLibrary::MetricsLibrary() : consent_file_(kConsentFile) {}
+MetricsLibrary::MetricsLibrary() : consent_file_(metrics::kConsentFilePath) {}
MetricsLibrary::~MetricsLibrary() {}
// We take buffer and buffer_size as parameters in order to simplify testing
@@ -123,47 +119,13 @@
time_t this_check_time = time(nullptr);
if (this_check_time != cached_enabled_time_) {
cached_enabled_time_ = this_check_time;
-
- if (!policy_provider_.get())
- policy_provider_.reset(new policy::PolicyProvider());
- policy_provider_->Reload();
- // We initialize with the default value which is false and will be preserved
- // if the policy is not set.
- bool enabled = false;
- bool has_policy = false;
- if (policy_provider_->device_policy_is_loaded()) {
- has_policy =
- policy_provider_->GetDevicePolicy().GetMetricsEnabled(&enabled);
- }
- // If policy couldn't be loaded or the metrics policy is not set we should
- // still respect the consent file if it is present for migration purposes.
- // TODO(pastarmovj)
- if (!has_policy) {
- enabled = stat(consent_file_.c_str(), &stat_buffer) >= 0;
- }
-
- if (enabled && !IsGuestMode())
- cached_enabled_ = true;
- else
- cached_enabled_ = false;
+ cached_enabled_ = stat(consent_file_.c_str(), &stat_buffer) >= 0;
}
return cached_enabled_;
}
void MetricsLibrary::Init() {
- uma_events_file_ = kUMAEventsPath;
-}
-
-bool MetricsLibrary::SendToAutotest(const std::string& name, int value) {
- FILE* autotest_file = fopen(kAutotestPath, "a+");
- if (autotest_file == nullptr) {
- PLOG(ERROR) << kAutotestPath << ": fopen";
- return false;
- }
-
- fprintf(autotest_file, "%s=%d\n", name.c_str(), value);
- fclose(autotest_file);
- return true;
+ uma_events_file_ = metrics::kMetricsEventsFilePath;
}
bool MetricsLibrary::SendToUMA(const std::string& name,
@@ -174,34 +136,30 @@
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::HistogramSample(name, sample, min, max, nbuckets)
.get(),
- kUMAEventsPath);
+ metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample,
int max) {
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::LinearHistogramSample(name, sample, max).get(),
- kUMAEventsPath);
+ metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) {
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::SparseHistogramSample(name, sample).get(),
- kUMAEventsPath);
+ metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendUserActionToUMA(const std::string& action) {
return metrics::SerializationUtils::WriteMetricToFile(
- *metrics::MetricSample::UserActionSample(action).get(), kUMAEventsPath);
+ *metrics::MetricSample::UserActionSample(action).get(), metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) {
return metrics::SerializationUtils::WriteMetricToFile(
- *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath);
-}
-
-void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) {
- policy_provider_.reset(provider);
+ *metrics::MetricSample::CrashSample(crash_kind).get(), metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) {
diff --git a/metrics/metrics_library_mock.h b/metricsd/metrics_library_mock.h
similarity index 100%
rename from metrics/metrics_library_mock.h
rename to metricsd/metrics_library_mock.h
diff --git a/metrics/metrics_library_test.cc b/metricsd/metrics_library_test.cc
similarity index 100%
rename from metrics/metrics_library_test.cc
rename to metricsd/metrics_library_test.cc
diff --git a/metrics/persistent_integer.cc b/metricsd/persistent_integer.cc
similarity index 91%
rename from metrics/persistent_integer.cc
rename to metricsd/persistent_integer.cc
index dd38f1e..0dcd52a 100644
--- a/metrics/persistent_integer.cc
+++ b/metricsd/persistent_integer.cc
@@ -2,21 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
#include <fcntl.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
+#include "constants.h"
#include "metrics/metrics_library.h"
-namespace {
-
-// The directory for the persistent storage.
-const char kBackingFilesDirectory[] = "/var/lib/metrics/";
-
-}
namespace chromeos_metrics {
@@ -31,7 +26,7 @@
if (testing_) {
backing_file_name_ = name_;
} else {
- backing_file_name_ = kBackingFilesDirectory + name_;
+ backing_file_name_ = metrics::kMetricsDirectory + name_;
}
}
diff --git a/metrics/persistent_integer.h b/metricsd/persistent_integer.h
similarity index 100%
rename from metrics/persistent_integer.h
rename to metricsd/persistent_integer.h
diff --git a/metrics/persistent_integer_mock.h b/metricsd/persistent_integer_mock.h
similarity index 93%
rename from metrics/persistent_integer_mock.h
rename to metricsd/persistent_integer_mock.h
index 2061e55..31bfc35 100644
--- a/metrics/persistent_integer_mock.h
+++ b/metricsd/persistent_integer_mock.h
@@ -9,7 +9,7 @@
#include <gmock/gmock.h>
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
namespace chromeos_metrics {
diff --git a/metrics/persistent_integer_test.cc b/metricsd/persistent_integer_test.cc
similarity index 97%
rename from metrics/persistent_integer_test.cc
rename to metricsd/persistent_integer_test.cc
index a56aede..4fccb72 100644
--- a/metrics/persistent_integer_test.cc
+++ b/metricsd/persistent_integer_test.cc
@@ -8,7 +8,7 @@
#include <base/files/file_enumerator.h>
#include <base/files/file_util.h>
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
const char kBackingFileName[] = "1.pibakf";
const char kBackingFilePattern[] = "*.pibakf";
diff --git a/metrics/platform2_preinstall.sh b/metricsd/platform2_preinstall.sh
similarity index 100%
rename from metrics/platform2_preinstall.sh
rename to metricsd/platform2_preinstall.sh
diff --git a/metrics/serialization/metric_sample.cc b/metricsd/serialization/metric_sample.cc
similarity index 98%
rename from metrics/serialization/metric_sample.cc
rename to metricsd/serialization/metric_sample.cc
index 5447497..bc6583d 100644
--- a/metrics/serialization/metric_sample.cc
+++ b/metricsd/serialization/metric_sample.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/serialization/metric_sample.h"
+#include "serialization/metric_sample.h"
#include <string>
#include <vector>
diff --git a/metrics/serialization/metric_sample.h b/metricsd/serialization/metric_sample.h
similarity index 100%
rename from metrics/serialization/metric_sample.h
rename to metricsd/serialization/metric_sample.h
diff --git a/metrics/serialization/serialization_utils.cc b/metricsd/serialization/serialization_utils.cc
similarity index 98%
rename from metrics/serialization/serialization_utils.cc
rename to metricsd/serialization/serialization_utils.cc
index 9aa076a..d18dcd7 100644
--- a/metrics/serialization/serialization_utils.cc
+++ b/metricsd/serialization/serialization_utils.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/serialization/serialization_utils.h"
+#include "serialization/serialization_utils.h"
#include <sys/file.h>
@@ -17,7 +17,7 @@
#include "base/memory/scoped_vector.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
-#include "metrics/serialization/metric_sample.h"
+#include "serialization/metric_sample.h"
#define READ_WRITE_ALL_FILE_FLAGS \
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
diff --git a/metrics/serialization/serialization_utils.h b/metricsd/serialization/serialization_utils.h
similarity index 100%
rename from metrics/serialization/serialization_utils.h
rename to metricsd/serialization/serialization_utils.h
diff --git a/metrics/serialization/serialization_utils_unittest.cc b/metricsd/serialization/serialization_utils_unittest.cc
similarity index 98%
rename from metrics/serialization/serialization_utils_unittest.cc
rename to metricsd/serialization/serialization_utils_unittest.cc
index 34d76cf..fb802bc 100644
--- a/metrics/serialization/serialization_utils_unittest.cc
+++ b/metricsd/serialization/serialization_utils_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/serialization/serialization_utils.h"
+#include "serialization/serialization_utils.h"
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
@@ -10,7 +10,7 @@
#include <base/strings/stringprintf.h>
#include <gtest/gtest.h>
-#include "metrics/serialization/metric_sample.h"
+#include "serialization/metric_sample.h"
namespace metrics {
namespace {
diff --git a/metrics/syslog_parser.sh b/metricsd/syslog_parser.sh
similarity index 100%
rename from metrics/syslog_parser.sh
rename to metricsd/syslog_parser.sh
diff --git a/metrics/timer.cc b/metricsd/timer.cc
similarity index 98%
rename from metrics/timer.cc
rename to metricsd/timer.cc
index 99f68fe..ce4bf67 100644
--- a/metrics/timer.cc
+++ b/metricsd/timer.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/timer.h"
+#include "timer.h"
#include <string>
diff --git a/metrics/timer.h b/metricsd/timer.h
similarity index 100%
rename from metrics/timer.h
rename to metricsd/timer.h
diff --git a/metrics/timer_mock.h b/metricsd/timer_mock.h
similarity index 97%
rename from metrics/timer_mock.h
rename to metricsd/timer_mock.h
index 2f2d0f4..ed76f12 100644
--- a/metrics/timer_mock.h
+++ b/metricsd/timer_mock.h
@@ -9,7 +9,7 @@
#include <gmock/gmock.h>
-#include "metrics/timer.h"
+#include "timer.h"
namespace chromeos_metrics {
diff --git a/metrics/timer_test.cc b/metricsd/timer_test.cc
similarity index 99%
rename from metrics/timer_test.cc
rename to metricsd/timer_test.cc
index ec6c6bd..b1689bf 100644
--- a/metrics/timer_test.cc
+++ b/metricsd/timer_test.cc
@@ -8,9 +8,9 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "metrics/metrics_library_mock.h"
-#include "metrics/timer.h"
-#include "metrics/timer_mock.h"
+#include "metrics_library_mock.h"
+#include "timer.h"
+#include "timer_mock.h"
using ::testing::_;
using ::testing::Return;
diff --git a/metrics/uploader/metrics_hashes.cc b/metricsd/uploader/metrics_hashes.cc
similarity index 95%
rename from metrics/uploader/metrics_hashes.cc
rename to metricsd/uploader/metrics_hashes.cc
index 87405a3..f9d0cfe 100644
--- a/metrics/uploader/metrics_hashes.cc
+++ b/metricsd/uploader/metrics_hashes.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_hashes.h"
+#include "uploader/metrics_hashes.h"
#include "base/logging.h"
#include "base/md5.h"
diff --git a/metrics/uploader/metrics_hashes.h b/metricsd/uploader/metrics_hashes.h
similarity index 100%
rename from metrics/uploader/metrics_hashes.h
rename to metricsd/uploader/metrics_hashes.h
diff --git a/metrics/uploader/metrics_hashes_unittest.cc b/metricsd/uploader/metrics_hashes_unittest.cc
similarity index 94%
rename from metrics/uploader/metrics_hashes_unittest.cc
rename to metricsd/uploader/metrics_hashes_unittest.cc
index f7e390f..8cdc7a9 100644
--- a/metrics/uploader/metrics_hashes_unittest.cc
+++ b/metricsd/uploader/metrics_hashes_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_hashes.h"
+#include "uploader/metrics_hashes.h"
#include <base/format_macros.h>
#include <base/macros.h>
diff --git a/metrics/uploader/metrics_log.cc b/metricsd/uploader/metrics_log.cc
similarity index 96%
rename from metrics/uploader/metrics_log.cc
rename to metricsd/uploader/metrics_log.cc
index 4d493b8..6f11f8a 100644
--- a/metrics/uploader/metrics_log.cc
+++ b/metricsd/uploader/metrics_log.cc
@@ -6,7 +6,7 @@
#include <string>
-#include "metrics/uploader/proto/system_profile.pb.h"
+#include "uploader/proto/system_profile.pb.h"
#include "uploader/system_profile_setter.h"
// We use default values for the MetricsLogBase constructor as the setter will
diff --git a/metrics/uploader/metrics_log.h b/metricsd/uploader/metrics_log.h
similarity index 96%
rename from metrics/uploader/metrics_log.h
rename to metricsd/uploader/metrics_log.h
index 5796325..a62798f 100644
--- a/metrics/uploader/metrics_log.h
+++ b/metricsd/uploader/metrics_log.h
@@ -9,7 +9,7 @@
#include <base/macros.h>
-#include "metrics/uploader/metrics_log_base.h"
+#include "uploader/metrics_log_base.h"
// This file defines a set of user experience metrics data recorded by
// the MetricsService. This is the unit of data that is sent to the server.
diff --git a/metrics/uploader/metrics_log_base.cc b/metricsd/uploader/metrics_log_base.cc
similarity index 94%
rename from metrics/uploader/metrics_log_base.cc
rename to metricsd/uploader/metrics_log_base.cc
index 7fe1ae1..3ae01e8 100644
--- a/metrics/uploader/metrics_log_base.cc
+++ b/metricsd/uploader/metrics_log_base.cc
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_log_base.h"
+#include "uploader/metrics_log_base.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
-#include "metrics/uploader/metrics_hashes.h"
-#include "metrics/uploader/proto/histogram_event.pb.h"
-#include "metrics/uploader/proto/system_profile.pb.h"
-#include "metrics/uploader/proto/user_action_event.pb.h"
+#include "uploader/metrics_hashes.h"
+#include "uploader/proto/histogram_event.pb.h"
+#include "uploader/proto/system_profile.pb.h"
+#include "uploader/proto/user_action_event.pb.h"
using base::Histogram;
using base::HistogramBase;
diff --git a/metrics/uploader/metrics_log_base.h b/metricsd/uploader/metrics_log_base.h
similarity index 97%
rename from metrics/uploader/metrics_log_base.h
rename to metricsd/uploader/metrics_log_base.h
index e871c0f..4173335 100644
--- a/metrics/uploader/metrics_log_base.h
+++ b/metricsd/uploader/metrics_log_base.h
@@ -13,7 +13,7 @@
#include "base/macros.h"
#include "base/metrics/histogram.h"
#include "base/time/time.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
namespace base {
class HistogramSamples;
diff --git a/metrics/uploader/metrics_log_base_unittest.cc b/metricsd/uploader/metrics_log_base_unittest.cc
similarity index 97%
rename from metrics/uploader/metrics_log_base_unittest.cc
rename to metricsd/uploader/metrics_log_base_unittest.cc
index 5da428a..dc03f00 100644
--- a/metrics/uploader/metrics_log_base_unittest.cc
+++ b/metricsd/uploader/metrics_log_base_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_log_base.h"
+#include "uploader/metrics_log_base.h"
#include <string>
@@ -10,7 +10,7 @@
#include <base/metrics/sample_vector.h>
#include <gtest/gtest.h>
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
namespace metrics {
diff --git a/metrics/uploader/mock/mock_system_profile_setter.h b/metricsd/uploader/mock/mock_system_profile_setter.h
similarity index 100%
rename from metrics/uploader/mock/mock_system_profile_setter.h
rename to metricsd/uploader/mock/mock_system_profile_setter.h
diff --git a/metrics/uploader/mock/sender_mock.cc b/metricsd/uploader/mock/sender_mock.cc
similarity index 100%
rename from metrics/uploader/mock/sender_mock.cc
rename to metricsd/uploader/mock/sender_mock.cc
diff --git a/metrics/uploader/mock/sender_mock.h b/metricsd/uploader/mock/sender_mock.h
similarity index 95%
rename from metrics/uploader/mock/sender_mock.h
rename to metricsd/uploader/mock/sender_mock.h
index 159b645..0a15d61 100644
--- a/metrics/uploader/mock/sender_mock.h
+++ b/metricsd/uploader/mock/sender_mock.h
@@ -8,7 +8,7 @@
#include <string>
#include "base/compiler_specific.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
#include "uploader/sender.h"
class SenderMock : public Sender {
diff --git a/metrics/uploader/proto/README b/metricsd/uploader/proto/README
similarity index 100%
rename from metrics/uploader/proto/README
rename to metricsd/uploader/proto/README
diff --git a/metrics/uploader/proto/chrome_user_metrics_extension.proto b/metricsd/uploader/proto/chrome_user_metrics_extension.proto
similarity index 91%
rename from metrics/uploader/proto/chrome_user_metrics_extension.proto
rename to metricsd/uploader/proto/chrome_user_metrics_extension.proto
index f712fc9..d4d4f24 100644
--- a/metrics/uploader/proto/chrome_user_metrics_extension.proto
+++ b/metricsd/uploader/proto/chrome_user_metrics_extension.proto
@@ -14,9 +14,9 @@
package metrics;
-import "histogram_event.proto";
-import "system_profile.proto";
-import "user_action_event.proto";
+import "system/core/metricsd/uploader/proto/histogram_event.proto";
+import "system/core/metricsd/uploader/proto/system_profile.proto";
+import "system/core/metricsd/uploader/proto/user_action_event.proto";
// Next tag: 13
message ChromeUserMetricsExtension {
diff --git a/metrics/uploader/proto/histogram_event.proto b/metricsd/uploader/proto/histogram_event.proto
similarity index 100%
rename from metrics/uploader/proto/histogram_event.proto
rename to metricsd/uploader/proto/histogram_event.proto
diff --git a/metrics/uploader/proto/system_profile.proto b/metricsd/uploader/proto/system_profile.proto
similarity index 100%
rename from metrics/uploader/proto/system_profile.proto
rename to metricsd/uploader/proto/system_profile.proto
diff --git a/metrics/uploader/proto/user_action_event.proto b/metricsd/uploader/proto/user_action_event.proto
similarity index 100%
rename from metrics/uploader/proto/user_action_event.proto
rename to metricsd/uploader/proto/user_action_event.proto
diff --git a/metrics/uploader/sender.h b/metricsd/uploader/sender.h
similarity index 100%
rename from metrics/uploader/sender.h
rename to metricsd/uploader/sender.h
diff --git a/metrics/uploader/sender_http.cc b/metricsd/uploader/sender_http.cc
similarity index 96%
rename from metrics/uploader/sender_http.cc
rename to metricsd/uploader/sender_http.cc
index 8488b66..a740310 100644
--- a/metrics/uploader/sender_http.cc
+++ b/metricsd/uploader/sender_http.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/sender_http.h"
+#include "uploader/sender_http.h"
#include <string>
diff --git a/metrics/uploader/sender_http.h b/metricsd/uploader/sender_http.h
similarity index 95%
rename from metrics/uploader/sender_http.h
rename to metricsd/uploader/sender_http.h
index 4880b28..380cad8 100644
--- a/metrics/uploader/sender_http.h
+++ b/metricsd/uploader/sender_http.h
@@ -9,7 +9,7 @@
#include <base/macros.h>
-#include "metrics/uploader/sender.h"
+#include "uploader/sender.h"
// Sender implemented using http_utils from libchromeos
class HttpSender : public Sender {
diff --git a/metricsd/uploader/system_profile_cache.cc b/metricsd/uploader/system_profile_cache.cc
new file mode 100644
index 0000000..adbe0ae
--- /dev/null
+++ b/metricsd/uploader/system_profile_cache.cc
@@ -0,0 +1,152 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "uploader/system_profile_cache.h"
+
+#include <base/files/file_util.h>
+#include <base/guid.h>
+#include <base/logging.h>
+#include <base/strings/string_number_conversions.h>
+#include <base/strings/string_util.h>
+#include <base/sys_info.h>
+#include <string>
+#include <vector>
+
+#include "constants.h"
+#include "persistent_integer.h"
+#include "uploader/metrics_log_base.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
+
+namespace {
+
+const char kPersistentSessionIdFilename[] = "Sysinfo.SessionId";
+
+} // namespace
+
+std::string ChannelToString(
+ const metrics::SystemProfileProto_Channel& channel) {
+ switch (channel) {
+ case metrics::SystemProfileProto::CHANNEL_STABLE:
+ return "STABLE";
+ case metrics::SystemProfileProto::CHANNEL_DEV:
+ return "DEV";
+ case metrics::SystemProfileProto::CHANNEL_BETA:
+ return "BETA";
+ case metrics::SystemProfileProto::CHANNEL_CANARY:
+ return "CANARY";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+SystemProfileCache::SystemProfileCache()
+ : initialized_(false),
+ testing_(false),
+ config_root_("/"),
+ session_id_(new chromeos_metrics::PersistentInteger(
+ kPersistentSessionIdFilename)) {
+}
+
+SystemProfileCache::SystemProfileCache(bool testing,
+ const std::string& config_root)
+ : initialized_(false),
+ testing_(testing),
+ config_root_(config_root),
+ session_id_(new chromeos_metrics::PersistentInteger(
+ kPersistentSessionIdFilename)) {
+}
+
+bool SystemProfileCache::Initialize() {
+ CHECK(!initialized_)
+ << "this should be called only once in the metrics_daemon lifetime.";
+
+ if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID",
+ &profile_.build_target_id)) {
+ LOG(ERROR) << "Could not initialize system profile.";
+ 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 =
+ testing_ ? "client_id_test" :
+ GetPersistentGUID(metrics::kMetricsGUIDFilePath);
+ profile_.hardware_class = "unknown";
+ profile_.channel = ProtoChannelFromString(channel);
+
+ // Increment the session_id everytime we initialize this. If metrics_daemon
+ // does not crash, this should correspond to the number of reboots of the
+ // system.
+ session_id_->Add(1);
+ profile_.session_id = static_cast<int32_t>(session_id_->Get());
+
+ initialized_ = true;
+ return initialized_;
+}
+
+bool SystemProfileCache::InitializeOrCheck() {
+ return initialized_ || Initialize();
+}
+
+void SystemProfileCache::Populate(
+ metrics::ChromeUserMetricsExtension* metrics_proto) {
+ CHECK(metrics_proto);
+ CHECK(InitializeOrCheck())
+ << "failed to initialize system information.";
+
+ // The client id is hashed before being sent.
+ metrics_proto->set_client_id(
+ metrics::MetricsLogBase::Hash(profile_.client_id));
+ metrics_proto->set_session_id(profile_.session_id);
+
+ // Sets the product id.
+ metrics_proto->set_product(9);
+
+ metrics::SystemProfileProto* profile_proto =
+ metrics_proto->mutable_system_profile();
+ profile_proto->mutable_hardware()->set_hardware_class(
+ profile_.hardware_class);
+ profile_proto->set_app_version(profile_.version);
+ profile_proto->set_channel(profile_.channel);
+ metrics::SystemProfileProto_BrilloDeviceData* device_data =
+ profile_proto->mutable_brillo();
+ device_data->set_build_target_id(profile_.build_target_id);
+}
+
+std::string SystemProfileCache::GetPersistentGUID(
+ const std::string& filename) {
+ std::string guid;
+ base::FilePath filepath(filename);
+ if (!base::ReadFileToString(filepath, &guid)) {
+ guid = base::GenerateGUID();
+ // If we can't read or write the file, the guid will not be preserved during
+ // the next reboot. Crash.
+ CHECK(base::WriteFile(filepath, guid.c_str(), guid.size()));
+ }
+ return guid;
+}
+
+metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString(
+ const std::string& channel) {
+ if (channel == "stable") {
+ return metrics::SystemProfileProto::CHANNEL_STABLE;
+ } else if (channel == "dev") {
+ return metrics::SystemProfileProto::CHANNEL_DEV;
+ } else if (channel == "beta") {
+ return metrics::SystemProfileProto::CHANNEL_BETA;
+ } else if (channel == "canary") {
+ return metrics::SystemProfileProto::CHANNEL_CANARY;
+ }
+
+ DLOG(INFO) << "unknown channel: " << channel;
+ return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
+}
diff --git a/metrics/uploader/system_profile_cache.h b/metricsd/uploader/system_profile_cache.h
similarity index 67%
rename from metrics/uploader/system_profile_cache.h
rename to metricsd/uploader/system_profile_cache.h
index e7a7337..b6ff337 100644
--- a/metrics/uploader/system_profile_cache.h
+++ b/metricsd/uploader/system_profile_cache.h
@@ -12,24 +12,21 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
-#include "chromeos/osrelease_reader.h"
-#include "metrics/persistent_integer.h"
-#include "metrics/uploader/proto/system_profile.pb.h"
-#include "metrics/uploader/system_profile_setter.h"
+#include "persistent_integer.h"
+#include "uploader/proto/system_profile.pb.h"
+#include "uploader/system_profile_setter.h"
namespace metrics {
class ChromeUserMetricsExtension;
}
struct SystemProfile {
- std::string os_name;
- std::string os_version;
- metrics::SystemProfileProto::Channel channel;
- std::string app_version;
+ std::string version;
std::string hardware_class;
std::string client_id;
- int32_t session_id;
- int32_t product_id;
+ int session_id;
+ metrics::SystemProfileProto::Channel channel;
+ std::string build_target_id;
};
// Retrieves general system informations needed by the protobuf for context and
@@ -43,9 +40,9 @@
SystemProfileCache(bool testing, const std::string& config_root);
// Populates the ProfileSystem protobuf with system information.
- void Populate(metrics::ChromeUserMetricsExtension* profile_proto) override;
+ void Populate(metrics::ChromeUserMetricsExtension* metrics_proto) override;
- // Converts a string representation of the channel (|channel|-channel) to a
+ // Converts a string representation of the channel to a
// SystemProfileProto_Channel
static metrics::SystemProfileProto_Channel ProtoChannelFromString(
const std::string& channel);
@@ -66,21 +63,6 @@
// Initializes |profile_| only if it has not been yet initialized.
bool InitializeOrCheck();
- // Gets the hardware ID using crossystem
- bool GetHardwareId(std::string* hwid);
-
- // Gets the product ID from the GOOGLE_METRICS_PRODUCT_ID field.
- bool GetProductId(int* product_id) const;
-
- // Generate the formatted chromeos version from the fields in
- // /etc/lsb-release. The format is A.B.C.D where A, B, C and D are positive
- // integer representing:
- // * the chrome milestone
- // * the build number
- // * the branch number
- // * the patch number
- bool GetChromeOSVersion(std::string* version);
-
bool initialized_;
bool testing_;
std::string config_root_;
diff --git a/metrics/uploader/system_profile_setter.h b/metricsd/uploader/system_profile_setter.h
similarity index 100%
rename from metrics/uploader/system_profile_setter.h
rename to metricsd/uploader/system_profile_setter.h
diff --git a/metrics/uploader/upload_service.cc b/metricsd/uploader/upload_service.cc
similarity index 95%
rename from metrics/uploader/upload_service.cc
rename to metricsd/uploader/upload_service.cc
index 92c9e10..3411004 100644
--- a/metrics/uploader/upload_service.cc
+++ b/metricsd/uploader/upload_service.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/upload_service.h"
+#include "uploader/upload_service.h"
#include <string>
@@ -17,11 +17,11 @@
#include <base/metrics/statistics_recorder.h>
#include <base/sha1.h>
-#include "metrics/serialization/metric_sample.h"
-#include "metrics/serialization/serialization_utils.h"
-#include "metrics/uploader/metrics_log.h"
-#include "metrics/uploader/sender_http.h"
-#include "metrics/uploader/system_profile_cache.h"
+#include "serialization/metric_sample.h"
+#include "serialization/serialization_utils.h"
+#include "uploader/metrics_log.h"
+#include "uploader/sender_http.h"
+#include "uploader/system_profile_setter.h"
const int UploadService::kMaxFailedUpload = 10;
diff --git a/metrics/uploader/upload_service.h b/metricsd/uploader/upload_service.h
similarity index 97%
rename from metrics/uploader/upload_service.h
rename to metricsd/uploader/upload_service.h
index ebbb54f..c08fc1a 100644
--- a/metrics/uploader/upload_service.h
+++ b/metricsd/uploader/upload_service.h
@@ -12,9 +12,9 @@
#include "base/metrics/histogram_snapshot_manager.h"
#include "metrics/metrics_library.h"
-#include "metrics/uploader/metrics_log.h"
-#include "metrics/uploader/sender.h"
-#include "metrics/uploader/system_profile_cache.h"
+#include "uploader/metrics_log.h"
+#include "uploader/sender.h"
+#include "uploader/system_profile_cache.h"
namespace metrics {
class ChromeUserMetricsExtension;
diff --git a/metrics/uploader/upload_service_test.cc b/metricsd/uploader/upload_service_test.cc
similarity index 92%
rename from metrics/uploader/upload_service_test.cc
rename to metricsd/uploader/upload_service_test.cc
index ee17e15..efd0a56 100644
--- a/metrics/uploader/upload_service_test.cc
+++ b/metricsd/uploader/upload_service_test.cc
@@ -9,19 +9,16 @@
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/sys_info.h"
-#include "metrics/metrics_library_mock.h"
-#include "metrics/serialization/metric_sample.h"
-#include "metrics/uploader/metrics_log.h"
-#include "metrics/uploader/mock/mock_system_profile_setter.h"
-#include "metrics/uploader/mock/sender_mock.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
-#include "metrics/uploader/proto/histogram_event.pb.h"
-#include "metrics/uploader/proto/system_profile.pb.h"
-#include "metrics/uploader/system_profile_cache.h"
-#include "metrics/uploader/upload_service.h"
-
-static const char kMetricsServer[] = "https://clients4.google.com/uma/v2";
-static const char kMetricsFilePath[] = "/var/run/metrics/uma-events";
+#include "metrics_library_mock.h"
+#include "serialization/metric_sample.h"
+#include "uploader/metrics_log.h"
+#include "uploader/mock/mock_system_profile_setter.h"
+#include "uploader/mock/sender_mock.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/histogram_event.pb.h"
+#include "uploader/proto/system_profile.pb.h"
+#include "uploader/system_profile_cache.h"
+#include "uploader/upload_service.h"
class UploadServiceTest : public testing::Test {
protected: