1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_ 6 #define BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_ 7 8 #include <optional> 9 10 #include "base/base_export.h" 11 #include "base/threading/platform_thread.h" 12 #include "build/build_config.h" 13 14 #if BUILDFLAG(IS_ANDROID) 15 #include <pthread.h> 16 #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) 17 #include <stdint.h> 18 #endif 19 20 namespace base { 21 22 // SamplingProfilerThreadToken represents the thread identifier(s) required by 23 // sampling profiler to operate on a thread. PlatformThreadId is needed for all 24 // platforms, while Android also requires a pthread_t to pass to pthread 25 // functions used to obtain the stack base address. 26 struct SamplingProfilerThreadToken { 27 PlatformThreadId id; 28 #if BUILDFLAG(IS_ANDROID) 29 pthread_t pthread_id; 30 #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) 31 // Due to the sandbox, we can only retrieve the stack base address for the 32 // current thread. We must grab it during 33 // GetSamplingProfilerCurrentThreadToken() and not try to get it later. 34 std::optional<uintptr_t> stack_base_address; 35 #endif 36 }; 37 38 BASE_EXPORT SamplingProfilerThreadToken GetSamplingProfilerCurrentThreadToken(); 39 40 } // namespace base 41 42 #endif // BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_ 43