Loading metricsd/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ metricsd_common := \ uploader/metrics_hashes.cc \ uploader/metrics_log_base.cc \ uploader/metrics_log.cc \ uploader/metricsd_service_runner.cc \ uploader/sender_http.cc \ uploader/system_profile_cache.cc \ uploader/upload_service.cc Loading Loading @@ -84,6 +85,7 @@ metrics_collector_static_libraries := libmetricscollectorservice metricsd_shared_libraries := \ libbinder \ libbrillo \ libbrillo-binder \ libbrillo-http \ libchrome \ libprotobuf-cpp-lite \ Loading metricsd/metricsd_main.cc +3 −17 Original line number Diff line number Diff line Loading @@ -14,21 +14,15 @@ * limitations under the License. */ #include <thread> #include <base/at_exit.h> #include <base/command_line.h> #include <base/files/file_path.h> #include <base/logging.h> #include <base/metrics/statistics_recorder.h> #include <base/strings/string_util.h> #include <base/time/time.h> #include <brillo/flag_helper.h> #include <brillo/syslog_logging.h> #include "constants.h" #include "uploader/bn_metricsd_impl.h" #include "uploader/crash_counters.h" #include "uploader/metricsd_service_runner.h" #include "uploader/upload_service.h" int main(int argc, char** argv) { Loading Loading @@ -76,18 +70,10 @@ int main(int argc, char** argv) { return errno; } std::shared_ptr<CrashCounters> counters(new CrashCounters); UploadService upload_service( FLAGS_server, base::TimeDelta::FromSeconds(FLAGS_upload_interval_secs), base::FilePath(FLAGS_private_directory), base::FilePath(FLAGS_shared_directory), counters); base::StatisticsRecorder::Initialize(); // Create and start the binder thread. BnMetricsdImpl binder_service(counters); std::thread binder_thread(&BnMetricsdImpl::Run, &binder_service); base::FilePath(FLAGS_shared_directory)); upload_service.Run(); return upload_service.Run(); } metricsd/uploader/bn_metricsd_impl.cc +0 −12 Original line number Diff line number Diff line Loading @@ -19,8 +19,6 @@ #include <base/metrics/histogram.h> #include <base/metrics/sparse_histogram.h> #include <base/metrics/statistics_recorder.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> #include <utils/Errors.h> #include <utils/String16.h> #include <utils/String8.h> Loading @@ -37,16 +35,6 @@ BnMetricsdImpl::BnMetricsdImpl(const std::shared_ptr<CrashCounters>& counters) CHECK(counters_) << "Invalid counters argument to constructor"; } void BnMetricsdImpl::Run() { android::status_t status = android::defaultServiceManager()->addService(getInterfaceDescriptor(), this); CHECK(status == android::OK) << "Metricsd service registration failed"; android::ProcessState::self()->setThreadPoolMaxThreadCount(0); android::IPCThreadState::self()->disableBackgroundScheduling(true); android::IPCThreadState::self()->joinThreadPool(); } Status BnMetricsdImpl::recordHistogram( const String16& name, int sample, int min, int max, int nbuckets) { base::HistogramBase* histogram = base::Histogram::FactoryGet( Loading metricsd/uploader/bn_metricsd_impl.h +0 −3 Original line number Diff line number Diff line Loading @@ -25,9 +25,6 @@ class BnMetricsdImpl : public android::brillo::metrics::BnMetricsd { explicit BnMetricsdImpl(const std::shared_ptr<CrashCounters>& counters); virtual ~BnMetricsdImpl() = default; // Starts the binder main loop. void Run(); // Records a histogram. android::binder::Status recordHistogram(const android::String16& name, int sample, Loading metricsd/uploader/metricsd_service_runner.cc 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * 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 "uploader/metricsd_service_runner.h" #include <thread> #include <binder/IServiceManager.h> #include <brillo/binder_watcher.h> #include <utils/Errors.h> #include "uploader/bn_metricsd_impl.h" MetricsdServiceRunner::MetricsdServiceRunner( std::shared_ptr<CrashCounters> counters) : counters_(counters) {} void MetricsdServiceRunner::Start() { thread_.reset(new std::thread(&MetricsdServiceRunner::Run, this)); } void MetricsdServiceRunner::Run() { android::sp<BnMetricsdImpl> metrics_service(new BnMetricsdImpl(counters_)); android::status_t status = android::defaultServiceManager()->addService( metrics_service->getInterfaceDescriptor(), metrics_service); CHECK(status == android::OK) << "Metricsd service registration failed"; message_loop_for_io_.reset(new base::MessageLoopForIO); brillo::BinderWatcher watcher; CHECK(watcher.Init()) << "failed to initialize the binder file descriptor " << "watcher"; message_loop_for_io_->Run(); // Delete the message loop here as it needs to be deconstructed in the thread // it is attached to. message_loop_for_io_.reset(); } void MetricsdServiceRunner::Stop() { message_loop_for_io_->PostTask(FROM_HERE, message_loop_for_io_->QuitClosure()); thread_->join(); } Loading
metricsd/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ metricsd_common := \ uploader/metrics_hashes.cc \ uploader/metrics_log_base.cc \ uploader/metrics_log.cc \ uploader/metricsd_service_runner.cc \ uploader/sender_http.cc \ uploader/system_profile_cache.cc \ uploader/upload_service.cc Loading Loading @@ -84,6 +85,7 @@ metrics_collector_static_libraries := libmetricscollectorservice metricsd_shared_libraries := \ libbinder \ libbrillo \ libbrillo-binder \ libbrillo-http \ libchrome \ libprotobuf-cpp-lite \ Loading
metricsd/metricsd_main.cc +3 −17 Original line number Diff line number Diff line Loading @@ -14,21 +14,15 @@ * limitations under the License. */ #include <thread> #include <base/at_exit.h> #include <base/command_line.h> #include <base/files/file_path.h> #include <base/logging.h> #include <base/metrics/statistics_recorder.h> #include <base/strings/string_util.h> #include <base/time/time.h> #include <brillo/flag_helper.h> #include <brillo/syslog_logging.h> #include "constants.h" #include "uploader/bn_metricsd_impl.h" #include "uploader/crash_counters.h" #include "uploader/metricsd_service_runner.h" #include "uploader/upload_service.h" int main(int argc, char** argv) { Loading Loading @@ -76,18 +70,10 @@ int main(int argc, char** argv) { return errno; } std::shared_ptr<CrashCounters> counters(new CrashCounters); UploadService upload_service( FLAGS_server, base::TimeDelta::FromSeconds(FLAGS_upload_interval_secs), base::FilePath(FLAGS_private_directory), base::FilePath(FLAGS_shared_directory), counters); base::StatisticsRecorder::Initialize(); // Create and start the binder thread. BnMetricsdImpl binder_service(counters); std::thread binder_thread(&BnMetricsdImpl::Run, &binder_service); base::FilePath(FLAGS_shared_directory)); upload_service.Run(); return upload_service.Run(); }
metricsd/uploader/bn_metricsd_impl.cc +0 −12 Original line number Diff line number Diff line Loading @@ -19,8 +19,6 @@ #include <base/metrics/histogram.h> #include <base/metrics/sparse_histogram.h> #include <base/metrics/statistics_recorder.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> #include <utils/Errors.h> #include <utils/String16.h> #include <utils/String8.h> Loading @@ -37,16 +35,6 @@ BnMetricsdImpl::BnMetricsdImpl(const std::shared_ptr<CrashCounters>& counters) CHECK(counters_) << "Invalid counters argument to constructor"; } void BnMetricsdImpl::Run() { android::status_t status = android::defaultServiceManager()->addService(getInterfaceDescriptor(), this); CHECK(status == android::OK) << "Metricsd service registration failed"; android::ProcessState::self()->setThreadPoolMaxThreadCount(0); android::IPCThreadState::self()->disableBackgroundScheduling(true); android::IPCThreadState::self()->joinThreadPool(); } Status BnMetricsdImpl::recordHistogram( const String16& name, int sample, int min, int max, int nbuckets) { base::HistogramBase* histogram = base::Histogram::FactoryGet( Loading
metricsd/uploader/bn_metricsd_impl.h +0 −3 Original line number Diff line number Diff line Loading @@ -25,9 +25,6 @@ class BnMetricsdImpl : public android::brillo::metrics::BnMetricsd { explicit BnMetricsdImpl(const std::shared_ptr<CrashCounters>& counters); virtual ~BnMetricsdImpl() = default; // Starts the binder main loop. void Run(); // Records a histogram. android::binder::Status recordHistogram(const android::String16& name, int sample, Loading
metricsd/uploader/metricsd_service_runner.cc 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * 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 "uploader/metricsd_service_runner.h" #include <thread> #include <binder/IServiceManager.h> #include <brillo/binder_watcher.h> #include <utils/Errors.h> #include "uploader/bn_metricsd_impl.h" MetricsdServiceRunner::MetricsdServiceRunner( std::shared_ptr<CrashCounters> counters) : counters_(counters) {} void MetricsdServiceRunner::Start() { thread_.reset(new std::thread(&MetricsdServiceRunner::Run, this)); } void MetricsdServiceRunner::Run() { android::sp<BnMetricsdImpl> metrics_service(new BnMetricsdImpl(counters_)); android::status_t status = android::defaultServiceManager()->addService( metrics_service->getInterfaceDescriptor(), metrics_service); CHECK(status == android::OK) << "Metricsd service registration failed"; message_loop_for_io_.reset(new base::MessageLoopForIO); brillo::BinderWatcher watcher; CHECK(watcher.Init()) << "failed to initialize the binder file descriptor " << "watcher"; message_loop_for_io_->Run(); // Delete the message loop here as it needs to be deconstructed in the thread // it is attached to. message_loop_for_io_.reset(); } void MetricsdServiceRunner::Stop() { message_loop_for_io_->PostTask(FROM_HERE, message_loop_for_io_->QuitClosure()); thread_->join(); }