diff options
author | Alexander Gololobov <davenger@yandex-team.com> | 2022-02-10 16:47:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:37 +0300 |
commit | 39608cdb86363c75ce55b2b9a69841c3b71f22cf (patch) | |
tree | 4ec132c1665bd4d68e3628aa18d937c70d32413b /library/cpp/lfalloc | |
parent | 54295b9bd4dc45c54d804084fd846d945148a7f0 (diff) | |
download | ydb-39608cdb86363c75ce55b2b9a69841c3b71f22cf.tar.gz |
Restoring authorship annotation for Alexander Gololobov <davenger@yandex-team.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/lfalloc')
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/profiler.cpp | 16 | ||||
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/profiler.h | 12 | ||||
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/profiler_ut.cpp | 150 | ||||
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/stackcollect.cpp | 156 | ||||
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/stackcollect.h | 162 | ||||
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/ut/ya.make | 38 | ||||
-rw-r--r-- | library/cpp/lfalloc/alloc_profiler/ya.make | 30 | ||||
-rw-r--r-- | library/cpp/lfalloc/dbg_info/dbg_info.cpp | 14 | ||||
-rw-r--r-- | library/cpp/lfalloc/dbg_info/dbg_info.h | 4 | ||||
-rw-r--r-- | library/cpp/lfalloc/lf_allocX64.h | 60 |
10 files changed, 321 insertions, 321 deletions
diff --git a/library/cpp/lfalloc/alloc_profiler/profiler.cpp b/library/cpp/lfalloc/alloc_profiler/profiler.cpp index 0e30927a5a..beb0ffb289 100644 --- a/library/cpp/lfalloc/alloc_profiler/profiler.cpp +++ b/library/cpp/lfalloc/alloc_profiler/profiler.cpp @@ -8,7 +8,7 @@ #include <util/generic/vector.h> #include <util/stream/str.h> -namespace NAllocProfiler { +namespace NAllocProfiler { namespace { @@ -50,32 +50,32 @@ void DeallocationCallback(int stackId, int tag, size_t size, int sizeIdx) //////////////////////////////////////////////////////////////////////////////// -bool StartAllocationSampling(bool profileAllThreads) +bool StartAllocationSampling(bool profileAllThreads) { auto& collector = AllocationStackCollector(); collector.Clear(); - NAllocDbg::SetProfileAllThreads(profileAllThreads); + NAllocDbg::SetProfileAllThreads(profileAllThreads); NAllocDbg::SetAllocationCallback(AllocationCallback); NAllocDbg::SetDeallocationCallback(DeallocationCallback); NAllocDbg::SetAllocationSamplingEnabled(true); return true; } -bool StopAllocationSampling(IAllocationStatsDumper &out, int count) +bool StopAllocationSampling(IAllocationStatsDumper &out, int count) { NAllocDbg::SetAllocationCallback(nullptr); NAllocDbg::SetDeallocationCallback(nullptr); NAllocDbg::SetAllocationSamplingEnabled(false); auto& collector = AllocationStackCollector(); - collector.Dump(count, out); + collector.Dump(count, out); return true; } -bool StopAllocationSampling(IOutputStream& out, int count) { - TAllocationStatsDumper dumper(out); - return StopAllocationSampling(dumper, count); +bool StopAllocationSampling(IOutputStream& out, int count) { + TAllocationStatsDumper dumper(out); + return StopAllocationSampling(dumper, count); } } // namespace NProfiler diff --git a/library/cpp/lfalloc/alloc_profiler/profiler.h b/library/cpp/lfalloc/alloc_profiler/profiler.h index 4ea49b9dcc..592849b460 100644 --- a/library/cpp/lfalloc/alloc_profiler/profiler.h +++ b/library/cpp/lfalloc/alloc_profiler/profiler.h @@ -1,13 +1,13 @@ #pragma once -#include "stackcollect.h" +#include "stackcollect.h" #include <library/cpp/lfalloc/dbg_info/dbg_info.h> #include <util/generic/noncopyable.h> #include <util/stream/output.h> -namespace NAllocProfiler { +namespace NAllocProfiler { //////////////////////////////////////////////////////////////////////////////// @@ -21,9 +21,9 @@ inline bool SetProfileCurrentThread(bool value) return NAllocDbg::SetProfileCurrentThread(value); } -bool StartAllocationSampling(bool profileAllThreads = false); -bool StopAllocationSampling(IAllocationStatsDumper& out, int count = 100); -bool StopAllocationSampling(IOutputStream& out, int count = 100); +bool StartAllocationSampling(bool profileAllThreads = false); +bool StopAllocationSampling(IAllocationStatsDumper& out, int count = 100); +bool StopAllocationSampling(IOutputStream& out, int count = 100); //////////////////////////////////////////////////////////////////////////////// @@ -42,4 +42,4 @@ public: } }; -} // namespace NAllocProfiler +} // namespace NAllocProfiler diff --git a/library/cpp/lfalloc/alloc_profiler/profiler_ut.cpp b/library/cpp/lfalloc/alloc_profiler/profiler_ut.cpp index 4341dda6ed..21b667e730 100644 --- a/library/cpp/lfalloc/alloc_profiler/profiler_ut.cpp +++ b/library/cpp/lfalloc/alloc_profiler/profiler_ut.cpp @@ -1,76 +1,76 @@ -#include "profiler.h" - +#include "profiler.h" + #include <library/cpp/testing/unittest/registar.h> - -namespace NAllocProfiler { - -//////////////////////////////////////////////////////////////////////////////// - -Y_UNIT_TEST_SUITE(Profiler) { - Y_UNIT_TEST(StackCollection) - { - TStringStream str; - - NAllocProfiler::StartAllocationSampling(true); - TVector<TAutoPtr<int>> test; - // Do many allocations and no deallocations - for (int i = 0; i < 10000; ++i) { - test.push_back(new int); - } - NAllocProfiler::StopAllocationSampling(str); - //Cout << str.Str() << Endl; - -#if !defined(ARCH_AARCH64) - /* Check that output resembles this: - - STACK #2: 0 Allocs: 10 Frees: 0 CurrentSize: 40 - 0000000000492353 ?? - 000000000048781F operator new(unsigned long) +1807 - 00000000003733FA NAllocProfiler::NTestSuiteProfiler::TTestCaseStackCollection::Execute_(NUnitTest::TTestContext&) +218 - 00000000004A1938 NUnitTest::TTestBase::Run(std::__y1::function<void ()>, TString, char const*, bool) +120 - 0000000000375656 NAllocProfiler::NTestSuiteProfiler::TCurrentTest::Execute() +342 - 00000000004A20CF NUnitTest::TTestFactory::Execute() +847 - 000000000049922D NUnitTest::RunMain(int, char**) +1965 - 00007FF665778F45 __libc_start_main +245 - */ - - UNIT_ASSERT_STRING_CONTAINS(str.Str(), "StackCollection"); - UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NUnitTest::TTestBase::Run"); - UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NAllocProfiler::NTestSuiteProfiler::TCurrentTest::Execute"); - UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NUnitTest::TTestFactory::Execute"); - UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NUnitTest::RunMain"); -#endif - } - - class TAllocDumper : public NAllocProfiler::TAllocationStatsDumper { - public: - explicit TAllocDumper(IOutputStream& out) : NAllocProfiler::TAllocationStatsDumper(out) {} - - TString FormatTag(int tag) override { - UNIT_ASSERT_VALUES_EQUAL(tag, 42); - return "TAG_NAME_42"; - } - }; - - Y_UNIT_TEST(TagNames) - { - TStringStream str; - - NAllocProfiler::StartAllocationSampling(true); - TVector<TAutoPtr<int>> test; - NAllocProfiler::TProfilingScope scope(42); - // Do many allocations and no deallocations - for (int i = 0; i < 10000; ++i) { - test.push_back(new int); - } - - TAllocDumper dumper(str); - NAllocProfiler::StopAllocationSampling(dumper); - -#if !defined(ARCH_AARCH64) - UNIT_ASSERT_STRING_CONTAINS(str.Str(), "TAG_NAME_42"); -#endif - } -} - -} + +namespace NAllocProfiler { + +//////////////////////////////////////////////////////////////////////////////// + +Y_UNIT_TEST_SUITE(Profiler) { + Y_UNIT_TEST(StackCollection) + { + TStringStream str; + + NAllocProfiler::StartAllocationSampling(true); + TVector<TAutoPtr<int>> test; + // Do many allocations and no deallocations + for (int i = 0; i < 10000; ++i) { + test.push_back(new int); + } + NAllocProfiler::StopAllocationSampling(str); + //Cout << str.Str() << Endl; + +#if !defined(ARCH_AARCH64) + /* Check that output resembles this: + + STACK #2: 0 Allocs: 10 Frees: 0 CurrentSize: 40 + 0000000000492353 ?? + 000000000048781F operator new(unsigned long) +1807 + 00000000003733FA NAllocProfiler::NTestSuiteProfiler::TTestCaseStackCollection::Execute_(NUnitTest::TTestContext&) +218 + 00000000004A1938 NUnitTest::TTestBase::Run(std::__y1::function<void ()>, TString, char const*, bool) +120 + 0000000000375656 NAllocProfiler::NTestSuiteProfiler::TCurrentTest::Execute() +342 + 00000000004A20CF NUnitTest::TTestFactory::Execute() +847 + 000000000049922D NUnitTest::RunMain(int, char**) +1965 + 00007FF665778F45 __libc_start_main +245 + */ + + UNIT_ASSERT_STRING_CONTAINS(str.Str(), "StackCollection"); + UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NUnitTest::TTestBase::Run"); + UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NAllocProfiler::NTestSuiteProfiler::TCurrentTest::Execute"); + UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NUnitTest::TTestFactory::Execute"); + UNIT_ASSERT_STRING_CONTAINS(str.Str(), "NUnitTest::RunMain"); +#endif + } + + class TAllocDumper : public NAllocProfiler::TAllocationStatsDumper { + public: + explicit TAllocDumper(IOutputStream& out) : NAllocProfiler::TAllocationStatsDumper(out) {} + + TString FormatTag(int tag) override { + UNIT_ASSERT_VALUES_EQUAL(tag, 42); + return "TAG_NAME_42"; + } + }; + + Y_UNIT_TEST(TagNames) + { + TStringStream str; + + NAllocProfiler::StartAllocationSampling(true); + TVector<TAutoPtr<int>> test; + NAllocProfiler::TProfilingScope scope(42); + // Do many allocations and no deallocations + for (int i = 0; i < 10000; ++i) { + test.push_back(new int); + } + + TAllocDumper dumper(str); + NAllocProfiler::StopAllocationSampling(dumper); + +#if !defined(ARCH_AARCH64) + UNIT_ASSERT_STRING_CONTAINS(str.Str(), "TAG_NAME_42"); +#endif + } +} + +} diff --git a/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp b/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp index fded4e2fd1..d608803e84 100644 --- a/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp +++ b/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp @@ -5,16 +5,16 @@ #include <util/generic/algorithm.h> #include <util/generic/vector.h> #include <util/stream/format.h> -#include <util/stream/str.h> -#include <util/string/cast.h> -#include <util/string/printf.h> +#include <util/stream/str.h> +#include <util/string/cast.h> +#include <util/string/printf.h> #include <util/system/backtrace.h> #include <util/system/spinlock.h> #include <util/system/yassert.h> -namespace NAllocProfiler { - +namespace NAllocProfiler { + //////////////////////////////////////////////////////////////////////////////// template <typename T> @@ -87,11 +87,11 @@ public: return Y_ARRAY_SIZE(Frames); } - void BackTrace(const TFrameInfo* stack, TStackVec<void*, 64>& frames) const + void BackTrace(const TFrameInfo* stack, TStackVec<void*, 64>& frames) const { - frames.clear(); + frames.clear(); for (size_t i = 0; i < 100; ++i) { - frames.push_back(stack->Addr); + frames.push_back(stack->Addr); int prevInd = stack->PrevInd; if (prevInd == -1) { break; @@ -174,11 +174,11 @@ private: //////////////////////////////////////////////////////////////////////////////// -class TAllocationStackCollector::TImpl: public TStackCollector<TStats> { - using TBase = TStackCollector<TStats>; +class TAllocationStackCollector::TImpl: public TStackCollector<TStats> { + using TBase = TStackCollector<TStats>; private: - TStats Total; + TStats Total; public: int Alloc(void** stack, size_t frameCount, int tag, size_t size) @@ -203,7 +203,7 @@ public: Total.Clear(); } - void Dump(int count, IAllocationStatsDumper& out) const + void Dump(int count, IAllocationStatsDumper& out) const { const TFrameInfo* frames = TBase::GetFrames(); size_t framesCount = TBase::GetFramesCount(); @@ -225,18 +225,18 @@ public: : ls.Frees > rs.Frees; }); - out.DumpTotal(Total); + out.DumpTotal(Total); - TAllocationInfo allocInfo; + TAllocationInfo allocInfo; int printedCount = 0; for (const TFrameInfo* stack: stacks) { - allocInfo.Clear(); - allocInfo.Tag = stack->Tag; - allocInfo.Stats = stack->Stats; - TBase::BackTrace(stack, allocInfo.Stack); - - out.DumpEntry(allocInfo); + allocInfo.Clear(); + allocInfo.Tag = stack->Tag; + allocInfo.Stats = stack->Stats; + TBase::BackTrace(stack, allocInfo.Stack); + out.DumpEntry(allocInfo); + if (++printedCount >= count) { break; } @@ -268,65 +268,65 @@ void TAllocationStackCollector::Clear() Impl->Clear(); } -void TAllocationStackCollector::Dump(int count, IAllocationStatsDumper &out) const +void TAllocationStackCollector::Dump(int count, IAllocationStatsDumper &out) const { Impl->Dump(count, out); } - -TString IAllocationStatsDumper::FormatTag(int tag) { - return ToString(tag); -} - -TString IAllocationStatsDumper::FormatSize(intptr_t sz) { - return ToString(sz); -} - - -TAllocationStatsDumper::TAllocationStatsDumper(IOutputStream& out) - : PrintedCount(0) - , Out(out) - , SymbolCache(2048) -{} - -void TAllocationStatsDumper::DumpTotal(const TStats& total) { - Out << "TOTAL" - << "\tAllocs: " << total.Allocs - << "\tFrees: " << total.Frees - << "\tCurrentSize: " << FormatSize(total.CurrentSize) - << Endl; -} - -void TAllocationStatsDumper::DumpEntry(const TAllocationInfo& allocInfo) { - Out << Endl - << "STACK #" << PrintedCount+1 << ": " << FormatTag(allocInfo.Tag) - << "\tAllocs: " << allocInfo.Stats.Allocs - << "\tFrees: " << allocInfo.Stats.Frees - << "\tCurrentSize: " << FormatSize(allocInfo.Stats.CurrentSize) - << Endl; - FormatBackTrace(allocInfo.Stack.data(), allocInfo.Stack.size()); - PrintedCount++; -} - -void TAllocationStatsDumper::FormatBackTrace(void* const* stack, size_t sz) { - char name[1024]; - for (size_t i = 0; i < sz; ++i) { - TSymbol symbol; - auto it = SymbolCache.Find(stack[i]); - if (it != SymbolCache.End()) { - symbol = it.Value(); - } else { - TResolvedSymbol rs = ResolveSymbol(stack[i], name, sizeof(name)); - symbol = {rs.NearestSymbol, rs.Name}; - SymbolCache.Insert(stack[i], symbol); - } - - Out << Hex((intptr_t)stack[i], HF_FULL) << "\t" << symbol.Name; - intptr_t offset = (intptr_t)stack[i] - (intptr_t)symbol.Address; - if (offset) - Out << " +" << offset; - Out << Endl; - } -} - -} // namespace NAllocProfiler + +TString IAllocationStatsDumper::FormatTag(int tag) { + return ToString(tag); +} + +TString IAllocationStatsDumper::FormatSize(intptr_t sz) { + return ToString(sz); +} + + +TAllocationStatsDumper::TAllocationStatsDumper(IOutputStream& out) + : PrintedCount(0) + , Out(out) + , SymbolCache(2048) +{} + +void TAllocationStatsDumper::DumpTotal(const TStats& total) { + Out << "TOTAL" + << "\tAllocs: " << total.Allocs + << "\tFrees: " << total.Frees + << "\tCurrentSize: " << FormatSize(total.CurrentSize) + << Endl; +} + +void TAllocationStatsDumper::DumpEntry(const TAllocationInfo& allocInfo) { + Out << Endl + << "STACK #" << PrintedCount+1 << ": " << FormatTag(allocInfo.Tag) + << "\tAllocs: " << allocInfo.Stats.Allocs + << "\tFrees: " << allocInfo.Stats.Frees + << "\tCurrentSize: " << FormatSize(allocInfo.Stats.CurrentSize) + << Endl; + FormatBackTrace(allocInfo.Stack.data(), allocInfo.Stack.size()); + PrintedCount++; +} + +void TAllocationStatsDumper::FormatBackTrace(void* const* stack, size_t sz) { + char name[1024]; + for (size_t i = 0; i < sz; ++i) { + TSymbol symbol; + auto it = SymbolCache.Find(stack[i]); + if (it != SymbolCache.End()) { + symbol = it.Value(); + } else { + TResolvedSymbol rs = ResolveSymbol(stack[i], name, sizeof(name)); + symbol = {rs.NearestSymbol, rs.Name}; + SymbolCache.Insert(stack[i], symbol); + } + + Out << Hex((intptr_t)stack[i], HF_FULL) << "\t" << symbol.Name; + intptr_t offset = (intptr_t)stack[i] - (intptr_t)symbol.Address; + if (offset) + Out << " +" << offset; + Out << Endl; + } +} + +} // namespace NAllocProfiler diff --git a/library/cpp/lfalloc/alloc_profiler/stackcollect.h b/library/cpp/lfalloc/alloc_profiler/stackcollect.h index 80715ed7cb..7c10cd2ffd 100644 --- a/library/cpp/lfalloc/alloc_profiler/stackcollect.h +++ b/library/cpp/lfalloc/alloc_profiler/stackcollect.h @@ -2,89 +2,89 @@ #include <library/cpp/containers/stack_vector/stack_vec.h> #include <library/cpp/cache/cache.h> - + #include <util/generic/noncopyable.h> #include <util/generic/ptr.h> #include <util/stream/output.h> -namespace NAllocProfiler { - -struct TStats { - intptr_t Allocs = 0; - intptr_t Frees = 0; - intptr_t CurrentSize = 0; - - void Clear() - { - Allocs = 0; - Frees = 0; - CurrentSize = 0; - } - - void Alloc(size_t size) - { - AtomicIncrement(Allocs); - AtomicAdd(CurrentSize, size); - } - - void Free(size_t size) - { - AtomicIncrement(Frees); - AtomicSub(CurrentSize, size); - } -}; - -struct TAllocationInfo { - int Tag; - TStats Stats; - TStackVec<void*, 64> Stack; - - void Clear() { - Tag = 0; - Stats.Clear(); - Stack.clear(); - } -}; - - -class IAllocationStatsDumper { -public: - virtual ~IAllocationStatsDumper() = default; - - // Total stats - virtual void DumpTotal(const TStats& total) = 0; - - // Stats for individual stack - virtual void DumpEntry(const TAllocationInfo& allocInfo) = 0; - - // App-specific tag printer - virtual TString FormatTag(int tag); - - // Size printer (e.g. "10KB", "100MB", "over 9000") - virtual TString FormatSize(intptr_t sz); -}; - -// Default implementation -class TAllocationStatsDumper: public IAllocationStatsDumper { -public: - explicit TAllocationStatsDumper(IOutputStream& out); - void DumpTotal(const TStats& total) override; - void DumpEntry(const TAllocationInfo& allocInfo) override; - -private: - void FormatBackTrace(void* const* stack, size_t sz); - -private: - struct TSymbol { - const void* Address; - TString Name; - }; - - size_t PrintedCount; - IOutputStream& Out; - TLFUCache<void*, TSymbol> SymbolCache; -}; - +namespace NAllocProfiler { + +struct TStats { + intptr_t Allocs = 0; + intptr_t Frees = 0; + intptr_t CurrentSize = 0; + + void Clear() + { + Allocs = 0; + Frees = 0; + CurrentSize = 0; + } + + void Alloc(size_t size) + { + AtomicIncrement(Allocs); + AtomicAdd(CurrentSize, size); + } + + void Free(size_t size) + { + AtomicIncrement(Frees); + AtomicSub(CurrentSize, size); + } +}; + +struct TAllocationInfo { + int Tag; + TStats Stats; + TStackVec<void*, 64> Stack; + + void Clear() { + Tag = 0; + Stats.Clear(); + Stack.clear(); + } +}; + + +class IAllocationStatsDumper { +public: + virtual ~IAllocationStatsDumper() = default; + + // Total stats + virtual void DumpTotal(const TStats& total) = 0; + + // Stats for individual stack + virtual void DumpEntry(const TAllocationInfo& allocInfo) = 0; + + // App-specific tag printer + virtual TString FormatTag(int tag); + + // Size printer (e.g. "10KB", "100MB", "over 9000") + virtual TString FormatSize(intptr_t sz); +}; + +// Default implementation +class TAllocationStatsDumper: public IAllocationStatsDumper { +public: + explicit TAllocationStatsDumper(IOutputStream& out); + void DumpTotal(const TStats& total) override; + void DumpEntry(const TAllocationInfo& allocInfo) override; + +private: + void FormatBackTrace(void* const* stack, size_t sz); + +private: + struct TSymbol { + const void* Address; + TString Name; + }; + + size_t PrintedCount; + IOutputStream& Out; + TLFUCache<void*, TSymbol> SymbolCache; +}; + //////////////////////////////////////////////////////////////////////////////// class TAllocationStackCollector: private TNonCopyable { @@ -101,7 +101,7 @@ public: void Clear(); - void Dump(int count, IAllocationStatsDumper& out) const; + void Dump(int count, IAllocationStatsDumper& out) const; }; -} // namespace NAllocProfiler +} // namespace NAllocProfiler diff --git a/library/cpp/lfalloc/alloc_profiler/ut/ya.make b/library/cpp/lfalloc/alloc_profiler/ut/ya.make index 8a7daa74af..c90a1278d5 100644 --- a/library/cpp/lfalloc/alloc_profiler/ut/ya.make +++ b/library/cpp/lfalloc/alloc_profiler/ut/ya.make @@ -1,22 +1,22 @@ UNITTEST_FOR(library/cpp/lfalloc/alloc_profiler) - -OWNER(g:rtmr g:kikimr) - -PEERDIR( + +OWNER(g:rtmr g:kikimr) + +PEERDIR( library/cpp/testing/unittest -) - -IF (ARCH_AARCH64) - PEERDIR( - contrib/libs/jemalloc - ) -ELSE() - ALLOCATOR(LF_DBG) -ENDIF() - -SRCS( - profiler_ut.cpp +) + +IF (ARCH_AARCH64) + PEERDIR( + contrib/libs/jemalloc + ) +ELSE() + ALLOCATOR(LF_DBG) +ENDIF() + +SRCS( + profiler_ut.cpp align_ut.cpp -) - -END() +) + +END() diff --git a/library/cpp/lfalloc/alloc_profiler/ya.make b/library/cpp/lfalloc/alloc_profiler/ya.make index 0f58d91767..dd1bfb0918 100644 --- a/library/cpp/lfalloc/alloc_profiler/ya.make +++ b/library/cpp/lfalloc/alloc_profiler/ya.make @@ -1,17 +1,17 @@ -LIBRARY() - -OWNER(g:rtmr g:kikimr) - -SRCS( - profiler.cpp - stackcollect.cpp -) - -PEERDIR( +LIBRARY() + +OWNER(g:rtmr g:kikimr) + +SRCS( + profiler.cpp + stackcollect.cpp +) + +PEERDIR( library/cpp/lfalloc/dbg_info library/cpp/cache -) - -END() - -RECURSE(ut) +) + +END() + +RECURSE(ut) diff --git a/library/cpp/lfalloc/dbg_info/dbg_info.cpp b/library/cpp/lfalloc/dbg_info/dbg_info.cpp index 1fb9f7ad93..7667e444a2 100644 --- a/library/cpp/lfalloc/dbg_info/dbg_info.cpp +++ b/library/cpp/lfalloc/dbg_info/dbg_info.cpp @@ -15,7 +15,7 @@ namespace NAllocDbg { int& numSizes); using TSetProfileCurrentThread = bool(bool newVal); - using TSetProfileAllThreads = bool(bool newVal); + using TSetProfileAllThreads = bool(bool newVal); using TSetAllocationSamplingEnabled = bool(bool newVal); using TSetAllocationSampleRate = size_t(size_t newVal); @@ -32,7 +32,7 @@ namespace NAllocDbg { TGetPerTagAllocInfo* GetPerTagAllocInfo = nullptr; TSetProfileCurrentThread* SetProfileCurrentThread = nullptr; - TSetProfileAllThreads* SetProfileAllThreads = nullptr; + TSetProfileAllThreads* SetProfileAllThreads = nullptr; TSetAllocationSamplingEnabled* SetAllocationSamplingEnabled = nullptr; TSetAllocationSampleRate* SetAllocationSampleRate = nullptr; @@ -51,7 +51,7 @@ namespace NAllocDbg { GetPerTagAllocInfo = (TGetPerTagAllocInfo*)mallocInfo.GetParam("GetPerTagAllocInfo"); SetProfileCurrentThread = (TSetProfileCurrentThread*)mallocInfo.GetParam("SetProfileCurrentThread"); - SetProfileAllThreads = (TSetProfileAllThreads*)mallocInfo.GetParam("SetProfileAllThreads"); + SetProfileAllThreads = (TSetProfileAllThreads*)mallocInfo.GetParam("SetProfileAllThreads"); SetAllocationSamplingEnabled = (TSetAllocationSamplingEnabled*)mallocInfo.GetParam("SetAllocationSamplingEnabled"); SetAllocationSampleRate = (TSetAllocationSampleRate*)mallocInfo.GetParam("SetAllocationSampleRate"); @@ -97,10 +97,10 @@ namespace NAllocDbg { return AllocFn.SetProfileCurrentThread ? AllocFn.SetProfileCurrentThread(newVal) : false; } - bool SetProfileAllThreads(bool newVal) { - return AllocFn.SetProfileAllThreads ? AllocFn.SetProfileAllThreads(newVal) : false; - } - + bool SetProfileAllThreads(bool newVal) { + return AllocFn.SetProfileAllThreads ? AllocFn.SetProfileAllThreads(newVal) : false; + } + bool SetAllocationSamplingEnabled(bool newVal) { return AllocFn.SetAllocationSamplingEnabled ? AllocFn.SetAllocationSamplingEnabled(newVal) : false; } diff --git a/library/cpp/lfalloc/dbg_info/dbg_info.h b/library/cpp/lfalloc/dbg_info/dbg_info.h index 071562a81a..8c6ead7180 100644 --- a/library/cpp/lfalloc/dbg_info/dbg_info.h +++ b/library/cpp/lfalloc/dbg_info/dbg_info.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/system/types.h> namespace NAllocDbg { @@ -60,7 +60,7 @@ namespace NAllocDbg { // Allocation sampling could be used to collect detailed information bool SetProfileCurrentThread(bool newVal); - bool SetProfileAllThreads(bool newVal); + bool SetProfileAllThreads(bool newVal); bool SetAllocationSamplingEnabled(bool newVal); size_t SetAllocationSampleRate(size_t newVal); diff --git a/library/cpp/lfalloc/lf_allocX64.h b/library/cpp/lfalloc/lf_allocX64.h index fd2a906d6f..161d42243e 100644 --- a/library/cpp/lfalloc/lf_allocX64.h +++ b/library/cpp/lfalloc/lf_allocX64.h @@ -128,11 +128,11 @@ static bool TransparentHugePages = false; // force MADV_HUGEPAGE for large alloc static bool MapHugeTLB = false; // force MAP_HUGETLB for small allocs static bool EnableDefrag = true; -// Buffers that are larger than this size will not be filled with 0xcf -#ifndef DBG_FILL_MAX_SIZE -#define DBG_FILL_MAX_SIZE 0x01000000000000ULL -#endif - +// Buffers that are larger than this size will not be filled with 0xcf +#ifndef DBG_FILL_MAX_SIZE +#define DBG_FILL_MAX_SIZE 0x01000000000000ULL +#endif + template <class T> inline T* DoCas(T* volatile* target, T* exchange, T* compare) { #if defined(__has_builtin) && __has_builtin(__sync_val_compare_and_swap) @@ -304,7 +304,7 @@ enum EMMapMode { #ifndef _MSC_VER inline void VerifyMmapResult(void* result) { if (Y_UNLIKELY(result == MAP_FAILED)) - NMalloc::AbortFromCorruptedAllocator("negative size requested? or just out of mem"); + NMalloc::AbortFromCorruptedAllocator("negative size requested? or just out of mem"); } #endif @@ -337,7 +337,7 @@ static char* AllocWithMMapLinuxImpl(uintptr_t sz, EMMapMode mode) { char* nextAllocPtr = prevAllocPtr + sz; if (uintptr_t(nextAllocPtr - (char*)nullptr) >= areaFinish) { if (Y_UNLIKELY(wrapped)) { - NMalloc::AbortFromCorruptedAllocator("virtual memory is over fragmented"); + NMalloc::AbortFromCorruptedAllocator("virtual memory is over fragmented"); } // wrap after all area is used DoCas(areaPtr, areaStart, prevAllocPtr); @@ -368,15 +368,15 @@ static char* AllocWithMMap(uintptr_t sz, EMMapMode mode) { #ifdef _MSC_VER char* largeBlock = (char*)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_READWRITE); if (Y_UNLIKELY(largeBlock == nullptr)) - NMalloc::AbortFromCorruptedAllocator("out of memory"); + NMalloc::AbortFromCorruptedAllocator("out of memory"); if (Y_UNLIKELY(uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= N_MAX_WORKSET_SIZE)) - NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); + NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); #else #if defined(_freebsd_) || !defined(_64_) char* largeBlock = (char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); VerifyMmapResult(largeBlock); if (Y_UNLIKELY(uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= N_MAX_WORKSET_SIZE)) - NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); + NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); #else char* largeBlock = AllocWithMMapLinuxImpl(sz, mode); if (TransparentHugePages) { @@ -453,7 +453,7 @@ static void* LargeBlockAlloc(size_t _nSize, ELFAllocCounter counter) { #ifdef _MSC_VER char* pRes = (char*)VirtualAlloc(0, (pgCount + 1) * 4096ll, MEM_COMMIT, PAGE_READWRITE); if (Y_UNLIKELY(pRes == 0)) { - NMalloc::AbortFromCorruptedAllocator("out of memory"); + NMalloc::AbortFromCorruptedAllocator("out of memory"); } #else @@ -784,7 +784,7 @@ static bool DefragmentMem() { int* nFreeCount = (int*)SystemAlloc(N_CHUNKS * sizeof(int)); if (Y_UNLIKELY(!nFreeCount)) { //__debugbreak(); - NMalloc::AbortFromCorruptedAllocator("debugbreak"); + NMalloc::AbortFromCorruptedAllocator("debugbreak"); } memset(nFreeCount, 0, N_CHUNKS * sizeof(int)); @@ -1004,7 +1004,7 @@ static Y_FORCE_INLINE void PutBlocksToGlobalFreeList(ptrdiff_t nSizeIdx, char** ////////////////////////////////////////////////////////////////////////// static TAtomic GlobalCounters[CT_MAX]; const int MAX_LOCAL_UPDATES = 100; -const intptr_t MAX_LOCAL_DELTA = 1*1024*1024; +const intptr_t MAX_LOCAL_DELTA = 1*1024*1024; struct TLocalCounter { intptr_t Value; @@ -1019,7 +1019,7 @@ struct TLocalCounter { Y_FORCE_INLINE void Increment(size_t value) { Value += value; - if (++Updates > MAX_LOCAL_UPDATES || Value > MAX_LOCAL_DELTA) { + if (++Updates > MAX_LOCAL_UPDATES || Value > MAX_LOCAL_DELTA) { Flush(); } } @@ -1344,13 +1344,13 @@ extern "C" bool SetProfileCurrentThread(bool newVal) { return prevVal; } -static volatile bool ProfileAllThreads; -extern "C" bool SetProfileAllThreads(bool newVal) { - bool prevVal = ProfileAllThreads; - ProfileAllThreads = newVal; - return prevVal; -} - +static volatile bool ProfileAllThreads; +extern "C" bool SetProfileAllThreads(bool newVal) { + bool prevVal = ProfileAllThreads; + ProfileAllThreads = newVal; + return prevVal; +} + static volatile bool AllocationSamplingEnabled; extern "C" bool SetAllocationSamplingEnabled(bool newVal) { bool prevVal = AllocationSamplingEnabled; @@ -1394,7 +1394,7 @@ PERTHREAD bool InAllocationCallback; static const int DBG_ALLOC_INVALID_COOKIE = -1; static inline int SampleAllocation(TAllocHeader* p, int sizeIdx) { int cookie = DBG_ALLOC_INVALID_COOKIE; - if (AllocationSamplingEnabled && (ProfileCurrentThread || ProfileAllThreads) && !InAllocationCallback) { + if (AllocationSamplingEnabled && (ProfileCurrentThread || ProfileAllThreads) && !InAllocationCallback) { if (p->Size > AllocationSampleMaxSize || ++AllocationsCount % AllocationSampleRate == 0) { if (AllocationCallback) { InAllocationCallback = true; @@ -1556,7 +1556,7 @@ static Y_FORCE_INLINE void* LFAllocImpl(size_t _nSize) { if (count == 0) { count = LFAllocNoCacheMultiple(nSizeIdx, buf); if (count == 0) { - NMalloc::AbortFromCorruptedAllocator("no way LFAllocNoCacheMultiple() can fail"); + NMalloc::AbortFromCorruptedAllocator("no way LFAllocNoCacheMultiple() can fail"); } } char** dstBuf = thr->FreePtrs[nSizeIdx] + freePtrIdx - 1; @@ -1773,7 +1773,7 @@ static void DumpMemoryBlockUtilizationLocked() { nBadPages += page == 3; nTotalPages += page != 1; } - DebugTraceMMgr("entry = %lld; size = %lld; free = %lld; system %lld; utilisation = %g%%, fragmentation = %g%%\n", + DebugTraceMMgr("entry = %lld; size = %lld; free = %lld; system %lld; utilisation = %g%%, fragmentation = %g%%\n", k, nSize, cs.FreeCount * nSize, csGB.FreeCount * nSize, (N_CHUNK_SIZE - cs.FreeCount * nSize) * 100.0f / N_CHUNK_SIZE, 100.0f * nBadPages / Y_ARRAY_SIZE(pages)); nTotalAllocated += N_CHUNK_SIZE; @@ -1781,10 +1781,10 @@ static void DumpMemoryBlockUtilizationLocked() { nTotalBadPages += nBadPages; } SystemFree(entries); - DebugTraceMMgr("Total allocated = %llu, free = %lld, system = %lld, locked for future use %lld, utilisation = %g, fragmentation = %g\n", + DebugTraceMMgr("Total allocated = %llu, free = %lld, system = %lld, locked for future use %lld, utilisation = %g, fragmentation = %g\n", nTotalAllocated, nTotalFree, nTotalGroupBlocks, nTotalLocked, 100.0f * (nTotalAllocated - nTotalFree) / nTotalAllocated, 100.0f * nTotalBadPages / nTotalPages); - DebugTraceMMgr("Total %lld bytes used, %lld bytes in used pages\n", nTotalUsed, nTotalPages * N_PAGE_SIZE); + DebugTraceMMgr("Total %lld bytes used, %lld bytes in used pages\n", nTotalUsed, nTotalPages * N_PAGE_SIZE); for (int nSizeIdx = 0; nSizeIdx < N_SIZES; ++nSizeIdx) globalFreeLists[nSizeIdx].ReturnWholeList(wholeLists[nSizeIdx]); @@ -1850,7 +1850,7 @@ static const char* LFAlloc_GetParam(const char* param) { #if defined(LFALLOC_DBG) {"SetThreadAllocTag", (const char*)&SetThreadAllocTag}, {"SetProfileCurrentThread", (const char*)&SetProfileCurrentThread}, - {"SetProfileAllThreads", (const char*)&SetProfileAllThreads}, + {"SetProfileAllThreads", (const char*)&SetProfileAllThreads}, {"SetAllocationSamplingEnabled", (const char*)&SetAllocationSamplingEnabled}, {"SetAllocationSampleRate", (const char*)&SetAllocationSampleRate}, {"SetAllocationSampleMaxSize", (const char*)&SetAllocationSampleMaxSize}, @@ -1870,11 +1870,11 @@ static const char* LFAlloc_GetParam(const char* param) { static Y_FORCE_INLINE int LFPosixMemalign(void** memptr, size_t alignment, size_t size) { if (Y_UNLIKELY(alignment > 4096)) { - const char* error = "Larger alignment are not guaranteed with this implementation\n"; + const char* error = "Larger alignment are not guaranteed with this implementation\n"; #ifdef _win_ - OutputDebugStringA(error); + OutputDebugStringA(error); #endif - NMalloc::AbortFromCorruptedAllocator(error); + NMalloc::AbortFromCorruptedAllocator(error); } size_t bigsize = size; if (bigsize <= alignment) { |