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/lwtrace | |
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/lwtrace')
-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 |
9 files changed, 826 insertions, 826 deletions
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) |