diff options
author | lukyan <lukyan@yandex-team.com> | 2024-06-18 01:36:29 +0300 |
---|---|---|
committer | lukyan <lukyan@yandex-team.com> | 2024-06-18 01:49:09 +0300 |
commit | 325358f21d3808ecca45bbc4f461a56971acebe0 (patch) | |
tree | 2d4f4ab24305343bb6c1734cceb233d1994ba56b /library | |
parent | c4f4721ec589408ff50f675a0025f95d3c5ec18f (diff) | |
download | ydb-325358f21d3808ecca45bbc4f461a56971acebe0.tar.gz |
Track source locations of propagating storage
a27af83d265ebf4e7f4bf273eb41f69850817b05
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/yt/misc/source_location.cpp | 19 | ||||
-rw-r--r-- | library/cpp/yt/misc/source_location.h | 14 |
2 files changed, 31 insertions, 2 deletions
diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp index 37eb5edd53..f3f396ee90 100644 --- a/library/cpp/yt/misc/source_location.cpp +++ b/library/cpp/yt/misc/source_location.cpp @@ -70,6 +70,25 @@ bool TSourceLocation::operator==(const TSourceLocation& other) const Line_ == other.Line_; } +#ifdef __cpp_lib_source_location +TSourceLocation TSourceLocation::FromStd(const std::source_location& location) +{ + return TSourceLocation(location.file_name(), location.line()); +} +#endif // __cpp_lib_source_location + +void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf /*spec*/) +{ + if (location.GetFileName() != nullptr) { + builder->AppendFormat( + "%v:%v", + location.GetFileName(), + location.GetLine()); + } else { + builder->AppendString("<unknown>"); + } +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h index 43b2b86fcd..0496a4e496 100644 --- a/library/cpp/yt/misc/source_location.h +++ b/library/cpp/yt/misc/source_location.h @@ -10,11 +10,11 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// +class TStringBuilderBase; + // 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 /*spec*/); #endif // __cpp_lib_source_location @@ -41,6 +41,10 @@ public: bool operator<(const TSourceLocation& other) const; bool operator==(const TSourceLocation& other) const; +#ifdef __cpp_lib_source_location + static TSourceLocation FromStd(const std::source_location& location); +#endif // __cpp_lib_source_location + private: const char* FileName_; int Line_; @@ -48,7 +52,13 @@ private: }; //! Defines a macro to record the current source location. +#ifdef __cpp_lib_source_location +#define FROM_HERE ::NYT::TSourceLocation::FromStd(std::source_location::current()) +#else #define FROM_HERE ::NYT::TSourceLocation(__FILE__, __LINE__) +#endif // __cpp_lib_source_location + +void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf spec); //////////////////////////////////////////////////////////////////////////////// |