blob: 6da632b96cf6d1db91a19657e481dfb804f6657f [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 Cuicb4c17e2015-10-26 16:15:29 -070030std::vector<int> GetCpusFromString(const std::string& s);
Yabin Cui9759e1b2015-04-28 15:54:13 -070031
Yabin Cuibe6afa32015-06-25 13:23:55 -070032constexpr char DEFAULT_KERNEL_MMAP_NAME[] = "[kernel.kallsyms]_text";
Yabin Cui7d59bb42015-05-04 20:27:57 -070033
34struct KernelMmap {
35 std::string name;
36 uint64_t start_addr;
37 uint64_t len;
Yabin Cui7d59bb42015-05-04 20:27:57 -070038 std::string filepath;
39};
40
Yabin Cui9fbb28c2016-03-25 17:43:43 -070041void GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<KernelMmap>* module_mmaps);
Yabin Cui7d59bb42015-05-04 20:27:57 -070042
43struct ThreadComm {
Yabin Cui41d4ba92015-06-22 12:27:58 -070044 pid_t pid, tid;
Yabin Cui7d59bb42015-05-04 20:27:57 -070045 std::string comm;
Yabin Cui7d59bb42015-05-04 20:27:57 -070046};
47
48bool GetThreadComms(std::vector<ThreadComm>* thread_comms);
49
Yabin Cuibe6afa32015-06-25 13:23:55 -070050constexpr char DEFAULT_EXECNAME_FOR_THREAD_MMAP[] = "//anon";
Yabin Cui7d59bb42015-05-04 20:27:57 -070051
52struct ThreadMmap {
53 uint64_t start_addr;
54 uint64_t len;
55 uint64_t pgoff;
56 std::string name;
57 bool executable;
58};
59
60bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
61
Yabin Cuibe6afa32015-06-25 13:23:55 -070062constexpr char DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID[] = "[kernel.kallsyms]";
Yabin Cui8f622512015-05-05 19:58:07 -070063
64bool GetKernelBuildId(BuildId* build_id);
65bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
66
Yabin Cuib032de72015-06-17 21:15:09 -070067bool GetValidThreadsFromProcessString(const std::string& pid_str, std::set<pid_t>* tid_set);
68bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>* tid_set);
69
Yabin Cuid713f952015-06-23 18:50:36 -070070bool GetExecPath(std::string* exec_path);
71
Yabin Cui9759e1b2015-04-28 15:54:13 -070072// Expose the following functions for unit tests.
Yabin Cui7d59bb42015-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);
Yabin Cui92c688b2016-06-01 15:39:39 -070082bool CheckPerfEventLimit();
Yabin Cui7d59bb42015-05-04 20:27:57 -070083
Yabin Cui323e9452015-04-20 18:07:17 -070084#endif // SIMPLE_PERF_ENVIRONMENT_H_