• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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/test/clang_profiling.h"
6 
7 #include "base/no_destructor.h"
8 #include "base/synchronization/lock.h"
9 #include "build/build_config.h"
10 
11 extern "C" int __llvm_profile_dump(void);
12 
13 namespace base {
14 
WriteClangProfilingProfile()15 void WriteClangProfilingProfile() {
16   // __llvm_profile_dump() guarantees that it will not dump profiling
17   // information if it is being called twice or more. However, it is not thread
18   // safe, as it is supposed to be called from atexit() handler rather than
19   // being called directly from random places. Since we have to call it
20   // ourselves, we must ensure thread safety in order to prevent duplication of
21   // profiling counters.
22   static base::NoDestructor<base::Lock> lock;
23   base::AutoLock auto_lock(*lock);
24 
25 // Fuchsia's profile runtime does not handle profile dumping.
26 #if !BUILDFLAG(IS_FUCHSIA)
27   __llvm_profile_dump();
28 #endif  // !BUILDFLAG(IS_FUCHSIA)
29 }
30 
31 }  // namespace base
32