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 "src/traced/probes/ftrace/discover_vendor_tracepoints.h"
18
19 #include "perfetto/ext/base/string_splitter.h"
20 #include "perfetto/ext/base/string_utils.h"
21 #include "src/traced/probes/ftrace/atrace_wrapper.h"
22
23 namespace perfetto {
24 namespace vendor_tracepoints {
25
DiscoverTracepoints(AtraceHalWrapper * hal,FtraceProcfs * ftrace,const std::string & category)26 std::vector<GroupAndName> DiscoverTracepoints(AtraceHalWrapper* hal,
27 FtraceProcfs* ftrace,
28 const std::string& category) {
29 ftrace->DisableAllEvents();
30 hal->EnableCategories({category});
31
32 std::vector<GroupAndName> events;
33 for (const std::string& group_name : ftrace->ReadEnabledEvents()) {
34 size_t pos = group_name.find('/');
35 PERFETTO_CHECK(pos != std::string::npos);
36 events.push_back(
37 GroupAndName(group_name.substr(0, pos), group_name.substr(pos + 1)));
38 }
39
40 hal->DisableAllCategories();
41 ftrace->DisableAllEvents();
42 return events;
43 }
44
DiscoverVendorTracepoints(AtraceHalWrapper * hal,FtraceProcfs * ftrace)45 std::map<std::string, std::vector<GroupAndName>> DiscoverVendorTracepoints(
46 AtraceHalWrapper* hal,
47 FtraceProcfs* ftrace) {
48 std::map<std::string, std::vector<GroupAndName>> results;
49 for (const auto& category : hal->ListCategories()) {
50 results.emplace(category, DiscoverTracepoints(hal, ftrace, category));
51 }
52 return results;
53 }
54
55 } // namespace vendor_tracepoints
56 } // namespace perfetto
57