LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - pgstat_checkpointer.c (source / functions) Coverage Total Hit GIC GNC CBC ECB
Current: Differential Code Coverage HEAD vs 15 Lines: 100.0 % 43 43 13 1 29 14
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 4 4 3 1 3
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           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-2023, 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
      30 CBC        7107 : pgstat_report_checkpointer(void)
      31                 : {
      32                 :     /* We assume this initializes to zeroes */
      33                 :     static const PgStat_CheckpointerStats all_zeroes;
      34            7107 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
      35                 : 
      36            7107 :     Assert(!pgStatLocal.shmem->is_shutdown);
      37            7107 :     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            7107 :     if (memcmp(&PendingCheckpointerStats, &all_zeroes,
      44                 :                sizeof(all_zeroes)) == 0)
      45             617 :         return;
      46                 : 
      47            6490 :     pgstat_begin_changecount_write(&stats_shmem->changecount);
      48                 : 
      49                 : #define CHECKPOINTER_ACC(fld) stats_shmem->stats.fld += PendingCheckpointerStats.fld
      50            6490 :     CHECKPOINTER_ACC(timed_checkpoints);
      51            6490 :     CHECKPOINTER_ACC(requested_checkpoints);
      52            6490 :     CHECKPOINTER_ACC(checkpoint_write_time);
      53            6490 :     CHECKPOINTER_ACC(checkpoint_sync_time);
      54            6490 :     CHECKPOINTER_ACC(buf_written_checkpoints);
      55            6490 :     CHECKPOINTER_ACC(buf_written_backend);
      56            6490 :     CHECKPOINTER_ACC(buf_fsync_backend);
      57                 : #undef CHECKPOINTER_ACC
      58                 : 
      59            6490 :     pgstat_end_changecount_write(&stats_shmem->changecount);
      60                 : 
      61                 :     /*
      62                 :      * Clear out the statistics buffer, so it can be re-used.
      63                 :      */
      64           51920 :     MemSet(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats));
      65                 : 
      66                 :     /*
      67                 :      * Report IO statistics
      68                 :      */
      69 GNC        6490 :     pgstat_flush_io(false);
      70                 : }
      71                 : 
      72                 : /*
      73                 :  * pgstat_fetch_stat_checkpointer() -
      74 ECB             :  *
      75                 :  * Support function for the SQL-callable pgstat* functions. Returns
      76                 :  * a pointer to the checkpointer statistics struct.
      77                 :  */
      78                 : PgStat_CheckpointerStats *
      79 GIC          14 : pgstat_fetch_stat_checkpointer(void)
      80                 : {
      81              14 :     pgstat_snapshot_fixed(PGSTAT_KIND_CHECKPOINTER);
      82                 : 
      83              14 :     return &pgStatLocal.snapshot.checkpointer;
      84 ECB             : }
      85                 : 
      86                 : void
      87 GIC         442 : pgstat_checkpointer_reset_all_cb(TimestampTz ts)
      88 ECB             : {
      89 GIC         442 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
      90                 : 
      91                 :     /* see explanation above PgStatShared_Checkpointer for the reset protocol */
      92 CBC         442 :     LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
      93 GIC         442 :     pgstat_copy_changecounted_stats(&stats_shmem->reset_offset,
      94 CBC         442 :                                     &stats_shmem->stats,
      95                 :                                     sizeof(stats_shmem->stats),
      96                 :                                     &stats_shmem->changecount);
      97             442 :     LWLockRelease(&stats_shmem->lock);
      98             442 : }
      99 ECB             : 
     100                 : void
     101 GIC        1002 : pgstat_checkpointer_snapshot_cb(void)
     102 ECB             : {
     103 CBC        1002 :     PgStatShared_Checkpointer *stats_shmem = &pgStatLocal.shmem->checkpointer;
     104 GIC        1002 :     PgStat_CheckpointerStats *reset_offset = &stats_shmem->reset_offset;
     105                 :     PgStat_CheckpointerStats reset;
     106 ECB             : 
     107 GIC        1002 :     pgstat_copy_changecounted_stats(&pgStatLocal.snapshot.checkpointer,
     108 CBC        1002 :                                     &stats_shmem->stats,
     109 ECB             :                                     sizeof(stats_shmem->stats),
     110                 :                                     &stats_shmem->changecount);
     111                 : 
     112 CBC        1002 :     LWLockAcquire(&stats_shmem->lock, LW_SHARED);
     113            1002 :     memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
     114 GIC        1002 :     LWLockRelease(&stats_shmem->lock);
     115                 : 
     116                 :     /* compensate by reset offsets */
     117 ECB             : #define CHECKPOINTER_COMP(fld) pgStatLocal.snapshot.checkpointer.fld -= reset.fld;
     118 CBC        1002 :     CHECKPOINTER_COMP(timed_checkpoints);
     119            1002 :     CHECKPOINTER_COMP(requested_checkpoints);
     120 GIC        1002 :     CHECKPOINTER_COMP(checkpoint_write_time);
     121            1002 :     CHECKPOINTER_COMP(checkpoint_sync_time);
     122            1002 :     CHECKPOINTER_COMP(buf_written_checkpoints);
     123 CBC        1002 :     CHECKPOINTER_COMP(buf_written_backend);
     124            1002 :     CHECKPOINTER_COMP(buf_fsync_backend);
     125 ECB             : #undef CHECKPOINTER_COMP
     126 CBC        1002 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a