OSDN Git Service

Update simpleperf for LLVM rebase to r256229.
[android-x86/system-extras.git] / simpleperf / environment.h
1 /*
2  * Copyright (C) 2015 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 #ifndef SIMPLE_PERF_ENVIRONMENT_H_
18 #define SIMPLE_PERF_ENVIRONMENT_H_
19
20 #include <sys/types.h>
21
22 #include <functional>
23 #include <set>
24 #include <string>
25 #include <vector>
26
27 #include "build_id.h"
28
29 std::vector<int> GetOnlineCpus();
30 std::vector<int> GetCpusFromString(const std::string& s);
31
32 constexpr char DEFAULT_KERNEL_MMAP_NAME[] = "[kernel.kallsyms]_text";
33
34 struct KernelMmap {
35   std::string name;
36   uint64_t start_addr;
37   uint64_t len;
38   uint64_t pgoff;
39 };
40
41 struct ModuleMmap {
42   std::string name;
43   uint64_t start_addr;
44   uint64_t len;
45   std::string filepath;
46 };
47
48 bool GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<ModuleMmap>* module_mmaps);
49
50 struct ThreadComm {
51   pid_t pid, tid;
52   std::string comm;
53 };
54
55 bool GetThreadComms(std::vector<ThreadComm>* thread_comms);
56
57 constexpr char DEFAULT_EXECNAME_FOR_THREAD_MMAP[] = "//anon";
58
59 struct ThreadMmap {
60   uint64_t start_addr;
61   uint64_t len;
62   uint64_t pgoff;
63   std::string name;
64   bool executable;
65 };
66
67 bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
68
69 constexpr char DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID[] = "[kernel.kallsyms]";
70
71 bool GetKernelBuildId(BuildId* build_id);
72 bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
73
74 bool GetValidThreadsFromProcessString(const std::string& pid_str, std::set<pid_t>* tid_set);
75 bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>* tid_set);
76
77 bool GetExecPath(std::string* exec_path);
78
79 // Expose the following functions for unit tests.
80 struct KernelSymbol {
81   uint64_t addr;
82   char type;
83   const char* name;
84   const char* module;  // If nullptr, the symbol is not in a kernel module.
85 };
86
87 bool ProcessKernelSymbols(const std::string& symbol_file,
88                           std::function<bool(const KernelSymbol&)> callback);
89
90 #endif  // SIMPLE_PERF_ENVIRONMENT_H_