blob: c41106775380b3ed3ca7cebf7511f2c26802ecff [file] [log] [blame]
Yabin Cui323e9452015-04-20 18:07:17 -07001/*
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
Yabin Cui5beebc82015-05-04 20:27:57 -070020#include <functional>
Yabin Cui323e9452015-04-20 18:07:17 -070021#include <string>
22#include <vector>
23
24std::vector<int> GetOnlineCpus();
Yabin Cuied91cd92015-04-28 15:54:13 -070025
Yabin Cui5beebc82015-05-04 20:27:57 -070026static const char* DEFAULT_KERNEL_MMAP_NAME = "[kernel.kallsyms]_text";
27
28struct KernelMmap {
29 std::string name;
30 uint64_t start_addr;
31 uint64_t len;
32 uint64_t pgoff;
33};
34
35struct ModuleMmap {
36 std::string name;
37 uint64_t start_addr;
38 uint64_t len;
39 std::string filepath;
40};
41
42bool GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<ModuleMmap>* module_mmaps);
43
44struct ThreadComm {
45 pid_t tgid, tid;
46 std::string comm;
47 bool is_process;
48};
49
50bool GetThreadComms(std::vector<ThreadComm>* thread_comms);
51
52static const char* DEFAULT_EXECNAME_FOR_THREAD_MMAP = "//anon";
53
54struct ThreadMmap {
55 uint64_t start_addr;
56 uint64_t len;
57 uint64_t pgoff;
58 std::string name;
59 bool executable;
60};
61
62bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
63
Yabin Cuied91cd92015-04-28 15:54:13 -070064// Expose the following functions for unit tests.
Yabin Cui323e9452015-04-20 18:07:17 -070065std::vector<int> GetOnlineCpusFromString(const std::string& s);
66
Yabin Cui5beebc82015-05-04 20:27:57 -070067struct KernelSymbol {
68 uint64_t addr;
69 char type;
70 const char* name;
71 const char* module; // If nullptr, the symbol is not in a kernel module.
72};
73
74bool ProcessKernelSymbols(const std::string& symbol_file,
75 std::function<bool(const KernelSymbol&)> callback);
76
Yabin Cui323e9452015-04-20 18:07:17 -070077#endif // SIMPLE_PERF_ENVIRONMENT_H_