Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67906c6b authored by Steve Fung's avatar Steve Fung Committed by chrome-internal-fetch
Browse files

metrics: remove gflags dependency

We are switching to using chromeos/flag_helper.h instead to standardize the
code everywhere.

BUG=chromium:375017
TEST=`FEATURES=test emerge-panther metrics`
TEST=`cbuildbot --remote --hwtest -p 'chromiumos/platform2'
      falco-paladin` passes

Change-Id: Icd08f65fd639e82ac6fe1581c763d60a189db827
Reviewed-on: https://chromium-review.googlesource.com/221757


Reviewed-by: default avatarBertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Steve Fung <stevefung@chromium.org>
Tested-by: default avatarSteve Fung <stevefung@chromium.org>
parent e812249c
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
      'link_settings': {
        'libraries': [
          '-lrootdev',
          '-lgflags',
        ],
      },
      'sources': [
@@ -56,7 +55,6 @@
      ],
      'link_settings': {
        'libraries': [
          '-lgflags',
          '-lvboot_host',
        ],
      },
+12 −5
Original line number Diff line number Diff line
@@ -187,8 +187,8 @@ void MetricsDaemon::Run(bool run_as_daemon) {
}

void MetricsDaemon::RunUploaderTest() {
  upload_service_.reset(new UploadService(testing_));
  upload_service_->Init();
  upload_service_.reset(new UploadService(testing_, server_));
  upload_service_->Init(upload_interval_secs_, metrics_file_);
  upload_service_->UploadEvent();
}

@@ -215,11 +215,18 @@ void MetricsDaemon::Init(bool testing,
                         const string& diskstats_path,
                         const string& vmstats_path,
                         const string& scaling_max_freq_path,
                         const string& cpuinfo_max_freq_path) {
                         const string& cpuinfo_max_freq_path,
                         int upload_interval_secs,
                         const string& server,
                         const string& metrics_file) {
  testing_ = testing;
  DCHECK(metrics_lib != nullptr);
  metrics_lib_ = metrics_lib;

  upload_interval_secs_ = upload_interval_secs;
  server_ = server;
  metrics_file_ = metrics_file;

  // Get ticks per second (HZ) on this system.
  // Sysconf cannot fail, so no sanity checks are needed.
  ticks_per_second_ = sysconf(_SC_CLK_TCK);
@@ -314,8 +321,8 @@ void MetricsDaemon::Init(bool testing,

  if (uploader_active) {
    LOG(INFO) << "uploader enabled";
    upload_service_.reset(new UploadService(testing_));
    upload_service_->Init();
    upload_service_.reset(new UploadService(testing_, server_));
    upload_service_->Init(upload_interval_secs_, metrics_file_);
  }
}

+8 −1
Original line number Diff line number Diff line
@@ -36,7 +36,10 @@ class MetricsDaemon {
            const std::string& diskstats_path,
            const std::string& vmstats_path,
            const std::string& cpuinfo_max_freq_path,
            const std::string& scaling_max_freq_path);
            const std::string& scaling_max_freq_path,
            int upload_interval_secs,
            const std::string& server,
            const std::string& metrics_file);

  // Does all the work. If |run_as_daemon| is true, daemonizes by
  // forking.
@@ -372,6 +375,10 @@ class MetricsDaemon {
  std::string scaling_max_freq_path_;
  std::string cpuinfo_max_freq_path_;

  int upload_interval_secs_;
  std::string server_;
  std::string metrics_file_;

  scoped_ptr<UploadService> upload_service_;
};

+29 −17
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@
#include <base/command_line.h>
#include <base/logging.h>
#include <base/strings/string_util.h>
#include <chromeos/flag_helper.h>
#include <chromeos/syslog_logging.h>
#include <gflags/gflags.h>
#include <rootdev/rootdev.h>

#include "metrics/metrics_daemon.h"
@@ -17,19 +17,6 @@ const char kScalingMaxFreqPath[] =
const char kCpuinfoMaxFreqPath[] =
    "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";

// TODO(bsimonnet): Change this to use base::CommandLine (crbug.com/375017)
DEFINE_bool(daemon, true, "run as daemon (use -nodaemon for debugging)");

// The uploader is disabled by default on ChromeOS as Chrome is responsible for
// sending the metrics.
DEFINE_bool(uploader, false, "activate the uploader");

// Upload the metrics once and exit. (used for testing)
DEFINE_bool(
    uploader_test,
    false,
    "run the uploader once and exit");

// Returns the path to the disk stats in the sysfs.  Returns the null string if
// it cannot find the disk stats file.
static
@@ -56,8 +43,30 @@ const std::string MetricsMainDiskStatsPath() {
}

int main(int argc, char** argv) {
  CommandLine::Init(argc, argv);
  google::ParseCommandLineFlags(&argc, &argv, true);
  DEFINE_bool(daemon, true, "run as daemon (use -nodaemon for debugging)");

  // The uploader is disabled by default on ChromeOS as Chrome is responsible
  // for sending the metrics.
  DEFINE_bool(uploader, false, "activate the uploader");

  // Upload the metrics once and exit. (used for testing)
  DEFINE_bool(uploader_test,
              false,
              "run the uploader once and exit");

  // 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",
                "Server to upload the metrics to. (needs -uploader)");
  DEFINE_string(metrics_file,
                "/var/run/metrics/uma-events",
                "File to use as a proxy for uploading the metrics");

  chromeos::FlagHelper::Init(argc, argv, "Chromium OS Metrics Daemon");

  // Also log to stderr when not running as daemon.
  chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogHeader |
@@ -71,7 +80,10 @@ int main(int argc, char** argv) {
              MetricsMainDiskStatsPath(),
              "/proc/vmstat",
              kScalingMaxFreqPath,
              kCpuinfoMaxFreqPath);
              kCpuinfoMaxFreqPath,
              FLAGS_upload_interval_secs,
              FLAGS_server,
              FLAGS_metrics_file);


  base::AtExitManager at_exit_manager;
+6 −1
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ static const uint64_t kFakeWriteSectors[] = {3000, 4000};
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/run/metrics/uma-events";

class MetricsDaemonTest : public testing::Test {
 protected:
@@ -69,7 +71,10 @@ class MetricsDaemonTest : public testing::Test {
                 kFakeDiskStatsName,
                 kFakeVmStatsName,
                 kFakeScalingMaxFreqPath,
                 kFakeCpuinfoMaxFreqPath);
                 kFakeCpuinfoMaxFreqPath,
                 1800,
                 kMetricsServer,
                 kMetricsFilePath);

    // Replace original persistent values with mock ones.
    daily_active_use_mock_ =
Loading