1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <include/simpleperf_profcollect.hpp>
18
19 #include "ETMRecorder.h"
20 #include "command.h"
21 #include "event_attr.h"
22 #include "event_fd.h"
23 #include "event_type.h"
24
25 using namespace simpleperf;
26
HasSupport()27 bool HasSupport() {
28 if (!ETMRecorder::GetInstance().CheckEtmSupport()) {
29 return false;
30 }
31 const EventType* type = FindEventTypeByName("cs-etm", false);
32 if (type == nullptr) {
33 return false;
34 }
35 return IsEventAttrSupported(CreateDefaultPerfEventAttr(*type), type->name);
36 }
37
Record(const char * event_name,const char * output,float duration)38 bool Record(const char* event_name, const char* output, float duration) {
39 auto recordCmd = CreateCommandInstance("record");
40 std::vector<std::string> args;
41 args.push_back("-a");
42 args.insert(args.end(), {"-e", event_name});
43 args.insert(args.end(), {"--duration", std::to_string(duration)});
44 args.insert(args.end(), {"-o", output});
45 return recordCmd->Run(args);
46 }
47
Inject(const char * traceInput,const char * profileOutput)48 bool Inject(const char* traceInput, const char* profileOutput) {
49 auto injectCmd = CreateCommandInstance("inject");
50 std::vector<std::string> args;
51 args.insert(args.end(), {"-i", traceInput});
52 args.insert(args.end(), {"-o", profileOutput});
53 args.insert(args.end(), {"--output", "branch-list"});
54 args.emplace_back("--exclude-perf");
55 return injectCmd->Run(args);
56 }
57