• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "base/profiler/sampling_profiler_thread_token.h"
6 
7 #include "build/build_config.h"
8 
9 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
10 #include <pthread.h>
11 
12 #include "base/profiler/stack_base_address_posix.h"
13 #endif
14 
15 namespace base {
16 
GetSamplingProfilerCurrentThreadToken()17 SamplingProfilerThreadToken GetSamplingProfilerCurrentThreadToken() {
18   PlatformThreadId id = PlatformThread::CurrentId();
19 #if BUILDFLAG(IS_ANDROID)
20   return {id, pthread_self()};
21 #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
22   absl::optional<uintptr_t> maybe_stack_base =
23       GetThreadStackBaseAddress(id, pthread_self());
24   return {id, maybe_stack_base};
25 #else
26   return {id};
27 #endif
28 }
29 
30 }  // namespace base
31