LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - backend_progress.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: 4b3c9325757dfd8f2312e9f1a8decf4431f344ae vs e87b024bfb8dd55e3049b1b6e6ab4e810cf1abc8 Lines: 90.6 % 53 48 5 3 45 2
Current Date: 2026-11-28 16:48:44 +0900 Functions: 100.0 % 6 6 2 4
Baseline: lcov-20261128-baseline Branches: 56.5 % 62 35 27 2 33
Baseline Date: 2026-11-28 16:48:48 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 3 3 3
(360..) days: 90.0 % 50 45 5 45
Function coverage date bins:
(360..) days: 100.0 % 6 6 2 4
Branch coverage date bins:
(30,360] days: 100.0 % 2 2 2
(360..) days: 55.0 % 60 33 27 33

 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-2026, 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 "storage/proc.h"
                                 16                 :                : #include "utils/backend_progress.h"
                                 17                 :                : #include "utils/backend_status.h"
                                 18                 :                : 
                                 19                 :                : 
                                 20                 :                : /*-----------
                                 21                 :                :  * pgstat_progress_start_command() -
                                 22                 :                :  *
                                 23                 :                :  * Set st_progress_command (and st_progress_command_target) in own backend
                                 24                 :                :  * entry.  Also, zero-initialize st_progress_param array.
                                 25                 :                :  *-----------
                                 26                 :                :  */
                                 27                 :                : void
 2065 andres@anarazel.de         28                 :CBC       55255 : pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
                                 29                 :                : {
                                 30                 :          55255 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 31                 :                : 
                                 32   [ +  -  -  + ]:          55255 :     if (!beentry || !pgstat_track_activities)
 2065 andres@anarazel.de         33                 :UBC           0 :         return;
                                 34                 :                : 
 2065 andres@anarazel.de         35                 :CBC       55255 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 36                 :          55255 :     beentry->st_progress_command = cmdtype;
                                 37                 :          55255 :     beentry->st_progress_command_target = relid;
   40 peter@eisentraut.org       38         [ +  + ]:GNC     1160355 :     for (int i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
                                 39                 :        1105100 :         beentry->st_progress_param[i] = 0;
 2065 andres@anarazel.de         40   [ -  +  -  + ]:CBC       55255 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 41                 :                : }
                                 42                 :                : 
                                 43                 :                : /*-----------
                                 44                 :                :  * pgstat_progress_update_param() -
                                 45                 :                :  *
                                 46                 :                :  * Update index'th member in st_progress_param[] of own backend entry.
                                 47                 :                :  *-----------
                                 48                 :                :  */
                                 49                 :                : void
                                 50                 :       13646077 : pgstat_progress_update_param(int index, int64 val)
                                 51                 :                : {
                                 52                 :       13646077 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 53                 :                : 
                                 54   [ +  -  -  + ]:       13646077 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
                                 55                 :                : 
                                 56   [ +  -  -  + ]:       13646077 :     if (!beentry || !pgstat_track_activities)
 2065 andres@anarazel.de         57                 :UBC           0 :         return;
                                 58                 :                : 
 2065 andres@anarazel.de         59                 :CBC    13646077 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 60                 :       13646077 :     beentry->st_progress_param[index] = val;
                                 61   [ -  +  -  + ]:       13646077 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 62                 :                : }
                                 63                 :                : 
                                 64                 :                : /*-----------
                                 65                 :                :  * pgstat_progress_incr_param() -
                                 66                 :                :  *
                                 67                 :                :  * Increment index'th member in st_progress_param[] of own backend entry.
                                 68                 :                :  *-----------
                                 69                 :                :  */
                                 70                 :                : void
 1344 tgl@sss.pgh.pa.us          71                 :           1960 : pgstat_progress_incr_param(int index, int64 incr)
                                 72                 :                : {
                                 73                 :           1960 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 74                 :                : 
                                 75   [ +  -  -  + ]:           1960 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
                                 76                 :                : 
                                 77   [ +  -  -  + ]:           1960 :     if (!beentry || !pgstat_track_activities)
 1344 tgl@sss.pgh.pa.us          78                 :UBC           0 :         return;
                                 79                 :                : 
 1344 tgl@sss.pgh.pa.us          80                 :CBC        1960 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 81                 :           1960 :     beentry->st_progress_param[index] += incr;
                                 82   [ -  +  -  + ]:           1960 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 83                 :                : }
                                 84                 :                : 
                                 85                 :                : /*-----------
                                 86                 :                :  * pgstat_progress_parallel_incr_param() -
                                 87                 :                :  *
                                 88                 :                :  * A variant of pgstat_progress_incr_param to allow a worker to poke at
                                 89                 :                :  * a leader to do an incremental progress update.
                                 90                 :                :  *-----------
                                 91                 :                :  */
                                 92                 :                : void
 1236 msawada@postgresql.o       93                 :            154 : pgstat_progress_parallel_incr_param(int index, int64 incr)
                                 94                 :                : {
                                 95                 :                :     /*
                                 96                 :                :      * Parallel workers notify a leader through a PqParallelMsg_Progress
                                 97                 :                :      * message to update progress, passing the progress index and incremented
                                 98                 :                :      * value. Leaders can just call pgstat_progress_incr_param directly.
                                 99                 :                :      */
                                100         [ +  + ]:            154 :     if (IsParallelWorker())
                                101                 :                :     {
                                102                 :                :         static StringInfoData progress_message;
                                103                 :                : 
   79 nathan@postgresql.or      104                 :GNC          15 :         pq_beginmessage(&progress_message, PqParallelMsg_Progress);
 1236 msawada@postgresql.o      105                 :CBC          15 :         pq_sendint32(&progress_message, index);
                                106                 :             15 :         pq_sendint64(&progress_message, incr);
                                107                 :             15 :         pq_endmessage(&progress_message);
                                108                 :                :     }
                                109                 :                :     else
                                110                 :            139 :         pgstat_progress_incr_param(index, incr);
                                111                 :            154 : }
                                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
 2065 andres@anarazel.de        121                 :         728671 : pgstat_progress_update_multi_param(int nparam, const int *index,
                                122                 :                :                                    const int64 *val)
                                123                 :                : {
                                124                 :         728671 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                125                 :                :     int         i;
                                126                 :                : 
                                127   [ +  -  +  -  :         728671 :     if (!beentry || !pgstat_track_activities || nparam == 0)
                                              -  + ]
 2065 andres@anarazel.de        128                 :UBC           0 :         return;
                                129                 :                : 
 2065 andres@anarazel.de        130                 :CBC      728671 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                131                 :                : 
                                132         [ +  + ]:        1875615 :     for (i = 0; i < nparam; ++i)
                                133                 :                :     {
                                134   [ +  -  -  + ]:        1146944 :         Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
                                135                 :                : 
                                136                 :        1146944 :         beentry->st_progress_param[index[i]] = val[i];
                                137                 :                :     }
                                138                 :                : 
                                139   [ -  +  -  + ]:         728671 :     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                 :          96656 : pgstat_progress_end_command(void)
                                151                 :                : {
                                152                 :          96656 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                153                 :                : 
                                154   [ +  -  -  + ]:          96656 :     if (!beentry || !pgstat_track_activities)
 2065 andres@anarazel.de        155                 :UBC           0 :         return;
                                156                 :                : 
 2065 andres@anarazel.de        157         [ +  + ]:CBC       96656 :     if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
                                158                 :          42156 :         return;
                                159                 :                : 
                                160                 :          54500 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                161                 :          54500 :     beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
                                162                 :          54500 :     beentry->st_progress_command_target = InvalidOid;
                                163   [ -  +  -  + ]:          54500 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                164                 :                : }
        

Generated by: LCOV version 2.0-1