OSDN Git Service

am db1d49c7: (-s ours) DO NOT MERGE New ext4enc kernel switching from xattrs to ioctl
[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 <functional>
21 #include <string>
22 #include <vector>
23
24 #include "build_id.h"
25
26 std::vector<int> GetOnlineCpus();
27
28 static const char* DEFAULT_KERNEL_MMAP_NAME = "[kernel.kallsyms]_text";
29
30 struct KernelMmap {
31   std::string name;
32   uint64_t start_addr;
33   uint64_t len;
34   uint64_t pgoff;
35 };
36
37 struct ModuleMmap {
38   std::string name;
39   uint64_t start_addr;
40   uint64_t len;
41   std::string filepath;
42 };
43
44 bool GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<ModuleMmap>* module_mmaps);
45
46 struct ThreadComm {
47   pid_t tgid, tid;
48   std::string comm;
49   bool is_process;
50 };
51
52 bool GetThreadComms(std::vector<ThreadComm>* thread_comms);
53
54 static const char* DEFAULT_EXECNAME_FOR_THREAD_MMAP = "//anon";
55
56 struct ThreadMmap {
57   uint64_t start_addr;
58   uint64_t len;
59   uint64_t pgoff;
60   std::string name;
61   bool executable;
62 };
63
64 bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
65
66 static const char* DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID = "[kernel.kallsyms]";
67
68 bool GetKernelBuildId(BuildId* build_id);
69 bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
70
71 // Expose the following functions for unit tests.
72 std::vector<int> GetOnlineCpusFromString(const std::string& s);
73
74 struct KernelSymbol {
75   uint64_t addr;
76   char type;
77   const char* name;
78   const char* module;  // If nullptr, the symbol is not in a kernel module.
79 };
80
81 bool ProcessKernelSymbols(const std::string& symbol_file,
82                           std::function<bool(const KernelSymbol&)> callback);
83
84 #endif  // SIMPLE_PERF_ENVIRONMENT_H_