xref: /aosp_15_r20/external/bcc/src/cc/common.h (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker /*
2*387f9dfdSAndroid Build Coastguard Worker  * Copyright (c) 2015 PLUMgrid, Inc.
3*387f9dfdSAndroid Build Coastguard Worker  *
4*387f9dfdSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*387f9dfdSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*387f9dfdSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*387f9dfdSAndroid Build Coastguard Worker  *
8*387f9dfdSAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
9*387f9dfdSAndroid Build Coastguard Worker  *
10*387f9dfdSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*387f9dfdSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*387f9dfdSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*387f9dfdSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*387f9dfdSAndroid Build Coastguard Worker  * limitations under the License.
15*387f9dfdSAndroid Build Coastguard Worker  */
16*387f9dfdSAndroid Build Coastguard Worker 
17*387f9dfdSAndroid Build Coastguard Worker #pragma once
18*387f9dfdSAndroid Build Coastguard Worker 
19*387f9dfdSAndroid Build Coastguard Worker #include <memory>
20*387f9dfdSAndroid Build Coastguard Worker #include <string>
21*387f9dfdSAndroid Build Coastguard Worker #include <unistd.h>
22*387f9dfdSAndroid Build Coastguard Worker #include <vector>
23*387f9dfdSAndroid Build Coastguard Worker 
24*387f9dfdSAndroid Build Coastguard Worker namespace ebpf {
25*387f9dfdSAndroid Build Coastguard Worker 
26*387f9dfdSAndroid Build Coastguard Worker #ifdef __cpp_lib_make_unique
27*387f9dfdSAndroid Build Coastguard Worker using std::make_unique;
28*387f9dfdSAndroid Build Coastguard Worker #else
29*387f9dfdSAndroid Build Coastguard Worker template <class T, class... Args>
30*387f9dfdSAndroid Build Coastguard Worker typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
31*387f9dfdSAndroid Build Coastguard Worker make_unique(Args &&... args) {
32*387f9dfdSAndroid Build Coastguard Worker   return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
33*387f9dfdSAndroid Build Coastguard Worker }
34*387f9dfdSAndroid Build Coastguard Worker #endif
35*387f9dfdSAndroid Build Coastguard Worker 
36*387f9dfdSAndroid Build Coastguard Worker std::vector<int> get_online_cpus();
37*387f9dfdSAndroid Build Coastguard Worker 
38*387f9dfdSAndroid Build Coastguard Worker std::vector<int> get_possible_cpus();
39*387f9dfdSAndroid Build Coastguard Worker 
40*387f9dfdSAndroid Build Coastguard Worker std::string get_pid_exe(pid_t pid);
41*387f9dfdSAndroid Build Coastguard Worker 
42*387f9dfdSAndroid Build Coastguard Worker std::string tracefs_path();
43*387f9dfdSAndroid Build Coastguard Worker 
44*387f9dfdSAndroid Build Coastguard Worker std::string tracepoint_format_file(std::string const& category,
45*387f9dfdSAndroid Build Coastguard Worker                                    std::string const& event);
46*387f9dfdSAndroid Build Coastguard Worker 
47*387f9dfdSAndroid Build Coastguard Worker std::string parse_tracepoint(std::istream &input, std::string const& category,
48*387f9dfdSAndroid Build Coastguard Worker                              std::string const& event);
49*387f9dfdSAndroid Build Coastguard Worker }  // namespace ebpf
50