diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/lwtrace/param_traits.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/lwtrace/param_traits.h')
-rw-r--r-- | library/cpp/lwtrace/param_traits.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/library/cpp/lwtrace/param_traits.h b/library/cpp/lwtrace/param_traits.h new file mode 100644 index 00000000000..a0faeb50dbb --- /dev/null +++ b/library/cpp/lwtrace/param_traits.h @@ -0,0 +1,66 @@ +#pragma once +#include "signature.h" + +#include <util/datetime/base.h> +#include <util/string/builder.h> + +#include <limits> + +#ifndef LWTRACE_DISABLE + +namespace NLWTrace { + + template <> + struct TParamTraits<TInstant> { + using TStoreType = double; + using TFuncParam = TInstant; + + inline static void ToString(TStoreType value, TString* out) { + *out = TParamConv<TStoreType>::ToString(value); + } + + inline static TStoreType ToStoreType(TInstant value) { + if (value == TInstant::Max()) { + return std::numeric_limits<TStoreType>::infinity(); + } else { + return static_cast<TStoreType>(value.MicroSeconds()) / 1000000.0; // seconds count + } + } + }; + + template <> + struct TParamTraits<TDuration> { + using TStoreType = double; + using TFuncParam = TDuration; + + inline static void ToString(TStoreType value, TString* out) { + *out = TParamConv<TStoreType>::ToString(value); + } + + inline static TStoreType ToStoreType(TDuration value) { + if (value == TDuration::Max()) { + return std::numeric_limits<TStoreType>::infinity(); + } else { + return static_cast<TStoreType>(value.MicroSeconds()) / 1000.0; // milliseconds count + } + } + }; + + // Param for enum with GENERATE_ENUM_SERIALIZATION enabled or operator<< implemented + template <class TEnum> + struct TEnumParamWithSerialization { + using TStoreType = typename TParamTraits<std::underlying_type_t<TEnum>>::TStoreType; + using TFuncParam = TEnum; + + inline static void ToString(TStoreType stored, TString* out) { + *out = TStringBuilder() << static_cast<TEnum>(stored) << " (" << stored << ")"; + } + + inline static TStoreType ToStoreType(TFuncParam v) { + return static_cast<TStoreType>(v); + } + }; + +} // namespace NLWTrace + +#endif // LWTRACE_DISABLE |