Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion ydb/core/mon_alloc/tcmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

#include <ydb/library/actors/prof/tag.h>
#include <library/cpp/cache/cache.h>
#include <library/cpp/dwarf_backtrace/backtrace.h>

#if defined(USE_DWARF_BACKTRACE)
# include <library/cpp/dwarf_backtrace/backtrace.h>
#endif

#include <library/cpp/html/pcdata/pcdata.h>
#include <library/cpp/monlib/service/pages/templates.h>

Expand Down Expand Up @@ -207,6 +211,7 @@ class TAllocationAnalyzer {
bool Prepared = false;

private:
#if defined(USE_DWARF_BACKTRACE)
void PrintBackTrace(IOutputStream& out, void* const* stack, size_t size, const char* sep) {
// TODO: ignore symbol cache for now - because of inlines.
if (auto error = NDwarf::ResolveBacktrace(TArrayRef<const void* const>(stack, size), [&](const NDwarf::TLineInfo& info) {
Expand All @@ -219,6 +224,28 @@ class TAllocationAnalyzer {
out << sep;
}
}
#else
void PrintBackTrace(IOutputStream& out, void* const* stack, size_t sz, const char* sep) {
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) << " " << symbol.Name;
intptr_t offset = (intptr_t)stack[i] - (intptr_t)symbol.Address;
if (offset)
out << " +" << offset;
out << sep;
}
}
#endif

void PrintSample(IOutputStream& out, const tcmalloc::Profile::Sample* sample,
const char* sep) const
Expand Down
10 changes: 9 additions & 1 deletion ydb/core/mon_alloc/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ SRCS(
tcmalloc.cpp
)

IF (OS_LINUX AND ARCH_X86_64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну как-то консистентно: здесь написано "линукс и 64 бита", а внутри кода "юникс". Как будто если будем собирать под мак -- оно сломается, так как нет пирдира на library/cpp/dwarf_backtrace

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно более бы корректно выставлять на уровне ямэйка дефайн USE_DWARF_BACKTRACE, а в коде на основе него принимать решение -- будет одно место где принимаем решение

CFLAGS(
-DUSE_DWARF_BACKTRACE
)
PEERDIR(
library/cpp/dwarf_backtrace
)
ENDIF()

PEERDIR(
contrib/libs/tcmalloc/malloc_extension
library/cpp/dwarf_backtrace
library/cpp/html/pcdata
library/cpp/lfalloc/alloc_profiler
library/cpp/lfalloc/dbg_info
Expand Down