blob: f81005ce8ee09feb8532655db79c8c5b34d1f541 [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>
Yabin Cui568b82a2015-05-05 19:58:07 -070023#include "build_id.h"
Yabin Cui323e9452015-04-20 18:07:17 -070024
25std::vector<int> GetOnlineCpus();
Yabin Cuied91cd92015-04-28 15:54:13 -070026
Yabin Cui5beebc82015-05-04 20:27:57 -070027static const char* DEFAULT_KERNEL_MMAP_NAME = "[kernel.kallsyms]_text";
28
29struct KernelMmap {
30 std::string name;
31 uint64_t start_addr;
32 uint64_t len;
33 uint64_t pgoff;
34};
35
36struct ModuleMmap {
37 std::string name;
38 uint64_t start_addr;
39 uint64_t len;
40 std::string filepath;
41};
42
43bool GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<ModuleMmap>* module_mmaps);
44
45struct ThreadComm {
46 pid_t tgid, tid;
47 std::string comm;
48 bool is_process;
49};
50
51bool GetThreadComms(std::vector<ThreadComm>* thread_comms);
52
53static const char* DEFAULT_EXECNAME_FOR_THREAD_MMAP = "//anon";
54
55struct ThreadMmap {
56 uint64_t start_addr;
57 uint64_t len;
58 uint64_t pgoff;
59 std::string name;
60 bool executable;
61};
62
63bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
64
Yabin Cui568b82a2015-05-05 19:58:07 -070065static const char* DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID = "[kernel.kallsyms]";
66
67bool GetKernelBuildId(BuildId* build_id);
68bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
69
Yabin Cuied91cd92015-04-28 15:54:13 -070070// Expose the following functions for unit tests.
Yabin Cui323e9452015-04-20 18:07:17 -070071std::vector<int> GetOnlineCpusFromString(const std::string& s);
72
Yabin Cui5beebc82015-05-04 20:27:57 -070073struct KernelSymbol {
74 uint64_t addr;
75 char type;
76 const char* name;
77 const char* module; // If nullptr, the symbol is not in a kernel module.
78};
79
80bool ProcessKernelSymbols(const std::string& symbol_file,
81 std::function<bool(const KernelSymbol&)> callback);
82
Yabin Cui323e9452015-04-20 18:07:17 -070083#endif // SIMPLE_PERF_ENVIRONMENT_H_