@@ -425,21 +425,33 @@ class TKqpExecuterBase : public TActor<TDerived> {
425
425
426
426
YQL_ENSURE (Stats);
427
427
428
- if (state.HasStats () && Request.ProgressStatsPeriod ) {
428
+ if (state.HasStats ()) {
429
+ ui64 cycleCount = GetCycleCountFast ();
430
+
429
431
Stats->UpdateTaskStats (taskId, state.GetStats ());
430
- auto now = TInstant::Now ();
431
- if (LastProgressStats + Request.ProgressStatsPeriod <= now) {
432
- auto progress = MakeHolder<TEvKqpExecuter::TEvExecuterProgress>();
433
- auto & execStats = *progress->Record .MutableQueryStats ()->AddExecutions ();
434
- Stats->ExportExecStats (execStats);
435
- for (ui32 txId = 0 ; txId < Request.Transactions .size (); ++txId) {
436
- const auto & tx = Request.Transactions [txId].Body ;
437
- auto planWithStats = AddExecStatsToTxPlan (tx->GetPlan (), execStats);
438
- execStats.AddTxPlansWithStats (planWithStats);
432
+ if (Request.ProgressStatsPeriod ) {
433
+ auto now = TInstant::Now ();
434
+ if (LastProgressStats + Request.ProgressStatsPeriod <= now) {
435
+ auto progress = MakeHolder<TEvKqpExecuter::TEvExecuterProgress>();
436
+ auto & execStats = *progress->Record .MutableQueryStats ()->AddExecutions ();
437
+ Stats->ExportExecStats (execStats);
438
+ for (ui32 txId = 0 ; txId < Request.Transactions .size (); ++txId) {
439
+ const auto & tx = Request.Transactions [txId].Body ;
440
+ auto planWithStats = AddExecStatsToTxPlan (tx->GetPlan (), execStats);
441
+ execStats.AddTxPlansWithStats (planWithStats);
442
+ }
443
+ this ->Send (Target, progress.Release ());
444
+ LastProgressStats = now;
439
445
}
440
- this ->Send (Target, progress.Release ());
441
- LastProgressStats = now;
442
446
}
447
+ auto collectBytes = Stats->EstimateCollectMem ();
448
+ auto deltaCpuTime = NHPTimer::GetSeconds (GetCycleCountFast () - cycleCount);
449
+
450
+ Counters->Counters ->QueryStatMemCollectInflightBytes ->Add (
451
+ static_cast <i64 >(collectBytes) - static_cast <i64 >(StatCollectInflightBytes)
452
+ );
453
+ StatCollectInflightBytes = collectBytes;
454
+ Counters->Counters ->QueryStatCpuCollectUs ->Add (deltaCpuTime * 1'000'000 );
443
455
}
444
456
445
457
YQL_ENSURE (Planner);
@@ -450,6 +462,8 @@ class TKqpExecuterBase : public TActor<TDerived> {
450
462
case NYql::NDqProto::COMPUTE_STATE_FINISHED:
451
463
// Don't finalize stats twice.
452
464
if (Planner->CompletedCA (taskId, computeActor)) {
465
+ ui64 cycleCount = GetCycleCountFast ();
466
+
453
467
auto & extraData = ExtraData[computeActor];
454
468
extraData.TaskId = taskId;
455
469
extraData.Data .Swap (state.MutableExtraData ());
@@ -462,6 +476,15 @@ class TKqpExecuterBase : public TActor<TDerived> {
462
476
463
477
LastTaskId = taskId;
464
478
LastComputeActorId = computeActor.ToString ();
479
+
480
+ auto collectBytes = Stats->EstimateFinishMem ();
481
+ auto deltaCpuTime = NHPTimer::GetSeconds (GetCycleCountFast () - cycleCount);
482
+
483
+ Counters->Counters ->QueryStatMemFinishInflightBytes ->Add (
484
+ static_cast <i64 >(collectBytes) - static_cast <i64 >(StatFinishInflightBytes)
485
+ );
486
+ StatFinishInflightBytes = collectBytes;
487
+ Counters->Counters ->QueryStatCpuFinishUs ->Add (deltaCpuTime * 1'000'000 );
465
488
}
466
489
default :
467
490
; // ignore all other states.
@@ -1974,15 +1997,26 @@ class TKqpExecuterBase : public TActor<TDerived> {
1974
1997
ReportEventElapsedTime ();
1975
1998
1976
1999
Stats->FinishTs = TInstant::Now ();
2000
+
1977
2001
Stats->Finish ();
1978
2002
1979
2003
if (Stats->CollectStatsByLongTasks || CollectFullStats (Request.StatsMode )) {
2004
+
2005
+ ui64 jsonSize = 0 ;
2006
+ ui64 cycleCount = GetCycleCountFast ();
2007
+
1980
2008
response.MutableResult ()->MutableStats ()->ClearTxPlansWithStats ();
1981
2009
for (ui32 txId = 0 ; txId < Request.Transactions .size (); ++txId) {
1982
2010
const auto & tx = Request.Transactions [txId].Body ;
1983
2011
auto planWithStats = AddExecStatsToTxPlan (tx->GetPlan (), response.GetResult ().GetStats ());
2012
+ jsonSize += planWithStats.size ();
1984
2013
response.MutableResult ()->MutableStats ()->AddTxPlansWithStats (planWithStats);
1985
2014
}
2015
+
2016
+ auto deltaCpuTime = NHPTimer::GetSeconds (GetCycleCountFast () - cycleCount);
2017
+ Counters->Counters ->QueryStatCpuConvertUs ->Add (deltaCpuTime * 1'000'000 );
2018
+ Counters->Counters ->QueryStatMemConvertBytes ->Add (jsonSize);
2019
+ response.MutableResult ()->MutableStats ()->SetStatConvertBytes (jsonSize);
1986
2020
}
1987
2021
1988
2022
if (Stats->CollectStatsByLongTasks ) {
@@ -1991,8 +2025,17 @@ class TKqpExecuterBase : public TActor<TDerived> {
1991
2025
LOG_I (" Full stats: " << response.GetResult ().GetStats ());
1992
2026
}
1993
2027
}
2028
+
2029
+ auto finishSize = Stats->EstimateFinishMem ();
2030
+ Counters->Counters ->QueryStatMemFinishBytes ->Add (finishSize);
2031
+ response.MutableResult ()->MutableStats ()->SetStatFinishBytes (finishSize);
1994
2032
}
1995
2033
2034
+ Counters->Counters ->QueryStatMemCollectInflightBytes ->Sub (StatCollectInflightBytes);
2035
+ StatCollectInflightBytes = 0 ;
2036
+ Counters->Counters ->QueryStatMemFinishInflightBytes ->Sub (StatFinishInflightBytes);
2037
+ StatFinishInflightBytes = 0 ;
2038
+
1996
2039
Request.Transactions .crop (0 );
1997
2040
this ->Send (Target, ResponseEv.release ());
1998
2041
@@ -2139,6 +2182,8 @@ class TKqpExecuterBase : public TActor<TDerived> {
2139
2182
const bool VerboseMemoryLimitException;
2140
2183
TMaybe<ui8> ArrayBufferMinFillPercentage;
2141
2184
2185
+ ui64 StatCollectInflightBytes = 0 ;
2186
+ ui64 StatFinishInflightBytes = 0 ;
2142
2187
private:
2143
2188
static constexpr TDuration ResourceUsageUpdateInterval = TDuration::MilliSeconds(100 );
2144
2189
};
0 commit comments