diff options
Diffstat (limited to 'profcollectd/libprofcollectd/binder_service.cpp')
-rw-r--r-- | profcollectd/libprofcollectd/binder_service.cpp | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/profcollectd/libprofcollectd/binder_service.cpp b/profcollectd/libprofcollectd/binder_service.cpp index 0e9534b3..1fbead9b 100644 --- a/profcollectd/libprofcollectd/binder_service.cpp +++ b/profcollectd/libprofcollectd/binder_service.cpp @@ -20,6 +20,7 @@ #include <android-base/logging.h> +#include "config_utils.h" #include "hwtrace_provider.h" #include "scheduler.h" @@ -31,7 +32,17 @@ using ::com::android::server::profcollect::IProfCollectd; namespace { -Status HandleIfError(const std::function<OptError()>& action) { +static constexpr const char* NOT_ENABLED_ERRMSG = + "profcollectd is not enabled through device config."; +static constexpr config_t CONFIG_ENABLED = {"enabled", "0"}; // Disabled by default. + +} // namespace + +Status ProfcollectdBinder::ForwardScheduler(const std::function<OptError()>& action) { + if (Scheduler == nullptr) { + return Status::fromExceptionCode(1, NOT_ENABLED_ERRMSG); + } + auto errmsg = action(); if (errmsg) { LOG(ERROR) << errmsg.value(); @@ -40,39 +51,43 @@ Status HandleIfError(const std::function<OptError()>& action) { return Status::ok(); } -} // namespace - ProfcollectdBinder::ProfcollectdBinder() { - ProfcollectdBinder::Scheduler = std::make_unique<ProfcollectdScheduler>(); - LOG(INFO) << "Binder service started"; + static bool enabled = getConfigFlagBool(CONFIG_ENABLED); + + if (enabled) { + ProfcollectdBinder::Scheduler = std::make_unique<ProfcollectdScheduler>(); + LOG(INFO) << "Binder service started"; + } else { + LOG(INFO) << NOT_ENABLED_ERRMSG; + } } Status ProfcollectdBinder::ReadConfig() { - return HandleIfError([=]() { return Scheduler->ReadConfig(); }); + return ForwardScheduler([=]() { return Scheduler->ReadConfig(); }); } Status ProfcollectdBinder::ScheduleCollection() { - return HandleIfError([=]() { return Scheduler->ScheduleCollection(); }); + return ForwardScheduler([=]() { return Scheduler->ScheduleCollection(); }); } Status ProfcollectdBinder::TerminateCollection() { - return HandleIfError([=]() { return Scheduler->TerminateCollection(); }); + return ForwardScheduler([=]() { return Scheduler->TerminateCollection(); }); } Status ProfcollectdBinder::TraceOnce(const std::string& tag) { - return HandleIfError([=]() { return Scheduler->TraceOnce(tag); }); + return ForwardScheduler([=]() { return Scheduler->TraceOnce(tag); }); } Status ProfcollectdBinder::ProcessProfile() { - return HandleIfError([=]() { return Scheduler->ProcessProfile(); }); + return ForwardScheduler([=]() { return Scheduler->ProcessProfile(); }); } Status ProfcollectdBinder::CreateProfileReport() { - return HandleIfError([=]() { return Scheduler->CreateProfileReport(); }); + return ForwardScheduler([=]() { return Scheduler->CreateProfileReport(); }); } Status ProfcollectdBinder::GetSupportedProvider(std::string* provider) { - return HandleIfError([=]() { return Scheduler->GetSupportedProvider(*provider); }); + return ForwardScheduler([=]() { return Scheduler->GetSupportedProvider(*provider); }); } } // namespace profcollectd |