aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/lfalloc/alloc_profiler/profiler.cpp
diff options
context:
space:
mode:
authorvskipin <vskipin@yandex-team.ru>2022-02-10 16:46:00 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:00 +0300
commit4e4b78bd7b67e2533da4dbb9696374a6d6068e32 (patch)
treea7a5543d815c451256ece74081d960b4e1d70ec2 /library/cpp/lfalloc/alloc_profiler/profiler.cpp
parent5b00ed04a5137a452fa6d3423cb0c9b54ac27408 (diff)
downloadydb-4e4b78bd7b67e2533da4dbb9696374a6d6068e32.tar.gz
Restoring authorship annotation for <vskipin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/lfalloc/alloc_profiler/profiler.cpp')
-rw-r--r--library/cpp/lfalloc/alloc_profiler/profiler.cpp142
1 files changed, 71 insertions, 71 deletions
diff --git a/library/cpp/lfalloc/alloc_profiler/profiler.cpp b/library/cpp/lfalloc/alloc_profiler/profiler.cpp
index 0e30927a5a..4c081bf64f 100644
--- a/library/cpp/lfalloc/alloc_profiler/profiler.cpp
+++ b/library/cpp/lfalloc/alloc_profiler/profiler.cpp
@@ -1,81 +1,81 @@
-#include "profiler.h"
+#include "profiler.h"
-#include "stackcollect.h"
-
-#include <util/generic/algorithm.h>
-#include <util/generic/singleton.h>
+#include "stackcollect.h"
+
+#include <util/generic/algorithm.h>
+#include <util/generic/singleton.h>
#include <util/generic/string.h>
-#include <util/generic/vector.h>
-#include <util/stream/str.h>
-
+#include <util/generic/vector.h>
+#include <util/stream/str.h>
+
namespace NAllocProfiler {
-
-namespace {
-
-static TAllocationStackCollector& AllocationStackCollector()
-{
- return *Singleton<TAllocationStackCollector>();
-}
-
-int AllocationCallback(int tag, size_t size, int sizeIdx)
-{
- Y_UNUSED(sizeIdx);
-
- static const size_t STACK_FRAMES_COUNT = 32;
- static const size_t STACK_FRAMES_SKIP = 1;
-
- void* frames[STACK_FRAMES_COUNT];
- size_t frameCount = BackTrace(frames, Y_ARRAY_SIZE(frames));
- if (frameCount <= STACK_FRAMES_SKIP) {
- return -1;
- }
-
- void** stack = &frames[STACK_FRAMES_SKIP];
- frameCount -= STACK_FRAMES_SKIP;
-
- auto& collector = AllocationStackCollector();
- return collector.Alloc(stack, frameCount, tag, size);
-}
-
-void DeallocationCallback(int stackId, int tag, size_t size, int sizeIdx)
-{
- Y_UNUSED(tag);
- Y_UNUSED(sizeIdx);
-
- auto& collector = AllocationStackCollector();
- collector.Free(stackId, size);
-}
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-
+
+namespace {
+
+static TAllocationStackCollector& AllocationStackCollector()
+{
+ return *Singleton<TAllocationStackCollector>();
+}
+
+int AllocationCallback(int tag, size_t size, int sizeIdx)
+{
+ Y_UNUSED(sizeIdx);
+
+ static const size_t STACK_FRAMES_COUNT = 32;
+ static const size_t STACK_FRAMES_SKIP = 1;
+
+ void* frames[STACK_FRAMES_COUNT];
+ size_t frameCount = BackTrace(frames, Y_ARRAY_SIZE(frames));
+ if (frameCount <= STACK_FRAMES_SKIP) {
+ return -1;
+ }
+
+ void** stack = &frames[STACK_FRAMES_SKIP];
+ frameCount -= STACK_FRAMES_SKIP;
+
+ auto& collector = AllocationStackCollector();
+ return collector.Alloc(stack, frameCount, tag, size);
+}
+
+void DeallocationCallback(int stackId, int tag, size_t size, int sizeIdx)
+{
+ Y_UNUSED(tag);
+ Y_UNUSED(sizeIdx);
+
+ auto& collector = AllocationStackCollector();
+ collector.Free(stackId, size);
+}
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+
bool StartAllocationSampling(bool profileAllThreads)
-{
- auto& collector = AllocationStackCollector();
- collector.Clear();
-
+{
+ auto& collector = AllocationStackCollector();
+ collector.Clear();
+
NAllocDbg::SetProfileAllThreads(profileAllThreads);
- NAllocDbg::SetAllocationCallback(AllocationCallback);
- NAllocDbg::SetDeallocationCallback(DeallocationCallback);
- NAllocDbg::SetAllocationSamplingEnabled(true);
- return true;
-}
-
+ NAllocDbg::SetAllocationCallback(AllocationCallback);
+ NAllocDbg::SetDeallocationCallback(DeallocationCallback);
+ NAllocDbg::SetAllocationSamplingEnabled(true);
+ return true;
+}
+
bool StopAllocationSampling(IAllocationStatsDumper &out, int count)
-{
- NAllocDbg::SetAllocationCallback(nullptr);
- NAllocDbg::SetDeallocationCallback(nullptr);
- NAllocDbg::SetAllocationSamplingEnabled(false);
-
- auto& collector = AllocationStackCollector();
+{
+ NAllocDbg::SetAllocationCallback(nullptr);
+ NAllocDbg::SetDeallocationCallback(nullptr);
+ NAllocDbg::SetAllocationSamplingEnabled(false);
+
+ auto& collector = AllocationStackCollector();
collector.Dump(count, out);
- return true;
-}
-
+ return true;
+}
+
bool StopAllocationSampling(IOutputStream& out, int count) {
TAllocationStatsDumper dumper(out);
return StopAllocationSampling(dumper, count);
-}
-
-} // namespace NProfiler
+}
+
+} // namespace NProfiler