2010-04-14 20:32:20 +00:00
|
|
|
// Copyright (c) 2009 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.
|
|
|
|
|
2014-06-25 21:38:07 +00:00
|
|
|
#include <base/at_exit.h>
|
2014-04-21 21:33:32 +00:00
|
|
|
#include <base/command_line.h>
|
2011-02-28 19:17:43 +00:00
|
|
|
#include <base/logging.h>
|
2014-02-06 07:26:25 +00:00
|
|
|
#include <base/strings/string_util.h>
|
2014-10-06 22:15:30 +00:00
|
|
|
#include <chromeos/flag_helper.h>
|
2014-04-21 21:33:32 +00:00
|
|
|
#include <chromeos/syslog_logging.h>
|
2010-04-14 20:32:20 +00:00
|
|
|
|
2015-07-28 22:38:14 +00:00
|
|
|
#include "metrics_daemon.h"
|
2010-04-14 20:32:20 +00:00
|
|
|
|
2013-05-07 23:55:00 +00:00
|
|
|
const char kScalingMaxFreqPath[] =
|
|
|
|
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq";
|
|
|
|
const char kCpuinfoMaxFreqPath[] =
|
|
|
|
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
|
|
|
|
|
2010-04-14 20:32:20 +00:00
|
|
|
int main(int argc, char** argv) {
|
2014-10-06 22:15:30 +00:00
|
|
|
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,
|
2015-03-06 22:43:58 +00:00
|
|
|
"/var/lib/metrics/uma-events",
|
2014-10-06 22:15:30 +00:00
|
|
|
"File to use as a proxy for uploading the metrics");
|
2014-10-07 18:26:25 +00:00
|
|
|
DEFINE_string(config_root,
|
|
|
|
"/", "Root of the configuration files (testing only)");
|
2014-10-06 22:15:30 +00:00
|
|
|
|
|
|
|
chromeos::FlagHelper::Init(argc, argv, "Chromium OS Metrics Daemon");
|
2014-04-21 21:33:32 +00:00
|
|
|
|
|
|
|
// Also log to stderr when not running as daemon.
|
|
|
|
chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogHeader |
|
|
|
|
(FLAGS_daemon ? 0 : chromeos::kLogToStderr));
|
2014-12-01 21:38:21 +00:00
|
|
|
|
|
|
|
if (FLAGS_daemon && daemon(0, 0) != 0) {
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2010-05-18 18:00:59 +00:00
|
|
|
MetricsLibrary metrics_lib;
|
|
|
|
metrics_lib.Init();
|
|
|
|
MetricsDaemon daemon;
|
2014-09-11 14:38:17 +00:00
|
|
|
daemon.Init(FLAGS_uploader_test,
|
2014-06-25 21:38:07 +00:00
|
|
|
FLAGS_uploader | FLAGS_uploader_test,
|
|
|
|
&metrics_lib,
|
|
|
|
"/proc/vmstat",
|
|
|
|
kScalingMaxFreqPath,
|
2014-10-06 22:15:30 +00:00
|
|
|
kCpuinfoMaxFreqPath,
|
2014-10-09 17:14:13 +00:00
|
|
|
base::TimeDelta::FromSeconds(FLAGS_upload_interval_secs),
|
2014-10-06 22:15:30 +00:00
|
|
|
FLAGS_server,
|
2014-10-07 18:26:25 +00:00
|
|
|
FLAGS_metrics_file,
|
|
|
|
FLAGS_config_root);
|
2014-06-25 21:38:07 +00:00
|
|
|
|
|
|
|
if (FLAGS_uploader_test) {
|
|
|
|
daemon.RunUploaderTest();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-01 21:38:21 +00:00
|
|
|
daemon.Run();
|
2010-04-14 20:32:20 +00:00
|
|
|
}
|