diff options
author | yegorskii <yegorskii@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
commit | 6c7ed19fb4e807d81f39d5b370b1dba604558a17 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp | |
parent | 7902ff9c26a2eacba73e7137a81aed2df9b3e9c1 (diff) | |
download | ydb-6c7ed19fb4e807d81f39d5b370b1dba604558a17.tar.gz |
Restoring authorship annotation for <yegorskii@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/actors/core/log_settings.cpp | 12 | ||||
-rw-r--r-- | library/cpp/actors/core/log_settings.h | 8 | ||||
-rw-r--r-- | library/cpp/actors/core/log_ut.cpp | 112 | ||||
-rw-r--r-- | library/cpp/actors/core/mon.h | 24 | ||||
-rw-r--r-- | library/cpp/logger/system.cpp | 10 | ||||
-rw-r--r-- | library/cpp/lwtrace/control.cpp | 194 | ||||
-rw-r--r-- | library/cpp/lwtrace/control.h | 94 | ||||
-rw-r--r-- | library/cpp/lwtrace/log_shuttle.h | 106 | ||||
-rw-r--r-- | library/cpp/lwtrace/lwprobe.h | 4 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/mon_lwtrace.cpp | 12 | ||||
-rw-r--r-- | library/cpp/lwtrace/preprocessor.h | 6 | ||||
-rw-r--r-- | library/cpp/lwtrace/probes.h | 4 | ||||
-rw-r--r-- | library/cpp/lwtrace/protos/lwtrace.proto | 254 | ||||
-rw-r--r-- | library/cpp/lwtrace/protos/ya.make | 4 | ||||
-rw-r--r-- | library/cpp/lwtrace/shuttle.h | 30 | ||||
-rw-r--r-- | library/cpp/lwtrace/signature.h | 328 | ||||
-rw-r--r-- | library/cpp/lwtrace/trace.cpp | 20 | ||||
-rw-r--r-- | library/cpp/lwtrace/trace_ut.cpp | 330 | ||||
-rw-r--r-- | library/cpp/lwtrace/ya.make | 6 |
19 files changed, 779 insertions, 779 deletions
diff --git a/library/cpp/actors/core/log_settings.cpp b/library/cpp/actors/core/log_settings.cpp index e49abf4717..f52f2fc5d2 100644 --- a/library/cpp/actors/core/log_settings.cpp +++ b/library/cpp/actors/core/log_settings.cpp @@ -6,11 +6,11 @@ namespace NActors { namespace NLog { TSettings::TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, EComponent minVal, EComponent maxVal, EComponentToStringFunc func, - EPriority defPriority, EPriority defSamplingPriority, - ui32 defSamplingRate, ui64 timeThresholdMs) + EPriority defPriority, EPriority defSamplingPriority, + ui32 defSamplingRate, ui64 timeThresholdMs) : LoggerActorId(loggerActorId) , LoggerComponent(loggerComponent) - , TimeThresholdMs(timeThresholdMs) + , TimeThresholdMs(timeThresholdMs) , AllowDrop(true) , ThrottleDelay(TDuration::MilliSeconds(100)) , MinVal(0) @@ -28,11 +28,11 @@ namespace NActors { } TSettings::TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, - EPriority defPriority, EPriority defSamplingPriority, - ui32 defSamplingRate, ui64 timeThresholdMs) + EPriority defPriority, EPriority defSamplingPriority, + ui32 defSamplingRate, ui64 timeThresholdMs) : LoggerActorId(loggerActorId) , LoggerComponent(loggerComponent) - , TimeThresholdMs(timeThresholdMs) + , TimeThresholdMs(timeThresholdMs) , AllowDrop(true) , ThrottleDelay(TDuration::MilliSeconds(100)) , MinVal(0) diff --git a/library/cpp/actors/core/log_settings.h b/library/cpp/actors/core/log_settings.h index ebb689be09..7fe4504edd 100644 --- a/library/cpp/actors/core/log_settings.h +++ b/library/cpp/actors/core/log_settings.h @@ -100,12 +100,12 @@ namespace NActors { // YOURTYPE_Name for you. TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, EComponent minVal, EComponent maxVal, EComponentToStringFunc func, - EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, - ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); + EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, + ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, - EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, - ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); + EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, + ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); void Append(EComponent minVal, EComponent maxVal, EComponentToStringFunc func); diff --git a/library/cpp/actors/core/log_ut.cpp b/library/cpp/actors/core/log_ut.cpp index d742357e3f..09b5f88ea2 100644 --- a/library/cpp/actors/core/log_ut.cpp +++ b/library/cpp/actors/core/log_ut.cpp @@ -22,19 +22,19 @@ namespace { return s; } - TIntrusivePtr<TSettings> DroppingSettings(ui64 timeThresholdMs) { - auto loggerId = TActorId{0, "Logger"}; - auto s = MakeIntrusive<TSettings>( - loggerId, - 0, - EPriority::PRI_TRACE, - EPriority::PRI_DEBUG, - (ui32)0, - timeThresholdMs); - s->Append(0, 1, ServiceToString); - return s; - } - + TIntrusivePtr<TSettings> DroppingSettings(ui64 timeThresholdMs) { + auto loggerId = TActorId{0, "Logger"}; + auto s = MakeIntrusive<TSettings>( + loggerId, + 0, + EPriority::PRI_TRACE, + EPriority::PRI_DEBUG, + (ui32)0, + timeThresholdMs); + s->Append(0, 1, ServiceToString); + return s; + } + class TMockBackend: public TLogBackend { public: using TWriteImpl = std::function<void(const TLogRecord&)>; @@ -68,30 +68,30 @@ namespace { }; struct TFixture { - TFixture( - TIntrusivePtr<TSettings> settings, - TMockBackend::TWriteImpl writeImpl = ThrowAlways) - { + TFixture( + TIntrusivePtr<TSettings> settings, + TMockBackend::TWriteImpl writeImpl = ThrowAlways) + { Runtime.Initialize(); LogBackend.reset(new TMockBackend{writeImpl}); - LoggerActor = Runtime.Register(new TLoggerActor{settings, LogBackend, Counters}); + LoggerActor = Runtime.Register(new TLoggerActor{settings, LogBackend, Counters}); Runtime.SetScheduledEventFilter([] (auto&&, auto&&, auto&&, auto) { return false; }); } - TFixture(TMockBackend::TWriteImpl writeImpl = ThrowAlways) - : TFixture(DefaultSettings(), writeImpl) - {} - + TFixture(TMockBackend::TWriteImpl writeImpl = ThrowAlways) + : TFixture(DefaultSettings(), writeImpl) + {} + void WriteLog() { Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(TInstant::Zero(), TLevel{EPrio::Emerg}, 0, "foo")}); } - void WriteLog(TInstant ts) { - Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{EPrio::Emerg}, 0, "foo")}); - } - + void WriteLog(TInstant ts) { + Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{EPrio::Emerg}, 0, "foo")}); + } + void Wakeup() { Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvents::TEvWakeup}); } @@ -152,34 +152,34 @@ Y_UNIT_TEST_SUITE(TLoggerActorTest) { UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT); } - - Y_UNIT_TEST(ShouldObeyTimeThresholdMsWhenOverloaded) { - TFixture test{DroppingSettings(5000)}; - - TVector<TString> messages; - auto acceptWrites = [&] (const TLogRecord& r) { - messages.emplace_back(r.Data, r.Len); - }; - - test.LogBackend->SetWriteImpl(acceptWrites); - test.Wakeup(); - - const auto COUNT = 11; - for (auto i = 0; i < COUNT; ++i) { - test.WriteLog(); - } - - UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT); - - test.Runtime.AdvanceCurrentTime(TDuration::Seconds(20)); - auto now = test.Runtime.GetCurrentTime(); - - test.WriteLog(now - TDuration::Seconds(5)); - - UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); - - test.WriteLog(now - TDuration::Seconds(6)); - - UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); - } + + Y_UNIT_TEST(ShouldObeyTimeThresholdMsWhenOverloaded) { + TFixture test{DroppingSettings(5000)}; + + TVector<TString> messages; + auto acceptWrites = [&] (const TLogRecord& r) { + messages.emplace_back(r.Data, r.Len); + }; + + test.LogBackend->SetWriteImpl(acceptWrites); + test.Wakeup(); + + const auto COUNT = 11; + for (auto i = 0; i < COUNT; ++i) { + test.WriteLog(); + } + + UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT); + + test.Runtime.AdvanceCurrentTime(TDuration::Seconds(20)); + auto now = test.Runtime.GetCurrentTime(); + + test.WriteLog(now - TDuration::Seconds(5)); + + UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); + + test.WriteLog(now - TDuration::Seconds(6)); + + UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); + } } diff --git a/library/cpp/actors/core/mon.h b/library/cpp/actors/core/mon.h index 3854356fa8..c450f2338e 100644 --- a/library/cpp/actors/core/mon.h +++ b/library/cpp/actors/core/mon.h @@ -88,14 +88,14 @@ namespace NActors { { } - TEvRemoteHttpInfo(const TString& query, HTTP_METHOD method) - : Query(query) - , Method(method) - { - } - + TEvRemoteHttpInfo(const TString& query, HTTP_METHOD method) + : Query(query) + , Method(method) + { + } + TString Query; - HTTP_METHOD Method; + HTTP_METHOD Method; TString PathInfo() const { const size_t pos = Query.find('?'); @@ -126,11 +126,11 @@ namespace NActors { static IEventBase* Load(TEventSerializedData* bufs) { return new TEvRemoteHttpInfo(bufs->GetString()); } - - HTTP_METHOD GetMethod() const - { - return Method; - } + + HTTP_METHOD GetMethod() const + { + return Method; + } }; struct TEvRemoteHttpInfoRes: public NActors::TEventBase<TEvRemoteHttpInfoRes, RemoteHttpInfoRes> { diff --git a/library/cpp/logger/system.cpp b/library/cpp/logger/system.cpp index 172719c716..42233f63d2 100644 --- a/library/cpp/logger/system.cpp +++ b/library/cpp/logger/system.cpp @@ -4,7 +4,7 @@ #include <util/system/yassert.h> #include <util/system/defaults.h> #include <util/generic/singleton.h> -#include <util/generic/utility.h> +#include <util/generic/utility.h> #if defined(_unix_) #include <syslog.h> @@ -64,12 +64,12 @@ void TSysLogBackend::ReopenLog() { } int TSysLogBackend::ELogPriority2SyslogPriority(ELogPriority priority) { -#if defined(_unix_) - return Min(int(priority), (int)LOG_PRIMASK); -#else +#if defined(_unix_) + return Min(int(priority), (int)LOG_PRIMASK); +#else // trivial conversion return int(priority); -#endif +#endif } namespace { diff --git a/library/cpp/lwtrace/control.cpp b/library/cpp/lwtrace/control.cpp index ffed939922..d9404ff269 100644 --- a/library/cpp/lwtrace/control.cpp +++ b/library/cpp/lwtrace/control.cpp @@ -1,97 +1,97 @@ -#include "probes.h" - -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> - -#include <util/generic/string.h> - -namespace NLWTrace { - -LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER); - -TProbeMap TManager::GetProbesMap() { - class TProbeReader - { - private: - TProbeMap& Result; - - public: - TProbeReader(TProbeMap& result) - : Result(result) - {} - - void Push(NLWTrace::TProbe* probe) - { - Result[std::make_pair(probe->Event.Name, probe->Event.GetProvider())] = probe; - } - }; - - TProbeMap result; - - auto reader = TProbeReader(result); - ReadProbes(reader); - return result; -} - -void TManager::CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit) -{ - msg.SetIsTraced(orbit.HasShuttles()); -} - -bool TManager::HandleTraceRequest( - const TTraceRequest& msg, - TOrbit& orbit) -{ - if (!msg.GetIsTraced()) { - return false; - } - TParams params; - SerializingExecutor->Execute(orbit, params); - return true; -} - -TTraceDeserializeStatus TManager::HandleTraceResponse( - const TTraceResponse& msg, - const TProbeMap& probesMap, - TOrbit& orbit, - i64 timeOffset, - double timeScale) -{ - TTraceDeserializeStatus result; - if (!msg.GetTrace().GetEvents().size()) { - return result; - } - - ui64 prev = EpochNanosecondsToCycles( - msg.GetTrace().GetEvents()[0].GetTimestampNanosec()); - - for (auto& v : msg.GetTrace().GetEvents()) { - auto it = probesMap.find(std::make_pair(v.GetName(), v.GetProvider())); - if (it != probesMap.end()) { - TProbe* probe = it->second; - TParams params; - if(!probe->Event.Signature.DeserializeFromPb(params, v.GetParams())) { - LWTRACK(DeserializationError, orbit, probe->Event.Name, probe->Event.GetProvider()); - result.AddFailedEventName(v.GetName()); - } else { - ui64 timestamp = EpochNanosecondsToCycles(v.GetTimestampNanosec()); - orbit.AddProbe( - probe, - params, - prev + (timestamp-prev)*timeScale + timeOffset); - probe->Event.Signature.DestroyParams(params); - prev = timestamp; - } - } else { - result.AddFailedEventName(v.GetName()); - } - } - return result; -} - -void TManager::CreateTraceResponse(TTraceResponse& msg, TOrbit& orbit) -{ - orbit.Serialize(0, *msg.MutableTrace()); -} - -} - +#include "probes.h" + +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> + +#include <util/generic/string.h> + +namespace NLWTrace { + +LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER); + +TProbeMap TManager::GetProbesMap() { + class TProbeReader + { + private: + TProbeMap& Result; + + public: + TProbeReader(TProbeMap& result) + : Result(result) + {} + + void Push(NLWTrace::TProbe* probe) + { + Result[std::make_pair(probe->Event.Name, probe->Event.GetProvider())] = probe; + } + }; + + TProbeMap result; + + auto reader = TProbeReader(result); + ReadProbes(reader); + return result; +} + +void TManager::CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit) +{ + msg.SetIsTraced(orbit.HasShuttles()); +} + +bool TManager::HandleTraceRequest( + const TTraceRequest& msg, + TOrbit& orbit) +{ + if (!msg.GetIsTraced()) { + return false; + } + TParams params; + SerializingExecutor->Execute(orbit, params); + return true; +} + +TTraceDeserializeStatus TManager::HandleTraceResponse( + const TTraceResponse& msg, + const TProbeMap& probesMap, + TOrbit& orbit, + i64 timeOffset, + double timeScale) +{ + TTraceDeserializeStatus result; + if (!msg.GetTrace().GetEvents().size()) { + return result; + } + + ui64 prev = EpochNanosecondsToCycles( + msg.GetTrace().GetEvents()[0].GetTimestampNanosec()); + + for (auto& v : msg.GetTrace().GetEvents()) { + auto it = probesMap.find(std::make_pair(v.GetName(), v.GetProvider())); + if (it != probesMap.end()) { + TProbe* probe = it->second; + TParams params; + if(!probe->Event.Signature.DeserializeFromPb(params, v.GetParams())) { + LWTRACK(DeserializationError, orbit, probe->Event.Name, probe->Event.GetProvider()); + result.AddFailedEventName(v.GetName()); + } else { + ui64 timestamp = EpochNanosecondsToCycles(v.GetTimestampNanosec()); + orbit.AddProbe( + probe, + params, + prev + (timestamp-prev)*timeScale + timeOffset); + probe->Event.Signature.DestroyParams(params); + prev = timestamp; + } + } else { + result.AddFailedEventName(v.GetName()); + } + } + return result; +} + +void TManager::CreateTraceResponse(TTraceResponse& msg, TOrbit& orbit) +{ + orbit.Serialize(0, *msg.MutableTrace()); +} + +} + diff --git a/library/cpp/lwtrace/control.h b/library/cpp/lwtrace/control.h index b85e8468be..16b24eafd2 100644 --- a/library/cpp/lwtrace/control.h +++ b/library/cpp/lwtrace/control.h @@ -3,7 +3,7 @@ #include "custom_action.h" #include "event.h" #include "log.h" -#include "log_shuttle.h" +#include "log_shuttle.h" #include "probe.h" #include <library/cpp/lwtrace/protos/lwtrace.pb.h> @@ -18,9 +18,9 @@ #include <util/generic/vector.h> namespace NLWTrace { - - using TProbeMap = THashMap<std::pair<TString, TString>, TProbe*>; - + + using TProbeMap = THashMap<std::pair<TString, TString>, TProbe*>; + // Interface for probe ownership management class IBox: public virtual TThrRefBase { private: @@ -203,38 +203,38 @@ namespace NLWTrace { void ToProtobuf(TLogPb& pb) const; }; - // Deserialization result. - // Either IsSuccess is true or FailedEventNames contains event names - // we were not able to deserialize. - struct TTraceDeserializeStatus - { - bool IsSuccess = true; - TVector<TString> FailedEventNames; - - void AddFailedEventName(const TString& name) - { - IsSuccess = false; - FailedEventNames.emplace_back(name); - } - }; - + // Deserialization result. + // Either IsSuccess is true or FailedEventNames contains event names + // we were not able to deserialize. + struct TTraceDeserializeStatus + { + bool IsSuccess = true; + TVector<TString> FailedEventNames; + + void AddFailedEventName(const TString& name) + { + IsSuccess = false; + FailedEventNames.emplace_back(name); + } + }; + // Just a registry of all active trace queries // Facade for all interactions with probes/traces class TManager: public TNonCopyable { private: TProbeRegistry& Registry; TMutex Mtx; - ui64 LastTraceIdx = 1; + ui64 LastTraceIdx = 1; typedef THashMap<TString, TSession*> TTraces; // traceId -> TSession TTraces Traces; bool DestructiveActionsAllowed; TCustomActionFactory CustomActionFactory; - THolder<TRunLogShuttleActionExecutor<TCyclicDepot>> SerializingExecutor; + THolder<TRunLogShuttleActionExecutor<TCyclicDepot>> SerializingExecutor; + + public: + static constexpr ui64 RemoteTraceIdx = 0; public: - static constexpr ui64 RemoteTraceIdx = 0; - - public: TManager(TProbeRegistry& registry, bool allowDestructiveActions); ~TManager(); bool HasTrace(const TString& id) const; @@ -324,28 +324,28 @@ namespace NLWTrace { return new T(probe, action, trace); }); } - - TProbeMap GetProbesMap(); - - void CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit); - - bool HandleTraceRequest( - const TTraceRequest& msg, - TOrbit& orbit); - - TTraceDeserializeStatus HandleTraceResponse( - const TTraceResponse& msg, - const TProbeMap& probesMap, - TOrbit& orbit, - i64 timeOffset = 0, - double timeScale = 1); - - void CreateTraceResponse( - TTraceResponse& msg, - TOrbit& orbit); - - bool IsTraced(TOrbit& orbit) { - return orbit.HasShuttle(TManager::RemoteTraceIdx); - } + + TProbeMap GetProbesMap(); + + void CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit); + + bool HandleTraceRequest( + const TTraceRequest& msg, + TOrbit& orbit); + + TTraceDeserializeStatus HandleTraceResponse( + const TTraceResponse& msg, + const TProbeMap& probesMap, + TOrbit& orbit, + i64 timeOffset = 0, + double timeScale = 1); + + void CreateTraceResponse( + TTraceResponse& msg, + TOrbit& orbit); + + bool IsTraced(TOrbit& orbit) { + return orbit.HasShuttle(TManager::RemoteTraceIdx); + } }; } diff --git a/library/cpp/lwtrace/log_shuttle.h b/library/cpp/lwtrace/log_shuttle.h index d3d5fe0bde..729a38615f 100644 --- a/library/cpp/lwtrace/log_shuttle.h +++ b/library/cpp/lwtrace/log_shuttle.h @@ -3,8 +3,8 @@ #include "log.h" #include "probe.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> - +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> + #include <util/system/spinlock.h> namespace NLWTrace { @@ -14,35 +14,35 @@ namespace NLWTrace { //////////////////////////////////////////////////////////////////////////////// struct THostTimeCalculator { - double K = 0; - ui64 B = 0; - + double K = 0; + ui64 B = 0; + THostTimeCalculator() { - TInstant now = TInstant::Now(); - ui64 tsNow = GetCycleCount(); - K = 1000000000 / NHPTimer::GetClockRate(); - B = now.NanoSeconds() - K * tsNow; - } - + TInstant now = TInstant::Now(); + ui64 tsNow = GetCycleCount(); + K = 1000000000 / NHPTimer::GetClockRate(); + B = now.NanoSeconds() - K * tsNow; + } + ui64 CyclesToEpochNanoseconds(ui64 cycles) const { - return K*cycles + B; - } - + return K*cycles + B; + } + ui64 EpochNanosecondsToCycles(ui64 ns) const { - return (ns - B) / K; - } - }; - + return (ns - B) / K; + } + }; + inline ui64 CyclesToEpochNanoseconds(ui64 cycles) { - return Singleton<THostTimeCalculator>()->CyclesToEpochNanoseconds(cycles); - } - + return Singleton<THostTimeCalculator>()->CyclesToEpochNanoseconds(cycles); + } + inline ui64 EpochNanosecondsToCycles(ui64 ns) { - return Singleton<THostTimeCalculator>()->EpochNanosecondsToCycles(ns); - } - - //////////////////////////////////////////////////////////////////////////////// - + return Singleton<THostTimeCalculator>()->EpochNanosecondsToCycles(ns); + } + + //////////////////////////////////////////////////////////////////////////////// + template <class TDepot> class TLogShuttle: public IShuttle { private: @@ -62,10 +62,10 @@ namespace NLWTrace { { } - bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) override; + bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) override; void DoEndOfTrack() override; void DoDrop() override; - void DoSerialize(TShuttleTrace& msg) override; + void DoSerialize(TShuttleTrace& msg) override; bool DoFork(TShuttlePtr& child) override; bool DoJoin(const TShuttlePtr& child) override; @@ -155,7 +155,7 @@ namespace NLWTrace { //////////////////////////////////////////////////////////////////////////////// template <class TDepot> - bool TLogShuttle<TDepot>::DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) { + bool TLogShuttle<TDepot>::DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) { with_lock (Lock) { if (TrackLog.Items.size() >= MaxTrackLength) { TrackLog.Truncated = true; @@ -168,7 +168,7 @@ namespace NLWTrace { if ((item->SavedParamsCount = probe->Event.Signature.ParamCount) > 0) { probe->Event.Signature.CloneParams(item->Params, params); } - item->TimestampCycles = timestamp ? timestamp : GetCycleCount(); + item->TimestampCycles = timestamp ? timestamp : GetCycleCount(); } return true; @@ -204,25 +204,25 @@ namespace NLWTrace { } template <class TDepot> - void TLogShuttle<TDepot>::DoSerialize(TShuttleTrace& msg) - { - with_lock (Lock) - { - if (!GetTrackLog().Items.size()) { - return ; - } - for (auto& record : GetTrackLog().Items) { - auto *rec = msg.AddEvents(); - rec->SetName(record.Probe->Event.Name); - rec->SetProvider(record.Probe->Event.GetProvider()); - rec->SetTimestampNanosec( - CyclesToEpochNanoseconds(record.TimestampCycles)); - record.Probe->Event.Signature.SerializeToPb(record.Params, *rec->MutableParams()); - } - } - } - - template <class TDepot> + void TLogShuttle<TDepot>::DoSerialize(TShuttleTrace& msg) + { + with_lock (Lock) + { + if (!GetTrackLog().Items.size()) { + return ; + } + for (auto& record : GetTrackLog().Items) { + auto *rec = msg.AddEvents(); + rec->SetName(record.Probe->Event.Name); + rec->SetProvider(record.Probe->Event.GetProvider()); + rec->SetTimestampNanosec( + CyclesToEpochNanoseconds(record.TimestampCycles)); + record.Probe->Event.Signature.SerializeToPb(record.Params, *rec->MutableParams()); + } + } + } + + template <class TDepot> TLogShuttle<TDepot>* TLogShuttleActionBase<TDepot>::Cast(const TShuttlePtr& shuttle) { return static_cast<TLogShuttle<TDepot>*>(shuttle.Get()); } @@ -247,7 +247,7 @@ namespace NLWTrace { , LastTrackId(lastTrackId) , LastSpanId(lastSpanId) { - ui64 size = Min<ui64>(Action.GetShuttlesCount() ? Action.GetShuttlesCount() : 1000, MaxShuttles); // Do not allow to allocate too much memory + ui64 size = Min<ui64>(Action.GetShuttlesCount() ? Action.GetShuttlesCount() : 1000, MaxShuttles); // Do not allow to allocate too much memory AllShuttles.reserve(size); Parking.reserve(size); for (ui64 i = 0; i < size; i++) { @@ -283,9 +283,9 @@ namespace NLWTrace { template <class TDepot> void TRunLogShuttleActionExecutor<TDepot>::RecordShuttle(TLogShuttle<TDepot>* shuttle) { - if (Depot == nullptr) { - return; - } + if (Depot == nullptr) { + return; + } typename TDepot::TAccessor a(*Depot); if (TTrackLog* trackLog = a.Add()) { *trackLog = shuttle->GetTrackLog(); diff --git a/library/cpp/lwtrace/lwprobe.h b/library/cpp/lwtrace/lwprobe.h index 021a580b2e..801fc3861b 100644 --- a/library/cpp/lwtrace/lwprobe.h +++ b/library/cpp/lwtrace/lwprobe.h @@ -61,8 +61,8 @@ namespace NLWTrace { signature.SerializeParamsFunc = &TUsrSign::SerializeParams; signature.CloneParamsFunc = &TUsrSign::CloneParams; signature.DestroyParamsFunc = &TUsrSign::DestroyParams; - signature.SerializeToPbFunc = &TUsrSign::SerializeToPb; - signature.DeserializeFromPbFunc = &TUsrSign::DeserializeFromPb; + signature.SerializeToPbFunc = &TUsrSign::SerializeToPb; + signature.DeserializeFromPbFunc = &TUsrSign::DeserializeFromPb; // register probe in global registry Register(*Singleton<NLWTrace::TProbeRegistry>()); diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.cpp b/library/cpp/lwtrace/mon/mon_lwtrace.cpp index 4ca9ff15f0..a61ee9ce22 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.cpp +++ b/library/cpp/lwtrace/mon/mon_lwtrace.cpp @@ -511,9 +511,9 @@ struct TAdHocTraceConfig { } auto block = Cfg.GetBlocks(blockIdx); auto pdesc = block.GetProbeDesc(); - if (pdesc.GetProvider()) { + if (pdesc.GetProvider()) { ss << "." << pdesc.GetProvider() << "." << pdesc.GetName(); - } else if (pdesc.GetGroup()) { + } else if (pdesc.GetGroup()) { ss << ".Group." << pdesc.GetGroup(); } // TODO[serxa]: handle predicate @@ -525,10 +525,10 @@ struct TAdHocTraceConfig { if (ls.GetIgnore()) { ss << "-i"; } - if (ls.GetShuttlesCount()) { + if (ls.GetShuttlesCount()) { ss << "-s" << ls.GetShuttlesCount(); } - if (ls.GetMaxTrackLength()) { + if (ls.GetMaxTrackLength()) { ss << "-t" << ls.GetMaxTrackLength(); } } else if (action.HasEditLogShuttleAction()) { @@ -542,10 +542,10 @@ struct TAdHocTraceConfig { } } } - if (Cfg.GetPerThreadLogSize()) { + if (Cfg.GetPerThreadLogSize()) { ss << ".l" << Cfg.GetPerThreadLogSize(); } - if (Cfg.GetLogDurationUs()) { + if (Cfg.GetLogDurationUs()) { ui64 logDurationUs = Cfg.GetLogDurationUs(); if (logDurationUs % (60 * 1000 * 1000) == 0) ss << ".d" << logDurationUs / (60 * 1000 * 1000) << "m"; diff --git a/library/cpp/lwtrace/preprocessor.h b/library/cpp/lwtrace/preprocessor.h index 1945a55c18..40865467b2 100644 --- a/library/cpp/lwtrace/preprocessor.h +++ b/library/cpp/lwtrace/preprocessor.h @@ -172,9 +172,9 @@ namespace NLWTrace { /* ParamCount */ ::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::ParamCount, \ /* SerializeParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::SerializeParams, \ /* CloneParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::CloneParams, \ - /* DestroyParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DestroyParams, \ - /* SerializeToPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::SerializeToPb, \ - /* DeserializeFromPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DeserializeFromPb\ + /* DestroyParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DestroyParams, \ + /* SerializeToPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::SerializeToPb, \ + /* DeserializeFromPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DeserializeFromPb\ } // Macro for TEvent POD structure static initialization diff --git a/library/cpp/lwtrace/probes.h b/library/cpp/lwtrace/probes.h index 4adcf7d00d..68810bd118 100644 --- a/library/cpp/lwtrace/probes.h +++ b/library/cpp/lwtrace/probes.h @@ -7,8 +7,8 @@ TYPES(double, double, double, double), \ NAMES("probeShare", "probeMinMs", "probeMaxMs", "probeAvgMs")) \ PROBE(DeserializationError, GROUPS("LWTraceError"), \ - TYPES(TString, TString), \ - NAMES("probeName", "providerName")) \ + TYPES(TString, TString), \ + NAMES("probeName", "providerName")) \ PROBE(Fork, GROUPS(), \ TYPES(ui64), \ NAMES("spanId")) \ diff --git a/library/cpp/lwtrace/protos/lwtrace.proto b/library/cpp/lwtrace/protos/lwtrace.proto index bdf6551a48..0051095719 100644 --- a/library/cpp/lwtrace/protos/lwtrace.proto +++ b/library/cpp/lwtrace/protos/lwtrace.proto @@ -1,35 +1,35 @@ /* * This file defines language for trace queries and serialization format for trace logs */ -syntax = "proto3"; - +syntax = "proto3"; + package NLWTrace; -option go_package = "a.yandex-team.ru/library/cpp/lwtrace/protos"; - +option go_package = "a.yandex-team.ru/library/cpp/lwtrace/protos"; + message TProbeDesc { - string Name = 1; // Use either name+provider - string Provider = 3; - string Group = 2; // or group + string Name = 1; // Use either name+provider + string Provider = 3; + string Group = 2; // or group } enum EOperatorType { - OT_EQ = 0; - OT_NE = 1; - OT_LT = 2; - OT_LE = 3; - OT_GT = 4; - OT_GE = 5; + OT_EQ = 0; + OT_NE = 1; + OT_LT = 2; + OT_LE = 3; + OT_GT = 4; + OT_GE = 5; } message TArgument { - string Param = 1; + string Param = 1; bytes Value = 2; - string Variable = 3; + string Variable = 3; } message TOperator { - EOperatorType Type = 1; + EOperatorType Type = 1; repeated TArgument Argument = 8; } @@ -39,9 +39,9 @@ message TPredicate { } message TLogAction { - bool DoNotLogParams = 2; - bool LogTimestamp = 3; - uint32 MaxRecords = 4; // Do not write more than MaxRecords records to the log (count from the trace beginning, not start) + bool DoNotLogParams = 2; + bool LogTimestamp = 3; + uint32 MaxRecords = 4; // Do not write more than MaxRecords records to the log (count from the trace beginning, not start) } message TPrintToStderrAction { @@ -51,72 +51,72 @@ message TKillAction { } message TSleepAction { - uint64 NanoSeconds = 1; + uint64 NanoSeconds = 1; } message TCustomAction { - string Name = 1; + string Name = 1; repeated string Opts = 2; } enum EStatementType { - ST_MOV = 0; - ST_ADD = 1; - ST_SUB = 2; - ST_MUL = 3; - ST_DIV = 4; - ST_MOD = 5; - ST_ADD_EQ = 6; - ST_SUB_EQ = 7; - ST_INC = 8; - ST_DEC = 9; + ST_MOV = 0; + ST_ADD = 1; + ST_SUB = 2; + ST_MUL = 3; + ST_DIV = 4; + ST_MOD = 5; + ST_ADD_EQ = 6; + ST_SUB_EQ = 7; + ST_INC = 8; + ST_DEC = 9; } message TStatementAction { - EStatementType Type = 1; + EStatementType Type = 1; repeated TArgument Argument = 2; } message TRunLogShuttleAction { - bool Ignore = 1; - uint64 ShuttlesCount = 2; - uint64 MaxTrackLength = 3; + bool Ignore = 1; + uint64 ShuttlesCount = 2; + uint64 MaxTrackLength = 3; } message TEditLogShuttleAction { - bool Ignore = 1; + bool Ignore = 1; } message TDropLogShuttleAction { } message TAction { - TLogAction LogAction = 2; - TPrintToStderrAction PrintToStderrAction = 3; - TCustomAction CustomAction = 4; - TKillAction KillAction = 6; - TSleepAction SleepAction = 7; - TStatementAction StatementAction = 8; - - TRunLogShuttleAction RunLogShuttleAction = 100; - TEditLogShuttleAction EditLogShuttleAction = 101; - TDropLogShuttleAction DropLogShuttleAction = 102; + TLogAction LogAction = 2; + TPrintToStderrAction PrintToStderrAction = 3; + TCustomAction CustomAction = 4; + TKillAction KillAction = 6; + TSleepAction SleepAction = 7; + TStatementAction StatementAction = 8; + + TRunLogShuttleAction RunLogShuttleAction = 100; + TEditLogShuttleAction EditLogShuttleAction = 101; + TDropLogShuttleAction DropLogShuttleAction = 102; } message TBlock { - TProbeDesc ProbeDesc = 1; - TPredicate Predicate = 2; + TProbeDesc ProbeDesc = 1; + TPredicate Predicate = 2; repeated TAction Action = 3; } message TQuery { // Number of events to hold for every thread in cyclic buffer // (Won't be used if LogDurationUs is set to non-zero value) - uint32 PerThreadLogSize = 1; + uint32 PerThreadLogSize = 1; // Hold events for last Duration microseconds // (If zero, than per-thread cyclic buffer will be used to store events) - uint64 LogDurationUs = 2; + uint64 LogDurationUs = 2; repeated TBlock Blocks = 3; } @@ -153,114 +153,114 @@ enum EParamTypePb { } message TEventPb { - string Name = 1; + string Name = 1; repeated string Groups = 2; // First group is provider repeated EParamTypePb ParamTypes = 3; repeated string ParamNames = 4; } message TLogItemPb { - uint64 Thread = 1; - string Name = 2; - string Provider = 3; + uint64 Thread = 1; + string Name = 2; + string Provider = 3; repeated bytes Params = 4; - uint64 Timestamp = 5; // microseconds since epoch - uint64 TimestampCycles = 6; // cycles since machine boot + uint64 Timestamp = 5; // microseconds since epoch + uint64 TimestampCycles = 6; // cycles since machine boot } message TThreadLogPb { - uint64 ThreadId = 1; + uint64 ThreadId = 1; repeated TLogItemPb LogItems = 2; } message TLogPb { // Trace info - string Name = 1; - string Description = 2; - uint64 EventsCount = 3; - uint64 CrtTime = 4; // Log creation time (seconds since epoch) + string Name = 1; + string Description = 2; + uint64 EventsCount = 3; + uint64 CrtTime = 4; // Log creation time (seconds since epoch) // Traced host info - string Hostname = 101; + string Hostname = 101; // Traced process info - string ProcessName = 201; + string ProcessName = 201; bytes CommandLine = 202; - uint64 ProcessStartTime = 203; - uint64 Pid = 204; - string VersionInfo = 205; // Svn info + uint64 ProcessStartTime = 203; + uint64 Pid = 204; + string VersionInfo = 205; // Svn info // Trace query and results - TQuery Query = 301; + TQuery Query = 301; repeated TEventPb Events = 302; repeated TThreadLogPb ThreadLogs = 303; } message TShuttlePb { repeated TLogPb Parts = 1; - TQuery Query = 2; + TQuery Query = 2; } message TOrbitPb { repeated TShuttlePb Shuttles = 1; } - -//////////////////////////////////////////////////////////////////////////////// -// Trace parameter. - -message TTraceParam -{ - // Value. - oneof Value - { - int64 IntValue = 2; - uint64 UintValue = 3; - double DoubleValue = 4; + +//////////////////////////////////////////////////////////////////////////////// +// Trace parameter. + +message TTraceParam +{ + // Value. + oneof Value + { + int64 IntValue = 2; + uint64 UintValue = 3; + double DoubleValue = 4; bytes StrValue = 5; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Trace Event . - -message TTraceEvent -{ - // Probe name. - string Name = 1; - - // Provider name. - string Provider = 2; - - // Probe parameters. - repeated TTraceParam Params = 3; - - // Event timestamp in nanosec since epoch. - uint64 TimestampNanosec = 4; -} - -//////////////////////////////////////////////////////////////////////////////// -// Shuttle trace . - -message TShuttleTrace -{ - // Request events. - repeated TTraceEvent Events = 1; -} - -//////////////////////////////////////////////////////////////////////////////// -// Trace request. - -message TTraceRequest -{ - // trace id of remote trace session - bool IsTraced = 1; -} - -//////////////////////////////////////////////////////////////////////////////// -// Trace response. - -message TTraceResponse -{ - // traced events - TShuttleTrace Trace = 1; -} + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Trace Event . + +message TTraceEvent +{ + // Probe name. + string Name = 1; + + // Provider name. + string Provider = 2; + + // Probe parameters. + repeated TTraceParam Params = 3; + + // Event timestamp in nanosec since epoch. + uint64 TimestampNanosec = 4; +} + +//////////////////////////////////////////////////////////////////////////////// +// Shuttle trace . + +message TShuttleTrace +{ + // Request events. + repeated TTraceEvent Events = 1; +} + +//////////////////////////////////////////////////////////////////////////////// +// Trace request. + +message TTraceRequest +{ + // trace id of remote trace session + bool IsTraced = 1; +} + +//////////////////////////////////////////////////////////////////////////////// +// Trace response. + +message TTraceResponse +{ + // traced events + TShuttleTrace Trace = 1; +} diff --git a/library/cpp/lwtrace/protos/ya.make b/library/cpp/lwtrace/protos/ya.make index cefcadc853..503d5e515f 100644 --- a/library/cpp/lwtrace/protos/ya.make +++ b/library/cpp/lwtrace/protos/ya.make @@ -2,8 +2,8 @@ PROTO_LIBRARY() OWNER(serxa) -INCLUDE_TAGS(GO_PROTO) - +INCLUDE_TAGS(GO_PROTO) + SRCS( lwtrace.proto ) diff --git a/library/cpp/lwtrace/shuttle.h b/library/cpp/lwtrace/shuttle.h index 14bf9e59f4..85c6e4da61 100644 --- a/library/cpp/lwtrace/shuttle.h +++ b/library/cpp/lwtrace/shuttle.h @@ -65,9 +65,9 @@ namespace NLWTrace { AtomicSub(Status, 2); return result; } - } - } - + } + } + template <class F> void UnlessDead(F func) { while (true) { @@ -91,7 +91,7 @@ namespace NLWTrace { } // Returns false iff shuttle should be destroyed - bool AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { + bool AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { return UnlessDead([&] { return DoAddProbe(probe, params, timestamp); }, false); @@ -161,10 +161,10 @@ namespace NLWTrace { } protected: - virtual bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) = 0; + virtual bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) = 0; virtual void DoEndOfTrack() = 0; virtual void DoDrop() = 0; - virtual void DoSerialize(TShuttleTrace& msg) = 0; + virtual void DoSerialize(TShuttleTrace& msg) = 0; virtual bool DoFork(TShuttlePtr& child) = 0; virtual bool DoJoin(const TShuttlePtr& child) = 0; }; @@ -227,7 +227,7 @@ namespace NLWTrace { }); } - void AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { + void AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { NotConcurrent([&] (TShuttlePtr& head) { TShuttlePtr* ref = &head; while (IShuttle* s = ref->Get()) { @@ -253,14 +253,14 @@ namespace NLWTrace { } }); } - + void Serialize(ui64 traceIdx, TShuttleTrace& msg) { ForEachShuttle(traceIdx, [&] (NLWTrace::IShuttle* shuttle) { - shuttle->Serialize(msg); - return false; - }); - } - + shuttle->Serialize(msg); + return false; + }); + } + bool HasShuttle(ui64 traceIdx) { return NotConcurrent([=] (TShuttlePtr& head) { TShuttlePtr ref = head; @@ -270,10 +270,10 @@ namespace NLWTrace { } else { ref = s->GetNext(); } - } + } return false; }); - } + } bool Fork(TOrbit& child) { return NotConcurrent([&] (TShuttlePtr& head) { diff --git a/library/cpp/lwtrace/signature.h b/library/cpp/lwtrace/signature.h index f5415998a9..868bd9bcf2 100644 --- a/library/cpp/lwtrace/signature.h +++ b/library/cpp/lwtrace/signature.h @@ -14,8 +14,8 @@ #include <google/protobuf/descriptor.h> #include <google/protobuf/generated_enum_reflection.h> -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> - +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> + #include <type_traits> namespace NLWTrace { @@ -390,8 +390,8 @@ namespace NLWTrace { TParam Param[LWTRACE_MAX_PARAMS]; }; - using TSerializedParams = google::protobuf::RepeatedPtrField<NLWTrace::TTraceParam>; - + using TSerializedParams = google::protobuf::RepeatedPtrField<NLWTrace::TTraceParam>; + // Represents a common class for all function "signatures" (parameter types and names). // Provides non-virtual interface to handle the signature and (emulated) virtual interface to handle TParams corresponding to the signature struct TSignature { @@ -403,8 +403,8 @@ namespace NLWTrace { void (*SerializeParamsFunc)(const TParams& params, TString* values); void (*CloneParamsFunc)(TParams& newParams, const TParams& oldParams); void (*DestroyParamsFunc)(TParams& params); - void (*SerializeToPbFunc)(const TParams& params, TSerializedParams& arr); - bool (*DeserializeFromPbFunc)(TParams& params, const TSerializedParams& arr); + void (*SerializeToPbFunc)(const TParams& params, TSerializedParams& arr); + bool (*DeserializeFromPbFunc)(TParams& params, const TSerializedParams& arr); // Virtual calls emulation void SerializeParams(const TParams& params, TString* values) const { @@ -419,16 +419,16 @@ namespace NLWTrace { (*DestroyParamsFunc)(params); } - void SerializeToPb(const TParams& params, TSerializedParams& arr) const - { - (*SerializeToPbFunc)(params, arr); - } - - bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) const - { - return (*DeserializeFromPbFunc)(params, arr); - } - + void SerializeToPb(const TParams& params, TSerializedParams& arr) const + { + (*SerializeToPbFunc)(params, arr); + } + + bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) const + { + return (*DeserializeFromPbFunc)(params, arr); + } + void ToProtobuf(TEventPb& pb) const; size_t FindParamIndex(const TString& param) const { @@ -564,118 +564,118 @@ namespace NLWTrace { } }; - inline EParamTypePb ParamTypeToProtobuf(const char* paramType) { -#define FOREACH_PARAMTYPE_MACRO(n, t, v) \ - if (strcmp(paramType, n) == 0) { \ - return PT_##v; \ - } \ - /**/ - FOREACH_PARAMTYPE(FOREACH_PARAMTYPE_MACRO) -#undef FOREACH_PARAMTYPE_MACRO - return PT_UNKNOWN; - } - - template <typename T> - inline void SaveParamToPb(TSerializedParams& msg, const TParam& param); - - template <> - inline void SaveParamToPb<TNil>(TSerializedParams& msg, const TParam& param) - { - Y_UNUSED(msg); - Y_UNUSED(param); - } - - template <> - inline void SaveParamToPb<i64>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetIntValue(param.Get<typename TParamTraits<i64>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<ui64>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetUintValue(param.Get<typename TParamTraits<ui64>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<double>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetDoubleValue(param.Get<typename TParamTraits<double>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<TString>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetStrValue(param.Get<typename TParamTraits<TString>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<TSymbol>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetStrValue(*param.Get<typename TParamTraits<TSymbol>::TStoreType>().Str); - } - - template <> - inline void SaveParamToPb<TCheck>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetIntValue(param.Get<typename TParamTraits<TCheck>::TStoreType>().Value); - } - - template <typename T> - inline void LoadParamFromPb(const TTraceParam& msg, TParam& param); - - template <> - inline void LoadParamFromPb<i64>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<i64>(); - param.Get<i64>() = msg.GetIntValue(); - } - - template <> - inline void LoadParamFromPb<ui64>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<ui64>(); - param.Get<ui64>() = msg.GetUintValue(); - } - - template <> - inline void LoadParamFromPb<double>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<double>(); - param.Get<double>() = msg.GetDoubleValue(); - } - - template <> - inline void LoadParamFromPb<TCheck>(const TTraceParam& msg, TParam& param) - { - param.CopyConstruct<TCheck>(TCheck(msg.GetIntValue())); - } - - template <> - inline void LoadParamFromPb<TSymbol>(const TTraceParam& msg, TParam& param) - { - Y_UNUSED(msg); - Y_UNUSED(param); - static TString unsupported("unsupported"); - // so far TSymbol deserialization is not supported - // since it is not used for probes, it is ok - param.CopyConstruct<TSymbol>(TSymbol(&unsupported)); - } - - template <> - inline void LoadParamFromPb<TString>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<TString>(); - param.Get<TString>() = msg.GetStrValue(); - } - - template <> - inline void LoadParamFromPb<TNil>(const TTraceParam& msg, TParam& param) - { - Y_UNUSED(msg); - Y_UNUSED(param); - } - + inline EParamTypePb ParamTypeToProtobuf(const char* paramType) { +#define FOREACH_PARAMTYPE_MACRO(n, t, v) \ + if (strcmp(paramType, n) == 0) { \ + return PT_##v; \ + } \ + /**/ + FOREACH_PARAMTYPE(FOREACH_PARAMTYPE_MACRO) +#undef FOREACH_PARAMTYPE_MACRO + return PT_UNKNOWN; + } + + template <typename T> + inline void SaveParamToPb(TSerializedParams& msg, const TParam& param); + + template <> + inline void SaveParamToPb<TNil>(TSerializedParams& msg, const TParam& param) + { + Y_UNUSED(msg); + Y_UNUSED(param); + } + + template <> + inline void SaveParamToPb<i64>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetIntValue(param.Get<typename TParamTraits<i64>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<ui64>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetUintValue(param.Get<typename TParamTraits<ui64>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<double>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetDoubleValue(param.Get<typename TParamTraits<double>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<TString>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetStrValue(param.Get<typename TParamTraits<TString>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<TSymbol>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetStrValue(*param.Get<typename TParamTraits<TSymbol>::TStoreType>().Str); + } + + template <> + inline void SaveParamToPb<TCheck>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetIntValue(param.Get<typename TParamTraits<TCheck>::TStoreType>().Value); + } + + template <typename T> + inline void LoadParamFromPb(const TTraceParam& msg, TParam& param); + + template <> + inline void LoadParamFromPb<i64>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<i64>(); + param.Get<i64>() = msg.GetIntValue(); + } + + template <> + inline void LoadParamFromPb<ui64>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<ui64>(); + param.Get<ui64>() = msg.GetUintValue(); + } + + template <> + inline void LoadParamFromPb<double>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<double>(); + param.Get<double>() = msg.GetDoubleValue(); + } + + template <> + inline void LoadParamFromPb<TCheck>(const TTraceParam& msg, TParam& param) + { + param.CopyConstruct<TCheck>(TCheck(msg.GetIntValue())); + } + + template <> + inline void LoadParamFromPb<TSymbol>(const TTraceParam& msg, TParam& param) + { + Y_UNUSED(msg); + Y_UNUSED(param); + static TString unsupported("unsupported"); + // so far TSymbol deserialization is not supported + // since it is not used for probes, it is ok + param.CopyConstruct<TSymbol>(TSymbol(&unsupported)); + } + + template <> + inline void LoadParamFromPb<TString>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<TString>(); + param.Get<TString>() = msg.GetStrValue(); + } + + template <> + inline void LoadParamFromPb<TNil>(const TTraceParam& msg, TParam& param) + { + Y_UNUSED(msg); + Y_UNUSED(param); + } + // Class representing a specific signature template <LWTRACE_TEMPLATE_PARAMS> struct TUserSignature { @@ -705,42 +705,42 @@ namespace NLWTrace { FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); #undef FOREACH_PARAMNUM_MACRO } - - // Implementation of virtual function (TSignature derived classes vtable emulation) - inline static void SerializeToPb(const TParams& params, TSerializedParams& arr) - { -#define FOREACH_PARAMNUM_MACRO(i) \ - SaveParamToPb<typename TParamTraits<TP##i>::TStoreType>( \ - arr, \ - params.Param[i]); \ -// FOREACH_PARAMNUM_MACRO - FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); -#undef FOREACH_PARAMNUM_MACRO - } - - // Implementation of virtual function (TSignature derived classes vtable emulation) - inline static bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) { - if (arr.size() != ParamCount) { - return false; - } - if (!ParamCount) { - return true; - } - - int paramIdx = 0; -#define FOREACH_PARAMNUM_MACRO(i) \ - if (paramIdx >= arr.size()) { \ - return true; \ - }; \ - LoadParamFromPb<typename TParamTraits<TP##i>::TStoreType>( \ - arr.Get(paramIdx), \ - params.Param[paramIdx]); \ - ++paramIdx; \ -// FOREACH_PARAMNUM_MACRO - FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); -#undef FOREACH_PARAMNUM_MACRO - return true; - } + + // Implementation of virtual function (TSignature derived classes vtable emulation) + inline static void SerializeToPb(const TParams& params, TSerializedParams& arr) + { +#define FOREACH_PARAMNUM_MACRO(i) \ + SaveParamToPb<typename TParamTraits<TP##i>::TStoreType>( \ + arr, \ + params.Param[i]); \ +// FOREACH_PARAMNUM_MACRO + FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); +#undef FOREACH_PARAMNUM_MACRO + } + + // Implementation of virtual function (TSignature derived classes vtable emulation) + inline static bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) { + if (arr.size() != ParamCount) { + return false; + } + if (!ParamCount) { + return true; + } + + int paramIdx = 0; +#define FOREACH_PARAMNUM_MACRO(i) \ + if (paramIdx >= arr.size()) { \ + return true; \ + }; \ + LoadParamFromPb<typename TParamTraits<TP##i>::TStoreType>( \ + arr.Get(paramIdx), \ + params.Param[paramIdx]); \ + ++paramIdx; \ +// FOREACH_PARAMNUM_MACRO + FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); +#undef FOREACH_PARAMNUM_MACRO + return true; + } }; // Array of static strings pointers for names of parameter types in a specific signature diff --git a/library/cpp/lwtrace/trace.cpp b/library/cpp/lwtrace/trace.cpp index 1aee64a16f..3c974c85a0 100644 --- a/library/cpp/lwtrace/trace.cpp +++ b/library/cpp/lwtrace/trace.cpp @@ -432,9 +432,9 @@ namespace NLWTrace { public: TLogActionExecutor(TProbe* probe, const TLogAction& action, TLog* log) - : LogParams(!action.GetDoNotLogParams()) + : LogParams(!action.GetDoNotLogParams()) , LogTimestamp(action.GetLogTimestamp()) - , MaxRecords(action.GetMaxRecords() ? new intptr_t(action.GetMaxRecords()) : nullptr) + , MaxRecords(action.GetMaxRecords() ? new intptr_t(action.GetMaxRecords()) : nullptr) , Records(0) , Probe(probe) , Log(log) @@ -475,11 +475,11 @@ namespace NLWTrace { const TArgument& arg = op.GetArgument(argumentIdx); TArgumentDescription operand; operand.ParamIdx = size_t(-1); - if (arg.GetVariable()) { + if (arg.GetVariable()) { operand.Type = OT_VARIABLE; - } else if (arg.GetValue()) { + } else if (arg.GetValue()) { operand.Type = OT_LITERAL; - } else if (arg.GetParam()) { + } else if (arg.GetParam()) { operand.Type = OT_PARAMETER; operand.ParamIdx = signature.FindParamIndex(arg.GetParam()); if (operand.ParamIdx == size_t(-1)) { @@ -672,7 +672,7 @@ namespace NLWTrace { } else if (action.HasSleepAction()) { if (destructiveActionsAllowed) { const TSleepAction& sleepAction = action.GetSleepAction(); - if (sleepAction.GetNanoSeconds()) { + if (sleepAction.GetNanoSeconds()) { ui64 nanoSeconds = sleepAction.GetNanoSeconds(); actExec.Reset(new NPrivate::TSleepActionExecutor(probe, nanoSeconds)); } else { @@ -858,9 +858,9 @@ namespace NLWTrace { , Registry(registry) , StoreDuration(TDuration::MicroSeconds(query.GetLogDurationUs() * 11 / 10)) // +10% to try avoid truncation while reading multiple threads/traces , ReadDuration(TDuration::MicroSeconds(query.GetLogDurationUs())) - , CyclicLog(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) + , CyclicLog(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) , DurationLog(StoreDuration) - , CyclicDepot(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) + , CyclicDepot(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) , DurationDepot(StoreDuration) , LastTrackId(0) , LastSpanId(0) @@ -879,7 +879,7 @@ namespace NLWTrace { ythrow yexception() << "block #" << bi + 1 << " has no action"; } const NProtoBuf::RepeatedPtrField<TAction>& actions = block.action(); - if (pdesc.GetName() && pdesc.GetProvider()) { + if (pdesc.GetName() && pdesc.GetProvider()) { TProbeRegistry::TProbesAccessor probes(Registry); bool found = false; for (auto& kv : probes) { @@ -894,7 +894,7 @@ namespace NLWTrace { ythrow yexception() << "block #" << bi + 1 << " has no matching probe with name '" << pdesc.GetName() << "' provider '" << pdesc.GetProvider() << "'"; } - } else if (pdesc.GetGroup()) { + } else if (pdesc.GetGroup()) { bool found = false; TProbeRegistry::TProbesAccessor probes(Registry); for (auto& kv : probes) { diff --git a/library/cpp/lwtrace/trace_ut.cpp b/library/cpp/lwtrace/trace_ut.cpp index 5e1256585e..cb03e4fbde 100644 --- a/library/cpp/lwtrace/trace_ut.cpp +++ b/library/cpp/lwtrace/trace_ut.cpp @@ -16,17 +16,17 @@ enum class EEnumClass { ValueD, }; -#define LWTRACE_UT_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ - PROBE(NoParam, GROUPS("Group"), TYPES(), NAMES()) \ - PROBE(IntParam, GROUPS("Group"), TYPES(ui32), NAMES("value")) \ - PROBE(StringParam, GROUPS("Group"), TYPES(TString), NAMES("value")) \ - PROBE(SymbolParam, GROUPS("Group"), TYPES(NLWTrace::TSymbol), NAMES("symbol")) \ - PROBE(CheckParam, GROUPS("Group"), TYPES(NLWTrace::TCheck), NAMES("value")) \ +#define LWTRACE_UT_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ + PROBE(NoParam, GROUPS("Group"), TYPES(), NAMES()) \ + PROBE(IntParam, GROUPS("Group"), TYPES(ui32), NAMES("value")) \ + PROBE(StringParam, GROUPS("Group"), TYPES(TString), NAMES("value")) \ + PROBE(SymbolParam, GROUPS("Group"), TYPES(NLWTrace::TSymbol), NAMES("symbol")) \ + PROBE(CheckParam, GROUPS("Group"), TYPES(NLWTrace::TCheck), NAMES("value")) \ PROBE(EnumParams, GROUPS("Group"), TYPES(ESimpleEnum, EEnumClass), NAMES("simpleEnum", "enumClass")) \ - PROBE(InstantParam, GROUPS("Group"), TYPES(TInstant), NAMES("value")) \ - PROBE(DurationParam, GROUPS("Group"), TYPES(TDuration), NAMES("value")) \ - PROBE(ProtoEnum, GROUPS("Group"), TYPES(NLWTrace::EOperatorType), NAMES("value")) \ - PROBE(IntIntParams, GROUPS("Group"), TYPES(ui32, ui64), NAMES("value1", "value2")) \ + PROBE(InstantParam, GROUPS("Group"), TYPES(TInstant), NAMES("value")) \ + PROBE(DurationParam, GROUPS("Group"), TYPES(TDuration), NAMES("value")) \ + PROBE(ProtoEnum, GROUPS("Group"), TYPES(NLWTrace::EOperatorType), NAMES("value")) \ + PROBE(IntIntParams, GROUPS("Group"), TYPES(ui32, ui64), NAMES("value1", "value2")) \ /**/ LWTRACE_DECLARE_PROVIDER(LWTRACE_UT_PROVIDER) @@ -546,7 +546,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { using TPbEnumTraits = TParamTraits<EOperatorType>; TString str; TPbEnumTraits::ToString(TPbEnumTraits::ToStoreType(OT_EQ), &str); - UNIT_ASSERT_STRINGS_EQUAL(str, "OT_EQ (0)"); + UNIT_ASSERT_STRINGS_EQUAL(str, "OT_EQ (0)"); } Y_UNIT_TEST(Track) { @@ -581,164 +581,164 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { } reader; mngr.ReadDepot("Query1", reader); } - - Y_UNIT_TEST(ShouldSerializeTracks) - { - TManager manager(*Singleton<TProbeRegistry>(), false); - - TOrbit orbit; - TTraceRequest req; - req.SetIsTraced(true); - manager.HandleTraceRequest(req, orbit); - - LWTRACK(NoParam, orbit); - LWTRACK(IntParam, orbit, 1); - LWTRACK(StringParam, orbit, "str"); - LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); - LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); - LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); + + Y_UNIT_TEST(ShouldSerializeTracks) + { + TManager manager(*Singleton<TProbeRegistry>(), false); + + TOrbit orbit; + TTraceRequest req; + req.SetIsTraced(true); + manager.HandleTraceRequest(req, orbit); + + LWTRACK(NoParam, orbit); + LWTRACK(IntParam, orbit, 1); + LWTRACK(StringParam, orbit, "str"); + LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); + LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); + LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); LWTRACK(ProtoEnum, orbit, OT_EQ); - LWTRACK(IntIntParams, orbit, 1, 2); - - TTraceResponse resp; - orbit.Serialize(0, *resp.MutableTrace()); - auto& r = resp.GetTrace(); - - UNIT_ASSERT_VALUES_EQUAL(8, r.EventsSize()); - - const auto& p0 = r.GetEvents(0); - UNIT_ASSERT_VALUES_EQUAL("NoParam", p0.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p0.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(0 , p0.ParamsSize()); - - const auto& p1 = r.GetEvents(1); - UNIT_ASSERT_VALUES_EQUAL("IntParam", p1.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p1.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(1, p1.GetParams(0).GetUintValue()); - - const auto& p2 = r.GetEvents(2); - UNIT_ASSERT_VALUES_EQUAL("StringParam", p2.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p2.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL("str", p2.GetParams(0).GetStrValue()); - - const auto& p3 = r.GetEvents(3); - UNIT_ASSERT_VALUES_EQUAL("EnumParams", p3.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p3.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL((ui32)ValueA, p3.GetParams(0).GetIntValue()); - UNIT_ASSERT_VALUES_EQUAL((ui32)EEnumClass::ValueC, p3.GetParams(1).GetIntValue()); - - const auto& p4 = r.GetEvents(4); - UNIT_ASSERT_VALUES_EQUAL("InstantParam", p4.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p4.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(42, p4.GetParams(0).GetDoubleValue()); - - const auto& p5 = r.GetEvents(5); - UNIT_ASSERT_VALUES_EQUAL("DurationParam", p5.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p5.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(146, p5.GetParams(0).GetDoubleValue()); - - const auto& p6 = r.GetEvents(6); - UNIT_ASSERT_VALUES_EQUAL("ProtoEnum", p6.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p6.GetProvider()); + LWTRACK(IntIntParams, orbit, 1, 2); + + TTraceResponse resp; + orbit.Serialize(0, *resp.MutableTrace()); + auto& r = resp.GetTrace(); + + UNIT_ASSERT_VALUES_EQUAL(8, r.EventsSize()); + + const auto& p0 = r.GetEvents(0); + UNIT_ASSERT_VALUES_EQUAL("NoParam", p0.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p0.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(0 , p0.ParamsSize()); + + const auto& p1 = r.GetEvents(1); + UNIT_ASSERT_VALUES_EQUAL("IntParam", p1.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p1.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(1, p1.GetParams(0).GetUintValue()); + + const auto& p2 = r.GetEvents(2); + UNIT_ASSERT_VALUES_EQUAL("StringParam", p2.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p2.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL("str", p2.GetParams(0).GetStrValue()); + + const auto& p3 = r.GetEvents(3); + UNIT_ASSERT_VALUES_EQUAL("EnumParams", p3.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p3.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL((ui32)ValueA, p3.GetParams(0).GetIntValue()); + UNIT_ASSERT_VALUES_EQUAL((ui32)EEnumClass::ValueC, p3.GetParams(1).GetIntValue()); + + const auto& p4 = r.GetEvents(4); + UNIT_ASSERT_VALUES_EQUAL("InstantParam", p4.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p4.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(42, p4.GetParams(0).GetDoubleValue()); + + const auto& p5 = r.GetEvents(5); + UNIT_ASSERT_VALUES_EQUAL("DurationParam", p5.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p5.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(146, p5.GetParams(0).GetDoubleValue()); + + const auto& p6 = r.GetEvents(6); + UNIT_ASSERT_VALUES_EQUAL("ProtoEnum", p6.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p6.GetProvider()); UNIT_ASSERT_VALUES_EQUAL((int)OT_EQ, p6.GetParams(0).GetIntValue()); - - const auto& p7 = r.GetEvents(7); - UNIT_ASSERT_VALUES_EQUAL("IntIntParams", p7.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p7.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(1, p7.GetParams(0).GetUintValue()); - UNIT_ASSERT_VALUES_EQUAL(2, p7.GetParams(1).GetUintValue()); - } - - Y_UNIT_TEST(ShouldDeserializeTracks) - { - TManager manager(*Singleton<TProbeRegistry>(), false); - - TTraceResponse resp; - auto& r = *resp.MutableTrace()->MutableEvents(); - - auto& p0 = *r.Add(); - p0.SetName("NoParam"); - p0.SetProvider("LWTRACE_UT_PROVIDER"); - - auto& p1 = *r.Add(); - p1.SetName("IntParam"); - p1.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p1param = *p1.MutableParams()->Add(); - p1param.SetUintValue(1); - - auto& p2 = *r.Add(); - p2.SetName("StringParam"); - p2.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p2param = *p2.MutableParams()->Add(); - p2param.SetStrValue("str"); - - auto& p3 = *r.Add(); - p3.SetName("EnumParams"); - p3.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p3param1 = *p3.MutableParams()->Add(); - p3param1.SetUintValue((ui64)EEnumClass::ValueC); - auto& p3param2 = *p3.MutableParams()->Add(); - p3param2.SetIntValue((ui64)EEnumClass::ValueC); - - auto& p4 = *r.Add(); - p4.SetName("InstantParam"); - p4.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p4param = *p4.MutableParams()->Add(); - p4param.SetDoubleValue(42); - - auto& p5 = *r.Add(); - p5.SetName("DurationParam"); - p5.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p5param = *p5.MutableParams()->Add(); - p5param.SetDoubleValue(146); - - auto& p6 = *r.Add(); - p6.SetName("ProtoEnum"); - p6.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p6param = *p6.MutableParams()->Add(); + + const auto& p7 = r.GetEvents(7); + UNIT_ASSERT_VALUES_EQUAL("IntIntParams", p7.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p7.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(1, p7.GetParams(0).GetUintValue()); + UNIT_ASSERT_VALUES_EQUAL(2, p7.GetParams(1).GetUintValue()); + } + + Y_UNIT_TEST(ShouldDeserializeTracks) + { + TManager manager(*Singleton<TProbeRegistry>(), false); + + TTraceResponse resp; + auto& r = *resp.MutableTrace()->MutableEvents(); + + auto& p0 = *r.Add(); + p0.SetName("NoParam"); + p0.SetProvider("LWTRACE_UT_PROVIDER"); + + auto& p1 = *r.Add(); + p1.SetName("IntParam"); + p1.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p1param = *p1.MutableParams()->Add(); + p1param.SetUintValue(1); + + auto& p2 = *r.Add(); + p2.SetName("StringParam"); + p2.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p2param = *p2.MutableParams()->Add(); + p2param.SetStrValue("str"); + + auto& p3 = *r.Add(); + p3.SetName("EnumParams"); + p3.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p3param1 = *p3.MutableParams()->Add(); + p3param1.SetUintValue((ui64)EEnumClass::ValueC); + auto& p3param2 = *p3.MutableParams()->Add(); + p3param2.SetIntValue((ui64)EEnumClass::ValueC); + + auto& p4 = *r.Add(); + p4.SetName("InstantParam"); + p4.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p4param = *p4.MutableParams()->Add(); + p4param.SetDoubleValue(42); + + auto& p5 = *r.Add(); + p5.SetName("DurationParam"); + p5.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p5param = *p5.MutableParams()->Add(); + p5param.SetDoubleValue(146); + + auto& p6 = *r.Add(); + p6.SetName("ProtoEnum"); + p6.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p6param = *p6.MutableParams()->Add(); p6param.SetIntValue((i64)OT_EQ); - - auto& p7 = *r.Add(); - p7.SetName("IntIntParams"); - p7.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p7param1 = *p7.MutableParams()->Add(); - p7param1.SetIntValue(1); - auto& p7param2 = *p7.MutableParams()->Add(); - p7param2.SetIntValue(2); - - TOrbit orbit; - UNIT_ASSERT_VALUES_EQUAL( - manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit).IsSuccess, - true); - } - - Y_UNIT_TEST(ShouldDeserializeWhatSerialized) - { - TManager manager(*Singleton<TProbeRegistry>(), false); - - TOrbit orbit; - TTraceRequest req; - req.SetIsTraced(true); - manager.HandleTraceRequest(req, orbit); - - LWTRACK(NoParam, orbit); - LWTRACK(IntParam, orbit, 1); - LWTRACK(StringParam, orbit, "str"); - LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); - LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); - LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); + + auto& p7 = *r.Add(); + p7.SetName("IntIntParams"); + p7.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p7param1 = *p7.MutableParams()->Add(); + p7param1.SetIntValue(1); + auto& p7param2 = *p7.MutableParams()->Add(); + p7param2.SetIntValue(2); + + TOrbit orbit; + UNIT_ASSERT_VALUES_EQUAL( + manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit).IsSuccess, + true); + } + + Y_UNIT_TEST(ShouldDeserializeWhatSerialized) + { + TManager manager(*Singleton<TProbeRegistry>(), false); + + TOrbit orbit; + TTraceRequest req; + req.SetIsTraced(true); + manager.HandleTraceRequest(req, orbit); + + LWTRACK(NoParam, orbit); + LWTRACK(IntParam, orbit, 1); + LWTRACK(StringParam, orbit, "str"); + LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); + LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); + LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); LWTRACK(ProtoEnum, orbit, OT_EQ); - LWTRACK(IntIntParams, orbit, 1, 2); - - TTraceResponse resp; - auto& r = *resp.MutableTrace(); - orbit.Serialize(0, r); - - TOrbit orbit1; - UNIT_ASSERT_VALUES_EQUAL( - manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit1).IsSuccess, - true); - } + LWTRACK(IntIntParams, orbit, 1, 2); + + TTraceResponse resp; + auto& r = *resp.MutableTrace(); + orbit.Serialize(0, r); + + TOrbit orbit1; + UNIT_ASSERT_VALUES_EQUAL( + manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit1).IsSuccess, + true); + } Y_UNIT_TEST(TrackForkJoin) { TManager mngr(*Singleton<TProbeRegistry>(), true); diff --git a/library/cpp/lwtrace/ya.make b/library/cpp/lwtrace/ya.make index d863638b7d..d9accb3006 100644 --- a/library/cpp/lwtrace/ya.make +++ b/library/cpp/lwtrace/ya.make @@ -8,7 +8,7 @@ PEERDIR( SRCS( check.cpp - control.cpp + control.cpp custom_action.cpp kill_action.cpp log_shuttle.cpp @@ -23,7 +23,7 @@ SRCS( ) END() - + RECURSE(mon) -RECURSE_FOR_TESTS(ut) +RECURSE_FOR_TESTS(ut) |