diff options
author | Andreas Gampe <agampe@google.com> | 2018-04-27 15:15:34 -0700 |
---|---|---|
committer | Andreas Gampe <agampe@google.com> | 2018-05-03 13:33:59 -0700 |
commit | 70f5f6faa2678dee412ba5a1ab1343d6fd6a6141 (patch) | |
tree | 32719f04d67f0e85ef5c153b531d8237720c3019 | |
parent | 57f73c361b50bfcc93d2872af068b1ac3982b79e (diff) | |
download | extras-70f5f6faa2678dee412ba5a1ab1343d6fd6a6141.tar.gz |
Perfprofd: Add string-based binder interface
Add a "weakly-typed" interface that works similar to the shellCommand
implementation, encoding parameters into a string decoded by the
ConfigReader.
(cherry picked from commit 9301b6f524b8267f14c88b0e5e2ed64bbc186fd4)
Bug: 73175642
Test: mmma system/extras/perfprofd
Merged-In: I9a7ad4452ba7a040906e237a76b63e50fbe5aa24
Change-Id: I9a7ad4452ba7a040906e237a76b63e50fbe5aa24
-rw-r--r-- | perfprofd/binder_interface/aidl/android/os/IPerfProfd.aidl | 7 | ||||
-rw-r--r-- | perfprofd/binder_interface/perfprofd_binder.cc | 22 |
2 files changed, 29 insertions, 0 deletions
diff --git a/perfprofd/binder_interface/aidl/android/os/IPerfProfd.aidl b/perfprofd/binder_interface/aidl/android/os/IPerfProfd.aidl index 5fdc09a9..e2628c71 100644 --- a/perfprofd/binder_interface/aidl/android/os/IPerfProfd.aidl +++ b/perfprofd/binder_interface/aidl/android/os/IPerfProfd.aidl @@ -27,6 +27,13 @@ interface IPerfProfd { boolean useElfSymbolizer, boolean sendToDropbox); /** + * Start continuous profiling with the given encoded parameters. + * Parameters should be encoded in the ConfigReader syntax, + * separated by colons. + */ + void startProfilingString(String config); + + /** * Start profiling with the parameters in the given protobuf. */ void startProfilingProtobuf(in byte[] config_proto); diff --git a/perfprofd/binder_interface/perfprofd_binder.cc b/perfprofd/binder_interface/perfprofd_binder.cc index e3f66eab..e4672c34 100644 --- a/perfprofd/binder_interface/perfprofd_binder.cc +++ b/perfprofd/binder_interface/perfprofd_binder.cc @@ -30,6 +30,7 @@ #include <android-base/logging.h> #include <android-base/stringprintf.h> +#include <android-base/strings.h> #include <binder/BinderService.h> #include <binder/IResultReceiver.h> #include <binder/Status.h> @@ -75,6 +76,7 @@ class PerfProfdNativeService : public BinderService<PerfProfdNativeService>, bool stackProfile, bool useElfSymbolizer, bool sendToDropbox) override; + Status startProfilingString(const String16& config) override; Status startProfilingProtobuf(const std::vector<uint8_t>& config_proto) override; Status stopProfiling() override; @@ -151,6 +153,26 @@ Status PerfProfdNativeService::startProfiling(int32_t collectionInterval, } return Status::ok(); } +Status PerfProfdNativeService::startProfilingString(const String16& config) { + ConfigReader reader; + std::string error_msg; + // Split configuration along colon. + std::vector<std::string> args = base::Split(String8(config).string(), ":"); + for (auto& arg : args) { + if (!reader.Read(arg, /* fail_on_error */ true)) { + error_msg = base::StringPrintf("Could not parse %s", arg.c_str()); + return Status::fromExceptionCode(1, error_msg.c_str()); + } + } + auto config_fn = [&](ThreadedConfig& config) { + config = ThreadedConfig(); // Reset to a default config. + reader.FillConfig(&config); + }; + if (!StartProfiling(config_fn, &error_msg)) { + return Status::fromExceptionCode(1, error_msg.c_str()); + } + return Status::ok(); +} Status PerfProfdNativeService::startProfilingProtobuf(const std::vector<uint8_t>& config_proto) { auto proto_loader_fn = [&config_proto](ProfilingConfig& proto_config) { return proto_config.ParseFromArray(config_proto.data(), config_proto.size()); |