@@ -349,6 +349,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
349
349
350
350
.fixed_amount = true,
351
351
352
+ .snapshot_ctl_off = offsetof(PgStat_Snapshot , archiver ),
352
353
.shared_ctl_off = offsetof(PgStat_ShmemControl , archiver ),
353
354
.shared_data_off = offsetof(PgStatShared_Archiver , stats ),
354
355
.shared_data_len = sizeof (((PgStatShared_Archiver * ) 0 )-> stats ),
@@ -362,6 +363,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
362
363
363
364
.fixed_amount = true,
364
365
366
+ .snapshot_ctl_off = offsetof(PgStat_Snapshot , bgwriter ),
365
367
.shared_ctl_off = offsetof(PgStat_ShmemControl , bgwriter ),
366
368
.shared_data_off = offsetof(PgStatShared_BgWriter , stats ),
367
369
.shared_data_len = sizeof (((PgStatShared_BgWriter * ) 0 )-> stats ),
@@ -375,6 +377,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
375
377
376
378
.fixed_amount = true,
377
379
380
+ .snapshot_ctl_off = offsetof(PgStat_Snapshot , checkpointer ),
378
381
.shared_ctl_off = offsetof(PgStat_ShmemControl , checkpointer ),
379
382
.shared_data_off = offsetof(PgStatShared_Checkpointer , stats ),
380
383
.shared_data_len = sizeof (((PgStatShared_Checkpointer * ) 0 )-> stats ),
@@ -388,6 +391,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
388
391
389
392
.fixed_amount = true,
390
393
394
+ .snapshot_ctl_off = offsetof(PgStat_Snapshot , io ),
391
395
.shared_ctl_off = offsetof(PgStat_ShmemControl , io ),
392
396
.shared_data_off = offsetof(PgStatShared_IO , stats ),
393
397
.shared_data_len = sizeof (((PgStatShared_IO * ) 0 )-> stats ),
@@ -401,6 +405,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
401
405
402
406
.fixed_amount = true,
403
407
408
+ .snapshot_ctl_off = offsetof(PgStat_Snapshot , slru ),
404
409
.shared_ctl_off = offsetof(PgStat_ShmemControl , slru ),
405
410
.shared_data_off = offsetof(PgStatShared_SLRU , stats ),
406
411
.shared_data_len = sizeof (((PgStatShared_SLRU * ) 0 )-> stats ),
@@ -414,6 +419,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
414
419
415
420
.fixed_amount = true,
416
421
422
+ .snapshot_ctl_off = offsetof(PgStat_Snapshot , wal ),
417
423
.shared_ctl_off = offsetof(PgStat_ShmemControl , wal ),
418
424
.shared_data_off = offsetof(PgStatShared_Wal , stats ),
419
425
.shared_data_len = sizeof (((PgStatShared_Wal * ) 0 )-> stats ),
@@ -1371,47 +1377,21 @@ pgstat_write_statsfile(void)
1371
1377
format_id = PGSTAT_FILE_FORMAT_ID ;
1372
1378
write_chunk_s (fpout , & format_id );
1373
1379
1374
- /*
1375
- * XXX: The following could now be generalized to just iterate over
1376
- * pgstat_kind_infos instead of knowing about the different kinds of
1377
- * stats.
1378
- */
1379
-
1380
- /*
1381
- * Write archiver stats struct
1382
- */
1383
- pgstat_build_snapshot_fixed (PGSTAT_KIND_ARCHIVER );
1384
- write_chunk_s (fpout , & pgStatLocal .snapshot .archiver );
1385
-
1386
- /*
1387
- * Write bgwriter stats struct
1388
- */
1389
- pgstat_build_snapshot_fixed (PGSTAT_KIND_BGWRITER );
1390
- write_chunk_s (fpout , & pgStatLocal .snapshot .bgwriter );
1391
-
1392
- /*
1393
- * Write checkpointer stats struct
1394
- */
1395
- pgstat_build_snapshot_fixed (PGSTAT_KIND_CHECKPOINTER );
1396
- write_chunk_s (fpout , & pgStatLocal .snapshot .checkpointer );
1380
+ /* Write various stats structs for fixed number of objects */
1381
+ for (int kind = PGSTAT_KIND_FIRST_VALID ; kind <= PGSTAT_KIND_LAST ; kind ++ )
1382
+ {
1383
+ char * ptr ;
1384
+ const PgStat_KindInfo * info = pgstat_get_kind_info (kind );
1397
1385
1398
- /*
1399
- * Write IO stats struct
1400
- */
1401
- pgstat_build_snapshot_fixed (PGSTAT_KIND_IO );
1402
- write_chunk_s (fpout , & pgStatLocal .snapshot .io );
1386
+ if (!info -> fixed_amount )
1387
+ continue ;
1403
1388
1404
- /*
1405
- * Write SLRU stats struct
1406
- */
1407
- pgstat_build_snapshot_fixed (PGSTAT_KIND_SLRU );
1408
- write_chunk_s (fpout , & pgStatLocal .snapshot .slru );
1389
+ Assert (info -> snapshot_ctl_off != 0 );
1409
1390
1410
- /*
1411
- * Write WAL stats struct
1412
- */
1413
- pgstat_build_snapshot_fixed (PGSTAT_KIND_WAL );
1414
- write_chunk_s (fpout , & pgStatLocal .snapshot .wal );
1391
+ pgstat_build_snapshot_fixed (kind );
1392
+ ptr = ((char * ) & pgStatLocal .snapshot ) + info -> snapshot_ctl_off ;
1393
+ write_chunk (fpout , ptr , info -> shared_data_len );
1394
+ }
1415
1395
1416
1396
/*
1417
1397
* Walk through the stats entries
0 commit comments