@@ -1218,90 +1218,114 @@ void TQueryExecutionStats::ExportAggAsyncBufferStats(TAsyncBufferStats& data, NY
1218
1218
void TQueryExecutionStats::ExportExecStats (NYql::NDqProto::TDqExecutionStats& stats) {
1219
1219
1220
1220
THashMap<ui32, NDqProto::TDqStageStats*> protoStages;
1221
- for (auto & [stageId, stagetype] : TasksGraph->GetStagesInfo ()) {
1222
- protoStages.emplace (stageId.StageId , GetOrCreateStageStats (stageId, *TasksGraph, stats));
1221
+
1222
+ if (CollectFullStats (StatsMode)) {
1223
+ for (auto & [stageId, stagetype] : TasksGraph->GetStagesInfo ()) {
1224
+ protoStages.emplace (stageId.StageId , GetOrCreateStageStats (stageId, *TasksGraph, stats));
1225
+ }
1223
1226
}
1224
1227
1228
+ std::unordered_map<TString, NYql::NDqProto::TDqTableStats*> currentTableStats;
1225
1229
for (auto & [stageId, stageStat] : StageStats) {
1226
- auto & stageStats = *protoStages[stageStat.StageId .StageId ];
1227
- stageStats.SetTotalTasksCount (stageStat.Task2Index .size ());
1228
-
1229
- stageStats.SetBaseTimeMs (BaseTimeMs);
1230
- stageStat.CpuTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableCpuTimeUs ());
1231
- ExportAggStats (stageStat.SourceCpuTimeUs , *stageStats.MutableSourceCpuTimeUs ());
1232
- stageStat.MaxMemoryUsage .ExportAggStats (BaseTimeMs, *stageStats.MutableMaxMemoryUsage ());
1233
-
1234
- ExportAggStats (stageStat.InputRows , *stageStats.MutableInputRows ());
1235
- ExportAggStats (stageStat.InputBytes , *stageStats.MutableInputBytes ());
1236
- ExportAggStats (stageStat.OutputRows , *stageStats.MutableOutputRows ());
1237
- ExportAggStats (stageStat.OutputBytes , *stageStats.MutableOutputBytes ());
1238
- ExportAggStats (stageStat.ResultRows , *stageStats.MutableResultRows ());
1239
- ExportAggStats (stageStat.ResultBytes , *stageStats.MutableResultBytes ());
1240
- ExportAggStats (stageStat.IngressRows , *stageStats.MutableIngressRows ());
1241
- ExportAggStats (stageStat.IngressBytes , *stageStats.MutableIngressBytes ());
1242
- ExportAggStats (stageStat.IngressDecompressedBytes , *stageStats.MutableIngressDecompressedBytes ());
1243
- ExportAggStats (stageStat.EgressRows , *stageStats.MutableEgressRows ());
1244
- ExportAggStats (stageStat.EgressBytes , *stageStats.MutableEgressBytes ());
1245
-
1246
- ExportOffsetAggStats (stageStat.StartTimeMs , *stageStats.MutableStartTimeMs (), BaseTimeMs);
1247
- ExportOffsetAggStats (stageStat.FinishTimeMs , *stageStats.MutableFinishTimeMs (), BaseTimeMs);
1248
- ExportAggStats (stageStat.DurationUs , *stageStats.MutableDurationUs ());
1249
- stageStat.WaitInputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitInputTimeUs ());
1250
- stageStat.WaitOutputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitOutputTimeUs ());
1251
-
1252
- stageStat.SpillingComputeBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeBytes ());
1253
- stageStat.SpillingChannelBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelBytes ());
1254
- stageStat.SpillingComputeTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeTimeUs ());
1255
- stageStat.SpillingChannelTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelTimeUs ());
1256
-
1257
- FillStageDurationUs (stageStats);
1258
-
1259
1230
for (auto & [path, t] : stageStat.Tables ) {
1260
- auto & table = *stageStats.AddTables ();
1261
- table.SetTablePath (path);
1262
- ExportAggStats (t.ReadRows , *table.MutableReadRows ());
1263
- ExportAggStats (t.ReadBytes , *table.MutableReadBytes ());
1264
- ExportAggStats (t.WriteRows , *table.MutableWriteRows ());
1265
- ExportAggStats (t.WriteBytes , *table.MutableWriteBytes ());
1266
- ExportAggStats (t.EraseRows , *table.MutableEraseRows ());
1267
- ExportAggStats (t.EraseBytes , *table.MutableEraseBytes ());
1268
- table.SetAffectedPartitions (ExportAggStats (t.AffectedPartitions ));
1269
- }
1270
- for (auto & [id, i] : stageStat.Ingress ) {
1271
- ExportAggAsyncBufferStats (i, (*stageStats.MutableIngress ())[id]);
1272
- }
1273
- for (auto & [id, i] : stageStat.Input ) {
1274
- ExportAggAsyncBufferStats (i, (*stageStats.MutableInput ())[id]);
1275
- }
1276
- for (auto & [id, o] : stageStat.Output ) {
1277
- ExportAggAsyncBufferStats (o, (*stageStats.MutableOutput ())[id]);
1278
- }
1279
- for (auto & [id, e] : stageStat.Egress ) {
1280
- ExportAggAsyncBufferStats (e, (*stageStats.MutableEgress ())[id]);
1281
- }
1282
- for (auto & [id, j] : stageStat.Joins ) {
1283
- auto & joinStat = (*stageStats.MutableOperatorJoin ())[id];
1284
- joinStat.SetOperatorId (id);
1285
- ExportAggStats (j.Bytes , *joinStat.MutableBytes ());
1286
- ExportAggStats (j.Rows , *joinStat.MutableRows ());
1287
- }
1288
- for (auto & [id, f] : stageStat.Filters ) {
1289
- auto & filterStat = (*stageStats.MutableOperatorFilter ())[id];
1290
- filterStat.SetOperatorId (id);
1291
- ExportAggStats (f.Bytes , *filterStat.MutableBytes ());
1292
- ExportAggStats (f.Rows , *filterStat.MutableRows ());
1231
+ NYql::NDqProto::TDqTableStats* tableAggr = nullptr ;
1232
+ if (auto it = currentTableStats.find (path); it != currentTableStats.end ()) {
1233
+ tableAggr = it->second ;
1234
+ } else {
1235
+ tableAggr = stats.AddTables ();
1236
+ tableAggr->SetTablePath (path);
1237
+ currentTableStats.emplace (path, tableAggr);
1238
+ }
1239
+
1240
+ tableAggr->SetReadRows (tableAggr->GetReadRows () + ExportAggStats (t.ReadRows ));
1241
+ tableAggr->SetReadBytes (tableAggr->GetReadBytes () + ExportAggStats (t.ReadBytes ));
1242
+ tableAggr->SetWriteRows (tableAggr->GetWriteRows () + ExportAggStats (t.WriteRows ));
1243
+ tableAggr->SetWriteBytes (tableAggr->GetWriteBytes () + ExportAggStats (t.WriteBytes ));
1244
+ tableAggr->SetEraseRows (tableAggr->GetEraseRows () + ExportAggStats (t.EraseRows ));
1245
+ tableAggr->SetAffectedPartitions (tableAggr->GetAffectedPartitions () + ExportAggStats (t.AffectedPartitions ));
1246
+
1293
1247
}
1294
- for (auto & [id, a] : stageStat.Aggregations ) {
1295
- auto & aggrStat = (*stageStats.MutableOperatorAggregation ())[id];
1296
- aggrStat.SetOperatorId (id);
1297
- ExportAggStats (a.Bytes , *aggrStat.MutableBytes ());
1298
- ExportAggStats (a.Rows , *aggrStat.MutableRows ());
1248
+
1249
+
1250
+ if (CollectFullStats (StatsMode)) {
1251
+ auto & stageStats = *protoStages[stageStat.StageId .StageId ];
1252
+ stageStats.SetTotalTasksCount (stageStat.Task2Index .size ());
1253
+
1254
+ stageStats.SetBaseTimeMs (BaseTimeMs);
1255
+ stageStat.CpuTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableCpuTimeUs ());
1256
+ ExportAggStats (stageStat.SourceCpuTimeUs , *stageStats.MutableSourceCpuTimeUs ());
1257
+ stageStat.MaxMemoryUsage .ExportAggStats (BaseTimeMs, *stageStats.MutableMaxMemoryUsage ());
1258
+
1259
+ ExportAggStats (stageStat.InputRows , *stageStats.MutableInputRows ());
1260
+ ExportAggStats (stageStat.InputBytes , *stageStats.MutableInputBytes ());
1261
+ ExportAggStats (stageStat.OutputRows , *stageStats.MutableOutputRows ());
1262
+ ExportAggStats (stageStat.OutputBytes , *stageStats.MutableOutputBytes ());
1263
+ ExportAggStats (stageStat.ResultRows , *stageStats.MutableResultRows ());
1264
+ ExportAggStats (stageStat.ResultBytes , *stageStats.MutableResultBytes ());
1265
+ ExportAggStats (stageStat.IngressRows , *stageStats.MutableIngressRows ());
1266
+ ExportAggStats (stageStat.IngressBytes , *stageStats.MutableIngressBytes ());
1267
+ ExportAggStats (stageStat.IngressDecompressedBytes , *stageStats.MutableIngressDecompressedBytes ());
1268
+ ExportAggStats (stageStat.EgressRows , *stageStats.MutableEgressRows ());
1269
+ ExportAggStats (stageStat.EgressBytes , *stageStats.MutableEgressBytes ());
1270
+
1271
+ ExportOffsetAggStats (stageStat.StartTimeMs , *stageStats.MutableStartTimeMs (), BaseTimeMs);
1272
+ ExportOffsetAggStats (stageStat.FinishTimeMs , *stageStats.MutableFinishTimeMs (), BaseTimeMs);
1273
+ ExportAggStats (stageStat.DurationUs , *stageStats.MutableDurationUs ());
1274
+ stageStat.WaitInputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitInputTimeUs ());
1275
+ stageStat.WaitOutputTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableWaitOutputTimeUs ());
1276
+
1277
+ stageStat.SpillingComputeBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeBytes ());
1278
+ stageStat.SpillingChannelBytes .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelBytes ());
1279
+ stageStat.SpillingComputeTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingComputeTimeUs ());
1280
+ stageStat.SpillingChannelTimeUs .ExportAggStats (BaseTimeMs, *stageStats.MutableSpillingChannelTimeUs ());
1281
+
1282
+ FillStageDurationUs (stageStats);
1283
+
1284
+ for (auto & [path, t] : stageStat.Tables ) {
1285
+ auto & table = *stageStats.AddTables ();
1286
+ table.SetTablePath (path);
1287
+ ExportAggStats (t.ReadRows , *table.MutableReadRows ());
1288
+ ExportAggStats (t.ReadBytes , *table.MutableReadBytes ());
1289
+ ExportAggStats (t.WriteRows , *table.MutableWriteRows ());
1290
+ ExportAggStats (t.WriteBytes , *table.MutableWriteBytes ());
1291
+ ExportAggStats (t.EraseRows , *table.MutableEraseRows ());
1292
+ ExportAggStats (t.EraseBytes , *table.MutableEraseBytes ());
1293
+ table.SetAffectedPartitions (ExportAggStats (t.AffectedPartitions ));
1294
+ }
1295
+ for (auto & [id, i] : stageStat.Ingress ) {
1296
+ ExportAggAsyncBufferStats (i, (*stageStats.MutableIngress ())[id]);
1297
+ }
1298
+ for (auto & [id, i] : stageStat.Input ) {
1299
+ ExportAggAsyncBufferStats (i, (*stageStats.MutableInput ())[id]);
1300
+ }
1301
+ for (auto & [id, o] : stageStat.Output ) {
1302
+ ExportAggAsyncBufferStats (o, (*stageStats.MutableOutput ())[id]);
1303
+ }
1304
+ for (auto & [id, e] : stageStat.Egress ) {
1305
+ ExportAggAsyncBufferStats (e, (*stageStats.MutableEgress ())[id]);
1306
+ }
1307
+ for (auto & [id, j] : stageStat.Joins ) {
1308
+ auto & joinStat = (*stageStats.MutableOperatorJoin ())[id];
1309
+ joinStat.SetOperatorId (id);
1310
+ ExportAggStats (j.Bytes , *joinStat.MutableBytes ());
1311
+ ExportAggStats (j.Rows , *joinStat.MutableRows ());
1312
+ }
1313
+ for (auto & [id, f] : stageStat.Filters ) {
1314
+ auto & filterStat = (*stageStats.MutableOperatorFilter ())[id];
1315
+ filterStat.SetOperatorId (id);
1316
+ ExportAggStats (f.Bytes , *filterStat.MutableBytes ());
1317
+ ExportAggStats (f.Rows , *filterStat.MutableRows ());
1318
+ }
1319
+ for (auto & [id, a] : stageStat.Aggregations ) {
1320
+ auto & aggrStat = (*stageStats.MutableOperatorAggregation ())[id];
1321
+ aggrStat.SetOperatorId (id);
1322
+ ExportAggStats (a.Bytes , *aggrStat.MutableBytes ());
1323
+ ExportAggStats (a.Rows , *aggrStat.MutableRows ());
1324
+ }
1299
1325
}
1300
1326
}
1301
1327
1302
- for (const auto & [_, tableStats] : TableStats) {
1303
- stats.AddTables ()->CopyFrom (*tableStats);
1304
- }
1328
+ stats.SetDurationUs (TInstant::Now ().MicroSeconds () - StartTs.MicroSeconds ());
1305
1329
}
1306
1330
1307
1331
void TQueryExecutionStats::AdjustExternalAggr (NYql::NDqProto::TDqExternalAggrStats& stats) {
0 commit comments