diff options
author | Alexander Rutkovsky <alexvru@mail.ru> | 2022-02-10 16:47:40 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:40 +0300 |
commit | 667a4ee7da2e004784b9c3cfab824a81e96f4d66 (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /library/cpp/actors/wilson | |
parent | f3646f91e0de459836a7800b9ce3e8dc57a2ab3a (diff) | |
download | ydb-667a4ee7da2e004784b9c3cfab824a81e96f4d66.tar.gz |
Restoring authorship annotation for Alexander Rutkovsky <alexvru@mail.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/actors/wilson')
-rw-r--r-- | library/cpp/actors/wilson/wilson_event.h | 198 | ||||
-rw-r--r-- | library/cpp/actors/wilson/wilson_trace.h | 262 | ||||
-rw-r--r-- | library/cpp/actors/wilson/ya.make | 4 |
3 files changed, 232 insertions, 232 deletions
diff --git a/library/cpp/actors/wilson/wilson_event.h b/library/cpp/actors/wilson/wilson_event.h index de3fbb8151..7d89c33b51 100644 --- a/library/cpp/actors/wilson/wilson_event.h +++ b/library/cpp/actors/wilson/wilson_event.h @@ -1,15 +1,15 @@ -#pragma once - -#include "wilson_trace.h" - +#pragma once + +#include "wilson_trace.h" + #include <library/cpp/string_utils/base64/base64.h> - + #include <library/cpp/actors/core/log.h> - -namespace NWilson { -#if !defined(_win_) -// works only for those compilers, who trait C++ as ISO IEC 14882, not their own standard - + +namespace NWilson { +#if !defined(_win_) +// works only for those compilers, who trait C++ as ISO IEC 14882, not their own standard + #define __UNROLL_PARAMS_8(N, F, X, ...) \ F(X, N - 8) \ __UNROLL_PARAMS_7(N, F, ##__VA_ARGS__) @@ -32,39 +32,39 @@ namespace NWilson { F(X, N - 2) \ __UNROLL_PARAMS_1(N, F, ##__VA_ARGS__) #define __UNROLL_PARAMS_1(N, F, X) F(X, N - 1) -#define __UNROLL_PARAMS_0(N, F) -#define __EX(...) __VA_ARGS__ -#define __NUM_PARAMS(...) __NUM_PARAMS_SELECT_N(__VA_ARGS__, __NUM_PARAMS_SEQ) -#define __NUM_PARAMS_SELECT_N(...) __EX(__NUM_PARAMS_SELECT(__VA_ARGS__)) -#define __NUM_PARAMS_SELECT(X, _1, _2, _3, _4, _5, _6, _7, _8, N, ...) N -#define __NUM_PARAMS_SEQ 8, 7, 6, 5, 4, 3, 2, 1, 0, ERROR +#define __UNROLL_PARAMS_0(N, F) +#define __EX(...) __VA_ARGS__ +#define __NUM_PARAMS(...) __NUM_PARAMS_SELECT_N(__VA_ARGS__, __NUM_PARAMS_SEQ) +#define __NUM_PARAMS_SELECT_N(...) __EX(__NUM_PARAMS_SELECT(__VA_ARGS__)) +#define __NUM_PARAMS_SELECT(X, _1, _2, _3, _4, _5, _6, _7, _8, N, ...) N +#define __NUM_PARAMS_SEQ 8, 7, 6, 5, 4, 3, 2, 1, 0, ERROR #define __CAT(X, Y) X##Y -#define __UNROLL_PARAMS_N(N, F, ...) __EX(__CAT(__UNROLL_PARAMS_, N)(N, F, ##__VA_ARGS__)) -#define __UNROLL_PARAMS(F, ...) __UNROLL_PARAMS_N(__NUM_PARAMS(X, ##__VA_ARGS__), F, ##__VA_ARGS__) -#define __EX2(F, X, INDEX) __INVOKE(F, __EX X, INDEX) -#define __INVOKE(F, ...) F(__VA_ARGS__) - -#define __DECLARE_PARAM(X, INDEX) __EX2(__DECLARE_PARAM_X, X, INDEX) +#define __UNROLL_PARAMS_N(N, F, ...) __EX(__CAT(__UNROLL_PARAMS_, N)(N, F, ##__VA_ARGS__)) +#define __UNROLL_PARAMS(F, ...) __UNROLL_PARAMS_N(__NUM_PARAMS(X, ##__VA_ARGS__), F, ##__VA_ARGS__) +#define __EX2(F, X, INDEX) __INVOKE(F, __EX X, INDEX) +#define __INVOKE(F, ...) F(__VA_ARGS__) + +#define __DECLARE_PARAM(X, INDEX) __EX2(__DECLARE_PARAM_X, X, INDEX) #define __DECLARE_PARAM_X(TYPE, NAME, INDEX) \ static const struct T##NAME##Param \ : ::NWilson::TParamBinder<INDEX, TYPE> { \ T##NAME##Param() { \ } \ - using ::NWilson::TParamBinder<INDEX, TYPE>::operator=; \ - } NAME; - -#define __TUPLE_PARAM(X, INDEX) __EX2(__TUPLE_PARAM_X, X, INDEX) -#define __TUPLE_PARAM_X(TYPE, NAME, INDEX) TYPE, - -#define __OUTPUT_PARAM(X, INDEX) __EX2(__OUTPUT_PARAM_X, X, INDEX) -#define __OUTPUT_PARAM_X(TYPE, NAME, INDEX) str << (INDEX ? ", " : "") << #NAME << "# " << std::get<INDEX>(ParamPack); - + using ::NWilson::TParamBinder<INDEX, TYPE>::operator=; \ + } NAME; + +#define __TUPLE_PARAM(X, INDEX) __EX2(__TUPLE_PARAM_X, X, INDEX) +#define __TUPLE_PARAM_X(TYPE, NAME, INDEX) TYPE, + +#define __OUTPUT_PARAM(X, INDEX) __EX2(__OUTPUT_PARAM_X, X, INDEX) +#define __OUTPUT_PARAM_X(TYPE, NAME, INDEX) str << (INDEX ? ", " : "") << #NAME << "# " << std::get<INDEX>(ParamPack); + #define __FILL_PARAM(P, INDEX) \ do { \ const auto& boundParam = (NParams::P); \ boundParam.Apply(event.ParamPack); \ } while (false); - + #define DECLARE_WILSON_EVENT(EVENT_NAME, ...) \ namespace N##EVENT_NAME##Params { \ __UNROLL_PARAMS(__DECLARE_PARAM, ##__VA_ARGS__) \ @@ -81,38 +81,38 @@ namespace NWilson { __UNROLL_PARAMS(__OUTPUT_PARAM, ##__VA_ARGS__) \ str << "}"; \ } \ - }; - + }; + template <size_t INDEX, typename T> - class TBoundParam { - mutable T Value; - - public: - TBoundParam(T&& value) - : Value(std::move(value)) + class TBoundParam { + mutable T Value; + + public: + TBoundParam(T&& value) + : Value(std::move(value)) { } - + template <typename TParamPack> - void Apply(TParamPack& pack) const { - std::get<INDEX>(pack) = std::move(Value); - } - }; - + void Apply(TParamPack& pack) const { + std::get<INDEX>(pack) = std::move(Value); + } + }; + template <size_t INDEX, typename T> - struct TParamBinder { + struct TParamBinder { template <typename TValue> - TBoundParam<INDEX, T> operator=(const TValue& value) const { - return TBoundParam<INDEX, T>(TValue(value)); - } - + TBoundParam<INDEX, T> operator=(const TValue& value) const { + return TBoundParam<INDEX, T>(TValue(value)); + } + template <typename TValue> - TBoundParam<INDEX, T> operator=(TValue&& value) const { - return TBoundParam<INDEX, T>(std::move(value)); - } - }; - -// generate wilson event having parent TRACE_ID and span TRACE_ID to become parent of logged event + TBoundParam<INDEX, T> operator=(TValue&& value) const { + return TBoundParam<INDEX, T>(std::move(value)); + } + }; + +// generate wilson event having parent TRACE_ID and span TRACE_ID to become parent of logged event #define WILSON_TRACE(CTX, TRACE_ID, EVENT_NAME, ...) \ if (::NWilson::TraceEnabled(CTX)) { \ ::NWilson::TTraceId* __traceId = (TRACE_ID); \ @@ -121,17 +121,17 @@ namespace NWilson { T##EVENT_NAME event; \ namespace NParams = N##EVENT_NAME##Params; \ __UNROLL_PARAMS(__FILL_PARAM, ##__VA_ARGS__) \ - ::NWilson::TraceEvent((CTX), __traceId, event, now); \ + ::NWilson::TraceEvent((CTX), __traceId, event, now); \ } \ } - - inline ui32 GetNodeId(const NActors::TActorSystem& actorSystem) { - return actorSystem.NodeId; - } - inline ui32 GetNodeId(const NActors::TActivationContext& ac) { - return GetNodeId(*ac.ExecutorThread.ActorSystem); - } - + + inline ui32 GetNodeId(const NActors::TActorSystem& actorSystem) { + return actorSystem.NodeId; + } + inline ui32 GetNodeId(const NActors::TActivationContext& ac) { + return GetNodeId(*ac.ExecutorThread.ActorSystem); + } + constexpr ui32 WilsonComponentId = 430; // kikimrservices: wilson template <typename TActorSystem> @@ -142,40 +142,40 @@ namespace NWilson { template <typename TActorSystem, typename TEvent> void TraceEvent(const TActorSystem& actorSystem, TTraceId* traceId, TEvent&& event, TInstant timestamp) { - // ensure that we are not using obsolete TraceId - traceId->CheckConsistency(); - - // store parent id (for logging) and generate child trace id - TTraceId parentTraceId(std::move(*traceId)); - *traceId = parentTraceId.Span(); - - // create encoded string buffer containing timestamp - const ui64 timestampValue = timestamp.GetValue(); - const size_t base64size = Base64EncodeBufSize(sizeof(timestampValue)); - char base64[base64size]; + // ensure that we are not using obsolete TraceId + traceId->CheckConsistency(); + + // store parent id (for logging) and generate child trace id + TTraceId parentTraceId(std::move(*traceId)); + *traceId = parentTraceId.Span(); + + // create encoded string buffer containing timestamp + const ui64 timestampValue = timestamp.GetValue(); + const size_t base64size = Base64EncodeBufSize(sizeof(timestampValue)); + char base64[base64size]; char* end = Base64Encode(base64, reinterpret_cast<const ui8*>(×tampValue), sizeof(timestampValue)); - - // cut trailing padding character to save some space - Y_VERIFY(end > base64 && end[-1] == '='); - --end; - - // generate log record + + // cut trailing padding character to save some space + Y_VERIFY(end > base64 && end[-1] == '='); + --end; + + // generate log record TString finalMessage; TStringOutput s(finalMessage); - s << GetNodeId(actorSystem) << " " << TStringBuf(base64, end) << " "; - traceId->Output(s, parentTraceId); - s << " "; - event.Output(s); - - // output wilson event FIXME: special facility for wilson events w/binary serialization + s << GetNodeId(actorSystem) << " " << TStringBuf(base64, end) << " "; + traceId->Output(s, parentTraceId); + s << " "; + event.Output(s); + + // output wilson event FIXME: special facility for wilson events w/binary serialization NActors::MemLogAdapter(actorSystem, NActors::NLog::PRI_DEBUG, WilsonComponentId, std::move(finalMessage)); - } - -#else - -#define DECLARE_WILSON_EVENT(...) -#define WILSON_TRACE(...) - -#endif - -} // NWilson + } + +#else + +#define DECLARE_WILSON_EVENT(...) +#define WILSON_TRACE(...) + +#endif + +} // NWilson diff --git a/library/cpp/actors/wilson/wilson_trace.h b/library/cpp/actors/wilson/wilson_trace.h index 7648915b95..3d1ca50562 100644 --- a/library/cpp/actors/wilson/wilson_trace.h +++ b/library/cpp/actors/wilson/wilson_trace.h @@ -1,161 +1,161 @@ -#pragma once - +#pragma once + #include <library/cpp/string_utils/base64/base64.h> - -#include <util/stream/output.h> -#include <util/random/random.h> - -#include <util/string/printf.h> - -namespace NWilson { - class TTraceId { - ui64 TraceId; // Random id of topmost client request - ui64 SpanId; // Span id of part of request currently being executed - - private: - TTraceId(ui64 traceId, ui64 spanId) - : TraceId(traceId) - , SpanId(spanId) + +#include <util/stream/output.h> +#include <util/random/random.h> + +#include <util/string/printf.h> + +namespace NWilson { + class TTraceId { + ui64 TraceId; // Random id of topmost client request + ui64 SpanId; // Span id of part of request currently being executed + + private: + TTraceId(ui64 traceId, ui64 spanId) + : TraceId(traceId) + , SpanId(spanId) { } - - static ui64 GenerateTraceId() { - ui64 traceId = 0; - while (!traceId) { - traceId = RandomNumber<ui64>(); - } - return traceId; - } - - static ui64 GenerateSpanId() { - return RandomNumber<ui64>(); - } - - public: - using TSerializedTraceId = char[2 * sizeof(ui64)]; - - public: - TTraceId() - : TraceId(0) - , SpanId(0) + + static ui64 GenerateTraceId() { + ui64 traceId = 0; + while (!traceId) { + traceId = RandomNumber<ui64>(); + } + return traceId; + } + + static ui64 GenerateSpanId() { + return RandomNumber<ui64>(); + } + + public: + using TSerializedTraceId = char[2 * sizeof(ui64)]; + + public: + TTraceId() + : TraceId(0) + , SpanId(0) { } - + explicit TTraceId(ui64 traceId) : TraceId(traceId) , SpanId(0) { } - TTraceId(const TSerializedTraceId& in) + TTraceId(const TSerializedTraceId& in) : TraceId(reinterpret_cast<const ui64*>(in)[0]) , SpanId(reinterpret_cast<const ui64*>(in)[1]) { } - - // allow move semantic - TTraceId(TTraceId&& other) - : TraceId(other.TraceId) - , SpanId(other.SpanId) - { - other.TraceId = 0; - other.SpanId = 1; // explicitly mark invalid - } - + + // allow move semantic + TTraceId(TTraceId&& other) + : TraceId(other.TraceId) + , SpanId(other.SpanId) + { + other.TraceId = 0; + other.SpanId = 1; // explicitly mark invalid + } + TTraceId& operator=(TTraceId&& other) { - TraceId = other.TraceId; - SpanId = other.SpanId; - other.TraceId = 0; - other.SpanId = 1; // explicitly mark invalid - return *this; - } - - // do not allow implicit copy of trace id - TTraceId(const TTraceId& other) = delete; + TraceId = other.TraceId; + SpanId = other.SpanId; + other.TraceId = 0; + other.SpanId = 1; // explicitly mark invalid + return *this; + } + + // do not allow implicit copy of trace id + TTraceId(const TTraceId& other) = delete; TTraceId& operator=(const TTraceId& other) = delete; - - static TTraceId NewTraceId() { - return TTraceId(GenerateTraceId(), 0); - } - - // create separate branch from this point - TTraceId SeparateBranch() const { - return Clone(); - } - - TTraceId Clone() const { - return TTraceId(TraceId, SpanId); - } - - TTraceId Span() const { - return *this ? TTraceId(TraceId, GenerateSpanId()) : TTraceId(); - } - + + static TTraceId NewTraceId() { + return TTraceId(GenerateTraceId(), 0); + } + + // create separate branch from this point + TTraceId SeparateBranch() const { + return Clone(); + } + + TTraceId Clone() const { + return TTraceId(TraceId, SpanId); + } + + TTraceId Span() const { + return *this ? TTraceId(TraceId, GenerateSpanId()) : TTraceId(); + } + ui64 GetTraceId() const { return TraceId; } - // Check if request tracing is enabled - operator bool() const { - return TraceId != 0; - } - - // Output trace id into a string stream + // Check if request tracing is enabled + operator bool() const { + return TraceId != 0; + } + + // Output trace id into a string stream void Output(IOutputStream& s, const TTraceId& parentTraceId) const { - union { - ui8 buffer[3 * sizeof(ui64)]; - struct { - ui64 traceId; - ui64 spanId; - ui64 parentSpanId; - } x; - }; - - x.traceId = TraceId; - x.spanId = SpanId; - x.parentSpanId = parentTraceId.SpanId; - - const size_t base64size = Base64EncodeBufSize(sizeof(x)); - char base64[base64size]; + union { + ui8 buffer[3 * sizeof(ui64)]; + struct { + ui64 traceId; + ui64 spanId; + ui64 parentSpanId; + } x; + }; + + x.traceId = TraceId; + x.spanId = SpanId; + x.parentSpanId = parentTraceId.SpanId; + + const size_t base64size = Base64EncodeBufSize(sizeof(x)); + char base64[base64size]; char* end = Base64Encode(base64, buffer, sizeof(x)); - s << TStringBuf(base64, end); - } - - // output just span id into stream + s << TStringBuf(base64, end); + } + + // output just span id into stream void OutputSpanId(IOutputStream& s) const { - const size_t base64size = Base64EncodeBufSize(sizeof(SpanId)); - char base64[base64size]; + const size_t base64size = Base64EncodeBufSize(sizeof(SpanId)); + char base64[base64size]; char* end = Base64Encode(base64, reinterpret_cast<const ui8*>(&SpanId), sizeof(SpanId)); - - // cut trailing padding character - Y_VERIFY(end > base64 && end[-1] == '='); - --end; - - s << TStringBuf(base64, end); - } - - void CheckConsistency() { - // if TraceId is zero, then SpanId must be zero too - Y_VERIFY_DEBUG(*this || !SpanId); - } - + + // cut trailing padding character + Y_VERIFY(end > base64 && end[-1] == '='); + --end; + + s << TStringBuf(base64, end); + } + + void CheckConsistency() { + // if TraceId is zero, then SpanId must be zero too + Y_VERIFY_DEBUG(*this || !SpanId); + } + friend bool operator==(const TTraceId& x, const TTraceId& y) { - return x.TraceId == y.TraceId && x.SpanId == y.SpanId; - } - + return x.TraceId == y.TraceId && x.SpanId == y.SpanId; + } + TString ToString() const { - return Sprintf("%" PRIu64 ":%" PRIu64, TraceId, SpanId); - } - - bool IsFromSameTree(const TTraceId& other) const { - return TraceId == other.TraceId; - } - + return Sprintf("%" PRIu64 ":%" PRIu64, TraceId, SpanId); + } + + bool IsFromSameTree(const TTraceId& other) const { + return TraceId == other.TraceId; + } + void Serialize(TSerializedTraceId* out) { ui64* p = reinterpret_cast<ui64*>(*out); - p[0] = TraceId; - p[1] = SpanId; - } - }; - + p[0] = TraceId; + p[1] = SpanId; + } + }; + } diff --git a/library/cpp/actors/wilson/ya.make b/library/cpp/actors/wilson/ya.make index 036839c0da..e371f5061d 100644 --- a/library/cpp/actors/wilson/ya.make +++ b/library/cpp/actors/wilson/ya.make @@ -1,4 +1,4 @@ -LIBRARY() +LIBRARY() PEERDIR( library/cpp/string_utils/base64 @@ -11,4 +11,4 @@ SRCS( wilson_trace.h ) -END() +END() |