clang_profiling.cc 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/test/clang_profiling.h"
  5. #include "base/no_destructor.h"
  6. #include "base/synchronization/lock.h"
  7. #include "build/build_config.h"
  8. extern "C" int __llvm_profile_dump(void);
  9. namespace base {
  10. void WriteClangProfilingProfile() {
  11. // __llvm_profile_dump() guarantees that it will not dump profiling
  12. // information if it is being called twice or more. However, it is not thread
  13. // safe, as it is supposed to be called from atexit() handler rather than
  14. // being called directly from random places. Since we have to call it
  15. // ourselves, we must ensure thread safety in order to prevent duplication of
  16. // profiling counters.
  17. static base::NoDestructor<base::Lock> lock;
  18. base::AutoLock auto_lock(*lock);
  19. // Fuchsia's profile runtime does not handle profile dumping.
  20. #if !BUILDFLAG(IS_FUCHSIA)
  21. __llvm_profile_dump();
  22. #endif // !BUILDFLAG(IS_FUCHSIA)
  23. }
  24. } // namespace base