LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - backend_progress.c (source / functions) Coverage Total Hit UBC CBC
Current: b45a8d7d8b306b43f31a002f1b3f1dddc8defeaf vs 8767b449a3a1e75626dfb08f24da54933171d4c5 Lines: 81.1 % 53 43 10 43
Current Date: 2025-10-28 08:26:42 +0900 Functions: 100.0 % 6 6 6
Baseline: lcov-20251028-005825-baseline Branches: 54.3 % 70 38 32 38
Baseline Date: 2025-10-27 06:37:35 +0000 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 81.1 % 53 43 10 43
Function coverage date bins:
(360..) days: 100.0 % 6 6 6
Branch coverage date bins:
(360..) days: 54.3 % 70 38 32 38

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /* ----------
                                  2                 :                :  * backend_progress.c
                                  3                 :                :  *
                                  4                 :                :  *  Command progress reporting infrastructure.
                                  5                 :                :  *
                                  6                 :                :  *  Copyright (c) 2001-2025, PostgreSQL Global Development Group
                                  7                 :                :  *
                                  8                 :                :  *  src/backend/utils/activity/backend_progress.c
                                  9                 :                :  * ----------
                                 10                 :                :  */
                                 11                 :                : #include "postgres.h"
                                 12                 :                : 
                                 13                 :                : #include "access/parallel.h"
                                 14                 :                : #include "libpq/pqformat.h"
                                 15                 :                : #include "utils/backend_progress.h"
                                 16                 :                : #include "utils/backend_status.h"
                                 17                 :                : 
                                 18                 :                : 
                                 19                 :                : /*-----------
                                 20                 :                :  * pgstat_progress_start_command() -
                                 21                 :                :  *
                                 22                 :                :  * Set st_progress_command (and st_progress_command_target) in own backend
                                 23                 :                :  * entry.  Also, zero-initialize st_progress_param array.
                                 24                 :                :  *-----------
                                 25                 :                :  */
                                 26                 :                : void
 1669 andres@anarazel.de         27                 :CBC       43658 : pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
                                 28                 :                : {
                                 29                 :          43658 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 30                 :                : 
                                 31   [ +  -  -  + ]:          43658 :     if (!beentry || !pgstat_track_activities)
 1669 andres@anarazel.de         32                 :UBC           0 :         return;
                                 33                 :                : 
 1669 andres@anarazel.de         34                 :CBC       43658 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 35                 :          43658 :     beentry->st_progress_command = cmdtype;
                                 36                 :          43658 :     beentry->st_progress_command_target = relid;
                                 37   [ +  -  +  -  :         916818 :     MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
                                     +  -  +  -  +  
                                                 + ]
                                 38   [ -  +  -  + ]:          43658 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 39                 :                : }
                                 40                 :                : 
                                 41                 :                : /*-----------
                                 42                 :                :  * pgstat_progress_update_param() -
                                 43                 :                :  *
                                 44                 :                :  * Update index'th member in st_progress_param[] of own backend entry.
                                 45                 :                :  *-----------
                                 46                 :                :  */
                                 47                 :                : void
                                 48                 :       11442307 : pgstat_progress_update_param(int index, int64 val)
                                 49                 :                : {
                                 50                 :       11442307 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 51                 :                : 
                                 52   [ +  -  -  + ]:       11442307 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
                                 53                 :                : 
                                 54   [ +  -  -  + ]:       11442307 :     if (!beentry || !pgstat_track_activities)
 1669 andres@anarazel.de         55                 :UBC           0 :         return;
                                 56                 :                : 
 1669 andres@anarazel.de         57                 :CBC    11442307 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 58                 :       11442307 :     beentry->st_progress_param[index] = val;
                                 59   [ -  +  -  + ]:       11442307 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 60                 :                : }
                                 61                 :                : 
                                 62                 :                : /*-----------
                                 63                 :                :  * pgstat_progress_incr_param() -
                                 64                 :                :  *
                                 65                 :                :  * Increment index'th member in st_progress_param[] of own backend entry.
                                 66                 :                :  *-----------
                                 67                 :                :  */
                                 68                 :                : void
  948 tgl@sss.pgh.pa.us          69                 :           1370 : pgstat_progress_incr_param(int index, int64 incr)
                                 70                 :                : {
                                 71                 :           1370 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 72                 :                : 
                                 73   [ +  -  -  + ]:           1370 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
                                 74                 :                : 
                                 75   [ +  -  -  + ]:           1370 :     if (!beentry || !pgstat_track_activities)
  948 tgl@sss.pgh.pa.us          76                 :UBC           0 :         return;
                                 77                 :                : 
  948 tgl@sss.pgh.pa.us          78                 :CBC        1370 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 79                 :           1370 :     beentry->st_progress_param[index] += incr;
                                 80   [ -  +  -  + ]:           1370 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 81                 :                : }
                                 82                 :                : 
                                 83                 :                : /*-----------
                                 84                 :                :  * pgstat_progress_parallel_incr_param() -
                                 85                 :                :  *
                                 86                 :                :  * A variant of pgstat_progress_incr_param to allow a worker to poke at
                                 87                 :                :  * a leader to do an incremental progress update.
                                 88                 :                :  *-----------
                                 89                 :                :  */
                                 90                 :                : void
  840 msawada@postgresql.o       91                 :            110 : pgstat_progress_parallel_incr_param(int index, int64 incr)
                                 92                 :                : {
                                 93                 :                :     /*
                                 94                 :                :      * Parallel workers notify a leader through a PqMsg_Progress message to
                                 95                 :                :      * update progress, passing the progress index and incremented value.
                                 96                 :                :      * Leaders can just call pgstat_progress_incr_param directly.
                                 97                 :                :      */
                                 98         [ -  + ]:            110 :     if (IsParallelWorker())
                                 99                 :                :     {
                                100                 :                :         static StringInfoData progress_message;
                                101                 :                : 
  840 msawada@postgresql.o      102                 :UBC           0 :         initStringInfo(&progress_message);
                                103                 :                : 
  468 nathan@postgresql.or      104                 :              0 :         pq_beginmessage(&progress_message, PqMsg_Progress);
  840 msawada@postgresql.o      105                 :              0 :         pq_sendint32(&progress_message, index);
                                106                 :              0 :         pq_sendint64(&progress_message, incr);
                                107                 :              0 :         pq_endmessage(&progress_message);
                                108                 :                :     }
                                109                 :                :     else
  840 msawada@postgresql.o      110                 :CBC         110 :         pgstat_progress_incr_param(index, incr);
                                111                 :            110 : }
                                112                 :                : 
                                113                 :                : /*-----------
                                114                 :                :  * pgstat_progress_update_multi_param() -
                                115                 :                :  *
                                116                 :                :  * Update multiple members in st_progress_param[] of own backend entry.
                                117                 :                :  * This is atomic; readers won't see intermediate states.
                                118                 :                :  *-----------
                                119                 :                :  */
                                120                 :                : void
 1669 andres@anarazel.de        121                 :         587432 : pgstat_progress_update_multi_param(int nparam, const int *index,
                                122                 :                :                                    const int64 *val)
                                123                 :                : {
                                124                 :         587432 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                125                 :                :     int         i;
                                126                 :                : 
                                127   [ +  -  +  -  :         587432 :     if (!beentry || !pgstat_track_activities || nparam == 0)
                                              -  + ]
 1669 andres@anarazel.de        128                 :UBC           0 :         return;
                                129                 :                : 
 1669 andres@anarazel.de        130                 :CBC      587432 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                131                 :                : 
                                132         [ +  + ]:        1547439 :     for (i = 0; i < nparam; ++i)
                                133                 :                :     {
                                134   [ +  -  -  + ]:         960007 :         Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
                                135                 :                : 
                                136                 :         960007 :         beentry->st_progress_param[index[i]] = val[i];
                                137                 :                :     }
                                138                 :                : 
                                139   [ -  +  -  + ]:         587432 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                140                 :                : }
                                141                 :                : 
                                142                 :                : /*-----------
                                143                 :                :  * pgstat_progress_end_command() -
                                144                 :                :  *
                                145                 :                :  * Reset st_progress_command (and st_progress_command_target) in own backend
                                146                 :                :  * entry.  This signals the end of the command.
                                147                 :                :  *-----------
                                148                 :                :  */
                                149                 :                : void
                                150                 :          72300 : pgstat_progress_end_command(void)
                                151                 :                : {
                                152                 :          72300 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                153                 :                : 
                                154   [ +  -  -  + ]:          72300 :     if (!beentry || !pgstat_track_activities)
 1669 andres@anarazel.de        155                 :UBC           0 :         return;
                                156                 :                : 
 1669 andres@anarazel.de        157         [ +  + ]:CBC       72300 :     if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
                                158                 :          29395 :         return;
                                159                 :                : 
                                160                 :          42905 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                161                 :          42905 :     beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
                                162                 :          42905 :     beentry->st_progress_command_target = InvalidOid;
                                163   [ -  +  -  + ]:          42905 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                164                 :                : }
        

Generated by: LCOV version 2.4-beta