diff options
author | lianabatalova <lianabatalova@yandex-team.ru> | 2022-02-10 16:49:11 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:11 +0300 |
commit | 5bb473368cbb2d67a30433d2cd55e8e32460dea8 (patch) | |
tree | 05d166cc67f02e379edbe07942017ed65bcf0cf6 /library/cpp | |
parent | 6c7ed19fb4e807d81f39d5b370b1dba604558a17 (diff) | |
download | ydb-5bb473368cbb2d67a30433d2cd55e8e32460dea8.tar.gz |
Restoring authorship annotation for <lianabatalova@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/actors/README.md | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/actor_ut.cpp | 482 | ||||
-rw-r--r-- | library/cpp/actors/core/ya.make | 4 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/csv_output.h | 4 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/data.h | 82 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/html_output.h | 8 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/transform.h | 52 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/mon_lwtrace.cpp | 572 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/mon_lwtrace.h | 16 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/ya.make | 4 | ||||
-rw-r--r-- | library/cpp/lwtrace/trace_ut.cpp | 910 | ||||
-rw-r--r-- | library/cpp/lwtrace/ya.make | 4 |
12 files changed, 1070 insertions, 1070 deletions
diff --git a/library/cpp/actors/README.md b/library/cpp/actors/README.md index c39908f2f5..76222392b6 100644 --- a/library/cpp/actors/README.md +++ b/library/cpp/actors/README.md @@ -72,7 +72,7 @@ SelfId – узнать собственный адрес. Возвращаем В рамках одной акторсистемы может сосуществовать несколько независимых тредпулов, каждый актор регистрируется на конкретном и в процессе жизни не может мигрировать (но может создавать новые акторы на произвольном тредпуле). Используется для крупноблочного разделения ресурсов, либо между разными активностями (вот здесь – обрабатываем один класс запросов, а вот здесь - другой), либо между разными профилями активности (вот здесь обрабатываем быстрые запросы, здесь – медленные, а вот там – вообще батчёвые). Например в YDB работает системный тредпул (в котором запускаются акторы, необходимые для функционирования YDB, и для которого мы следим что бы не было длительной блокировки в обработчиках), пользовательский тредпул (в котором обрабатываются запросы и потенциально обработчики могут уходить в себя подольше, но это не повлияет на инфраструктуру), батчёвый тредпул (куда отгружается длительная обработка – компакшены дисков, сканы таблиц и подобное) и, в жирных нодах – тредпул интерконнекта (как наиболее чувствительного к задержкам). Пересылка сообщений между акторами разных тредпулов но одной локальной акторсистемы остаётся локальной, принудительной сериализации сообщения не происходит. -При регистрации актор прикрепляется к мейлбоксу (в типичном случае на собственном мейлбоксе, но по особой нужде можно находясь внутри обработки сообщения прикрепить порождённый актор к текущему активному мейлбоксу – см. RegisterWithSameMailbox (ранее RegisterLocal) – в этом случае будет гарантироваться отсутствие конкурентной обработки сообщений). Собственно Send – это и есть заворачивание ивента в хендл, помещение хендла в очередь мейлбокса и добавление мейлбокса в очередь активации тредпула. В рамках одного мейлбокса – обработка FIFO, между мейлбоксами таких гарантий нет, хотя и стараемся активировать мейлбоксы примерно в порядке появления в них сообщений. +При регистрации актор прикрепляется к мейлбоксу (в типичном случае на собственном мейлбоксе, но по особой нужде можно находясь внутри обработки сообщения прикрепить порождённый актор к текущему активному мейлбоксу – см. RegisterWithSameMailbox (ранее RegisterLocal) – в этом случае будет гарантироваться отсутствие конкурентной обработки сообщений). Собственно Send – это и есть заворачивание ивента в хендл, помещение хендла в очередь мейлбокса и добавление мейлбокса в очередь активации тредпула. В рамках одного мейлбокса – обработка FIFO, между мейлбоксами таких гарантий нет, хотя и стараемся активировать мейлбоксы примерно в порядке появления в них сообщений. При регистрации актора можно выбрать тип мейлбокса, они немного отличаются стоимость добавления – либо дёшево, но похуже под контеншеном, либо почти wait-free, но подороже. См. комментарии к TMailboxType за актуальными подсказками что-как. diff --git a/library/cpp/actors/core/actor_ut.cpp b/library/cpp/actors/core/actor_ut.cpp index e1b765ec72..cbbddace9f 100644 --- a/library/cpp/actors/core/actor_ut.cpp +++ b/library/cpp/actors/core/actor_ut.cpp @@ -5,60 +5,60 @@ #include "scheduler_basic.h" #include "actor_bootstrapped.h" -#include <library/cpp/actors/util/threadparkpad.h> +#include <library/cpp/actors/util/threadparkpad.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/algorithm.h> -#include <util/system/atomic.h> -#include <util/system/rwlock.h> -#include <util/system/hp_timer.h> +#include <util/generic/algorithm.h> +#include <util/system/atomic.h> +#include <util/system/rwlock.h> +#include <util/system/hp_timer.h> using namespace NActors; -struct TTestEndDecorator : TDecorator { - TThreadParkPad* Pad; - TAtomic* ActorsAlive; - - TTestEndDecorator(THolder<IActor>&& actor, TThreadParkPad* pad, TAtomic* actorsAlive) - : TDecorator(std::move(actor)) - , Pad(pad) - , ActorsAlive(actorsAlive) - { - AtomicIncrement(*ActorsAlive); - } - - ~TTestEndDecorator() { - if (AtomicDecrement(*ActorsAlive) == 0) { - Pad->Unpark(); - } - } -}; - -Y_UNIT_TEST_SUITE(ActorBenchmark) { +struct TTestEndDecorator : TDecorator { + TThreadParkPad* Pad; + TAtomic* ActorsAlive; + + TTestEndDecorator(THolder<IActor>&& actor, TThreadParkPad* pad, TAtomic* actorsAlive) + : TDecorator(std::move(actor)) + , Pad(pad) + , ActorsAlive(actorsAlive) + { + AtomicIncrement(*ActorsAlive); + } + + ~TTestEndDecorator() { + if (AtomicDecrement(*ActorsAlive) == 0) { + Pad->Unpark(); + } + } +}; + +Y_UNIT_TEST_SUITE(ActorBenchmark) { static constexpr bool DefaultNoRealtime = true; - static constexpr ui32 DefaultSpinThreshold = 1000000; - static constexpr ui32 TotalEventsAmount = 1000; - - class TDummyActor : public TActor<TDummyActor> { - public: - TDummyActor() : TActor<TDummyActor>(&TDummyActor::StateFunc) {} - STFUNC(StateFunc) { + static constexpr ui32 DefaultSpinThreshold = 1000000; + static constexpr ui32 TotalEventsAmount = 1000; + + class TDummyActor : public TActor<TDummyActor> { + public: + TDummyActor() : TActor<TDummyActor>(&TDummyActor::StateFunc) {} + STFUNC(StateFunc) { (void)ev; - (void)ctx; - } - }; - + (void)ctx; + } + }; + enum ERole { Leader, Follower }; - class TSendReceiveActor : public TActorBootstrapped<TSendReceiveActor> { - public: + class TSendReceiveActor : public TActorBootstrapped<TSendReceiveActor> { + public: static constexpr auto ActorActivityType() { - return ACTORLIB_COMMON; + return ACTORLIB_COMMON; } - + TSendReceiveActor(double* elapsedTime, TActorId receiver, bool allocation, ERole role, ui32 neighbours = 0) : EventsCounter(TotalEventsAmount) , ElapsedTime(elapsedTime) @@ -66,48 +66,48 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { , AllocatesMemory(allocation) , Role(role) , MailboxNeighboursCount(neighbours) - {} - - void Bootstrap(const TActorContext &ctx) { - if (!Receiver) { - this->Receiver = SelfId(); + {} + + void Bootstrap(const TActorContext &ctx) { + if (!Receiver) { + this->Receiver = SelfId(); } else { EventsCounter /= 2; // We want to measure CPU requirement for one-way send - } - Timer.Reset(); - Become(&TThis::StateFunc); - for (ui32 i = 0; i < MailboxNeighboursCount; ++i) { - ctx.RegisterWithSameMailbox(new TDummyActor()); - } + } + Timer.Reset(); + Become(&TThis::StateFunc); + for (ui32 i = 0; i < MailboxNeighboursCount; ++i) { + ctx.RegisterWithSameMailbox(new TDummyActor()); + } if (Role == Leader) { Send(Receiver, new TEvents::TEvPing()); } - } - - STATEFN(StateFunc) { + } + + STATEFN(StateFunc) { if (EventsCounter == 0 && ElapsedTime != nullptr) { - *ElapsedTime = Timer.Passed() / TotalEventsAmount; - PassAway(); - } - - if (AllocatesMemory) { - Send(ev->Sender, new TEvents::TEvPing()); - } else { - std::swap(*const_cast<TActorId*>(&ev->Sender), *const_cast<TActorId*>(&ev->Recipient)); - ev->DropRewrite(); - TActivationContext::Send(ev.Release()); - } + *ElapsedTime = Timer.Passed() / TotalEventsAmount; + PassAway(); + } + + if (AllocatesMemory) { + Send(ev->Sender, new TEvents::TEvPing()); + } else { + std::swap(*const_cast<TActorId*>(&ev->Sender), *const_cast<TActorId*>(&ev->Recipient)); + ev->DropRewrite(); + TActivationContext::Send(ev.Release()); + } EventsCounter--; - } - - private: - THPTimer Timer; + } + + private: + THPTimer Timer; ui64 EventsCounter; - double* ElapsedTime; - TActorId Receiver; - bool AllocatesMemory; + double* ElapsedTime; + TActorId Receiver; + bool AllocatesMemory; ERole Role; - ui32 MailboxNeighboursCount; + ui32 MailboxNeighboursCount; }; void AddBasicPool(THolder<TActorSystemSetup>& setup, ui32 threads, bool activateEveryEvent) { @@ -121,10 +121,10 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { basic.EventsPerMailbox = 1; } else { basic.EventsPerMailbox = Max<ui32>(); - } + } setup->CpuManager.Basic.emplace_back(std::move(basic)); } - + void AddUnitedPool(THolder<TActorSystemSetup>& setup, ui32 concurrency, bool activateEveryEvent) { TUnitedExecutorPoolConfig united; united.PoolId = setup->GetExecutorsCount(); @@ -182,34 +182,34 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { double BenchSendReceive(bool allocation, NActors::TMailboxType::EType mType, EPoolType poolType) { THolder<TActorSystemSetup> setup = InitActorSystemSetup(poolType, 1, 1, false, false); - TActorSystem actorSystem(setup); - actorSystem.Start(); - - TThreadParkPad pad; - TAtomic actorsAlive = 0; - double elapsedTime = 0; + TActorSystem actorSystem(setup); + actorSystem.Start(); + + TThreadParkPad pad; + TAtomic actorsAlive = 0; + double elapsedTime = 0; THolder<IActor> endActor{ new TTestEndDecorator(THolder( new TSendReceiveActor(&elapsedTime, {}, allocation, Leader)), &pad, &actorsAlive)}; - - actorSystem.Register(endActor.Release(), mType); - - pad.Park(); - actorSystem.Stop(); - + + actorSystem.Register(endActor.Release(), mType); + + pad.Park(); + actorSystem.Stop(); + return 1e9 * elapsedTime; - } - + } + double BenchSendActivateReceive(ui32 poolsCount, ui32 threads, bool allocation, EPoolType poolType) { THolder<TActorSystemSetup> setup = InitActorSystemSetup(poolType, poolsCount, threads, true, false); TActorSystem actorSystem(setup); - actorSystem.Start(); - - TThreadParkPad pad; - TAtomic actorsAlive = 0; - double elapsedTime = 0; + actorSystem.Start(); + + TThreadParkPad pad; + TAtomic actorsAlive = 0; + double elapsedTime = 0; ui32 followerPoolId = 0; - + ui32 leaderPoolId = poolsCount == 1 ? 0 : 1; TActorId followerId = actorSystem.Register( new TSendReceiveActor(nullptr, {}, allocation, Follower), TMailboxType::HTSwap, followerPoolId); @@ -218,46 +218,46 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { new TSendReceiveActor(&elapsedTime, followerId, allocation, Leader)), &pad, &actorsAlive)}; actorSystem.Register(leader.Release(), TMailboxType::HTSwap, leaderPoolId); - pad.Park(); - actorSystem.Stop(); - + pad.Park(); + actorSystem.Stop(); + return 1e9 * elapsedTime; - } - + } + double BenchSendActivateReceiveWithMailboxNeighbours(ui32 MailboxNeighbourActors, EPoolType poolType) { THolder<TActorSystemSetup> setup = InitActorSystemSetup(poolType, 1, 1, false, false); TActorSystem actorSystem(setup); - actorSystem.Start(); - - TThreadParkPad pad; - TAtomic actorsAlive = 0; - double elapsedTime = 0; - + actorSystem.Start(); + + TThreadParkPad pad; + TAtomic actorsAlive = 0; + double elapsedTime = 0; + TActorId followerId = actorSystem.Register( new TSendReceiveActor(nullptr, {}, false, Follower, MailboxNeighbourActors), TMailboxType::HTSwap); THolder<IActor> leader{ new TTestEndDecorator(THolder( new TSendReceiveActor(&elapsedTime, followerId, false, Leader, MailboxNeighbourActors)), &pad, &actorsAlive)}; actorSystem.Register(leader.Release(), TMailboxType::HTSwap); - - pad.Park(); - actorSystem.Stop(); - + + pad.Park(); + actorSystem.Stop(); + return 1e9 * elapsedTime; - } - + } + double BenchContentedThreads(ui32 threads, ui32 actorsPairsCount, EPoolType poolType) { THolder<TActorSystemSetup> setup = InitActorSystemSetup(poolType, 1, threads, true, false); TActorSystem actorSystem(setup); - actorSystem.Start(); - - TThreadParkPad pad; - TAtomic actorsAlive = 0; - THPTimer Timer; - + actorSystem.Start(); + + TThreadParkPad pad; + TAtomic actorsAlive = 0; + THPTimer Timer; + TVector<double> dummy(actorsPairsCount); - Timer.Reset(); - for (ui32 i = 0; i < actorsPairsCount; ++i) { + Timer.Reset(); + for (ui32 i = 0; i < actorsPairsCount; ++i) { ui32 followerPoolId = 0; ui32 leaderPoolId = 0; TActorId followerId = actorSystem.Register( @@ -266,63 +266,63 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { new TTestEndDecorator(THolder( new TSendReceiveActor(&dummy[i], followerId, true, Leader)), &pad, &actorsAlive)}; actorSystem.Register(leader.Release(), TMailboxType::HTSwap, leaderPoolId); - } - - pad.Park(); - auto elapsedTime = Timer.Passed() / TotalEventsAmount; - actorSystem.Stop(); - + } + + pad.Park(); + auto elapsedTime = Timer.Passed() / TotalEventsAmount; + actorSystem.Stop(); + return 1e9 * elapsedTime; - } - - auto Mean(const TVector<double>& data) { + } + + auto Mean(const TVector<double>& data) { return Accumulate(data.begin(), data.end(), 0.0) / data.size(); - } - - auto Deviation(const TVector<double>& data) { - auto mean = Mean(data); - double deviation = 0.0; - for (const auto& x : data) { - deviation += (x - mean) * (x - mean); - } + } + + auto Deviation(const TVector<double>& data) { + auto mean = Mean(data); + double deviation = 0.0; + for (const auto& x : data) { + deviation += (x - mean) * (x - mean); + } return std::sqrt(deviation / data.size()); - } - - struct TStats { - double Mean; - double Deviation; - TString ToString() { + } + + struct TStats { + double Mean; + double Deviation; + TString ToString() { return TStringBuilder() << Mean << " ± " << Deviation << " ns " << std::ceil(Deviation / Mean * 1000) / 10.0 << "%"; - } - }; - - template <typename Func> + } + }; + + template <typename Func> TStats CountStats(Func func, ui32 itersCount = 5) { - TVector<double> elapsedTimes; - for (ui32 i = 0; i < itersCount; ++i) { - auto elapsedTime = func(); - elapsedTimes.push_back(elapsedTime); - } - return {Mean(elapsedTimes), Deviation(elapsedTimes)}; - } - - TVector<NActors::TMailboxType::EType> MailboxTypes = { - TMailboxType::Simple, - TMailboxType::Revolving, - TMailboxType::HTSwap, - TMailboxType::ReadAsFilled, - TMailboxType::TinyReadAsFilled - }; - + TVector<double> elapsedTimes; + for (ui32 i = 0; i < itersCount; ++i) { + auto elapsedTime = func(); + elapsedTimes.push_back(elapsedTime); + } + return {Mean(elapsedTimes), Deviation(elapsedTimes)}; + } + + TVector<NActors::TMailboxType::EType> MailboxTypes = { + TMailboxType::Simple, + TMailboxType::Revolving, + TMailboxType::HTSwap, + TMailboxType::ReadAsFilled, + TMailboxType::TinyReadAsFilled + }; + Y_UNIT_TEST(SendReceive1Pool1ThreadAlloc) { - for (const auto& mType : MailboxTypes) { - auto stats = CountStats([mType] { + for (const auto& mType : MailboxTypes) { + auto stats = CountStats([mType] { return BenchSendReceive(true, mType, EPoolType::Basic); - }); - Cerr << stats.ToString() << " " << mType << Endl; - } - } - + }); + Cerr << stats.ToString() << " " << mType << Endl; + } + } + Y_UNIT_TEST(SendReceive1Pool1ThreadAllocUnited) { for (const auto& mType : MailboxTypes) { auto stats = CountStats([mType] { @@ -332,14 +332,14 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { } } - Y_UNIT_TEST(SendReceive1Pool1ThreadNoAlloc) { - for (const auto& mType : MailboxTypes) { - auto stats = CountStats([mType] { + Y_UNIT_TEST(SendReceive1Pool1ThreadNoAlloc) { + for (const auto& mType : MailboxTypes) { + auto stats = CountStats([mType] { return BenchSendReceive(false, mType, EPoolType::Basic); - }); - Cerr << stats.ToString() << " " << mType << Endl; - } - } + }); + Cerr << stats.ToString() << " " << mType << Endl; + } + } Y_UNIT_TEST(SendReceive1Pool1ThreadNoAllocUnited) { for (const auto& mType : MailboxTypes) { @@ -350,13 +350,13 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { } } - Y_UNIT_TEST(SendActivateReceive1Pool1ThreadAlloc) { - auto stats = CountStats([] { + Y_UNIT_TEST(SendActivateReceive1Pool1ThreadAlloc) { + auto stats = CountStats([] { return BenchSendActivateReceive(1, 1, true, EPoolType::Basic); - }); - Cerr << stats.ToString() << Endl; - } - + }); + Cerr << stats.ToString() << Endl; + } + Y_UNIT_TEST(SendActivateReceive1Pool1ThreadAllocUnited) { auto stats = CountStats([] { return BenchSendActivateReceive(1, 1, true, EPoolType::United); @@ -364,13 +364,13 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { Cerr << stats.ToString() << Endl; } - Y_UNIT_TEST(SendActivateReceive1Pool1ThreadNoAlloc) { - auto stats = CountStats([] { + Y_UNIT_TEST(SendActivateReceive1Pool1ThreadNoAlloc) { + auto stats = CountStats([] { return BenchSendActivateReceive(1, 1, false, EPoolType::Basic); - }); - Cerr << stats.ToString() << Endl; - } - + }); + Cerr << stats.ToString() << Endl; + } + Y_UNIT_TEST(SendActivateReceive1Pool1ThreadNoAllocUnited) { auto stats = CountStats([] { return BenchSendActivateReceive(1, 1, false, EPoolType::United); @@ -378,13 +378,13 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { Cerr << stats.ToString() << Endl; } - Y_UNIT_TEST(SendActivateReceive1Pool2ThreadsAlloc) { - auto stats = CountStats([] { + Y_UNIT_TEST(SendActivateReceive1Pool2ThreadsAlloc) { + auto stats = CountStats([] { return BenchSendActivateReceive(1, 2, true, EPoolType::Basic); - }); - Cerr << stats.ToString() << Endl; - } - + }); + Cerr << stats.ToString() << Endl; + } + Y_UNIT_TEST(SendActivateReceive1Pool2ThreadsAllocUnited) { auto stats = CountStats([] { return BenchSendActivateReceive(1, 2, true, EPoolType::United); @@ -392,48 +392,48 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { Cerr << stats.ToString() << Endl; } - Y_UNIT_TEST(SendActivateReceive1Pool2ThreadsNoAlloc) { - auto stats = CountStats([] { + Y_UNIT_TEST(SendActivateReceive1Pool2ThreadsNoAlloc) { + auto stats = CountStats([] { return BenchSendActivateReceive(1, 2, false, EPoolType::Basic); - }); - Cerr << stats.ToString() << Endl; - } - + }); + Cerr << stats.ToString() << Endl; + } + Y_UNIT_TEST(SendActivateReceive1Pool2ThreadsNoAllocUnited) { - auto stats = CountStats([] { + auto stats = CountStats([] { return BenchSendActivateReceive(1, 2, false, EPoolType::United); - }); - Cerr << stats.ToString() << Endl; - } - + }); + Cerr << stats.ToString() << Endl; + } + Y_UNIT_TEST(SendActivateReceive2Pool1ThreadAlloc) { - auto stats = CountStats([] { + auto stats = CountStats([] { return BenchSendActivateReceive(2, 1, true, EPoolType::Basic); - }); - Cerr << stats.ToString() << Endl; - } - + }); + Cerr << stats.ToString() << Endl; + } + Y_UNIT_TEST(SendActivateReceive2Pool1ThreadAllocUnited) { auto stats = CountStats([] { return BenchSendActivateReceive(2, 1, true, EPoolType::United); }); Cerr << stats.ToString() << Endl; - } - + } + Y_UNIT_TEST(SendActivateReceive2Pool1ThreadNoAlloc) { auto stats = CountStats([] { return BenchSendActivateReceive(2, 1, false, EPoolType::Basic); }); Cerr << stats.ToString() << Endl; - } - + } + Y_UNIT_TEST(SendActivateReceive2Pool1ThreadNoAllocUnited) { auto stats = CountStats([] { return BenchSendActivateReceive(2, 1, false, EPoolType::United); }); Cerr << stats.ToString() << Endl; - } - + } + void RunBenchContentedThreads(ui32 threads, EPoolType poolType) { for (ui32 actorPairs = 1; actorPairs <= 2 * threads; actorPairs++) { auto stats = CountStats([threads, actorPairs, poolType] { @@ -441,8 +441,8 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { }); Cerr << stats.ToString() << " actorPairs: " << actorPairs << Endl; } - } - + } + Y_UNIT_TEST(SendActivateReceive1Pool1Threads) { RunBenchContentedThreads(1, EPoolType::Basic); } Y_UNIT_TEST(SendActivateReceive1Pool1ThreadsUnited) { RunBenchContentedThreads(1, EPoolType::United); } Y_UNIT_TEST(SendActivateReceive1Pool2Threads) { RunBenchContentedThreads(2, EPoolType::Basic); } @@ -460,15 +460,15 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { Y_UNIT_TEST(SendActivateReceive1Pool8Threads) { RunBenchContentedThreads(8, EPoolType::Basic); } Y_UNIT_TEST(SendActivateReceive1Pool8ThreadsUnited) { RunBenchContentedThreads(8, EPoolType::United); } - Y_UNIT_TEST(SendActivateReceiveWithMailboxNeighbours) { - TVector<ui32> NeighbourActors = {0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256}; - for (const auto& neighbour : NeighbourActors) { - auto stats = CountStats([neighbour] { + Y_UNIT_TEST(SendActivateReceiveWithMailboxNeighbours) { + TVector<ui32> NeighbourActors = {0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256}; + for (const auto& neighbour : NeighbourActors) { + auto stats = CountStats([neighbour] { return BenchSendActivateReceiveWithMailboxNeighbours(neighbour, EPoolType::Basic); - }); + }); Cerr << stats.ToString() << " neighbourActors: " << neighbour << Endl; - } - } + } + } Y_UNIT_TEST(SendActivateReceiveWithMailboxNeighboursUnited) { TVector<ui32> NeighbourActors = {0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256}; @@ -479,20 +479,20 @@ Y_UNIT_TEST_SUITE(ActorBenchmark) { Cerr << stats.ToString() << " neighbourActors: " << neighbour << Endl; } } -} - -Y_UNIT_TEST_SUITE(TestDecorator) { +} + +Y_UNIT_TEST_SUITE(TestDecorator) { struct TPingDecorator : TDecorator { TAutoPtr<IEventHandle> SavedEvent = nullptr; - ui64* Counter; + ui64* Counter; - TPingDecorator(THolder<IActor>&& actor, ui64* counter) + TPingDecorator(THolder<IActor>&& actor, ui64* counter) : TDecorator(std::move(actor)) , Counter(counter) { } - bool DoBeforeReceiving(TAutoPtr<IEventHandle>& ev, const TActorContext& ctx) override { + bool DoBeforeReceiving(TAutoPtr<IEventHandle>& ev, const TActorContext& ctx) override { *Counter += 1; if (ev->Type != TEvents::THelloWorld::Pong) { TAutoPtr<IEventHandle> pingEv = new IEventHandle(SelfId(), SelfId(), new TEvents::TEvPing()); @@ -506,15 +506,15 @@ Y_UNIT_TEST_SUITE(TestDecorator) { }; struct TPongDecorator : TDecorator { - ui64* Counter; + ui64* Counter; - TPongDecorator(THolder<IActor>&& actor, ui64* counter) + TPongDecorator(THolder<IActor>&& actor, ui64* counter) : TDecorator(std::move(actor)) , Counter(counter) { } - bool DoBeforeReceiving(TAutoPtr<IEventHandle>& ev, const TActorContext&) override { + bool DoBeforeReceiving(TAutoPtr<IEventHandle>& ev, const TActorContext&) override { *Counter += 1; if (ev->Type == TEvents::THelloWorld::Ping) { TAutoPtr<IEventHandle> pongEv = new IEventHandle(SelfId(), SelfId(), new TEvents::TEvPong()); @@ -555,14 +555,14 @@ Y_UNIT_TEST_SUITE(TestDecorator) { THolder<IActor> pongActor = MakeHolder<TPongDecorator>(std::move(innerActor), &pongCounter); ui64 pingCounter = 0; THolder<IActor> pingActor = MakeHolder<TPingDecorator>(std::move(pongActor), &pingCounter); - - TThreadParkPad pad; - TAtomic actorsAlive = 0; + + TThreadParkPad pad; + TAtomic actorsAlive = 0; THolder<IActor> endActor = MakeHolder<TTestEndDecorator>(std::move(pingActor), &pad, &actorsAlive); - actorSystem.Register(endActor.Release(), TMailboxType::HTSwap); - - pad.Park(); + actorSystem.Register(endActor.Release(), TMailboxType::HTSwap); + + pad.Park(); actorSystem.Stop(); UNIT_ASSERT(pongCounter == 2 && pingCounter == 2); } diff --git a/library/cpp/actors/core/ya.make b/library/cpp/actors/core/ya.make index 880a9d00db..69cecdb415 100644 --- a/library/cpp/actors/core/ya.make +++ b/library/cpp/actors/core/ya.make @@ -99,9 +99,9 @@ SRCS( servicemap.h ) -GENERATE_ENUM_SERIALIZATION(defs.h) +GENERATE_ENUM_SERIALIZATION(defs.h) GENERATE_ENUM_SERIALIZATION(actor.h) - + PEERDIR( library/cpp/actors/memory_log library/cpp/actors/prof diff --git a/library/cpp/lwtrace/mon/analytics/csv_output.h b/library/cpp/lwtrace/mon/analytics/csv_output.h index 90ded32f5d..7446418c11 100644 --- a/library/cpp/lwtrace/mon/analytics/csv_output.h +++ b/library/cpp/lwtrace/mon/analytics/csv_output.h @@ -41,8 +41,8 @@ inline TString ToCsv(const TTable& in, TString sep = TString("\t"), bool head = for (const TString& c : cols) { ss << (first? TString(): sep); first = false; - TString value; - ss << (row.GetAsString(c, value) ? value : TString("-")); + TString value; + ss << (row.GetAsString(c, value) ? value : TString("-")); } ss << Endl; } diff --git a/library/cpp/lwtrace/mon/analytics/data.h b/library/cpp/lwtrace/mon/analytics/data.h index 4b643fe20b..2998f0adca 100644 --- a/library/cpp/lwtrace/mon/analytics/data.h +++ b/library/cpp/lwtrace/mon/analytics/data.h @@ -3,57 +3,57 @@ #include <util/generic/string.h> #include <util/generic/hash.h> #include <util/generic/vector.h> -#include <util/string/builder.h> -#include <util/string/cast.h> - -#include <variant> +#include <util/string/builder.h> +#include <util/string/cast.h> +#include <variant> + namespace NAnalytics { -using TRowValue = std::variant<i64, ui64, double, TString>; - -TString ToString(const TRowValue& val) { - TStringBuilder builder; - std::visit([&builder] (auto&& arg) { - builder << arg; - }, val); - return builder; -} - -struct TRow : public THashMap<TString, TRowValue> { +using TRowValue = std::variant<i64, ui64, double, TString>; + +TString ToString(const TRowValue& val) { + TStringBuilder builder; + std::visit([&builder] (auto&& arg) { + builder << arg; + }, val); + return builder; +} + +struct TRow : public THashMap<TString, TRowValue> { TString Name; - template<typename T> - bool Get(const TString& name, T& value) const { - if constexpr (std::is_same_v<double, T>) { - if (name == "_count") { // Special values - value = 1.0; - return true; - } + template<typename T> + bool Get(const TString& name, T& value) const { + if constexpr (std::is_same_v<double, T>) { + if (name == "_count") { // Special values + value = 1.0; + return true; + } } auto iter = find(name); if (iter != end()) { - try { - value = std::get<T>(iter->second); - return true; - } catch (...) {} - } - return false; - } - - template<typename T = double> - T GetOrDefault(const TString& name, T dflt = T()) { - Get(name, dflt); - return dflt; - } - - bool GetAsString(const TString& name, TString& value) const { - auto iter = find(name); - if (iter != end()) { - value = ToString(iter->second); + try { + value = std::get<T>(iter->second); + return true; + } catch (...) {} + } + return false; + } + + template<typename T = double> + T GetOrDefault(const TString& name, T dflt = T()) { + Get(name, dflt); + return dflt; + } + + bool GetAsString(const TString& name, TString& value) const { + auto iter = find(name); + if (iter != end()) { + value = ToString(iter->second); return true; } - return false; + return false; } }; diff --git a/library/cpp/lwtrace/mon/analytics/html_output.h b/library/cpp/lwtrace/mon/analytics/html_output.h index f775f216b9..4ea65eff63 100644 --- a/library/cpp/lwtrace/mon/analytics/html_output.h +++ b/library/cpp/lwtrace/mon/analytics/html_output.h @@ -35,8 +35,8 @@ inline TString ToHtml(const TTable& in) ss << "<th>" << row.Name << "</th>"; } for (const TString& c : cols) { - TString value; - ss << "<td>" << (row.GetAsString(c, value) ? value : TString("-")) << "</td>"; + TString value; + ss << "<td>" << (row.GetAsString(c, value) ? value : TString("-")) << "</td>"; } ss << "</tr>"; } @@ -73,8 +73,8 @@ inline TString ToTransposedHtml(const TTable& in) ss << "<tr>"; ss << "<th>" << c << "</th>"; for (const TRow& row : in) { - TString value; - ss << "<td>" << (row.GetAsString(c, value) ? value : TString("-")) << "</td>"; + TString value; + ss << "<td>" << (row.GetAsString(c, value) ? value : TString("-")) << "</td>"; } ss << "</tr>"; } diff --git a/library/cpp/lwtrace/mon/analytics/transform.h b/library/cpp/lwtrace/mon/analytics/transform.h index f7dc9adb5b..e821ce566f 100644 --- a/library/cpp/lwtrace/mon/analytics/transform.h +++ b/library/cpp/lwtrace/mon/analytics/transform.h @@ -35,12 +35,12 @@ inline TTable Histogram(const TTable& in, TSkip skip, double y = y_in(row); ysum += y; if (i >= 0 && i < buckets) { - out[i][yn_sum] = y + out[i].GetOrDefault(yn_sum, 0.0); + out[i][yn_sum] = y + out[i].GetOrDefault(yn_sum, 0.0); } } for (TRow& row : out) { if (ysum != 0.0) { - row[yn_share] = row.GetOrDefault(yn_sum, 0.0) / ysum; + row[yn_share] = row.GetOrDefault(yn_sum, 0.0) / ysum; } } return out; @@ -90,21 +90,21 @@ inline TTable HistogramAll(const TTable& in, const TString& xn, double x1, doubl if (yn == xn) { continue; } - double y; - if (!row_in.Get(yn, y)) { - continue; - } + double y; + if (!row_in.Get(yn, y)) { + continue; + } colSum[yn] += y; if (i >= 0 && i < buckets) { - out[i][yn + "_cnt"] = out[i].GetOrDefault(yn + "_cnt") + 1; - out[i][yn + "_sum"] = out[i].GetOrDefault(yn + "_sum") + y; + out[i][yn + "_cnt"] = out[i].GetOrDefault(yn + "_cnt") + 1; + out[i][yn + "_sum"] = out[i].GetOrDefault(yn + "_sum") + y; if (out[i].contains(yn + "_min")) { - out[i][yn + "_min"] = Min(y, out[i].GetOrDefault(yn + "_min")); + out[i][yn + "_min"] = Min(y, out[i].GetOrDefault(yn + "_min")); } else { out[i][yn + "_min"] = y; } if (out[i].contains(yn + "_max")) { - out[i][yn + "_max"] = Max(y, out[i].GetOrDefault(yn + "_max")); + out[i][yn + "_max"] = Max(y, out[i].GetOrDefault(yn + "_max")); } else { out[i][yn + "_max"] = y; } @@ -112,19 +112,19 @@ inline TTable HistogramAll(const TTable& in, const TString& xn, double x1, doubl } colSum["_count"]++; if (i >= 0 && i < buckets) { - out[i]["_count_sum"] = out[i].GetOrDefault("_count_sum") + 1; + out[i]["_count_sum"] = out[i].GetOrDefault("_count_sum") + 1; } } for (TRow& row : out) { for (const TString& col : cols) { double ysum = colSum[col]; if (col != "_count") { - if (row.GetOrDefault(col + "_cnt") != 0.0) { - row[col + "_avg"] = row.GetOrDefault(col + "_sum") / row.GetOrDefault(col + "_cnt"); + if (row.GetOrDefault(col + "_cnt") != 0.0) { + row[col + "_avg"] = row.GetOrDefault(col + "_sum") / row.GetOrDefault(col + "_cnt"); } } if (ysum != 0.0) { - row[col + "_share"] = row.GetOrDefault(col + "_sum") / ysum; + row[col + "_share"] = row.GetOrDefault(col + "_sum") / ysum; } } } @@ -158,10 +158,10 @@ inline TMatrix CovarianceMatrix(const TTable& in) for (const TRow& row : in) { for (const auto& kv : row) { const TString& xn = kv.first; - double x; - if (!row.Get(xn, x)) { - continue; - } + double x; + if (!row.Get(xn, x)) { + continue; + } TAggregate& aggr = colAggr[xn]; aggr.Sum += x; aggr.Count++; @@ -177,16 +177,16 @@ inline TMatrix CovarianceMatrix(const TTable& in) TMatrix cov(cols.size(), cols.size()); for (const TRow& row : in) { for (const auto& kv1 : row) { - double x; - if (!row.Get(kv1.first, x)) { - continue; - } + double x; + if (!row.Get(kv1.first, x)) { + continue; + } TAggregate& xaggr = colAggr[kv1.first]; for (const auto& kv2 : row) { - double y; - if (!row.Get(kv2.first, y)) { - continue; - } + double y; + if (!row.Get(kv2.first, y)) { + continue; + } TAggregate& yaggr = colAggr[kv2.first]; covCount.Cell(xaggr.Idx, yaggr.Idx)++; cov.Cell(xaggr.Idx, yaggr.Idx) += (x - xaggr.Mean) * (y - yaggr.Mean); diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.cpp b/library/cpp/lwtrace/mon/mon_lwtrace.cpp index a61ee9ce22..18684c7ed5 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.cpp +++ b/library/cpp/lwtrace/mon/mon_lwtrace.cpp @@ -4,7 +4,7 @@ #include <iterator> #include <google/protobuf/text_format.h> -#include <library/cpp/lwtrace/mon/analytics/all.h> +#include <library/cpp/lwtrace/mon/analytics/all.h> #include <library/cpp/lwtrace/all.h> #include <library/cpp/monlib/service/pages/mon_page.h> #include <library/cpp/monlib/service/pages/resource_mon_page.h> @@ -1404,24 +1404,24 @@ void RequireMultipleSelection(TStringStream& ss, const TCgiParameters& e, const } } -void OptionalSelection(TStringStream& ss, const TCgiParameters& e, const TString& param, - const TString& text, const TVariants& variants) -{ - TSet<TString> selectedValues; - for (const TString& subvalue : Subvalues(e, param)) { - selectedValues.insert(subvalue); - } - if (!selectedValues.empty()) { - SelectorTitle(ss, text); - } - for (const TString& subvalue : Subvalues(e, param)) { - DropdownSelector<Erasable, true>(ss, e, param, subvalue, "", variants); - } - if (selectedValues.empty()) { - BtnHref<Button|ExtraSmall>(ss, text, MakeUrlAddSub(e, param, "")); - } -} - +void OptionalSelection(TStringStream& ss, const TCgiParameters& e, const TString& param, + const TString& text, const TVariants& variants) +{ + TSet<TString> selectedValues; + for (const TString& subvalue : Subvalues(e, param)) { + selectedValues.insert(subvalue); + } + if (!selectedValues.empty()) { + SelectorTitle(ss, text); + } + for (const TString& subvalue : Subvalues(e, param)) { + DropdownSelector<Erasable, true>(ss, e, param, subvalue, "", variants); + } + if (selectedValues.empty()) { + BtnHref<Button|ExtraSmall>(ss, text, MakeUrlAddSub(e, param, "")); + } +} + void OptionalMultipleSelection(TStringStream& ss, const TCgiParameters& e, const TString& param, const TString& text, const TVariants& variants) { @@ -1650,54 +1650,54 @@ private: }; void TDashboardRegistry::Register(const NLWTrace::TDashboard& dashboard) { - TGuard<TMutex> g(Mutex); - Dashboards[dashboard.GetName()] = dashboard; -} - + TGuard<TMutex> g(Mutex); + Dashboards[dashboard.GetName()] = dashboard; +} + void TDashboardRegistry::Register(const TVector<NLWTrace::TDashboard>& dashboards) { for (const auto& dashboard : dashboards) { Register(dashboard); } } -void TDashboardRegistry::Register(const TString& dashText) { +void TDashboardRegistry::Register(const TString& dashText) { NLWTrace::TDashboard dash; - if (!google::protobuf::TextFormat::ParseFromString(dashText, &dash)) { - ythrow yexception() << "Couldn't parse into dashboard"; - } - Register(dash); -} - + if (!google::protobuf::TextFormat::ParseFromString(dashText, &dash)) { + ythrow yexception() << "Couldn't parse into dashboard"; + } + Register(dash); +} + bool TDashboardRegistry::Get(const TString& name, NLWTrace::TDashboard& dash) { - TGuard<TMutex> g(Mutex); - if (!Dashboards.contains(name)) { - return false; - } - dash = Dashboards[name]; - return true; -} - -void TDashboardRegistry::Output(TStringStream& ss) { - HTML(ss) { - TABLE() { - TABLEHEAD() { - TABLEH() { ss << "Name"; } - } - TABLEBODY() { - TGuard<TMutex> g(Mutex); - for (auto& kv : Dashboards) { - const auto& dash = kv.second; - TABLER() { - TABLED() { - ss << "<a href='?mode=dashboard&name=" << dash.GetName() << "'>" << dash.GetName() << "</a>"; - } - } - } - } - } - } -} - + TGuard<TMutex> g(Mutex); + if (!Dashboards.contains(name)) { + return false; + } + dash = Dashboards[name]; + return true; +} + +void TDashboardRegistry::Output(TStringStream& ss) { + HTML(ss) { + TABLE() { + TABLEHEAD() { + TABLEH() { ss << "Name"; } + } + TABLEBODY() { + TGuard<TMutex> g(Mutex); + for (auto& kv : Dashboards) { + const auto& dash = kv.second; + TABLER() { + TABLED() { + ss << "<a href='?mode=dashboard&name=" << dash.GetName() << "'>" << dash.GetName() << "</a>"; + } + } + } + } + } + } +} + class ILogSource { public: virtual ~ILogSource() {} @@ -2267,17 +2267,17 @@ public: , ShowTs(showTs) {} - TLogTextPrinter(const TCgiParameters& e) - : TLogTextPrinter( + TLogTextPrinter(const TCgiParameters& e) + : TLogTextPrinter( Subvalues(e, "f"), e.Has("head")? FromString<ui64>(e.Get("head")): 0, - e.Has("tail")? FromString<ui64>(e.Get("tail")): 0, - e.Get("s"), - e.Get("reverse") == "y", - e.Get("cutts") == "y", - e.Get("showts") == "y") - {} - + e.Has("tail")? FromString<ui64>(e.Get("tail")): 0, + e.Get("s"), + e.Get("reverse") == "y", + e.Get("cutts") == "y", + e.Get("showts") == "y") + {} + enum EFormat { Text, Json @@ -2548,11 +2548,11 @@ private: item.Probe->Event.Signature.SerializeParams(item.Params, paramValues); for (size_t i = 0; i < item.SavedParamsCount; i++) { double value = FromString<double>(paramValues[i].data(), paramValues[i].size(), NAN); - // If value cannot be cast to double or is inf/nan -- assume it's a string + // If value cannot be cast to double or is inf/nan -- assume it's a string if (isfinite(value)) { row[item.Probe->Event.Signature.ParamNames[i]] = value; - } else { - row[item.Probe->Event.Signature.ParamNames[i]] = paramValues[i]; + } else { + row[item.Probe->Event.Signature.ParamNames[i]] = paramValues[i]; } } } @@ -2749,8 +2749,8 @@ struct TPatternNode { return ret; } - template <typename TReader> - void OutputSample(const TString& bn, double b1, double b2, const TSampleOpts& opts, TReader& reader) const + template <typename TReader> + void OutputSample(const TString& bn, double b1, double b2, const TSampleOpts& opts, TReader& reader) const { bool filterTotal = false; if (bn == "resTotal") { @@ -2775,13 +2775,13 @@ struct TPatternNode { } } - NLWTrace::TTrackLog tl; - for (TTrackIter i = TTrackTr::begin(*track), e = TTrackTr::end(*track); i != e; ++i) { + NLWTrace::TTrackLog tl; + for (TTrackIter i = TTrackTr::begin(*track), e = TTrackTr::end(*track); i != e; ++i) { const NLWTrace::TLogItem& item = *i; - const auto threadId = i->ThreadId; - tl.Items.push_back(NLWTrace::TTrackLog::TItem(threadId, item)); + const auto threadId = i->ThreadId; + tl.Items.push_back(NLWTrace::TTrackLog::TItem(threadId, item)); } - reader.Push(0, tl); + reader.Push(0, tl); if (spaceLeft) { spaceLeft--; if (!spaceLeft) { @@ -2941,11 +2941,11 @@ public: } } - template <typename TReader> - void OutputSelectedSample(const TString& bn, double b1, double b2, const TSampleOpts& opts, TReader& reader) + template <typename TReader> + void OutputSelectedSample(const TString& bn, double b1, double b2, const TSampleOpts& opts, TReader& reader) { if (SelectedNode) { - SelectedNode->OutputSample(bn, b1, b2, opts, reader); + SelectedNode->OutputSample(bn, b1, b2, opts, reader); } } @@ -3276,10 +3276,10 @@ public: } // Selected sample - template <typename TReader> - void OutputSample(const TString& bn, double b1, double b2, const TSampleOpts& opts, TReader& reader) + template <typename TReader> + void OutputSample(const TString& bn, double b1, double b2, const TSampleOpts& opts, TReader& reader) { - Tree.OutputSelectedSample(bn, b1, b2, opts, reader); + Tree.OutputSelectedSample(bn, b1, b2, opts, reader); } // Tabular representation of tracks data @@ -3770,7 +3770,7 @@ NLWTrace::TProbeRegistry g_Probes; TString g_sanitizerTest("TString g_sanitizerTest"); NLWTrace::TManager g_SafeManager(g_Probes, false); NLWTrace::TManager g_UnsafeManager(g_Probes, true); -TDashboardRegistry g_DashboardRegistry; +TDashboardRegistry g_DashboardRegistry; class TLWTraceMonPage : public NMonitoring::IMonPage { private: @@ -3796,10 +3796,10 @@ public: OutputTracesAndSnapshots(request, out); } else if (request.GetParams().Get("mode") == "probes") { OutputProbes(request, out); - } else if (request.GetParams().Get("mode") == "dashboards") { - OutputDashboards(request, out); - } else if (request.GetParams().Get("mode") == "dashboard") { - OutputDashboard(request, out); + } else if (request.GetParams().Get("mode") == "dashboards") { + OutputDashboards(request, out); + } else if (request.GetParams().Get("mode") == "dashboard") { + OutputDashboard(request, out); } else if (request.GetParams().Get("mode") == "log") { OutputLog(request, out); } else if (request.GetParams().Get("mode") == "query") { @@ -3849,7 +3849,7 @@ private: "<ul class=\"nav navbar-nav\">" "<li" << (request.GetParams().Get("mode") == ""? active: "") << "><a href=\"?mode=\">Traces</a></li>" "<li" << (request.GetParams().Get("mode") == "probes"? active: "") << "><a href=\"?mode=probes\">Probes</a></li>" - "<li" << (request.GetParams().Get("mode") == "dashboards"? active: "") << "><a href=\"?mode=dashboards\">Dashboard</a></li>" + "<li" << (request.GetParams().Get("mode") == "dashboards"? active: "") << "><a href=\"?mode=dashboards\">Dashboard</a></li>" "<li" << (request.GetParams().Get("mode") == "builder"? active: "") << "><a href=\"?mode=builder\">Builder</a></li>" "<li" << (request.GetParams().Get("mode") == "analytics"? active: "") << "><a href=\"?mode=analytics&id=\">Analytics</a></li>" "<li><a href=\"https://wiki.yandex-team.ru/development/poisk/arcadia/library/cpp/lwtrace/\" target=\"_blank\">Documentation</a></li>" @@ -3902,28 +3902,28 @@ private: } } - void OutputDashboards(const NMonitoring::IMonHttpRequest& request, IOutputStream& out) - { - TStringStream ss; - g_DashboardRegistry.Output(ss); - - WWW_HTML(out) { - OutputNavbar(request, out); - out << ss.Str(); + void OutputDashboards(const NMonitoring::IMonHttpRequest& request, IOutputStream& out) + { + TStringStream ss; + g_DashboardRegistry.Output(ss); + + WWW_HTML(out) { + OutputNavbar(request, out); + out << ss.Str(); } - } - - void OutputDashboard(const NMonitoring::IMonHttpRequest& request, IOutputStream& out) { - if (!request.GetParams().Has("name")) { - ythrow yexception() << "Cgi-parameter 'name' is not specified"; - } else { - auto name = request.GetParams().Get("name"); + } + + void OutputDashboard(const NMonitoring::IMonHttpRequest& request, IOutputStream& out) { + if (!request.GetParams().Has("name")) { + ythrow yexception() << "Cgi-parameter 'name' is not specified"; + } else { + auto name = request.GetParams().Get("name"); NLWTrace::TDashboard dash; - if (!g_DashboardRegistry.Get(name, dash)) { - ythrow yexception() << "Dashboard doesn't exist"; - } - WWW_HTML(out) { - OutputNavbar(request, out); + if (!g_DashboardRegistry.Get(name, dash)) { + ythrow yexception() << "Dashboard doesn't exist"; + } + WWW_HTML(out) { + OutputNavbar(request, out); out << "<style type='text/css'>html, body { height: 100%; }</style>"; out << "<h2>" << dash.GetName() << "</h2>"; if (dash.GetDescription()) { @@ -3955,7 +3955,7 @@ private: if (url) { if (title) { out << "<td rowspan='" << rowSpan << "' colSpan='1'><a href=" << url << ">" << title << "</a><br>"; - } + } out << "<iframe scrolling='no' width='" << 100 * colSpan << "%' height='" << height << "%' style='border: 0' src=" << url << "></iframe></td>"; // Add fake cells to fix html table for (ui32 left = 1; left < colSpan; ++left) { @@ -3964,14 +3964,14 @@ private: } } else { out << "<td style='font-size: 25px' align='left' rowspan='" << rowSpan << "' colSpan='" << colSpan << "'>" << text << "</td>"; - } - } + } + } } - out << "</tbody></table>"; - } - } - } - + out << "</tbody></table>"; + } + } + } + static double ParseDouble(const TString& s) { if (s == "inf") { @@ -3988,7 +3988,7 @@ private: if (request.GetParams().NumOfValues("id") == 0) { ythrow yexception() << "Cgi-parameter 'id' is not specified"; } else { - const TCgiParameters& e = request.GetParams(); + const TCgiParameters& e = request.GetParams(); TStringStream ss; if (e.Get("format") == "json") { TLogJsonPrinter printer(ss); @@ -4009,38 +4009,38 @@ private: printer.OutputJson(ss); out << HTTPOKJSON; out << ss.Str(); - } else if (e.Get("format") == "analytics" && e.Get("aggr") == "tracks") { - TLogTrackExtractor logTrackExtractor(e, - Subvalues(e, "f"), - Subvalues(e, "g") - ); - for (const TString& id : Subvalues(e, "id")) { - CheckAdHocTrace(id, TDuration::Minutes(1)); - TraceMngr->ReadLog(id, logTrackExtractor); - TraceMngr->ReadDepot(id, logTrackExtractor); - } - TString patternAnalyzer; - if (e.Get("pattern")) { - patternAnalyzer = e.Get("ptrn_anlz"); - } - logTrackExtractor.Run(); - - TLogTextPrinter printer(e); - const TString& distBy = patternAnalyzer; + } else if (e.Get("format") == "analytics" && e.Get("aggr") == "tracks") { + TLogTrackExtractor logTrackExtractor(e, + Subvalues(e, "f"), + Subvalues(e, "g") + ); + for (const TString& id : Subvalues(e, "id")) { + CheckAdHocTrace(id, TDuration::Minutes(1)); + TraceMngr->ReadLog(id, logTrackExtractor); + TraceMngr->ReadDepot(id, logTrackExtractor); + } + TString patternAnalyzer; + if (e.Get("pattern")) { + patternAnalyzer = e.Get("ptrn_anlz"); + } + logTrackExtractor.Run(); + + TLogTextPrinter printer(e); + const TString& distBy = patternAnalyzer; double sel_x1 = e.Get("sel_x1")? ParseDouble(e.Get("sel_x1")): NAN; double sel_x2 = e.Get("sel_x2")? ParseDouble(e.Get("sel_x2")): NAN; - TSampleOpts opts; - opts.ShowProvider = (e.Get("show_provider") == "y"); - if (e.Get("size_limit")) { - opts.SizeLimit = FromString<size_t>(e.Get("size_limit")); - } - logTrackExtractor.OutputSample(distBy, sel_x1, sel_x2, opts, printer); - printer.Output(ss); - out << HTTPOKTEXT; - out << ss.Str(); + TSampleOpts opts; + opts.ShowProvider = (e.Get("show_provider") == "y"); + if (e.Get("size_limit")) { + opts.SizeLimit = FromString<size_t>(e.Get("size_limit")); + } + logTrackExtractor.OutputSample(distBy, sel_x1, sel_x2, opts, printer); + printer.Output(ss); + out << HTTPOKTEXT; + out << ss.Str(); } else { - TLogTextPrinter printer(e); - for (const TString& id : Subvalues(e, "id")) { + TLogTextPrinter printer(e); + for (const TString& id : Subvalues(e, "id")) { CheckAdHocTrace(id, TDuration::Minutes(1)); TraceMngr->ReadLog(id, printer); TraceMngr->ReadDepot(id, printer); @@ -4131,23 +4131,23 @@ private: } logFilter->FilterSelectors(out, e, "f"); - + OptionalMultipleSelection(out, e, "g", "group by", logFilter->ListParamNames()); - { - auto paramNamesList = logFilter->ListParamNames(); - if (e.Get("aggr") == "tracks") { - paramNamesList.emplace_back("_trackMs", "_trackMs"); - } - OptionalSelection(out, e, "s", "order by", paramNamesList); - } - - if (e.Get("s")) { - TVariants variants; - variants.emplace_back("", "asc"); - variants.emplace_back("y", "desc"); - DropdownSelector<Link>(out, e, "reverse", e.Get("reverse"), "", variants); - } - + { + auto paramNamesList = logFilter->ListParamNames(); + if (e.Get("aggr") == "tracks") { + paramNamesList.emplace_back("_trackMs", "_trackMs"); + } + OptionalSelection(out, e, "s", "order by", paramNamesList); + } + + if (e.Get("s")) { + TVariants variants; + variants.emplace_back("", "asc"); + variants.emplace_back("y", "desc"); + DropdownSelector<Link>(out, e, "reverse", e.Get("reverse"), "", variants); + } + TString aggr = e.Get("aggr"); TVariants variants1; // MSVS2013 doesn't understand complex initializer lists variants1.emplace_back("", "without aggregation"); @@ -4211,7 +4211,7 @@ private: NAnalytics::TTable distData; bool showSample = false; - TLogTextPrinter printer(e); + TLogTextPrinter printer(e); if (patternAnalyzer == "resTotal" || patternAnalyzer == "resLast") { distBy = patternAnalyzer; @@ -4225,7 +4225,7 @@ private: if (e.Get("size_limit")) { opts.SizeLimit = FromString<size_t>(e.Get("size_limit")); } - logTracks->OutputSample(distBy, sel_x1, sel_x2, opts, printer); + logTracks->OutputSample(distBy, sel_x1, sel_x2, opts, printer); } } @@ -4273,35 +4273,35 @@ private: if (distBy) { out << NResource::Find("lwtrace/mon/static/analytics.flot.html") << Endl; if (showSample) { - static const THashSet<TString> keepParams = { - "f", - "g", - "head", - "tail", - "s", - "reverse", - "cutts", - "showts", - "show_provider", - "size_limit", - "aggr", - "id", - "pattern", - "ptrn_anlz", - "sel_x1", - "sel_x2" - }; - TCgiParameters cgiParams; - for (const auto& kv : request.GetParams()) { - if (keepParams.count(kv.first)) { - cgiParams.insert(kv); - } - } - cgiParams.insert(std::pair<TString, TString>("mode", "log")); - BtnHref<Button|Medium>(out, "Open logs", MakeUrlAdd(cgiParams, "format", "analytics")); - out << "<pre>\n"; - printer.Output(out); - out << "</pre>\n"; + static const THashSet<TString> keepParams = { + "f", + "g", + "head", + "tail", + "s", + "reverse", + "cutts", + "showts", + "show_provider", + "size_limit", + "aggr", + "id", + "pattern", + "ptrn_anlz", + "sel_x1", + "sel_x2" + }; + TCgiParameters cgiParams; + for (const auto& kv : request.GetParams()) { + if (keepParams.count(kv.first)) { + cgiParams.insert(kv); + } + } + cgiParams.insert(std::pair<TString, TString>("mode", "log")); + BtnHref<Button|Medium>(out, "Open logs", MakeUrlAdd(cgiParams, "format", "analytics")); + out << "<pre>\n"; + printer.Output(out); + out << "</pre>\n"; } } @@ -4342,7 +4342,7 @@ private: variants2.emplace_back("text", "text"); variants2.emplace_back("csv", "CSV"); variants2.emplace_back("json_flot", "JSON"); - + RequireSelection(out, e, "out", "and show", variants2); if (outFormat == "csv") { TString sep = e.Get("sep")? e.Get("sep"): TString("\t"); @@ -4427,90 +4427,90 @@ private: } } } - } else if (outFormat = "text") { + } else if (outFormat = "text") { out << " <input type='text' id='logsLimit' size='2' placeholder='Limit'>" << Endl; out << - R"END(<script> - { - var url = new URL(window.location.href); - if (url.searchParams.has('head')) { - document.getElementById('logsLimit').value = url.searchParams.get('head'); - } - } - - $('#logsLimit').on('keypress', function(ev) { - if (ev.keyCode == 13) { - var url = new URL(window.location.href); - var limit_value = document.getElementById('logsLimit').value; - if (limit_value && !isNaN(limit_value)) { - url.searchParams.set('head', limit_value); - window.location.href = url.toString(); - } else if (!limit_value) { - url.searchParams.delete('head'); - window.location.href = url.toString(); - } - } - }); - </script>)END"; - TString selectors = out.Str(); - TLogTextPrinter printer(e); - TStringStream ss; - for (const TString& id : Subvalues(e, "id")) { - CheckAdHocTrace(id, TDuration::Minutes(1)); - TraceMngr->ReadLog(id, printer); - TraceMngr->ReadDepot(id, printer); - } - printer.Output(ss); - - out.Clear(); - out << NMonitoring::HTTPOKHTML; - out << "<!DOCTYPE html>" << Endl; - HTML(out) { - HTML_TAG() { - HEAD() { + R"END(<script> + { + var url = new URL(window.location.href); + if (url.searchParams.has('head')) { + document.getElementById('logsLimit').value = url.searchParams.get('head'); + } + } + + $('#logsLimit').on('keypress', function(ev) { + if (ev.keyCode == 13) { + var url = new URL(window.location.href); + var limit_value = document.getElementById('logsLimit').value; + if (limit_value && !isNaN(limit_value)) { + url.searchParams.set('head', limit_value); + window.location.href = url.toString(); + } else if (!limit_value) { + url.searchParams.delete('head'); + window.location.href = url.toString(); + } + } + }); + </script>)END"; + TString selectors = out.Str(); + TLogTextPrinter printer(e); + TStringStream ss; + for (const TString& id : Subvalues(e, "id")) { + CheckAdHocTrace(id, TDuration::Minutes(1)); + TraceMngr->ReadLog(id, printer); + TraceMngr->ReadDepot(id, printer); + } + printer.Output(ss); + + out.Clear(); + out << NMonitoring::HTTPOKHTML; + out << "<!DOCTYPE html>" << Endl; + HTML(out) { + HTML_TAG() { + HEAD() { out << NResource::Find("lwtrace/mon/static/analytics.header.html") << Endl; - } - BODY() { - // Wrap selectors with navbar - { TSelectorsContainer sc(out); - out << selectors; - } - static const THashSet<TString> keepParams = { - "s", - "head", - "reverse", - "cutts", - "showts", - "id", - "out" - }; - TCgiParameters cgiParams; - for (const auto& kv : request.GetParams()) { - if (keepParams.count(kv.first)) { - cgiParams.insert(kv); - } - } - cgiParams.insert(std::pair<TString, TString>("mode", "analytics")); - - auto toggledButton = [&out, &e, &cgiParams] (const TString& label, const TString& cgiKey) { - if (e.Get(cgiKey) == "y") { - BtnHref<Button|Medium>(out, label, MakeUrlErase(cgiParams, cgiKey, "y"), true); - } else { - BtnHref<Button|Medium>(out, label, MakeUrlAdd(cgiParams, cgiKey, "y")); - } - }; - toggledButton("Cut Tails", "cutts"); - toggledButton("Relative Time", "showts"); - - cgiParams.erase("mode"); - cgiParams.insert(std::pair<TString, TString>("mode", "log")); - BtnHref<Button|Medium>(out, "Fullscreen", MakeUrlAdd(cgiParams, "format", "text")); - out << "<pre>\n"; - out << ss.Str() << Endl; - out << "</pre>\n"; - } - } - } + } + BODY() { + // Wrap selectors with navbar + { TSelectorsContainer sc(out); + out << selectors; + } + static const THashSet<TString> keepParams = { + "s", + "head", + "reverse", + "cutts", + "showts", + "id", + "out" + }; + TCgiParameters cgiParams; + for (const auto& kv : request.GetParams()) { + if (keepParams.count(kv.first)) { + cgiParams.insert(kv); + } + } + cgiParams.insert(std::pair<TString, TString>("mode", "analytics")); + + auto toggledButton = [&out, &e, &cgiParams] (const TString& label, const TString& cgiKey) { + if (e.Get(cgiKey) == "y") { + BtnHref<Button|Medium>(out, label, MakeUrlErase(cgiParams, cgiKey, "y"), true); + } else { + BtnHref<Button|Medium>(out, label, MakeUrlAdd(cgiParams, cgiKey, "y")); + } + }; + toggledButton("Cut Tails", "cutts"); + toggledButton("Relative Time", "showts"); + + cgiParams.erase("mode"); + cgiParams.insert(std::pair<TString, TString>("mode", "log")); + BtnHref<Button|Medium>(out, "Fullscreen", MakeUrlAdd(cgiParams, "format", "text")); + out << "<pre>\n"; + out << ss.Str() << Endl; + out << "</pre>\n"; + } + } + } } } } @@ -4650,11 +4650,11 @@ private: out << "OK\n"; } } - - void RegisterDashboard(const TString& dashConfig) { - g_DashboardRegistry.Register(dashConfig); - } - + + void RegisterDashboard(const TString& dashConfig) { + g_DashboardRegistry.Register(dashConfig); + } + private: // Returns true iff trace is ad-hoc and ensures trace is created bool CheckAdHocTrace(const TString& id, TDuration timeout) @@ -4716,8 +4716,8 @@ NLWTrace::TManager& TraceManager(bool allowUnsafe) { return allowUnsafe? g_UnsafeManager: g_SafeManager; } -TDashboardRegistry& DashboardRegistry() { - return g_DashboardRegistry; -} - +TDashboardRegistry& DashboardRegistry() { + return g_DashboardRegistry; +} + } // namespace NLwTraceMonPage diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.h b/library/cpp/lwtrace/mon/mon_lwtrace.h index 8030f6ea61..f6ba43751e 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.h +++ b/library/cpp/lwtrace/mon/mon_lwtrace.h @@ -8,20 +8,20 @@ namespace NLwTraceMonPage { -class TDashboardRegistry { +class TDashboardRegistry { THashMap<TString, NLWTrace::TDashboard> Dashboards; - TMutex Mutex; -public: + TMutex Mutex; +public: void Register(const NLWTrace::TDashboard& dashboard); void Register(const TVector<NLWTrace::TDashboard>& dashboards); - void Register(const TString& dashText); + void Register(const TString& dashText); bool Get(const TString& name, NLWTrace::TDashboard& dash); - void Output(TStringStream& ss); -}; - + void Output(TStringStream& ss); +}; + void RegisterPages(NMonitoring::TMonService2* mon, bool allowUnsafe = false); NLWTrace::TProbeRegistry& ProbeRegistry(); // This is not safe to use this function before main() NLWTrace::TManager& TraceManager(bool allowUnsafe = false); -TDashboardRegistry& DashboardRegistry(); +TDashboardRegistry& DashboardRegistry(); } // namespace NLwTraceMonPage diff --git a/library/cpp/lwtrace/mon/ya.make b/library/cpp/lwtrace/mon/ya.make index bdcb315754..419685dcbf 100644 --- a/library/cpp/lwtrace/mon/ya.make +++ b/library/cpp/lwtrace/mon/ya.make @@ -44,12 +44,12 @@ SRCS( ) PEERDIR( - library/cpp/html/pcdata + library/cpp/html/pcdata library/cpp/lwtrace library/cpp/lwtrace/mon/analytics library/cpp/monlib/dynamic_counters library/cpp/resource - library/cpp/string_utils/base64 + library/cpp/string_utils/base64 ) END() diff --git a/library/cpp/lwtrace/trace_ut.cpp b/library/cpp/lwtrace/trace_ut.cpp index cb03e4fbde..07c397dd85 100644 --- a/library/cpp/lwtrace/trace_ut.cpp +++ b/library/cpp/lwtrace/trace_ut.cpp @@ -36,7 +36,7 @@ LWTRACE_USING(LWTRACE_UT_PROVIDER) using namespace NLWTrace; Y_UNIT_TEST_SUITE(LWTraceTrace) { -#ifndef LWTRACE_DISABLE +#ifndef LWTRACE_DISABLE Y_UNIT_TEST(Smoke) { TManager mngr(*Singleton<TProbeRegistry>(), true); TQuery q; @@ -65,487 +65,487 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { LWPROBE(EnumParams, ValueA, EEnumClass::ValueC); LWPROBE(InstantParam, TInstant::Seconds(42)); LWPROBE(DurationParam, TDuration::MilliSeconds(146)); - LWPROBE(ProtoEnum, OT_EQ); + LWPROBE(ProtoEnum, OT_EQ); } - Y_UNIT_TEST(Predicate) { - TManager mngr(*Singleton<TProbeRegistry>(), true); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - Blocks { + Y_UNIT_TEST(Predicate) { + TManager mngr(*Singleton<TProbeRegistry>(), true); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + Blocks { ProbeDesc { - Name: "IntParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Predicate { - Operators { - Type: OT_NE - Argument { Param: "value" } - Argument { Value: "1" } - } - } - Action { + Name: "IntParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Predicate { + Operators { + Type: OT_NE + Argument { Param: "value" } + Argument { Value: "1" } + } + } + Action { LogAction { } - } - } - )END", &q); - UNIT_ASSERT(parsed); - mngr.New("QueryName", q); - LWPROBE(IntParam, 3); - LWPROBE(IntParam, 1); - LWPROBE(IntParam, 4); - LWPROBE(IntParam, 1); - LWPROBE(IntParam, 1); - LWPROBE(IntParam, 5); - struct { - ui32 expected = 3; - ui32 logsCount = 0; - void Push(TThread::TId, const TLogItem& item) { - UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntParam"); - ui32 value = item.GetParam("value").GetParam().Get<ui32>(); - UNIT_ASSERT(value == expected); - expected++; - logsCount++; - } - } reader; - mngr.ReadLog("QueryName", reader); - UNIT_ASSERT(reader.logsCount == 3); - } - - Y_UNIT_TEST(StatementAction) { - TManager mngr(*Singleton<TProbeRegistry>(), true); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - Blocks { + } + } + )END", &q); + UNIT_ASSERT(parsed); + mngr.New("QueryName", q); + LWPROBE(IntParam, 3); + LWPROBE(IntParam, 1); + LWPROBE(IntParam, 4); + LWPROBE(IntParam, 1); + LWPROBE(IntParam, 1); + LWPROBE(IntParam, 5); + struct { + ui32 expected = 3; + ui32 logsCount = 0; + void Push(TThread::TId, const TLogItem& item) { + UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntParam"); + ui32 value = item.GetParam("value").GetParam().Get<ui32>(); + UNIT_ASSERT(value == expected); + expected++; + logsCount++; + } + } reader; + mngr.ReadLog("QueryName", reader); + UNIT_ASSERT(reader.logsCount == 3); + } + + Y_UNIT_TEST(StatementAction) { + TManager mngr(*Singleton<TProbeRegistry>(), true); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + Blocks { ProbeDesc { - Name: "IntParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Action { - StatementAction { - Type: ST_INC - Argument { Variable: "varInc" } - } - } - Action { - StatementAction { - Type: ST_DEC - Argument { Variable: "varDec" } - } - } - Action { - StatementAction { - Type: ST_MOV - Argument { Variable: "varMov" } - Argument { Value: "3" } - } - } - Action { - StatementAction { - Type: ST_ADD_EQ - Argument { Variable: "varAddEq" } - Argument { Value: "2" } - } - } - Action { - StatementAction { - Type: ST_ADD_EQ - Argument { Variable: "varAddEq" } - Argument { Value: "3" } - } - } - Action { - StatementAction { - Type: ST_SUB_EQ - Argument { Variable: "varSubEq" } - Argument { Value: "5" } - } - } - Action { - StatementAction { - Type: ST_ADD - Argument { Variable: "varAdd" } - Argument { Value: "3" } - Argument { Value: "2" } - } - } - Action { - StatementAction { - Type: ST_SUB - Argument { Variable: "varSub" } - Argument { Value: "3" } - Argument { Value: "2" } - } - } - Action { - StatementAction { - Type: ST_MUL - Argument { Variable: "varMul" } - Argument { Value: "6" } - Argument { Value: "2" } - } - } - Action { - StatementAction { - Type: ST_DIV - Argument { Variable: "varDiv" } - Argument { Value: "6" } - Argument { Value: "2" } - } - } - Action { - StatementAction { - Type: ST_MOD - Argument { Variable: "varMod" } - Argument { Value: "17" } - Argument { Value: "5" } - } - } - } - Blocks { + Name: "IntParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Action { + StatementAction { + Type: ST_INC + Argument { Variable: "varInc" } + } + } + Action { + StatementAction { + Type: ST_DEC + Argument { Variable: "varDec" } + } + } + Action { + StatementAction { + Type: ST_MOV + Argument { Variable: "varMov" } + Argument { Value: "3" } + } + } + Action { + StatementAction { + Type: ST_ADD_EQ + Argument { Variable: "varAddEq" } + Argument { Value: "2" } + } + } + Action { + StatementAction { + Type: ST_ADD_EQ + Argument { Variable: "varAddEq" } + Argument { Value: "3" } + } + } + Action { + StatementAction { + Type: ST_SUB_EQ + Argument { Variable: "varSubEq" } + Argument { Value: "5" } + } + } + Action { + StatementAction { + Type: ST_ADD + Argument { Variable: "varAdd" } + Argument { Value: "3" } + Argument { Value: "2" } + } + } + Action { + StatementAction { + Type: ST_SUB + Argument { Variable: "varSub" } + Argument { Value: "3" } + Argument { Value: "2" } + } + } + Action { + StatementAction { + Type: ST_MUL + Argument { Variable: "varMul" } + Argument { Value: "6" } + Argument { Value: "2" } + } + } + Action { + StatementAction { + Type: ST_DIV + Argument { Variable: "varDiv" } + Argument { Value: "6" } + Argument { Value: "2" } + } + } + Action { + StatementAction { + Type: ST_MOD + Argument { Variable: "varMod" } + Argument { Value: "17" } + Argument { Value: "5" } + } + } + } + Blocks { ProbeDesc { - Name: "IntParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Predicate { - Operators { - Type: OT_EQ - Argument { Variable: "varInc" } - Argument { Value: "1" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varDec" } + Name: "IntParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Predicate { + Operators { + Type: OT_EQ + Argument { Variable: "varInc" } + Argument { Value: "1" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varDec" } Argument { Value: "-1" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varMov" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varMov" } Argument { Value: "3" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varAddEq" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varAddEq" } Argument { Value: "5" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varSubEq" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varSubEq" } Argument { Value: "-5" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varAdd" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varAdd" } Argument { Value: "5" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varSub" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varSub" } Argument { Value: "1" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varMul" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varMul" } Argument { Value: "12" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varDiv" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varDiv" } Argument { Value: "3" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varMod" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varMod" } Argument { Value: "2" } - } - } - Action { - LogAction { } - } - } - )END", &q); - UNIT_ASSERT(parsed); - mngr.New("QueryName", q); - LWPROBE(IntParam, 1); - LWPROBE(IntParam, 2); - struct { - int logsCount = 0; - void Push(TThread::TId, const TLogItem& item) { - UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntParam"); - ui32 value = item.GetParam("value").GetParam().Get<ui32>(); - UNIT_ASSERT(value == 1); - logsCount++; + } + } + Action { + LogAction { } + } } - } reader; - mngr.ReadLog("QueryName", reader); - UNIT_ASSERT(reader.logsCount == 1); - } - - Y_UNIT_TEST(StatementActionWithParams) { - TManager mngr(*Singleton<TProbeRegistry>(), true); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - Blocks { + )END", &q); + UNIT_ASSERT(parsed); + mngr.New("QueryName", q); + LWPROBE(IntParam, 1); + LWPROBE(IntParam, 2); + struct { + int logsCount = 0; + void Push(TThread::TId, const TLogItem& item) { + UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntParam"); + ui32 value = item.GetParam("value").GetParam().Get<ui32>(); + UNIT_ASSERT(value == 1); + logsCount++; + } + } reader; + mngr.ReadLog("QueryName", reader); + UNIT_ASSERT(reader.logsCount == 1); + } + + Y_UNIT_TEST(StatementActionWithParams) { + TManager mngr(*Singleton<TProbeRegistry>(), true); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + Blocks { ProbeDesc { - Name: "IntIntParams" - Provider: "LWTRACE_UT_PROVIDER" - } - Action { - StatementAction { - Type: ST_MOV - Argument { Variable: "varMov" } - Argument { Param: "value1" } - } - } - Action { - StatementAction { - Type: ST_ADD_EQ - Argument { Variable: "varAddEq" } - Argument { Param: "value1" } - } - } - Action { - StatementAction { - Type: ST_SUB_EQ - Argument { Variable: "varSubEq" } - Argument { Param: "value1" } - } - } - Action { - StatementAction { - Type: ST_ADD - Argument { Variable: "varAdd" } - Argument { Param: "value1" } - Argument { Param: "value2" } - } - } - Action { - StatementAction { - Type: ST_SUB - Argument { Variable: "varSub" } - Argument { Param: "value1" } - Argument { Param: "value2" } - } - } - Action { - StatementAction { - Type: ST_MUL - Argument { Variable: "varMul" } - Argument { Param: "value1" } - Argument { Param: "value2" } - } - } - Action { - StatementAction { - Type: ST_DIV - Argument { Variable: "varDiv" } - Argument { Param: "value1" } - Argument { Param: "value2" } - } - } - Action { - StatementAction { - Type: ST_MOD - Argument { Variable: "varMod" } - Argument { Param: "value1" } - Argument { Param: "value2" } - } - } - } - Blocks { + Name: "IntIntParams" + Provider: "LWTRACE_UT_PROVIDER" + } + Action { + StatementAction { + Type: ST_MOV + Argument { Variable: "varMov" } + Argument { Param: "value1" } + } + } + Action { + StatementAction { + Type: ST_ADD_EQ + Argument { Variable: "varAddEq" } + Argument { Param: "value1" } + } + } + Action { + StatementAction { + Type: ST_SUB_EQ + Argument { Variable: "varSubEq" } + Argument { Param: "value1" } + } + } + Action { + StatementAction { + Type: ST_ADD + Argument { Variable: "varAdd" } + Argument { Param: "value1" } + Argument { Param: "value2" } + } + } + Action { + StatementAction { + Type: ST_SUB + Argument { Variable: "varSub" } + Argument { Param: "value1" } + Argument { Param: "value2" } + } + } + Action { + StatementAction { + Type: ST_MUL + Argument { Variable: "varMul" } + Argument { Param: "value1" } + Argument { Param: "value2" } + } + } + Action { + StatementAction { + Type: ST_DIV + Argument { Variable: "varDiv" } + Argument { Param: "value1" } + Argument { Param: "value2" } + } + } + Action { + StatementAction { + Type: ST_MOD + Argument { Variable: "varMod" } + Argument { Param: "value1" } + Argument { Param: "value2" } + } + } + } + Blocks { ProbeDesc { - Name: "IntIntParams" - Provider: "LWTRACE_UT_PROVIDER" - } - Predicate { - Operators { - Type: OT_EQ - Argument { Variable: "varMov" } + Name: "IntIntParams" + Provider: "LWTRACE_UT_PROVIDER" + } + Predicate { + Operators { + Type: OT_EQ + Argument { Variable: "varMov" } Argument { Param: "value1" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varAddEq" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varAddEq" } Argument { Param: "value1" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varSubEq" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varSubEq" } Argument { Value: "-22" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varAdd" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varAdd" } Argument { Value: "25" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varSub" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varSub" } Argument { Value: "19" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varMul" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varMul" } Argument { Value: "66" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varDiv" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varDiv" } Argument { Value: "7" } - } - Operators { - Type: OT_EQ - Argument { Variable: "varMod" } + } + Operators { + Type: OT_EQ + Argument { Variable: "varMod" } Argument { Value: "1" } - } - } - Action { - LogAction { } - } - } - )END", &q); - UNIT_ASSERT(parsed); - mngr.New("QueryName", q); - LWPROBE(IntIntParams, 22, 3); - struct { - int logsCount = 0; - void Push(TThread::TId, const TLogItem& item) { - UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntIntParams"); - logsCount++; + } + } + Action { + LogAction { } + } } - } reader; - mngr.ReadLog("QueryName", reader); - UNIT_ASSERT(reader.logsCount == 1); - } - - Y_UNIT_TEST(PerThreadLogSize) { - TManager mngr(*Singleton<TProbeRegistry>(), true); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - PerThreadLogSize: 3 - Blocks { + )END", &q); + UNIT_ASSERT(parsed); + mngr.New("QueryName", q); + LWPROBE(IntIntParams, 22, 3); + struct { + int logsCount = 0; + void Push(TThread::TId, const TLogItem& item) { + UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntIntParams"); + logsCount++; + } + } reader; + mngr.ReadLog("QueryName", reader); + UNIT_ASSERT(reader.logsCount == 1); + } + + Y_UNIT_TEST(PerThreadLogSize) { + TManager mngr(*Singleton<TProbeRegistry>(), true); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + PerThreadLogSize: 3 + Blocks { ProbeDesc { - Name: "IntParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Action { + Name: "IntParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Action { LogAction { } - } - } - )END", &q); - UNIT_ASSERT(parsed); - mngr.New("QueryRandom", q); - LWPROBE(IntParam, 1); - LWPROBE(IntParam, 2); - LWPROBE(IntParam, 3); - LWPROBE(IntParam, 4); - struct { - ui32 logsCount = 0; - ui32 expected = 2; - void Push(TThread::TId, const TLogItem& item) { - UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntParam"); - ui32 value = item.GetParam("value").GetParam().Get<ui32>(); - UNIT_ASSERT(value == expected); - logsCount++; - expected++; - } - } reader; - mngr.ReadLog("QueryRandom", reader); - UNIT_ASSERT(reader.logsCount == 3); - } - - Y_UNIT_TEST(CustomAction) { - static ui32 nCustomActionsCalls = 0; - class TMyActionExecutor: public TCustomActionExecutor { - public: - TMyActionExecutor(TProbe* probe, const TCustomAction&, TSession*) - : TCustomActionExecutor(probe, false /* not destructive */) - {} - private: + } + } + )END", &q); + UNIT_ASSERT(parsed); + mngr.New("QueryRandom", q); + LWPROBE(IntParam, 1); + LWPROBE(IntParam, 2); + LWPROBE(IntParam, 3); + LWPROBE(IntParam, 4); + struct { + ui32 logsCount = 0; + ui32 expected = 2; + void Push(TThread::TId, const TLogItem& item) { + UNIT_ASSERT(TString(item.Probe->Event.Name) == "IntParam"); + ui32 value = item.GetParam("value").GetParam().Get<ui32>(); + UNIT_ASSERT(value == expected); + logsCount++; + expected++; + } + } reader; + mngr.ReadLog("QueryRandom", reader); + UNIT_ASSERT(reader.logsCount == 3); + } + + Y_UNIT_TEST(CustomAction) { + static ui32 nCustomActionsCalls = 0; + class TMyActionExecutor: public TCustomActionExecutor { + public: + TMyActionExecutor(TProbe* probe, const TCustomAction&, TSession*) + : TCustomActionExecutor(probe, false /* not destructive */) + {} + private: bool DoExecute(TOrbit&, const TParams& params) override { - (void)params; - nCustomActionsCalls++; - return true; - } - }; - - TManager mngr(*Singleton<TProbeRegistry>(), true); - mngr.RegisterCustomAction("MyCustomAction", [](TProbe* probe, - const TCustomAction& action, - TSession* session) { - return new TMyActionExecutor(probe, action, session); - } - ); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - Blocks { - ProbeDesc { - Name: "NoParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Action { - CustomAction { - Name: "MyCustomAction" - } - } - } - )END", &q); - UNIT_ASSERT(parsed); - mngr.New("Query1", q); - LWPROBE(NoParam); - UNIT_ASSERT(nCustomActionsCalls == 1); - } - - Y_UNIT_TEST(SafeModeSleepException) { - TManager mngr(*Singleton<TProbeRegistry>(), false); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - Blocks { + (void)params; + nCustomActionsCalls++; + return true; + } + }; + + TManager mngr(*Singleton<TProbeRegistry>(), true); + mngr.RegisterCustomAction("MyCustomAction", [](TProbe* probe, + const TCustomAction& action, + TSession* session) { + return new TMyActionExecutor(probe, action, session); + } + ); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + Blocks { + ProbeDesc { + Name: "NoParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Action { + CustomAction { + Name: "MyCustomAction" + } + } + } + )END", &q); + UNIT_ASSERT(parsed); + mngr.New("Query1", q); + LWPROBE(NoParam); + UNIT_ASSERT(nCustomActionsCalls == 1); + } + + Y_UNIT_TEST(SafeModeSleepException) { + TManager mngr(*Singleton<TProbeRegistry>(), false); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + Blocks { ProbeDesc { - Name: "NoParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Action { - SleepAction { - NanoSeconds: 1000000000 - } - } - } - )END", &q); - UNIT_ASSERT(parsed); - UNIT_ASSERT_EXCEPTION(mngr.New("QueryName", q), yexception); - } - - Y_UNIT_TEST(Sleep) { - TManager mngr(*Singleton<TProbeRegistry>(), true); - TQuery q; - bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( - Blocks { + Name: "NoParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Action { + SleepAction { + NanoSeconds: 1000000000 + } + } + } + )END", &q); + UNIT_ASSERT(parsed); + UNIT_ASSERT_EXCEPTION(mngr.New("QueryName", q), yexception); + } + + Y_UNIT_TEST(Sleep) { + TManager mngr(*Singleton<TProbeRegistry>(), true); + TQuery q; + bool parsed = NProtoBuf::TextFormat::ParseFromString(R"END( + Blocks { ProbeDesc { - Name: "NoParam" - Provider: "LWTRACE_UT_PROVIDER" - } - Action { - SleepAction { - NanoSeconds: 1000 - } - } - } - )END", &q); - UNIT_ASSERT(parsed); - mngr.New("QueryName", q); - const ui64 sleepTimeNs = 1000; // 1 us - - TInstant t0 = Now(); - LWPROBE(NoParam); - TInstant t1 = Now(); + Name: "NoParam" + Provider: "LWTRACE_UT_PROVIDER" + } + Action { + SleepAction { + NanoSeconds: 1000 + } + } + } + )END", &q); + UNIT_ASSERT(parsed); + mngr.New("QueryName", q); + const ui64 sleepTimeNs = 1000; // 1 us + + TInstant t0 = Now(); + LWPROBE(NoParam); + TInstant t1 = Now(); UNIT_ASSERT(t1.NanoSeconds() - t0.NanoSeconds() >= sleepTimeNs); - } - + } + Y_UNIT_TEST(ProtoEnumTraits) { - using TPbEnumTraits = TParamTraits<EOperatorType>; + using TPbEnumTraits = TParamTraits<EOperatorType>; TString str; - TPbEnumTraits::ToString(TPbEnumTraits::ToStoreType(OT_EQ), &str); + TPbEnumTraits::ToString(TPbEnumTraits::ToStoreType(OT_EQ), &str); UNIT_ASSERT_STRINGS_EQUAL(str, "OT_EQ (0)"); } @@ -562,7 +562,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { RunLogShuttleAction { } } } - )END", &q); + )END", &q); UNIT_ASSERT(parsed); mngr.New("Query1", q); @@ -597,7 +597,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); - LWTRACK(ProtoEnum, orbit, OT_EQ); + LWTRACK(ProtoEnum, orbit, OT_EQ); LWTRACK(IntIntParams, orbit, 1, 2); TTraceResponse resp; @@ -640,7 +640,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { 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()); + UNIT_ASSERT_VALUES_EQUAL((int)OT_EQ, p6.GetParams(0).GetIntValue()); const auto& p7 = r.GetEvents(7); UNIT_ASSERT_VALUES_EQUAL("IntIntParams", p7.GetName()); @@ -696,7 +696,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { p6.SetName("ProtoEnum"); p6.SetProvider("LWTRACE_UT_PROVIDER"); auto& p6param = *p6.MutableParams()->Add(); - p6param.SetIntValue((i64)OT_EQ); + p6param.SetIntValue((i64)OT_EQ); auto& p7 = *r.Add(); p7.SetName("IntIntParams"); @@ -727,7 +727,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); - LWTRACK(ProtoEnum, orbit, OT_EQ); + LWTRACK(ProtoEnum, orbit, OT_EQ); LWTRACK(IntIntParams, orbit, 1, 2); TTraceResponse resp; @@ -753,7 +753,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { RunLogShuttleAction { } } } - )END", &q); + )END", &q); UNIT_ASSERT(parsed); mngr.New("Query1", q); @@ -834,7 +834,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { } } } - )END", &q); + )END", &q); UNIT_ASSERT(parsed); mngr.New("Query1", q); @@ -876,5 +876,5 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { } reader; mngr.ReadDepot("Query1", reader); } -#endif // LWTRACE_DISABLE +#endif // LWTRACE_DISABLE } diff --git a/library/cpp/lwtrace/ya.make b/library/cpp/lwtrace/ya.make index d9accb3006..82bffc1dc3 100644 --- a/library/cpp/lwtrace/ya.make +++ b/library/cpp/lwtrace/ya.make @@ -24,6 +24,6 @@ SRCS( END() -RECURSE(mon) - +RECURSE(mon) + RECURSE_FOR_TESTS(ut) |