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