blob: 645dbc9128ffee6d9800a24771f349f49b4b72f3 [file] [log] [blame]
Yabin Cui142acc82020-10-14 10:24:38 -07001/*
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#pragma once
18
19#include <optional>
20#include <string>
21#include <vector>
22
23namespace simpleperf {
24
Yabin Cui61b4dac2023-11-03 15:19:14 -070025class EventSelectionSet;
26
Yabin Cui142acc82020-10-14 10:24:38 -070027struct ProbeEvent {
28 std::string group_name;
29 std::string event_name;
30};
31
32// Add kprobe events in /sys/kernel/debug/tracing/kprobe_events, and
33// delete them in ProbeEvents::clear().
34class ProbeEvents {
35 public:
Yabin Cui61b4dac2023-11-03 15:19:14 -070036 ProbeEvents(EventSelectionSet& event_selection_set) : event_selection_set_(event_selection_set) {}
37 ~ProbeEvents();
Yabin Cui142acc82020-10-14 10:24:38 -070038
39 static bool ParseKprobeEventName(const std::string& kprobe_cmd, ProbeEvent* event);
40 bool IsKprobeSupported();
41
42 // Accept kprobe cmd as in <linux_kernel>/Documentation/trace/kprobetrace.rst.
43 bool AddKprobe(const std::string& kprobe_cmd);
Yabin Cui68534b92020-10-19 14:50:54 -070044 // If not exist, add a kprobe tracepoint at the function entry.
45 bool CreateProbeEventIfNotExist(const std::string& event_name);
Yabin Cui142acc82020-10-14 10:24:38 -070046
47 private:
Yabin Cui61b4dac2023-11-03 15:19:14 -070048 bool IsProbeEvent(const std::string& event_name);
49 bool IsEmpty() const { return kprobe_events_.empty(); }
50 void Clear();
Yabin Cui142acc82020-10-14 10:24:38 -070051 bool WriteKprobeCmd(const std::string& kprobe_cmd);
52
Yabin Cui61b4dac2023-11-03 15:19:14 -070053 EventSelectionSet& event_selection_set_;
Yabin Cui142acc82020-10-14 10:24:38 -070054 std::vector<ProbeEvent> kprobe_events_;
55 std::optional<std::string> kprobe_control_path_;
56};
57
58} // namespace simpleperf