am 011b2bc3: Merge "metrics: Add a CLI flag to disable dbus."

* commit '011b2bc3ebba01de7acec1a6ed7a287a492b6fa0':
  metrics: Add a CLI flag to disable dbus.
This commit is contained in:
Gaurav Shah 2015-08-10 22:45:08 +00:00 committed by Android Git Automerger
commit 0e8acc3c16
3 changed files with 34 additions and 20 deletions

View file

@ -210,6 +210,7 @@ uint32_t MetricsDaemon::GetOsVersionHash() {
void MetricsDaemon::Init(bool testing, void MetricsDaemon::Init(bool testing,
bool uploader_active, bool uploader_active,
bool dbus_enabled,
MetricsLibraryInterface* metrics_lib, MetricsLibraryInterface* metrics_lib,
const string& vmstats_path, const string& vmstats_path,
const string& scaling_max_freq_path, const string& scaling_max_freq_path,
@ -220,6 +221,7 @@ void MetricsDaemon::Init(bool testing,
const string& config_root) { const string& config_root) {
testing_ = testing; testing_ = testing;
uploader_active_ = uploader_active; uploader_active_ = uploader_active;
dbus_enabled_ = dbus_enabled;
config_root_ = config_root; config_root_ = config_root;
DCHECK(metrics_lib != nullptr); DCHECK(metrics_lib != nullptr);
metrics_lib_ = metrics_lib; metrics_lib_ = metrics_lib;
@ -275,36 +277,39 @@ void MetricsDaemon::Init(bool testing,
} }
int MetricsDaemon::OnInit() { 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) if (return_code != EX_OK)
return return_code; return return_code;
if (testing_) if (testing_)
return EX_OK; return EX_OK;
bus_->AssertOnDBusThread(); if (dbus_enabled_) {
CHECK(bus_->SetUpAsyncOperations()); bus_->AssertOnDBusThread();
CHECK(bus_->SetUpAsyncOperations());
if (bus_->is_connected()) { if (bus_->is_connected()) {
const std::string match_rule = const std::string match_rule =
base::StringPrintf(kCrashReporterMatchRule, base::StringPrintf(kCrashReporterMatchRule,
kCrashReporterInterface, kCrashReporterInterface,
kCrashReporterUserCrashSignal); kCrashReporterUserCrashSignal);
bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this); bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
DBusError error; DBusError error;
dbus_error_init(&error); dbus_error_init(&error);
bus_->AddMatch(match_rule, &error); bus_->AddMatch(match_rule, &error);
if (dbus_error_is_set(&error)) { if (dbus_error_is_set(&error)) {
LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got " LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
<< error.name << ": " << error.message; << error.name << ": " << error.message;
return EX_SOFTWARE; return EX_SOFTWARE;
}
} else {
LOG(ERROR) << "DBus isn't connected.";
return EX_UNAVAILABLE;
} }
} else {
LOG(ERROR) << "DBus isn't connected.";
return EX_UNAVAILABLE;
} }
if (uploader_active_) { if (uploader_active_) {
@ -317,7 +322,7 @@ int MetricsDaemon::OnInit() {
} }
void MetricsDaemon::OnShutdown(int* return_code) { void MetricsDaemon::OnShutdown(int* return_code) {
if (!testing_ && bus_->is_connected()) { if (!testing_ && dbus_enabled_ && bus_->is_connected()) {
const std::string match_rule = const std::string match_rule =
base::StringPrintf(kCrashReporterMatchRule, base::StringPrintf(kCrashReporterMatchRule,
kCrashReporterInterface, kCrashReporterInterface,

View file

@ -31,6 +31,7 @@ class MetricsDaemon : public chromeos::DBusDaemon {
// Initializes metrics class variables. // Initializes metrics class variables.
void Init(bool testing, void Init(bool testing,
bool uploader_active, bool uploader_active,
bool dbus_enabled,
MetricsLibraryInterface* metrics_lib, MetricsLibraryInterface* metrics_lib,
const std::string& vmstats_path, const std::string& vmstats_path,
const std::string& cpuinfo_max_freq_path, const std::string& cpuinfo_max_freq_path,
@ -289,6 +290,10 @@ class MetricsDaemon : public chromeos::DBusDaemon {
// Whether the uploader is enabled or disabled. // Whether the uploader is enabled or disabled.
bool uploader_active_; 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. // Root of the configuration files to use.
std::string config_root_; std::string config_root_;

View file

@ -29,6 +29,9 @@ int main(int argc, char** argv) {
false, false,
"run the uploader once and exit"); "run the uploader once and exit");
// Enable dbus.
DEFINE_bool(withdbus, true, "Enable dbus");
// Upload Service flags. // Upload Service flags.
DEFINE_int32(upload_interval_secs, DEFINE_int32(upload_interval_secs,
1800, 1800,
@ -58,6 +61,7 @@ int main(int argc, char** argv) {
MetricsDaemon daemon; MetricsDaemon daemon;
daemon.Init(FLAGS_uploader_test, daemon.Init(FLAGS_uploader_test,
FLAGS_uploader | FLAGS_uploader_test, FLAGS_uploader | FLAGS_uploader_test,
FLAGS_withdbus,
&metrics_lib, &metrics_lib,
"/proc/vmstat", "/proc/vmstat",
kScalingMaxFreqPath, kScalingMaxFreqPath,