blob: a0c085da53b9e7b27ba0b8e07cce08ffca7e8434 [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
Dan Albert918e4b72015-08-11 15:59:43 -070020#include <sys/types.h>
21
Yabin Cui7d59bb42015-05-04 20:27:57 -070022#include <functional>
Yabin Cuib032de72015-06-17 21:15:09 -070023#include <set>
Yabin Cui323e9452015-04-20 18:07:17 -070024#include <string>
25#include <vector>
Yabin Cuif569b472015-04-30 09:43:26 -070026
Yabin Cui8f622512015-05-05 19:58:07 -070027#include "build_id.h"
Yabin Cui323e9452015-04-20 18:07:17 -070028
29std::vector<int> GetOnlineCpus();
Yabin Cui9759e1b2015-04-28 15:54:13 -070030
Yabin Cuibe6afa32015-06-25 13:23:55 -070031constexpr char DEFAULT_KERNEL_MMAP_NAME[] = "[kernel.kallsyms]_text";
Yabin Cui7d59bb42015-05-04 20:27:57 -070032
33struct KernelMmap {
34 std::string name;
35 uint64_t start_addr;
36 uint64_t len;
37 uint64_t pgoff;
38};
39
40struct ModuleMmap {
41 std::string name;
42 uint64_t start_addr;
43 uint64_t len;
44 std::string filepath;
45};
46
47bool GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<ModuleMmap>* module_mmaps);
48
49struct ThreadComm {
Yabin Cui41d4ba92015-06-22 12:27:58 -070050 pid_t pid, tid;
Yabin Cui7d59bb42015-05-04 20:27:57 -070051 std::string comm;
Yabin Cui7d59bb42015-05-04 20:27:57 -070052};
53
54bool GetThreadComms(std::vector<ThreadComm>* thread_comms);
55
Yabin Cuibe6afa32015-06-25 13:23:55 -070056constexpr char DEFAULT_EXECNAME_FOR_THREAD_MMAP[] = "//anon";
Yabin Cui7d59bb42015-05-04 20:27:57 -070057
58struct ThreadMmap {
59 uint64_t start_addr;
60 uint64_t len;
61 uint64_t pgoff;
62 std::string name;
63 bool executable;
64};
65
66bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
67
Yabin Cuibe6afa32015-06-25 13:23:55 -070068constexpr char DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID[] = "[kernel.kallsyms]";
Yabin Cui8f622512015-05-05 19:58:07 -070069
70bool GetKernelBuildId(BuildId* build_id);
71bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
72
Yabin Cuib032de72015-06-17 21:15:09 -070073bool GetValidThreadsFromProcessString(const std::string& pid_str, std::set<pid_t>* tid_set);
74bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>* tid_set);
75
Yabin Cuid713f952015-06-23 18:50:36 -070076bool GetExecPath(std::string* exec_path);
77
Yabin Cui9759e1b2015-04-28 15:54:13 -070078// Expose the following functions for unit tests.
Yabin Cui323e9452015-04-20 18:07:17 -070079std::vector<int> GetOnlineCpusFromString(const std::string& s);
80
Yabin Cui7d59bb42015-05-04 20:27:57 -070081struct KernelSymbol {
82 uint64_t addr;
83 char type;
84 const char* name;
85 const char* module; // If nullptr, the symbol is not in a kernel module.
86};
87
88bool ProcessKernelSymbols(const std::string& symbol_file,
89 std::function<bool(const KernelSymbol&)> callback);
90
Yabin Cui323e9452015-04-20 18:07:17 -070091#endif // SIMPLE_PERF_ENVIRONMENT_H_