diff options
Diffstat (limited to 'simpleperf/environment.h')
-rw-r--r-- | simpleperf/environment.h | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/simpleperf/environment.h b/simpleperf/environment.h index 533d2987..180b98c3 100644 --- a/simpleperf/environment.h +++ b/simpleperf/environment.h @@ -26,8 +26,11 @@ #endif #include <functional> +#include <memory> +#include <optional> #include <set> #include <string> +#include <utility> #include <vector> #include <android-base/file.h> @@ -35,6 +38,8 @@ #include "build_id.h" #include "perf_regs.h" +namespace simpleperf { + std::vector<int> GetOnlineCpus(); struct KernelMmap { @@ -62,7 +67,8 @@ bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps); constexpr char DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID[] = "[kernel.kallsyms]"; bool GetKernelBuildId(BuildId* build_id); -bool GetModuleBuildId(const std::string& module_name, BuildId* build_id); +bool GetModuleBuildId(const std::string& module_name, BuildId* build_id, + const std::string& sysfs_dir = "/sys"); bool IsThreadAlive(pid_t tid); std::vector<pid_t> GetAllProcesses(); @@ -70,9 +76,6 @@ std::vector<pid_t> GetThreadsInProcess(pid_t pid); bool ReadThreadNameAndPid(pid_t tid, std::string* comm, pid_t* pid); bool GetProcessForThread(pid_t tid, pid_t* pid); bool GetThreadName(pid_t tid, std::string* name); - -bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>* tid_set); - bool CheckPerfEventLimit(); bool SetPerfEventLimits(uint64_t sample_freq, size_t cpu_percent, uint64_t mlock_kb); bool GetMaxSampleFrequency(uint64_t* max_sample_freq); @@ -81,61 +84,73 @@ bool GetCpuTimeMaxPercent(size_t* percent); bool SetCpuTimeMaxPercent(size_t percent); bool GetPerfEventMlockKb(uint64_t* mlock_kb); bool SetPerfEventMlockKb(uint64_t mlock_kb); -bool CheckKernelSymbolAddresses(); bool CanRecordRawData(); -#if defined(__linux__) -static inline uint64_t GetSystemClock() { - timespec ts; - // Assume clock_gettime() doesn't fail. - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000000000ULL + ts.tv_nsec; -} - -#if !defined(__ANDROID__) -static inline int gettid() { - return syscall(__NR_gettid); -} -#endif -#endif - ArchType GetMachineArch(); void PrepareVdsoFile(); std::set<pid_t> WaitForAppProcesses(const std::string& package_name); -bool IsAppDebuggable(const std::string& package_name); void SetRunInAppToolForTesting(bool run_as, bool simpleperf_app_runner); // for testing only bool RunInAppContext(const std::string& app_package_name, const std::string& cmd, const std::vector<std::string>& args, size_t workload_args_size, const std::string& output_filepath, bool need_tracepoint_events); +std::string GetAppType(const std::string& app_package_name); void AllowMoreOpenedFiles(); class ScopedTempFiles { public: - ScopedTempFiles(const std::string& tmp_dir); + static std::unique_ptr<ScopedTempFiles> Create(const std::string& tmp_dir); ~ScopedTempFiles(); // If delete_in_destructor = true, the temp file will be deleted in the destructor of // ScopedTempFile. Otherwise, it should be deleted by the caller. static std::unique_ptr<TemporaryFile> CreateTempFile(bool delete_in_destructor = true); + static void RegisterTempFile(const std::string& path); private: + ScopedTempFiles(const std::string& tmp_dir); + static std::string tmp_dir_; static std::vector<std::string> files_to_delete_; }; bool SignalIsIgnored(int signo); + +enum { + kAndroidVersionP = 9, + kAndroidVersionQ = 10, + kAndroidVersionR = 11, + kAndroidVersionS = 12, +}; + // Return 0 if no android version. int GetAndroidVersion(); - -constexpr int kAndroidVersionP = 9; +std::optional<std::pair<int, int>> GetKernelVersion(); std::string GetHardwareFromCpuInfo(const std::string& cpu_info); bool MappedFileOnlyExistInMemory(const char* filename); std::string GetCompleteProcessName(pid_t pid); - const char* GetTraceFsDir(); +#if defined(__linux__) +static inline uint64_t GetSystemClock() { + timespec ts; + // Assume clock_gettime() doesn't fail. + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec * 1000000000ULL + ts.tv_nsec; +} + +#if !defined(__ANDROID__) +static inline int gettid() { + return syscall(__NR_gettid); +} +#endif + +std::optional<uid_t> GetProcessUid(pid_t pid); +#endif // defined(__linux__) + +} // namespace simpleperf + #endif // SIMPLE_PERF_ENVIRONMENT_H_ |