LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - pgstat_checkpointer.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 100.0 % 46 46 17 29 14
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 4 4 3 1
Baseline: 16@8cea358b128 Branches: 64.3 % 14 9 5 9
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (60,120] days: 100.0 % 6 6 6
(120,180] days: 100.0 % 11 11 11
(240..) days: 100.0 % 29 29 29
Function coverage date bins:
(240..) days: 100.0 % 4 4 3 1
Branch coverage date bins:
(240..) days: 64.3 % 14 9 5 9

 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-2024, 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/pgstat_internal.h"
                                 21                 :                : 
                                 22                 :                : 
                                 23                 :                : PgStat_CheckpointerStats PendingCheckpointerStats = {0};
                                 24                 :                : 
                                 25                 :                : 
                                 26                 :                : /*
                                 27                 :                :  * Report checkpointer and IO statistics
                                 28                 :                :  */
                                 29                 :                : void
  739 andres@anarazel.de         30                 :CBC       10778 : pgstat_report_checkpointer(void)
                                 31                 :                : {
                                 32                 :                :     /* We assume this initializes to zeroes */
                                 33                 :                :     static const PgStat_CheckpointerStats all_zeroes;
                                 34                 :          10778 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
                                 35                 :                : 
                                 36         [ -  + ]:          10778 :     Assert(!pgStatLocal.shmem->is_shutdown);
                                 37                 :          10778 :     pgstat_assert_is_up();
                                 38                 :                : 
                                 39                 :                :     /*
                                 40                 :                :      * This function can be called even if nothing at all has happened. In
                                 41                 :                :      * this case, avoid unnecessarily modifying the stats entry.
                                 42                 :                :      */
                                 43         [ +  + ]:          10778 :     if (memcmp(&PendingCheckpointerStats, &all_zeroes,
                                 44                 :                :                sizeof(all_zeroes)) == 0)
  755                            45                 :           8685 :         return;
                                 46                 :                : 
  739                            47                 :           2093 :     pgstat_begin_changecount_write(&stats_shmem->changecount);
                                 48                 :                : 
                                 49                 :                : #define CHECKPOINTER_ACC(fld) stats_shmem->stats.fld += PendingCheckpointerStats.fld
  167 michael@paquier.xyz        50                 :GNC        2093 :     CHECKPOINTER_ACC(num_timed);
                                 51                 :           2093 :     CHECKPOINTER_ACC(num_requested);
  111 akorotkov@postgresql       52                 :           2093 :     CHECKPOINTER_ACC(restartpoints_timed);
                                 53                 :           2093 :     CHECKPOINTER_ACC(restartpoints_requested);
                                 54                 :           2093 :     CHECKPOINTER_ACC(restartpoints_performed);
  167 michael@paquier.xyz        55                 :           2093 :     CHECKPOINTER_ACC(write_time);
                                 56                 :           2093 :     CHECKPOINTER_ACC(sync_time);
                                 57                 :           2093 :     CHECKPOINTER_ACC(buffers_written);
                                 58                 :                : #undef CHECKPOINTER_ACC
                                 59                 :                : 
  739 andres@anarazel.de         60                 :CBC        2093 :     pgstat_end_changecount_write(&stats_shmem->changecount);
                                 61                 :                : 
                                 62                 :                :     /*
                                 63                 :                :      * Clear out the statistics buffer, so it can be re-used.
                                 64                 :                :      */
  755                            65   [ +  -  +  -  :          20930 :     MemSet(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats));
                                     +  -  +  -  +  
                                                 + ]
                                 66                 :                : 
                                 67                 :                :     /*
                                 68                 :                :      * Report IO statistics
                                 69                 :                :      */
  431                            70                 :           2093 :     pgstat_flush_io(false);
                                 71                 :                : }
                                 72                 :                : 
                                 73                 :                : /*
                                 74                 :                :  * pgstat_fetch_stat_checkpointer() -
                                 75                 :                :  *
                                 76                 :                :  * Support function for the SQL-callable pgstat* functions. Returns
                                 77                 :                :  * a pointer to the checkpointer statistics struct.
                                 78                 :                :  */
                                 79                 :                : PgStat_CheckpointerStats *
  739                            80                 :             24 : pgstat_fetch_stat_checkpointer(void)
                                 81                 :                : {
                                 82                 :             24 :     pgstat_snapshot_fixed(PGSTAT_KIND_CHECKPOINTER);
                                 83                 :                : 
                                 84                 :             24 :     return &pgStatLocal.snapshot.checkpointer;
                                 85                 :                : }
                                 86                 :                : 
                                 87                 :                : void
                                 88                 :            247 : pgstat_checkpointer_reset_all_cb(TimestampTz ts)
                                 89                 :                : {
                                 90                 :            247 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
                                 91                 :                : 
                                 92                 :                :     /* see explanation above PgStatShared_Checkpointer for the reset protocol */
                                 93                 :            247 :     LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
                                 94                 :            247 :     pgstat_copy_changecounted_stats(&stats_shmem->reset_offset,
                                 95                 :            247 :                                     &stats_shmem->stats,
                                 96                 :                :                                     sizeof(stats_shmem->stats),
                                 97                 :                :                                     &stats_shmem->changecount);
  167 michael@paquier.xyz        98                 :GNC         247 :     stats_shmem->stats.stat_reset_timestamp = ts;
  739 andres@anarazel.de         99                 :CBC         247 :     LWLockRelease(&stats_shmem->lock);
                                100                 :            247 : }
                                101                 :                : 
                                102                 :                : void
                                103                 :            557 : pgstat_checkpointer_snapshot_cb(void)
                                104                 :                : {
                                105                 :            557 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
                                106                 :            557 :     PgStat_CheckpointerStats *reset_offset = &stats_shmem->reset_offset;
                                107                 :                :     PgStat_CheckpointerStats reset;
                                108                 :                : 
                                109                 :            557 :     pgstat_copy_changecounted_stats(&pgStatLocal.snapshot.checkpointer,
                                110                 :            557 :                                     &stats_shmem->stats,
                                111                 :                :                                     sizeof(stats_shmem->stats),
                                112                 :                :                                     &stats_shmem->changecount);
                                113                 :                : 
                                114                 :            557 :     LWLockAcquire(&stats_shmem->lock, LW_SHARED);
                                115                 :            557 :     memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
                                116                 :            557 :     LWLockRelease(&stats_shmem->lock);
                                117                 :                : 
                                118                 :                :     /* compensate by reset offsets */
                                119                 :                : #define CHECKPOINTER_COMP(fld) pgStatLocal.snapshot.checkpointer.fld -= reset.fld;
  167 michael@paquier.xyz       120                 :GNC         557 :     CHECKPOINTER_COMP(num_timed);
                                121                 :            557 :     CHECKPOINTER_COMP(num_requested);
  111 akorotkov@postgresql      122                 :            557 :     CHECKPOINTER_COMP(restartpoints_timed);
                                123                 :            557 :     CHECKPOINTER_COMP(restartpoints_requested);
                                124                 :            557 :     CHECKPOINTER_COMP(restartpoints_performed);
  167 michael@paquier.xyz       125                 :            557 :     CHECKPOINTER_COMP(write_time);
                                126                 :            557 :     CHECKPOINTER_COMP(sync_time);
                                127                 :            557 :     CHECKPOINTER_COMP(buffers_written);
                                128                 :                : #undef CHECKPOINTER_COMP
  739 andres@anarazel.de        129                 :CBC         557 : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622