summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgolear <[email protected]>2024-05-21 01:03:40 +0300
committerdgolear <[email protected]>2024-05-21 01:15:41 +0300
commita92a0d80c339ed6f70624dffa79288e61b72e941 (patch)
tree14ae8539e97846150a92530242efeb4b5b5fc08e
parent52107f6c22b7a6a09f394b920b18b6bae386ceb7 (diff)
YT: Add FormatValue for std::source_location
YTORM-1057 0aa4ceb80d984a15c92a69f242ecf517b3c7a07c
-rw-r--r--library/cpp/yt/misc/source_location.cpp26
-rw-r--r--library/cpp/yt/misc/source_location.h18
-rw-r--r--yt/yt/library/ytprof/heap_profiler.cpp3
3 files changed, 46 insertions, 1 deletions
diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp
index 8d22d43636c..3fe45e23a76 100644
--- a/library/cpp/yt/misc/source_location.cpp
+++ b/library/cpp/yt/misc/source_location.cpp
@@ -1,11 +1,37 @@
#include "source_location.h"
+#include <library/cpp/yt/string/format.h>
+
#include <string.h>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
+#ifdef __cpp_lib_source_location
+
+void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*format*/)
+{
+ if (location.file_name() != nullptr) {
+ builder->AppendFormat(
+ "%v:%v:%v",
+ location.file_name(),
+ location.line(),
+ location.column());
+ } else {
+ builder->AppendString("<unknown>");
+ }
+}
+
+TString ToString(const std::source_location& location)
+{
+ return ToStringViaBuilder(location);
+}
+
+#endif // __cpp_lib_source_location
+
+////////////////////////////////////////////////////////////////////////////////
+
const char* TSourceLocation::GetFileName() const
{
return FileName_;
diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h
index 84213eea708..38a6f83c804 100644
--- a/library/cpp/yt/misc/source_location.h
+++ b/library/cpp/yt/misc/source_location.h
@@ -1,9 +1,27 @@
#pragma once
+#include <util/generic/string.h>
+
+#ifdef __cpp_lib_source_location
+#include <source_location>
+#endif // __cpp_lib_source_location
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
+// TODO(dgolear): Drop when LLVM-14 is eradicated.
+#ifdef __cpp_lib_source_location
+
+class TStringBuilderBase;
+
+void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*format*/);
+TString ToString(const std::source_location& location);
+
+#endif // __cpp_lib_source_location
+
+////////////////////////////////////////////////////////////////////////////////
+
class TSourceLocation
{
public:
diff --git a/yt/yt/library/ytprof/heap_profiler.cpp b/yt/yt/library/ytprof/heap_profiler.cpp
index 666491a0f65..822b96ffc29 100644
--- a/yt/yt/library/ytprof/heap_profiler.cpp
+++ b/yt/yt/library/ytprof/heap_profiler.cpp
@@ -12,6 +12,7 @@
#include <util/generic/hash_set.h>
#include <util/string/join.h>
+#include <util/string/cast.h>
#include <tcmalloc/malloc_extension.h>
@@ -45,7 +46,7 @@ Y_WEAK std::optional<TString> FindTagValue(
{
Y_UNUSED(tags);
Y_UNUSED(key);
- return ToString(NullMemoryTag);
+ return ::ToString(NullMemoryTag);
}
Y_WEAK void StartAllocationTagsCleanupThread(TDuration /*cleanupInterval*/)