Merge "Remove metrics collector service trampoline"

This commit is contained in:
Todd Poynor 2016-01-06 00:01:50 +00:00 committed by Gerrit Code Review
commit b256a47064
6 changed files with 28 additions and 133 deletions

View file

@ -28,7 +28,6 @@ metrics_collector_common := \
collectors/cpu_usage_collector.cc \
collectors/disk_usage_collector.cc \
metrics_collector.cc \
metrics_collector_service_trampoline.cc \
persistent_integer.cc
metricsd_common := \
@ -102,13 +101,13 @@ include $(BUILD_STATIC_LIBRARY)
# ==========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libmetricscollectorservice
LOCAL_CLANG := true
LOCAL_SHARED_LIBRARIES := libbinder libbrillo-binder libchrome libutils
LOCAL_CPP_EXTENSION := $(metrics_cpp_extension)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := \
aidl/android/brillo/metrics/IMetricsCollectorService.aidl \
metrics_collector_service_impl.cc \
metrics_collector_service_client.cc
include $(BUILD_STATIC_LIBRARY)
@ -166,7 +165,8 @@ LOCAL_INIT_RC := metrics_collector.rc
LOCAL_REQUIRED_MODULES := metrics.json
LOCAL_SHARED_LIBRARIES := $(metrics_collector_shared_libraries)
LOCAL_SRC_FILES := $(metrics_collector_common) \
metrics_collector_main.cc
metrics_collector_main.cc \
metrics_collector_service_impl.cc
LOCAL_STATIC_LIBRARIES := metricsd_binder_proxy \
$(metrics_collector_static_libraries)
include $(BUILD_EXECUTABLE)

View file

@ -30,12 +30,13 @@
#include <base/strings/string_split.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <brillo/binder_watcher.h>
#include <brillo/osrelease_reader.h>
#include <dbus/dbus.h>
#include <dbus/message.h>
#include "constants.h"
#include "metrics_collector_service_trampoline.h"
#include "metrics_collector_service_impl.h"
using base::FilePath;
using base::StringPrintf;
@ -128,10 +129,18 @@ int MetricsCollector::Run() {
version_cumulative_cpu_use_->Set(0);
}
// Start metricscollectorservice via trampoline
MetricsCollectorServiceTrampoline metricscollectorservice_trampoline(this);
metricscollectorservice_trampoline.Run();
// Start metricscollectorservice
android::sp<BnMetricsCollectorServiceImpl> metrics_collector_service =
new BnMetricsCollectorServiceImpl(this);
android::status_t status = android::defaultServiceManager()->addService(
metrics_collector_service->getInterfaceDescriptor(),
metrics_collector_service);
CHECK(status == android::OK)
<< "failed to register service metricscollectorservice";
// Watch Binder events in the main loop
brillo::BinderWatcher binder_watcher;
CHECK(binder_watcher.Init()) << "Binder FD watcher init failed";
return brillo::DBusDaemon::Run();
}

View file

@ -18,27 +18,18 @@
#include <binder/IServiceManager.h>
#include <binder/Status.h>
#include <brillo/binder_watcher.h>
#include <utils/Errors.h>
#include "metrics_collector_service_trampoline.h"
#include "metrics_collector.h"
using namespace android;
BnMetricsCollectorServiceImpl::BnMetricsCollectorServiceImpl(
MetricsCollectorServiceTrampoline* metrics_collector_service_trampoline) {
metrics_collector_service_trampoline_ = metrics_collector_service_trampoline;
}
void BnMetricsCollectorServiceImpl::Run() {
status_t status =
defaultServiceManager()->addService(getInterfaceDescriptor(), this);
CHECK(status == OK) << "libmetricscollectorservice: failed to add service";
binder_watcher_.reset(new ::brillo::BinderWatcher);
CHECK(binder_watcher_->Init()) << "Binder FD watcher init failed";
MetricsCollector* metrics_collector)
: metrics_collector_(metrics_collector) {
}
android::binder::Status BnMetricsCollectorServiceImpl::notifyUserCrash() {
metrics_collector_service_trampoline_->ProcessUserCrash();
metrics_collector_->ProcessUserCrash();
return android::binder::Status::ok();
}

View file

