memprof_mibmap.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //===-- memprof_mibmap.cpp -----------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of MemProfiler, a memory profiler.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "memprof_mibmap.h"
  13. #include "profile/MemProfData.inc"
  14. #include "sanitizer_common/sanitizer_allocator_internal.h"
  15. #include "sanitizer_common/sanitizer_mutex.h"
  16. namespace __memprof {
  17. using ::llvm::memprof::MemInfoBlock;
  18. void InsertOrMerge(const uptr Id, const MemInfoBlock &Block, MIBMapTy &Map) {
  19. MIBMapTy::Handle h(&Map, static_cast<uptr>(Id), /*remove=*/false,
  20. /*create=*/true);
  21. if (h.created()) {
  22. LockedMemInfoBlock *lmib =
  23. (LockedMemInfoBlock *)InternalAlloc(sizeof(LockedMemInfoBlock));
  24. lmib->mutex.Init();
  25. lmib->mib = Block;
  26. *h = lmib;
  27. } else {
  28. LockedMemInfoBlock *lmib = *h;
  29. SpinMutexLock lock(&lmib->mutex);
  30. lmib->mib.Merge(Block);
  31. }
  32. }
  33. } // namespace __memprof