@@ -1326,91 +1326,116 @@ void TQueryExecutionStats::ExportAggAsyncBufferStats(TAsyncBufferStats& data, NY
1326
1326
void TQueryExecutionStats::ExportExecStats (NYql::NDqProto::TDqExecutionStats& stats) {
1327
1327
1328
1328
THashMap<ui32, NDqProto::TDqStageStats*> protoStages;
1329
- for (auto & [stageId, stagetype] : TasksGraph->GetStagesInfo ()) {
1330
- protoStages.emplace (stageId.StageId , GetOrCreateStageStats (stageId, *TasksGraph, stats));
1329
+
1330
+ if (CollectFullStats (StatsMode)) {
1331
+ for (auto & [stageId, stagetype] : TasksGraph->GetStagesInfo ()) {
1332
+ protoStages.emplace (stageId.StageId , GetOrCreateStageStats (stageId, *TasksGraph, stats));
1333
+ }
1331
1334
}
1332
1335
1333
- for (auto & [stageId, stageStat] : StageStats) {
1334
- auto & stageStats = *protoStages[stageStat.StageId .StageId ];
1335
- stageStats.SetTotalTasksCount (stageStat.Task2Index .size ());
1336
- stageStats.SetFinishedTasksCount (stageStat.FinishedCount );
1337
-
1338
- stageStats.SetBaseTimeMs (BaseTimeMs);
1339
- stageStat.CpuTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableCpuTimeUs ());
1340
- ExportAggStats (stageStat.SourceCpuTimeUs , *stageStats.MutableSourceCpuTimeUs ());
1341
- stageStat.MaxMemoryUsage .ExportAggStats (BaseTimeMs, *stageStats.MutableMaxMemoryUsage ());
1342
-
1343
- ExportAggStats (stageStat.InputRows , *stageStats.MutableInputRows ());
1344
- ExportAggStats (stageStat.InputBytes , *stageStats.MutableInputBytes ());
1345
- ExportAggStats (stageStat.OutputRows , *stageStats.MutableOutputRows ());
1346
- ExportAggStats (stageStat.OutputBytes , *stageStats.MutableOutputBytes ());
1347
- ExportAggStats (stageStat.ResultRows , *stageStats.MutableResultRows ());
1348
- ExportAggStats (stageStat.ResultBytes , *stageStats.MutableResultBytes ());
1349
- ExportAggStats (stageStat.IngressRows , *stageStats.MutableIngressRows ());
1350
- ExportAggStats (stageStat.IngressBytes , *stageStats.MutableIngressBytes ());
1351
- ExportAggStats (stageStat.IngressDecompressedBytes , *stageStats.MutableIngressDecompressedBytes ());
1352
- ExportAggStats (stageStat.EgressRows , *stageStats.MutableEgressRows ());
1353
- ExportAggStats (stageStat.EgressBytes , *stageStats.MutableEgressBytes ());
1354
-
1355
- ExportOffsetAggStats (stageStat.StartTimeMs , *stageStats.MutableStartTimeMs (), BaseTimeMs);
1356
- ExportOffsetAggStats (stageStat.FinishTimeMs , *stageStats.MutableFinishTimeMs (), BaseTimeMs);
1357
- ExportAggStats (stageStat.DurationUs , *stageStats.MutableDurationUs ());
1358
- stageStat.WaitInputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitInputTimeUs ());
1359
- stageStat.WaitOutputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitOutputTimeUs ());
1360
-
1361
- stageStat.SpillingComputeBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeBytes ());
1362
- stageStat.SpillingChannelBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelBytes ());
1363
- stageStat.SpillingComputeTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeTimeUs ());
1364
- stageStat.SpillingChannelTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelTimeUs ());
1365
-
1366
- FillStageDurationUs (stageStats);
1336
+ std::unordered_map<TString, NYql::NDqProto::TDqTableStats*> currentTableStats;
1367
1337
1338
+ for (auto & [stageId, stageStat] : StageStats) {
1368
1339
for (auto & [path, t] : stageStat.Tables ) {
1369
- auto & table = *stageStats.AddTables ();
1370
- table.SetTablePath (path);
1371
- ExportAggStats (t.ReadRows , *table.MutableReadRows ());
1372
- ExportAggStats (t.ReadBytes , *table.MutableReadBytes ());
1373
- ExportAggStats (t.WriteRows , *table.MutableWriteRows ());
1374
- ExportAggStats (t.WriteBytes , *table.MutableWriteBytes ());
1375
- ExportAggStats (t.EraseRows , *table.MutableEraseRows ());
1376
- ExportAggStats (t.EraseBytes , *table.MutableEraseBytes ());
1377
- table.SetAffectedPartitions (ExportAggStats (t.AffectedPartitions ));
1378
- }
1379
- for (auto & [id, i] : stageStat.Ingress ) {
1380
- ExportAggAsyncBufferStats (i, (*stageStats.MutableIngress ())[id]);
1381
- }
1382
- for (auto & [id, i] : stageStat.Input ) {
1383
- ExportAggAsyncBufferStats (i, (*stageStats.MutableInput ())[id]);
1384
- }
1385
- for (auto & [id, o] : stageStat.Output ) {
1386
- ExportAggAsyncBufferStats (o, (*stageStats.MutableOutput ())[id]);
1387
- }
1388
- for (auto & [id, e] : stageStat.Egress ) {
1389
- ExportAggAsyncBufferStats (e, (*stageStats.MutableEgress ())[id]);
1390
- }
1391
- for (auto & [id, j] : stageStat.Joins ) {
1392
- auto & joinStat = (*stageStats.MutableOperatorJoin ())[id];
1393
- joinStat.SetOperatorId (id);
1394
- ExportAggStats (j.Bytes , *joinStat.MutableBytes ());
1395
- ExportAggStats (j.Rows , *joinStat.MutableRows ());
1396
- }
1397
- for (auto & [id, f] : stageStat.Filters ) {
1398
- auto & filterStat = (*stageStats.MutableOperatorFilter ())[id];
1399
- filterStat.SetOperatorId (id);
1400
- ExportAggStats (f.Bytes , *filterStat.MutableBytes ());
1401
- ExportAggStats (f.Rows , *filterStat.MutableRows ());
1340
+ NYql::NDqProto::TDqTableStats* tableAggr = nullptr ;
1341
+ if (auto it = currentTableStats.find (path); it != currentTableStats.end ()) {
1342
+ tableAggr = it->second ;
1343
+ } else {
1344
+ tableAggr = stats.AddTables ();
1345
+ tableAggr->SetTablePath (path);
1346
+ currentTableStats.emplace (path, tableAggr);
1347
+ }
1348
+
1349
+ tableAggr->SetReadRows (tableAggr->GetReadRows () + ExportAggStats (t.ReadRows ));
1350
+ tableAggr->SetReadBytes (tableAggr->GetReadBytes () + ExportAggStats (t.ReadBytes ));
1351
+ tableAggr->SetWriteRows (tableAggr->GetWriteRows () + ExportAggStats (t.WriteRows ));
1352
+ tableAggr->SetWriteBytes (tableAggr->GetWriteBytes () + ExportAggStats (t.WriteBytes ));
1353
+ tableAggr->SetEraseRows (tableAggr->GetEraseRows () + ExportAggStats (t.EraseRows ));
1354
+ tableAggr->SetAffectedPartitions (tableAggr->GetAffectedPartitions () + ExportAggStats (t.AffectedPartitions ));
1355
+
1402
1356
}
1403
- for (auto & [id, a] : stageStat.Aggregations ) {
1404
- auto & aggrStat = (*stageStats.MutableOperatorAggregation ())[id];
1405
- aggrStat.SetOperatorId (id);
1406
- ExportAggStats (a.Bytes , *aggrStat.MutableBytes ());
1407
- ExportAggStats (a.Rows , *aggrStat.MutableRows ());
1357
+
1358
+
1359
+ if (CollectFullStats (StatsMode)) {
1360
+ auto & stageStats = *protoStages[stageStat.StageId .StageId ];
1361
+ stageStats.SetTotalTasksCount (stageStat.Task2Index .size ());
1362
+ stageStats.SetFinishedTasksCount (stageStat.FinishedCount );
1363
+
1364
+ stageStats.SetBaseTimeMs (BaseTimeMs);
1365
+ stageStat.CpuTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableCpuTimeUs ());
1366
+ ExportAggStats (stageStat.SourceCpuTimeUs , *stageStats.MutableSourceCpuTimeUs ());
1367
+ stageStat.MaxMemoryUsage .ExportAggStats (BaseTimeMs, *stageStats.MutableMaxMemoryUsage ());
1368
+
1369
+ ExportAggStats (stageStat.InputRows , *stageStats.MutableInputRows ());
1370
+ ExportAggStats (stageStat.InputBytes , *stageStats.MutableInputBytes ());
1371
+ ExportAggStats (stageStat.OutputRows , *stageStats.MutableOutputRows ());
1372
+ ExportAggStats (stageStat.OutputBytes , *stageStats.MutableOutputBytes ());
1373
+ ExportAggStats (stageStat.ResultRows , *stageStats.MutableResultRows ());
1374
+ ExportAggStats (stageStat.ResultBytes , *stageStats.MutableResultBytes ());
1375
+ ExportAggStats (stageStat.IngressRows , *stageStats.MutableIngressRows ());
1376
+ ExportAggStats (stageStat.IngressBytes , *stageStats.MutableIngressBytes ());
1377
+ ExportAggStats (stageStat.IngressDecompressedBytes , *stageStats.MutableIngressDecompressedBytes ());
1378
+ ExportAggStats (stageStat.EgressRows , *stageStats.MutableEgressRows ());
1379
+ ExportAggStats (stageStat.EgressBytes , *stageStats.MutableEgressBytes ());
1380
+
1381
+ ExportOffsetAggStats (stageStat.StartTimeMs , *stageStats.MutableStartTimeMs (), BaseTimeMs);
1382
+ ExportOffsetAggStats (stageStat.FinishTimeMs , *stageStats.MutableFinishTimeMs (), BaseTimeMs);
1383
+ ExportAggStats (stageStat.DurationUs , *stageStats.MutableDurationUs ());
1384
+ stageStat.WaitInputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitInputTimeUs ());
1385
+ stageStat.WaitOutputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitOutputTimeUs ());
1386
+
1387
+ stageStat.SpillingComputeBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeBytes ());
1388
+ stageStat.SpillingChannelBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelBytes ());
1389
+ stageStat.SpillingComputeTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeTimeUs ());
1390
+ stageStat.SpillingChannelTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelTimeUs ());
1391
+
1392
+ FillStageDurationUs (stageStats);
1393
+
1394
+ for (auto & [path, t] : stageStat.Tables ) {
1395
+ auto & table = *stageStats.AddTables ();
1396
+ table.SetTablePath (path);
1397
+ ExportAggStats (t.ReadRows , *table.MutableReadRows ());
1398
+ ExportAggStats (t.ReadBytes , *table.MutableReadBytes ());
1399
+ ExportAggStats (t.WriteRows , *table.MutableWriteRows ());
1400
+ ExportAggStats (t.WriteBytes , *table.MutableWriteBytes ());
1401
+ ExportAggStats (t.EraseRows , *table.MutableEraseRows ());
1402
+ ExportAggStats (t.EraseBytes , *table.MutableEraseBytes ());
1403
+ table.SetAffectedPartitions (ExportAggStats (t.AffectedPartitions ));
1404
+ }
1405
+ for (auto & [id, i] : stageStat.Ingress ) {
1406
+ ExportAggAsyncBufferStats (i, (*stageStats.MutableIngress ())[id]);
1407
+ }
1408
+ for (auto & [id, i] : stageStat.Input ) {
1409
+ ExportAggAsyncBufferStats (i, (*stageStats.MutableInput ())[id]);
1410
+ }
1411
+ for (auto & [id, o] : stageStat.Output ) {
1412
+ ExportAggAsyncBufferStats (o, (*stageStats.MutableOutput ())[id]);
1413
+ }
1414
+ for (auto & [id, e] : stageStat.Egress ) {
1415
+ ExportAggAsyncBufferStats (e, (*stageStats.MutableEgress ())[id]);
1416
+ }
1417
+ for (auto & [id, j] : stageStat.Joins ) {
1418
+ auto & joinStat = (*stageStats.MutableOperatorJoin ())[id];
1419
+ joinStat.SetOperatorId (id);
1420
+ ExportAggStats (j.Bytes , *joinStat.MutableBytes ());
1421
+ ExportAggStats (j.Rows , *joinStat.MutableRows ());
1422
+ }
1423
+ for (auto & [id, f] : stageStat.Filters ) {
1424
+ auto & filterStat = (*stageStats.MutableOperatorFilter ())[id];
1425
+ filterStat.SetOperatorId (id);
1426
+ ExportAggStats (f.Bytes , *filterStat.MutableBytes ());
1427
+ ExportAggStats (f.Rows , *filterStat.MutableRows ());
1428
+ }
1429
+ for (auto & [id, a] : stageStat.Aggregations ) {
1430
+ auto & aggrStat = (*stageStats.MutableOperatorAggregation ())[id];
1431
+ aggrStat.SetOperatorId (id);
1432
+ ExportAggStats (a.Bytes , *aggrStat.MutableBytes ());
1433
+ ExportAggStats (a.Rows , *aggrStat.MutableRows ());
1434
+ }
1408
1435
}
1409
1436
}
1410
1437
1411
- for (const auto & [_, tableStats] : TableStats) {
1412
- stats.AddTables ()->CopyFrom (*tableStats);
1413
- }
1438
+ stats.SetDurationUs (TInstant::Now ().MicroSeconds () - StartTs.MicroSeconds ());
1414
1439
}
1415
1440
1416
1441
void TQueryExecutionStats::AdjustExternalAggr (NYql::NDqProto::TDqExternalAggrStats& stats) {
0 commit comments