@ -18,45 +18,31 @@
#define METRICSD_METRICS_COLLECTOR_SERVICE_IMPL_H_
// metrics_collector binder service implementation. Constructed by
// MetricsCollectorServiceTrampoline, which we use to call back into
// MetricsCollector. The trampoline isolates us from the -frtti code of
// metrics_collector / libbrillo.
// MetricsCollector.
#include "android/brillo/metrics/BnMetricsCollectorService.h"
#include <memory>
#include <binder/Status.h>
#include <brillo/binder_watcher.h>
class MetricsCollectorServiceTrampoline;
//#include "metrics_collector_service_trampoline.h"
class MetricsCollector;
class BnMetricsCollectorServiceImpl
: public android::brillo::metrics::BnMetricsCollectorService {
public:
// Passed a this pointer from the MetricsCollectorServiceTrampoline
// object that constructs us.
// Passed a this pointer from the MetricsCollector object that constructs us.
explicit BnMetricsCollectorServiceImpl(
MetricsCollectorServiceTrampoline* metrics_collector_service_trampoline);
MetricsCollector* metrics_collector_service);
virtual ~BnMetricsCollectorServiceImpl() = default;
// Starts the binder main loop.
void Run();
// Called by crash_reporter to report a userspace crash event. We relay
// this to MetricsCollector using the trampoline.
// this to MetricsCollector.
android::binder::Status notifyUserCrash();
private:
// Trampoline object that constructs us, we use this to call MetricsCollector
// methods via the trampoline.
MetricsCollectorServiceTrampoline* metrics_collector_service_trampoline_;
// BinderWatcher object we construct for handling Binder traffic
std::unique_ptr<brillo::BinderWatcher> binder_watcher_;
// MetricsCollector object that constructs us, we use this to call back
// to it.
MetricsCollector* metrics_collector_;
};
#endif // METRICSD_METRICS_COLLECTOR_SERVICE_IMPL_H_

View file

@ -1,34 +0,0 @@
/*
* 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.
*/
#include "metrics_collector_service_trampoline.h"
#include "metrics_collector.h"
#include "metrics_collector_service_impl.h"
MetricsCollectorServiceTrampoline::MetricsCollectorServiceTrampoline(
MetricsCollector* metrics_collector) {
metrics_collector_ = metrics_collector;
}
void MetricsCollectorServiceTrampoline::Run() {
// Start metricscollectorservice binder service
metrics_collector_service.reset(new BnMetricsCollectorServiceImpl(this));
metrics_collector_service->Run();
}
void MetricsCollectorServiceTrampoline::ProcessUserCrash() {
metrics_collector_->ProcessUserCrash();
}

View file

@ -1,57 +0,0 @@
/*
* 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 METRICSD_METRICS_COLLECTOR_SERVICE_TRAMPOLINE_H_
#define METRICSD_METRICS_COLLECTOR_SERVICE_TRAMPOLINE_H_
// Trampoline between the -fno-rtti compile of libmetricsservice and the
// -frtti compile of metrics_collector. MetricsCollectorServiceTrampoline
// is called from MetricsCollector to run the IMetricsCollectorService
// server, and acts as a go-between for calls from server back to
// MetricsCollector.
#include <memory>
#include "metrics_collector_service_impl.h"
// Forward declaration of MetricsCollector. Don't include the header file
// for the class here, as it pulls in -frtti stuff.
class MetricsCollector;
class MetricsCollectorServiceTrampoline {
public:
// Constructor take a this pointer from the MetricsCollector class that
// constructs these objects.
explicit MetricsCollectorServiceTrampoline(
MetricsCollector* metrics_collector);
// Initialize and run the IMetricsCollectorService
void Run();
// Called from IMetricsCollectorService to trampoline into the
// MetricsCollector method of the same name.
void ProcessUserCrash();
private:
// The MetricsCollector object that constructs us, for which we act as
// the go-between for MetricsCollectorServiceImpl use.
MetricsCollector* metrics_collector_;
// The IMetricsCollectorService implementation we construct.
std::unique_ptr<BnMetricsCollectorServiceImpl> metrics_collector_service;
};
#endif // METRICSD_METRICS_COLLECTOR_SERVICE_TRAMPOLINE_H_