Skip to content

Commit 559d052

Browse files
committed
Intermediate changes
1 parent 87cfc6b commit 559d052

File tree

6 files changed

+96
-73
lines changed

6 files changed

+96
-73
lines changed

library/cpp/yt/backtrace/cursors/frame_pointer/frame_pointer_cursor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace NYT::NBacktrace {
66

77
////////////////////////////////////////////////////////////////////////////////
88

9+
#ifndef _x86_64_
10+
#error Unsupported platform
11+
#endif
12+
913
struct TFramePointerCursorContext
1014
{
1115
ui64 Rip;

library/cpp/yt/backtrace/cursors/interop/interop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace NYT::NBacktrace {
66

77
TFramePointerCursorContext FramePointerCursorContextFromUcontext(const ucontext_t& ucontext)
88
{
9-
#if defined(_linux_)
9+
#if defined(_linux_) && defined(_x86_64_)
1010
return {
1111
.Rip = static_cast<ui64>(ucontext.uc_mcontext.gregs[REG_RIP]),
1212
.Rsp = static_cast<ui64>(ucontext.uc_mcontext.gregs[REG_RSP]),
1313
.Rbp = static_cast<ui64>(ucontext.uc_mcontext.gregs[REG_RBP]),
1414
};
15-
#elif defined(_darwin_)
15+
#elif defined(_darwin_) && defined(_x86_64_)
1616
return {
1717
.Rip = static_cast<ui64>(ucontext.uc_mcontext->__ss.__rip),
1818
.Rsp = static_cast<ui64>(ucontext.uc_mcontext->__ss.__rsp),

yt/yt/library/ytprof/allocation_tag_profiler/allocation_tag_profiler.cpp

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,108 @@
11
#include "allocation_tag_profiler.h"
22

3+
#ifdef __x86_64__
34
#include <yt/yt/core/concurrency/periodic_executor.h>
5+
6+
#include <yt/yt/core/ypath/token.h>
7+
48
#include <yt/yt/library/ytprof/heap_profiler.h>
9+
#endif
510

611
namespace NYT::NYTProf {
712

13+
#ifdef __x86_64__
14+
815
using namespace NProfiling;
916
using namespace NConcurrency;
1017

1118
////////////////////////////////////////////////////////////////////////////////
1219

13-
THeapUsageProfiler::THeapUsageProfiler(
14-
std::vector<TString> tags,
15-
IInvokerPtr invoker,
16-
std::optional<TDuration> updatePeriod,
17-
std::optional<i64> samplingRate,
18-
NProfiling::TProfiler profiler)
19-
: Profiler_(std::move(profiler))
20-
, TagTypes_(std::move(tags))
21-
, UpdateExecutor_(New<TPeriodicExecutor>(
22-
std::move(invoker),
23-
BIND(&THeapUsageProfiler::UpdateGauges, MakeWeak(this)),
24-
std::move(updatePeriod)))
20+
class TAllocationTagProfiler
21+
: public IAllocationTagProfiler
2522
{
26-
if (samplingRate) {
27-
tcmalloc::MallocExtension::SetProfileSamplingRate(*samplingRate);
23+
public:
24+
TAllocationTagProfiler(
25+
std::vector<TString> tagNames,
26+
IInvokerPtr invoker,
27+
std::optional<TDuration> updatePeriod,
28+
std::optional<i64> samplingRate,
29+
NProfiling::TProfiler profiler)
30+
: Profiler_(std::move(profiler))
31+
, TagNames_(std::move(tagNames))
32+
, UpdateExecutor_(New<TPeriodicExecutor>(
33+
std::move(invoker),
34+
BIND(&TAllocationTagProfiler::UpdateGauges, MakeWeak(this)),
35+
std::move(updatePeriod)))
36+
{
37+
if (samplingRate) {
38+
tcmalloc::MallocExtension::SetProfileSamplingRate(*samplingRate);
39+
}
40+
41+
UpdateExecutor_->Start();
2842
}
2943

30-
UpdateExecutor_->Start();
31-
}
44+
private:
45+
const NProfiling::TProfiler Profiler_;
46+
const std::vector<TString> TagNames_;
3247

33-
void THeapUsageProfiler::UpdateGauges()
34-
{
35-
const auto memorySnapshot = GetMemoryUsageSnapshot();
36-
YT_VERIFY(memorySnapshot);
37-
38-
for (const auto& tagType : TagTypes_) {
39-
auto& heapUsageMap = HeapUsageByType_.emplace(tagType, THashMap<TString, TGauge>{}).first->second;
40-
const auto& snapshotSlice = memorySnapshot->GetUsage(tagType);
41-
42-
for (auto &[tag, gauge] : heapUsageMap) {
43-
if (const auto& iter = snapshotSlice.find(tag)) {
44-
gauge.Update(iter->second);
45-
} else {
46-
gauge.Update(0.0);
47-
}
48-
}
48+
const NConcurrency::TPeriodicExecutorPtr UpdateExecutor_;
49+
50+
THashMap<TString, THashMap<TString, NProfiling::TGauge>> HeapUsageByType_;
51+
52+
void UpdateGauges()
53+
{
54+
auto memorySnapshot = GetMemoryUsageSnapshot();
55+
YT_VERIFY(memorySnapshot);
4956

50-
for (const auto& [tag, usage] : snapshotSlice) {
51-
auto gauge = heapUsageMap.find(tag);
57+
for (const auto& tagName : TagNames_) {
58+
auto& heapUsageMap = HeapUsageByType_.emplace(tagName, THashMap<TString, TGauge>{}).first->second;
59+
const auto& snapshotSlice = memorySnapshot->GetUsage(tagName);
5260

53-
if (gauge.IsEnd()) {
54-
gauge = heapUsageMap.emplace(tag, Profiler_
55-
.WithTag(tagType, tag)
56-
.Gauge(tagType))
57-
.first;
58-
gauge->second.Update(usage);
61+
for (auto& [tagValue, gauge] : heapUsageMap) {
62+
if (auto it = snapshotSlice.find(tagValue)) {
63+
gauge.Update(it->second);
64+
} else {
65+
gauge.Update(0.0);
66+
}
67+
}
68+
69+
for (const auto& [tagValue, usage] : snapshotSlice) {
70+
auto it = heapUsageMap.find(tagValue);
71+
if (it == heapUsageMap.end()) {
72+
it = heapUsageMap.emplace(tagValue, Profiler_
73+
.WithTag(tagName, tagValue)
74+
.Gauge(Format("/%v", NYPath::ToYPathLiteral(tagName))))
75+
.first;
76+
it->second.Update(usage);
77+
}
5978
}
6079
}
6180
}
62-
}
81+
};
6382

64-
///////////////////////////////////////////////////////////////////
83+
#else
6584

66-
THeapUsageProfilerPtr CreateHeapProfilerWithTags(
67-
std::vector<TString>&& tags,
85+
class TAllocationTagProfiler
86+
: public IAllocationTagProfiler
87+
{
88+
public:
89+
TAllocationTagProfiler(auto&&... /*args*/)
90+
{ }
91+
};
92+
93+
#endif
94+
95+
////////////////////////////////////////////////////////////////////////////////
96+
97+
IAllocationTagProfilerPtr CreateAllocationTagProfiler(
98+
std::vector<TString> tagNames,
6899
IInvokerPtr invoker,
69100
std::optional<TDuration> updatePeriod,
70101
std::optional<i64> samplingRate,
71102
NYT::NProfiling::TProfiler profiler)
72103
{
73-
return New<THeapUsageProfiler>(
74-
std::move(tags),
104+
return New<TAllocationTagProfiler>(
105+
std::move(tagNames),
75106
std::move(invoker),
76107
std::move(updatePeriod),
77108
std::move(samplingRate),
@@ -81,4 +112,3 @@ THeapUsageProfilerPtr CreateHeapProfilerWithTags(
81112
////////////////////////////////////////////////////////////////////////////////
82113

83114
} // namespace NYT::NYTProf
84-

yt/yt/library/ytprof/allocation_tag_profiler/allocation_tag_profiler.h

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,20 @@ namespace NYT::NYTProf {
1616

1717
////////////////////////////////////////////////////////////////////////////////
1818

19-
class THeapUsageProfiler
19+
struct IAllocationTagProfiler
2020
: public TRefCounted
21-
{
22-
public:
23-
THeapUsageProfiler(
24-
std::vector<TString> tags,
25-
IInvokerPtr invoker,
26-
std::optional<TDuration> updatePeriod,
27-
std::optional<i64> samplingRate,
28-
NProfiling::TProfiler profiler);
21+
{ };
2922

30-
private:
31-
NProfiling::TProfiler Profiler_;
32-
const std::vector<TString> TagTypes_;
33-
THashMap<TString, THashMap<TString, NProfiling::TGauge>> HeapUsageByType_;
34-
35-
const NConcurrency::TPeriodicExecutorPtr UpdateExecutor_;
36-
37-
void UpdateGauges();
38-
};
39-
40-
DEFINE_REFCOUNTED_TYPE(THeapUsageProfiler)
23+
DEFINE_REFCOUNTED_TYPE(IAllocationTagProfiler);
4124

4225
////////////////////////////////////////////////////////////////////////////////
4326

44-
THeapUsageProfilerPtr CreateHeapProfilerWithTags(
45-
std::vector<TString>&& tags,
27+
IAllocationTagProfilerPtr CreateAllocationTagProfiler(
28+
std::vector<TString> tagNames,
4629
IInvokerPtr invoker,
4730
std::optional<TDuration> updatePeriod,
4831
std::optional<i64> samplingRate,
49-
NProfiling::TProfiler profiler = NProfiling::TProfiler{"/heap_usage/"});
32+
NProfiling::TProfiler profiler = NProfiling::TProfiler{"/memory/heap_usage"});
5033

5134
////////////////////////////////////////////////////////////////////////////////
5235

yt/yt/library/ytprof/allocation_tag_profiler/public.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace NYT::NYTProf {
66

77
////////////////////////////////////////////////////////////////////////////////
88

9-
DECLARE_REFCOUNTED_CLASS(THeapUsageProfiler);
9+
DECLARE_REFCOUNTED_STRUCT(IAllocationTagProfiler);
1010

1111
////////////////////////////////////////////////////////////////////////////////
1212

yt/yt/library/ytprof/allocation_tag_profiler/ya.make

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ PEERDIR(
1212
yt/yt/core
1313
)
1414

15+
IF(ARCH_X86_64)
16+
PEERDIR(
17+
yt/yt/library/ytprof
18+
)
19+
ENDIF()
20+
1521
END()
1622

1723

0 commit comments

Comments
 (0)