LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - pgstat_archiver.c (source / functions) Coverage Total Hit CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 100.0 % 42 42 42
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 4 4 4
Baseline: 16@8cea358b128 Branches: 100.0 % 6 6 6
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 100.0 % 42 42 42
Function coverage date bins:
(240..) days: 100.0 % 4 4 4
Branch coverage date bins:
(240..) days: 100.0 % 6 6 6

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /* -------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * pgstat_archiver.c
                                  4                 :                :  *    Implementation of archiver statistics.
                                  5                 :                :  *
                                  6                 :                :  * This file contains the implementation of archiver 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_archiver.c
                                 15                 :                :  * -------------------------------------------------------------------------
                                 16                 :                :  */
                                 17                 :                : 
                                 18                 :                : #include "postgres.h"
                                 19                 :                : 
                                 20                 :                : #include "utils/pgstat_internal.h"
                                 21                 :                : #include "utils/timestamp.h"
                                 22                 :                : 
                                 23                 :                : 
                                 24                 :                : /*
                                 25                 :                :  * Report archiver statistics
                                 26                 :                :  */
                                 27                 :                : void
  739 andres@anarazel.de         28                 :CBC         112 : pgstat_report_archiver(const char *xlog, bool failed)
                                 29                 :                : {
                                 30                 :            112 :     PgStatShared_Archiver *stats_shmem = &pgStatLocal.shmem->archiver;
                                 31                 :            112 :     TimestampTz now = GetCurrentTimestamp();
                                 32                 :                : 
                                 33                 :            112 :     pgstat_begin_changecount_write(&stats_shmem->changecount);
                                 34                 :                : 
                                 35         [ +  + ]:            112 :     if (failed)
                                 36                 :                :     {
                                 37                 :              4 :         ++stats_shmem->stats.failed_count;
                                 38                 :              4 :         memcpy(&stats_shmem->stats.last_failed_wal, xlog,
                                 39                 :                :                sizeof(stats_shmem->stats.last_failed_wal));
                                 40                 :              4 :         stats_shmem->stats.last_failed_timestamp = now;
                                 41                 :                :     }
                                 42                 :                :     else
                                 43                 :                :     {
                                 44                 :            108 :         ++stats_shmem->stats.archived_count;
                                 45                 :            108 :         memcpy(&stats_shmem->stats.last_archived_wal, xlog,
                                 46                 :                :                sizeof(stats_shmem->stats.last_archived_wal));
                                 47                 :            108 :         stats_shmem->stats.last_archived_timestamp = now;
                                 48                 :                :     }
                                 49                 :                : 
                                 50                 :            112 :     pgstat_end_changecount_write(&stats_shmem->changecount);
                                 51                 :            112 : }
                                 52                 :                : 
                                 53                 :                : /*
                                 54                 :                :  * Support function for the SQL-callable pgstat* functions. Returns
                                 55                 :                :  * a pointer to the archiver statistics struct.
                                 56                 :                :  */
                                 57                 :                : PgStat_ArchiverStats *
                                 58                 :             17 : pgstat_fetch_stat_archiver(void)
                                 59                 :                : {
                                 60                 :             17 :     pgstat_snapshot_fixed(PGSTAT_KIND_ARCHIVER);
                                 61                 :                : 
                                 62                 :             17 :     return &pgStatLocal.snapshot.archiver;
                                 63                 :                : }
                                 64                 :                : 
                                 65                 :                : void
                                 66                 :            246 : pgstat_archiver_reset_all_cb(TimestampTz ts)
                                 67                 :                : {
                                 68                 :            246 :     PgStatShared_Archiver *stats_shmem = &pgStatLocal.shmem->archiver;
                                 69                 :                : 
                                 70                 :                :     /* see explanation above PgStatShared_Archiver for the reset protocol */
                                 71                 :            246 :     LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
                                 72                 :            246 :     pgstat_copy_changecounted_stats(&stats_shmem->reset_offset,
                                 73                 :            246 :                                     &stats_shmem->stats,
                                 74                 :                :                                     sizeof(stats_shmem->stats),
                                 75                 :                :                                     &stats_shmem->changecount);
                                 76                 :            246 :     stats_shmem->stats.stat_reset_timestamp = ts;
                                 77                 :            246 :     LWLockRelease(&stats_shmem->lock);
                                 78                 :            246 : }
                                 79                 :                : 
                                 80                 :                : void
                                 81                 :            554 : pgstat_archiver_snapshot_cb(void)
                                 82                 :                : {
                                 83                 :            554 :     PgStatShared_Archiver *stats_shmem = &pgStatLocal.shmem->archiver;
                                 84                 :            554 :     PgStat_ArchiverStats *stat_snap = &pgStatLocal.snapshot.archiver;
                                 85                 :            554 :     PgStat_ArchiverStats *reset_offset = &stats_shmem->reset_offset;
                                 86                 :                :     PgStat_ArchiverStats reset;
                                 87                 :                : 
                                 88                 :            554 :     pgstat_copy_changecounted_stats(stat_snap,
                                 89                 :            554 :                                     &stats_shmem->stats,
                                 90                 :                :                                     sizeof(stats_shmem->stats),
                                 91                 :                :                                     &stats_shmem->changecount);
                                 92                 :                : 
                                 93                 :            554 :     LWLockAcquire(&stats_shmem->lock, LW_SHARED);
                                 94                 :            554 :     memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
                                 95                 :            554 :     LWLockRelease(&stats_shmem->lock);
                                 96                 :                : 
                                 97                 :                :     /* compensate by reset offsets */
                                 98         [ +  + ]:            554 :     if (stat_snap->archived_count == reset.archived_count)
                                 99                 :                :     {
                                100                 :            533 :         stat_snap->last_archived_wal[0] = 0;
                                101                 :            533 :         stat_snap->last_archived_timestamp = 0;
                                102                 :                :     }
                                103                 :            554 :     stat_snap->archived_count -= reset.archived_count;
                                104                 :                : 
                                105         [ +  + ]:            554 :     if (stat_snap->failed_count == reset.failed_count)
                                106                 :                :     {
                                107                 :            547 :         stat_snap->last_failed_wal[0] = 0;
                                108                 :            547 :         stat_snap->last_failed_timestamp = 0;
                                109                 :                :     }
                                110                 :            554 :     stat_snap->failed_count -= reset.failed_count;
  755                           111                 :            554 : }
        

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