blob: 5d9cee88465bfd73c22345c8fe6c13aa7082dc7c [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>
Yabin Cui003b2452016-09-29 15:32:45 -070021#include <time.h>
Dan Albert918e4b72015-08-11 15:59:43 -070022
Yabin Cui7d59bb42015-05-04 20:27:57 -070023#include <functional>
Yabin Cuib032de72015-06-17 21:15:09 -070024#include <set>
Yabin Cui323e9452015-04-20 18:07:17 -070025#include <string>
26#include <vector>
Yabin Cuif569b472015-04-30 09:43:26 -070027
Yabin Cui8f622512015-05-05 19:58:07 -070028#include "build_id.h"
Yabin Cui417df292016-11-16 12:26:13 -080029#include "perf_regs.h"
Yabin Cui323e9452015-04-20 18:07:17 -070030
31std::vector<int> GetOnlineCpus();
Yabin Cuicb4c17e2015-10-26 16:15:29 -070032std::vector<int> GetCpusFromString(const std::string& s);
Yabin Cui9759e1b2015-04-28 15:54:13 -070033
Yabin Cui7d59bb42015-05-04 20:27:57 -070034struct 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 Cui7134f382016-03-25 17:43:43 -070041void GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<KernelMmap>* module_mmaps);
Yabin Cui7d59bb42015-05-04 20:27:57 -070042
Yabin Cui7d59bb42015-05-04 20:27:57 -070043struct ThreadMmap {
44 uint64_t start_addr;
45 uint64_t len;
46 uint64_t pgoff;
47 std::string name;
48 bool executable;
49};
50
51bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
52
Yabin Cuibe6afa32015-06-25 13:23:55 -070053constexpr char DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID[] = "[kernel.kallsyms]";
Yabin Cui8f622512015-05-05 19:58:07 -070054
55bool GetKernelBuildId(BuildId* build_id);
56bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
57
Yabin Cui5f43fc42016-12-13 13:47:49 -080058bool IsThreadAlive(pid_t tid);
Yabin Cui0a7a06d2016-10-28 13:27:41 -070059std::vector<pid_t> GetAllProcesses();
Yabin Cuibc2a1022016-08-29 12:33:17 -070060std::vector<pid_t> GetThreadsInProcess(pid_t pid);
Yabin Cui0a7a06d2016-10-28 13:27:41 -070061bool GetProcessForThread(pid_t tid, pid_t* pid);
62bool GetThreadName(pid_t tid, std::string* name);
63
Yabin Cuib032de72015-06-17 21:15:09 -070064bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>* tid_set);
65
Yabin Cuiebf79f32016-06-01 15:39:39 -070066bool CheckPerfEventLimit();
Yabin Cuib8915492016-06-22 12:43:09 -070067bool CheckSampleFrequency(uint64_t sample_freq);
Yabin Cuiaf698952016-07-08 11:27:48 -070068bool CheckKernelSymbolAddresses();
Yabin Cuiebf79f32016-06-01 15:39:39 -070069
Yabin Cui003b2452016-09-29 15:32:45 -070070#if defined(__linux__)
71static inline uint64_t GetSystemClock() {
72 timespec ts;
73 // Assume clock_gettime() doesn't fail.
74 clock_gettime(CLOCK_MONOTONIC, &ts);
75 return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
76}
77#endif
78
Yabin Cui417df292016-11-16 12:26:13 -080079ArchType GetMachineArch();
80
Yabin Cui323e9452015-04-20 18:07:17 -070081#endif // SIMPLE_PERF_ENVIRONMENT_H_