Skip to content

Commit 7cfcc44

Browse files
authored
Use DWARF section to resolve symbols in the profiler reports (#9766)
1 parent 623cc67 commit 7cfcc44

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

ydb/core/mon_alloc/tcmalloc.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <ydb/library/actors/prof/tag.h>
66
#include <library/cpp/cache/cache.h>
7+
#include <library/cpp/dwarf_backtrace/backtrace.h>
78
#include <library/cpp/html/pcdata/pcdata.h>
89
#include <library/cpp/monlib/service/pages/templates.h>
910

@@ -206,25 +207,15 @@ class TAllocationAnalyzer {
206207
bool Prepared = false;
207208

208209
private:
209-
void PrintBackTrace(IOutputStream& out, void* const* stack, size_t sz,
210-
const char* sep)
211-
{
212-
char name[1024];
213-
for (size_t i = 0; i < sz; ++i) {
214-
TSymbol symbol;
215-
auto it = SymbolCache.Find(stack[i]);
216-
if (it != SymbolCache.End()) {
217-
symbol = it.Value();
218-
} else {
219-
TResolvedSymbol rs = ResolveSymbol(stack[i], name, sizeof(name));
220-
symbol = {rs.NearestSymbol, rs.Name};
221-
SymbolCache.Insert(stack[i], symbol);
222-
}
223-
224-
out << Hex((intptr_t)stack[i], HF_FULL) << " " << symbol.Name;
225-
intptr_t offset = (intptr_t)stack[i] - (intptr_t)symbol.Address;
226-
if (offset)
227-
out << " +" << offset;
210+
void PrintBackTrace(IOutputStream& out, void* const* stack, size_t size, const char* sep) {
211+
// TODO: ignore symbol cache for now - because of inlines.
212+
if (auto error = NDwarf::ResolveBacktrace(TArrayRef<const void* const>(stack, size), [&](const NDwarf::TLineInfo& info) {
213+
out << "#" << info.Index << " " << info.FunctionName << " at " << info.FileName << ':' << info.Line << ':' << info.Col << sep;
214+
return NDwarf::EResolving::Continue;
215+
})) {
216+
// TODO: print error message.
217+
out << "Failed to resolve stacktrace: " << error->Message << sep;
218+
} else {
228219
out << sep;
229220
}
230221
}

ydb/core/mon_alloc/ya.make

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ SRCS(
1616

1717
PEERDIR(
1818
contrib/libs/tcmalloc/malloc_extension
19-
ydb/library/actors/core
20-
ydb/library/actors/prof
19+
library/cpp/dwarf_backtrace
2120
library/cpp/html/pcdata
2221
library/cpp/lfalloc/alloc_profiler
2322
library/cpp/lfalloc/dbg_info
2423
library/cpp/malloc/api
2524
library/cpp/monlib/service/pages
2625
ydb/core/base
2726
ydb/core/control
27+
ydb/library/actors/core
28+
ydb/library/actors/prof
2829
ydb/library/services
2930
)
3031

0 commit comments

Comments
 (0)