diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-22 15:35:58 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-22 15:44:42 +0300 |
commit | 1475372a2d8a1ace4610a95415eb1cfe97fc26d1 (patch) | |
tree | 750ad949f410741d1273667d8ed3f983f1fd93c2 | |
parent | 21704936a7af83df23fd65a064171aae4d228914 (diff) | |
download | ydb-1475372a2d8a1ace4610a95415eb1cfe97fc26d1.tar.gz |
Intermediate changes
-rw-r--r-- | contrib/libs/tcmalloc/ya.make | 3 | ||||
-rw-r--r-- | yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp | 82 |
2 files changed, 74 insertions, 11 deletions
diff --git a/contrib/libs/tcmalloc/ya.make b/contrib/libs/tcmalloc/ya.make index 589a2a097c..2160ea481f 100644 --- a/contrib/libs/tcmalloc/ya.make +++ b/contrib/libs/tcmalloc/ya.make @@ -5,9 +5,10 @@ LICENSE(Apache-2.0) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) ALLOCATOR_IMPL() -# https://github.com/google/tcmalloc VERSION(2021-10-04-45c59ccbc062ac96d83710205033c656e490d376) +ORIGINAL_SOURCE(https://github.com/google/tcmalloc/archive/45c59ccbc062ac96d83710205033c656e490d376.tar.gz) + SRCS( # Options tcmalloc/want_hpaa.cc diff --git a/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp b/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp index b135c2b438..1828ada3c9 100644 --- a/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp +++ b/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp @@ -9,6 +9,10 @@ #include <yt/yt/core/misc/crash_handler.h> #include <yt/yt/core/misc/error.h> +#include <yt/yt/core/ytree/yson_struct.h> + +#include <yt/yt/core/yson/writer.h> + #include <library/cpp/yt/string/format.h> #include <library/cpp/yt/memory/atomic_intrusive_ptr.h> @@ -31,9 +35,9 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -void CollectAndDumpMemoryProfile(const TString& memoryProfilePath) +void CollectAndDumpMemoryProfile(const TString& memoryProfilePath, tcmalloc::ProfileType profileType) { - auto profile = NYTProf::ReadHeapProfile(tcmalloc::ProfileType::kHeap); + auto profile = NYTProf::ReadHeapProfile(profileType); SymbolizeByExternalPProf(&profile, NYTProf::TSymbolizationOptions{ .RunTool = [] (const std::vector<TString>& args) { TShellCommand command{args[0], TList<TString>{args.begin()+1, args.end()}}; @@ -62,6 +66,40 @@ void SetupMemoryProfileTimeout(int timeout) //////////////////////////////////////////////////////////////////////////////// +DECLARE_REFCOUNTED_STRUCT(TOomProfilePaths) + +struct TOomProfilePaths + : public NYTree::TYsonStruct +{ + TString HeapProfilePath; + TString PeakProfilePath; + + REGISTER_YSON_STRUCT(TOomProfilePaths); + + static void Register(TRegistrar registrar) + { + registrar.Parameter("heap_profile_path", &TThis::HeapProfilePath) + .Default(); + registrar.Parameter("peak_profile_path", &TThis::PeakProfilePath) + .Default(); + } +}; + +DEFINE_REFCOUNTED_TYPE(TOomProfilePaths) + +//////////////////////////////////////////////////////////////////////////////// + +void DumpProfilePaths(const TOomProfilePathsPtr& links, const TString& fileName) +{ + TFileOutput output(fileName); + NYson::TYsonWriter writer(&output, NYson::EYsonFormat::Pretty); + Serialize(links, &writer); + writer.Flush(); + output.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// + class TTCMallocLimitHandler : public TRefCounted { @@ -102,7 +140,6 @@ private: std::condition_variable CV_; std::thread Thread_; - void Handle() { std::unique_lock<std::mutex> lock(Mutex_); @@ -114,9 +151,16 @@ private: return; } - auto heapDumpPath = GetHeapDumpPath(); + auto timestamp = TInstant::Now().FormatLocalTime("%Y%m%dT%H%M%S"); + auto profilePaths = New<TOomProfilePaths>(); + auto profilePathsFile = GetProfilePaths(timestamp); + profilePaths->HeapProfilePath = GetHeapDumpPath(timestamp); + profilePaths->PeakProfilePath = GetPeakDumpPath(timestamp); + Cerr << "TTCMallocLimitHandler: Fork process to write heap profile: " - << heapDumpPath + << profilePaths->HeapProfilePath + << " peak profile path: " << profilePaths->PeakProfilePath + << " profiles path file: " << profilePathsFile << Endl; SetupMemoryProfileTimeout(Options_.Timeout.Seconds()); @@ -124,9 +168,11 @@ private: if (childPid == 0) { SetupMemoryProfileTimeout(Options_.Timeout.Seconds()); - CollectAndDumpMemoryProfile(heapDumpPath); + CollectAndDumpMemoryProfile(profilePaths->HeapProfilePath, tcmalloc::ProfileType::kHeap); + CollectAndDumpMemoryProfile(profilePaths->PeakProfilePath, tcmalloc::ProfileType::kPeakHeap); + DumpProfilePaths(profilePaths, profilePathsFile); - Cerr << "TTCMallocLimitHandler: Heap profile written" << Endl; + Cerr << "TTCMallocLimitHandler: Heap profiles are written" << Endl; AbortProcess(ToUnderlying(EProcessExitCode::OK)); } @@ -139,17 +185,33 @@ private: AbortProcess(ToUnderlying(EProcessExitCode::OK)); } - TString GetHeapDumpPath() const + TString GetHeapDumpPath(const TString& timestamp) const { return Format( "%v/heap_%v.pb.gz", Options_.HeapDumpDirectory, - TInstant::Now().FormatLocalTime("%Y%m%dT%H%M%S")); + timestamp); + } + + TString GetPeakDumpPath(const TString& timestamp) const + { + return Format( + "%v/peak_%v.pb.gz", + Options_.HeapDumpDirectory, + timestamp); + } + + TString GetProfilePaths(const TString& timestamp) const + { + return Format( + "%v/oom_profile_paths_%v.pb.gz", + Options_.HeapDumpDirectory, + timestamp); } void ExecWaitForChild(int pid) { - Cerr << "TTCMallocLimitHandler: Before waiting for child" << Endl; + Cerr << "TTCMallocLimitHandler: Start waiting for the child" << Endl; auto command = Format("while [ -e /proc/%v ]; do sleep 1; done;", pid); execl("/bin/bash", "/bin/bash", "-c", command.c_str(), (void*)nullptr); |