diff options
author | Yi Kong <yikong@google.com> | 2020-06-03 23:24:36 +0800 |
---|---|---|
committer | Yi Kong <yikong@google.com> | 2020-06-03 23:35:13 +0800 |
commit | a86c7e3afc42226ec913ef5b50a5e04ec4d0ad04 (patch) | |
tree | 75038167e64395b26ca36a3c31b42bd88eaa3f1e | |
parent | 3a6cb4a246232797aa8a44c4086b11856e2d03c8 (diff) | |
download | extras-a86c7e3afc42226ec913ef5b50a5e04ec4d0ad04.tar.gz |
simpleperf: expose ETM collection methods for profcollectd
Test: build
Bug: 79161490
Change-Id: I947cb0c08a9be2dacbe00f4985c35552855c6fdc
-rw-r--r-- | simpleperf/Android.bp | 13 | ||||
-rw-r--r-- | simpleperf/include/simpleperf_profcollect.h | 33 | ||||
-rw-r--r-- | simpleperf/profcollect.cpp | 58 |
3 files changed, 104 insertions, 0 deletions
diff --git a/simpleperf/Android.bp b/simpleperf/Android.bp index c93137da..3285a804 100644 --- a/simpleperf/Android.bp +++ b/simpleperf/Android.bp @@ -333,6 +333,19 @@ cc_binary { }, } +cc_library { + name: "libsimpleperf_profcollect", + defaults: [ + "simpleperf_shared_libs", + ], + host_supported: false, + srcs: ["profcollect.cpp"], + export_include_dirs: ["include"], + static_libs: ["libsimpleperf",], + shared_libs: ["libLLVM_android",], + visibility: ["//system/extras/profcollectd:__subpackages__"], +} + // simpleperf released in ndk cc_binary { name: "simpleperf_ndk", diff --git a/simpleperf/include/simpleperf_profcollect.h b/simpleperf/include/simpleperf_profcollect.h new file mode 100644 index 00000000..193aa641 --- /dev/null +++ b/simpleperf/include/simpleperf_profcollect.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 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. + */ + +#pragma once + +#include <chrono> +#include <filesystem> + +namespace simpleperf { +namespace etm { + +bool HasSupport(); +bool Record(const std::filesystem::path& output, + const std::chrono::seconds& duration); +bool Inject(const std::filesystem::path& traceInput, + const std::filesystem::path& output, + const std::string& binaryFilter); + +} // namespace etm +} // namespace simpleperf diff --git a/simpleperf/profcollect.cpp b/simpleperf/profcollect.cpp new file mode 100644 index 00000000..8d286381 --- /dev/null +++ b/simpleperf/profcollect.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 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 <include/simpleperf_profcollect.h> + +#include "command.h" +#include "event_attr.h" +#include "event_fd.h" +#include "event_type.h" + +namespace simpleperf { +namespace etm { + +bool HasSupport() { + const EventType* type = FindEventTypeByName("cs-etm"); + return IsEventAttrSupported(CreateDefaultPerfEventAttr(*type), type->name); +} + +bool Record(const std::filesystem::path& output, + const std::chrono::seconds& duration) { + auto recordCmd = CreateCommandInstance("record"); + std::vector<std::string> args; + args.push_back("-a"); + args.insert(args.end(), {"-e", "cs-etm:u"}); + args.insert(args.end(), {"--duration", std::to_string(duration.count())}); + args.insert(args.end(), {"-o", output}); + return recordCmd->Run(args); +} + +bool Inject(const std::filesystem::path& traceInput, + const std::filesystem::path& output, + const std::string& binaryFilter) { + auto injectCmd = CreateCommandInstance("inject"); + std::vector<std::string> args; + args.insert(args.end(), {"-i", traceInput}); + args.insert(args.end(), {"-o", output}); + args.insert(args.end(), {"--output", "branch-list"}); + if (!binaryFilter.empty()) { + args.insert(args.end(), {"--binary", binaryFilter}); + } + return injectCmd->Run(args); +} + +} // namespace etm +} // namespace simpleperf |