LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - pgstat_checkpointer.c (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 100.0 % 54 54 54
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 5 5 5
Baseline: lcov-20250906-005545-baseline Branches: 64.3 % 14 9 5 9
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 5 5 5
(360..) days: 100.0 % 49 49 49
Function coverage date bins:
(360..) days: 100.0 % 5 5 5
Branch coverage date bins:
(30,360] days: 100.0 % 2 2 2
(360..) days: 58.3 % 12 7 5 7

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /* -------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * pgstat_checkpointer.c
                                  4                 :                :  *    Implementation of checkpoint statistics.
                                  5                 :                :  *
                                  6                 :                :  * This file contains the implementation of checkpoint statistics. It is kept
                                  7                 :                :  * separate from pgstat.c to enforce the line between the statistics access /
                                  8                 :                :  * storage implementation and the details about individual types of
                                  9                 :                :  * statistics.
                                 10                 :                :  *
                                 11                 :                :  * Copyright (c) 2001-2025, PostgreSQL Global Development Group
                                 12                 :                :  *
                                 13                 :                :  * IDENTIFICATION
                                 14                 :                :  *    src/backend/utils/activity/pgstat_checkpointer.c
                                 15                 :                :  * -------------------------------------------------------------------------
                                 16                 :                :  */
                                 17                 :                : 
                                 18                 :                : #include "postgres.h"
                                 19                 :                : 
                                 20                 :                : #include "utils/memutils.h"
                                 21                 :                : #include "utils/pgstat_internal.h"
                                 22                 :                : 
                                 23                 :                : 
                                 24                 :                : PgStat_CheckpointerStats PendingCheckpointerStats = {0};
                                 25                 :                : 
                                 26                 :                : 
                                 27                 :                : /*
                                 28                 :                :  * Report checkpointer and IO statistics
                                 29                 :                :  */
                                 30                 :                : void
 1249 andres@anarazel.de         31                 :CBC       11290 : pgstat_report_checkpointer(void)
                                 32                 :                : {
                                 33                 :          11290 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
                                 34                 :                : 
                                 35         [ -  + ]:          11290 :     Assert(!pgStatLocal.shmem->is_shutdown);
                                 36                 :          11290 :     pgstat_assert_is_up();
                                 37                 :                : 
                                 38                 :                :     /*
                                 39                 :                :      * This function can be called even if nothing at all has happened. In
                                 40                 :                :      * this case, avoid unnecessarily modifying the stats entry.
                                 41                 :                :      */
  309 michael@paquier.xyz        42         [ +  + ]:          11290 :     if (pg_memory_is_all_zeros(&PendingCheckpointerStats,
                                 43                 :                :                                sizeof(struct PgStat_CheckpointerStats)))
 1265 andres@anarazel.de         44                 :           6027 :         return;
                                 45                 :                : 
 1249                            46                 :           5263 :     pgstat_begin_changecount_write(&stats_shmem->changecount);
                                 47                 :                : 
                                 48                 :                : #define CHECKPOINTER_ACC(fld) stats_shmem->stats.fld += PendingCheckpointerStats.fld
  677 michael@paquier.xyz        49                 :           5263 :     CHECKPOINTER_ACC(num_timed);
                                 50                 :           5263 :     CHECKPOINTER_ACC(num_requested);
  341 fujii@postgresql.org       51                 :           5263 :     CHECKPOINTER_ACC(num_performed);
  621 akorotkov@postgresql       52                 :           5263 :     CHECKPOINTER_ACC(restartpoints_timed);
                                 53                 :           5263 :     CHECKPOINTER_ACC(restartpoints_requested);
                                 54                 :           5263 :     CHECKPOINTER_ACC(restartpoints_performed);
  677 michael@paquier.xyz        55                 :           5263 :     CHECKPOINTER_ACC(write_time);
                                 56                 :           5263 :     CHECKPOINTER_ACC(sync_time);
                                 57                 :           5263 :     CHECKPOINTER_ACC(buffers_written);
  339 fujii@postgresql.org       58                 :           5263 :     CHECKPOINTER_ACC(slru_written);
                                 59                 :                : #undef CHECKPOINTER_ACC
                                 60                 :                : 
 1249 andres@anarazel.de         61                 :           5263 :     pgstat_end_changecount_write(&stats_shmem->changecount);
                                 62                 :                : 
                                 63                 :                :     /*
                                 64                 :                :      * Clear out the statistics buffer, so it can be re-used.
                                 65                 :                :      */
 1265                            66   [ +  -  +  -  :          63156 :     MemSet(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats));
                                     +  -  +  -  +  
                                                 + ]
                                 67                 :                : 
                                 68                 :                :     /*
                                 69                 :                :      * Report IO statistics
                                 70                 :                :      */
  941                            71                 :           5263 :     pgstat_flush_io(false);
                                 72                 :                : }
                                 73                 :                : 
                                 74                 :                : /*
                                 75                 :                :  * pgstat_fetch_stat_checkpointer() -
                                 76                 :                :  *
                                 77                 :                :  * Support function for the SQL-callable pgstat* functions. Returns
                                 78                 :                :  * a pointer to the checkpointer statistics struct.
                                 79                 :                :  */
                                 80                 :                : PgStat_CheckpointerStats *
 1249                            81                 :             24 : pgstat_fetch_stat_checkpointer(void)
                                 82                 :                : {
                                 83                 :             24 :     pgstat_snapshot_fixed(PGSTAT_KIND_CHECKPOINTER);
                                 84                 :                : 
                                 85                 :             24 :     return &pgStatLocal.snapshot.checkpointer;
                                 86                 :                : }
                                 87                 :                : 
                                 88                 :                : void
  422 michael@paquier.xyz        89                 :           1029 : pgstat_checkpointer_init_shmem_cb(void *stats)
                                 90                 :                : {
                                 91                 :           1029 :     PgStatShared_Checkpointer *stats_shmem = (PgStatShared_Checkpointer *) stats;
                                 92                 :                : 
                                 93                 :           1029 :     LWLockInitialize(&stats_shmem->lock, LWTRANCHE_PGSTATS_DATA);
                                 94                 :           1029 : }
                                 95                 :                : 
                                 96                 :                : void
 1249 andres@anarazel.de         97                 :            226 : pgstat_checkpointer_reset_all_cb(TimestampTz ts)
                                 98                 :                : {
                                 99                 :            226 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
                                100                 :                : 
                                101                 :                :     /* see explanation above PgStatShared_Checkpointer for the reset protocol */
                                102                 :            226 :     LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
                                103                 :            226 :     pgstat_copy_changecounted_stats(&stats_shmem->reset_offset,
                                104                 :            226 :                                     &stats_shmem->stats,
                                105                 :                :                                     sizeof(stats_shmem->stats),
                                106                 :                :                                     &stats_shmem->changecount);
  677 michael@paquier.xyz       107                 :            226 :     stats_shmem->stats.stat_reset_timestamp = ts;
 1249 andres@anarazel.de        108                 :            226 :     LWLockRelease(&stats_shmem->lock);
                                109                 :            226 : }
                                110                 :                : 
                                111                 :                : void
                                112                 :            651 : pgstat_checkpointer_snapshot_cb(void)
                                113                 :                : {
                                114                 :            651 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
                                115                 :            651 :     PgStat_CheckpointerStats *reset_offset = &stats_shmem->reset_offset;
                                116                 :                :     PgStat_CheckpointerStats reset;
                                117                 :                : 
                                118                 :            651 :     pgstat_copy_changecounted_stats(&pgStatLocal.snapshot.checkpointer,
                                119                 :            651 :                                     &stats_shmem->stats,
                                120                 :                :                                     sizeof(stats_shmem->stats),
                                121                 :                :                                     &stats_shmem->changecount);
                                122                 :                : 
                                123                 :            651 :     LWLockAcquire(&stats_shmem->lock, LW_SHARED);
                                124                 :            651 :     memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
                                125                 :            651 :     LWLockRelease(&stats_shmem->lock);
                                126                 :                : 
                                127                 :                :     /* compensate by reset offsets */
                                128                 :                : #define CHECKPOINTER_COMP(fld) pgStatLocal.snapshot.checkpointer.fld -= reset.fld;
  677 michael@paquier.xyz       129                 :            651 :     CHECKPOINTER_COMP(num_timed);
                                130                 :            651 :     CHECKPOINTER_COMP(num_requested);
  341 fujii@postgresql.org      131                 :            651 :     CHECKPOINTER_COMP(num_performed);
  621 akorotkov@postgresql      132                 :            651 :     CHECKPOINTER_COMP(restartpoints_timed);
                                133                 :            651 :     CHECKPOINTER_COMP(restartpoints_requested);
                                134                 :            651 :     CHECKPOINTER_COMP(restartpoints_performed);
  677 michael@paquier.xyz       135                 :            651 :     CHECKPOINTER_COMP(write_time);
                                136                 :            651 :     CHECKPOINTER_COMP(sync_time);
                                137                 :            651 :     CHECKPOINTER_COMP(buffers_written);
  339 fujii@postgresql.org      138                 :            651 :     CHECKPOINTER_COMP(slru_written);
                                139                 :                : #undef CHECKPOINTER_COMP
 1249 andres@anarazel.de        140                 :            651 : }
        

Generated by: LCOV version 2.4-beta