From b77ae4506f7bc9a9ee913427f52dc4acfd012737 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Mon, 4 Jan 2016 14:11:25 -0800 Subject: [PATCH] Remove metrics collector service trampoline No longer needed to trampoline between RTTI and non-RTTI compiles. Move the service impl from libmetricscollector service to the metrics_collector executable, now that RTTI is no longer used (and the impl is not used by binder clients). Other fixups, including: * Move service registration and binder watcher to metrics_collector main. * Compile libmetricscollectorservice with clang just because. Bug: 26292405 Change-Id: Iae8115c13b203ff03d49bf7678d5eb3ede30e855 --- metricsd/Android.mk | 6 +- metricsd/metrics_collector.cc | 17 ++++-- metricsd/metrics_collector_service_impl.cc | 17 ++---- metricsd/metrics_collector_service_impl.h | 30 +++------- .../metrics_collector_service_trampoline.cc | 34 ----------- .../metrics_collector_service_trampoline.h | 57 ------------------- 6 files changed, 28 insertions(+), 133 deletions(-) delete mode 100644 metricsd/metrics_collector_service_trampoline.cc delete mode 100644 metricsd/metrics_collector_service_trampoline.h diff --git a/metricsd/Android.mk b/metricsd/Android.mk index 2cd1f7bfb..89e4e9315 100644 --- a/metricsd/Android.mk +++ b/metricsd/Android.mk @@ -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) diff --git a/metricsd/metrics_collector.cc b/metricsd/metrics_collector.cc index a5daab5a2..97690ddf4 100644 --- a/metricsd/metrics_collector.cc +++ b/metricsd/metrics_collector.cc @@ -30,12 +30,13 @@ #include #include #include +#include #include #include #include #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 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(); } diff --git a/metricsd/metrics_collector_service_impl.cc b/metricsd/metrics_collector_service_impl.cc index dbb0578aa..4d9a05ace 100644 --- a/metricsd/metrics_collector_service_impl.cc +++ b/metricsd/metrics_collector_service_impl.cc @@ -18,27 +18,18 @@ #include #include -#include #include -#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(); } diff --git a/metricsd/metrics_collector_service_impl.h b/metricsd/metrics_collector_service_impl.h index bdcab5084..8db418aaa 100644 --- a/metricsd/metrics_collector_service_impl.h +++ b/metricsd/metrics_collector_service_impl.h @@ -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 - #include -#include -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 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_ diff --git a/metricsd/metrics_collector_service_trampoline.cc b/metricsd/metrics_collector_service_trampoline.cc deleted file mode 100644 index 12b80a192..000000000 --- a/metricsd/metrics_collector_service_trampoline.cc +++ /dev/null @@ -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(); -} diff --git a/metricsd/metrics_collector_service_trampoline.h b/metricsd/metrics_collector_service_trampoline.h deleted file mode 100644 index 5da9fa519..000000000 --- a/metricsd/metrics_collector_service_trampoline.h +++ /dev/null @@ -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 - -#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 metrics_collector_service; -}; - -#endif // METRICSD_METRICS_COLLECTOR_SERVICE_TRAMPOLINE_H_