diff options
| author | maxim-yurchuk <[email protected]> | 2025-09-11 18:10:35 +0300 | 
|---|---|---|
| committer | maxim-yurchuk <[email protected]> | 2025-09-11 18:29:46 +0300 | 
| commit | f4413504c29db8e1e7cce3a2103e89ecb4073271 (patch) | |
| tree | 1bf7e20cd558f17fc8ec8c18f73efda775fc447a /contrib/libs/clang20-rt/lib/memprof/memprof_mibmap.cpp | |
| parent | 542e74eb48caba00fb12eef75125e376ab12c0c9 (diff) | |
Add clang20-rt into ydb sync config
commit_hash:a644e6487e802adc4b59a62ef53000053f586377
Diffstat (limited to 'contrib/libs/clang20-rt/lib/memprof/memprof_mibmap.cpp')
| -rw-r--r-- | contrib/libs/clang20-rt/lib/memprof/memprof_mibmap.cpp | 48 | 
1 files changed, 48 insertions, 0 deletions
diff --git a/contrib/libs/clang20-rt/lib/memprof/memprof_mibmap.cpp b/contrib/libs/clang20-rt/lib/memprof/memprof_mibmap.cpp new file mode 100644 index 00000000000..a49ed8bf4fd --- /dev/null +++ b/contrib/libs/clang20-rt/lib/memprof/memprof_mibmap.cpp @@ -0,0 +1,48 @@ +//===-- memprof_mibmap.cpp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file is a part of MemProfiler, a memory profiler. +// +//===----------------------------------------------------------------------===// + +#include "memprof_mibmap.h" +#include "profile/MemProfData.inc" +#include "sanitizer_common/sanitizer_allocator_internal.h" +#include "sanitizer_common/sanitizer_mutex.h" + +namespace __memprof { +using ::llvm::memprof::MemInfoBlock; + +void InsertOrMerge(const uptr Id, const MemInfoBlock &Block, MIBMapTy &Map) { +  MIBMapTy::Handle h(&Map, static_cast<uptr>(Id), /*remove=*/false, +                     /*create=*/true); +  if (h.created()) { +    LockedMemInfoBlock *lmib = +        (LockedMemInfoBlock *)InternalAlloc(sizeof(LockedMemInfoBlock)); +    lmib->mutex.Init(); +    lmib->mib = Block; +    *h = lmib; +  } else { +    LockedMemInfoBlock *lmib = *h; +    SpinMutexLock lock(&lmib->mutex); +    uintptr_t ShorterHistogram; +    if (Block.AccessHistogramSize > lmib->mib.AccessHistogramSize) +      ShorterHistogram = lmib->mib.AccessHistogram; +    else +      ShorterHistogram = Block.AccessHistogram; + +    lmib->mib.Merge(Block); +    // The larger histogram is kept and the shorter histogram is discarded after +    // adding the counters to the larger historam. Free only the shorter +    // Histogram +    if (Block.AccessHistogramSize > 0 || lmib->mib.AccessHistogramSize > 0) +      InternalFree((void *)ShorterHistogram); +  } +} + +} // namespace __memprof  | 
