LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - backend_progress.c (source / functions) Coverage Total Hit UBC GBC CBC
Current: bed3ffbf9d952be6c7d739d068cdce44c046dfb7 vs 574581b50ac9c63dd9e4abebb731a3b67e5b50f6 Lines: 90.6 % 53 48 5 5 43
Current Date: 2026-05-05 10:23:31 +0900 Functions: 100.0 % 6 6 6
Baseline: lcov-20260505-025707-baseline Branches: 55.7 % 70 39 31 1 38
Baseline Date: 2026-05-05 10:27:06 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 90.6 % 53 48 5 5 43
Function coverage date bins:
(360..) days: 100.0 % 6 6 6
Branch coverage date bins:
(360..) days: 55.7 % 70 39 31 1 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-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
 1858 andres@anarazel.de         28                 :CBC       54434 : pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
                                 29                 :                : {
                                 30                 :          54434 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 31                 :                : 
                                 32   [ +  -  -  + ]:          54434 :     if (!beentry || !pgstat_track_activities)
 1858 andres@anarazel.de         33                 :UBC           0 :         return;
                                 34                 :                : 
 1858 andres@anarazel.de         35                 :CBC       54434 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 36                 :          54434 :     beentry->st_progress_command = cmdtype;
                                 37                 :          54434 :     beentry->st_progress_command_target = relid;
                                 38   [ +  -  +  -  :        1143114 :     MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
                                     +  -  +  -  +  
                                                 + ]
                                 39   [ -  +  -  + ]:          54434 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 40                 :                : }
                                 41                 :                : 
                                 42                 :                : /*-----------
                                 43                 :                :  * pgstat_progress_update_param() -
                                 44                 :                :  *
                                 45                 :                :  * Update index'th member in st_progress_param[] of own backend entry.
                                 46                 :                :  *-----------
                                 47                 :                :  */
                                 48                 :                : void
                                 49                 :       13490262 : pgstat_progress_update_param(int index, int64 val)
                                 50                 :                : {
                                 51                 :       13490262 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 52                 :                : 
                                 53   [ +  -  -  + ]:       13490262 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
                                 54                 :                : 
                                 55   [ +  -  -  + ]:       13490262 :     if (!beentry || !pgstat_track_activities)
 1858 andres@anarazel.de         56                 :UBC           0 :         return;
                                 57                 :                : 
 1858 andres@anarazel.de         58                 :CBC    13490262 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 59                 :       13490262 :     beentry->st_progress_param[index] = val;
                                 60   [ -  +  -  + ]:       13490262 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 61                 :                : }
                                 62                 :                : 
                                 63                 :                : /*-----------
                                 64                 :                :  * pgstat_progress_incr_param() -
                                 65                 :                :  *
                                 66                 :                :  * Increment index'th member in st_progress_param[] of own backend entry.
                                 67                 :                :  *-----------
                                 68                 :                :  */
                                 69                 :                : void
 1137 tgl@sss.pgh.pa.us          70                 :           2273 : pgstat_progress_incr_param(int index, int64 incr)
                                 71                 :                : {
                                 72                 :           2273 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                 73                 :                : 
                                 74   [ +  -  -  + ]:           2273 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
                                 75                 :                : 
                                 76   [ +  -  -  + ]:           2273 :     if (!beentry || !pgstat_track_activities)
 1137 tgl@sss.pgh.pa.us          77                 :UBC           0 :         return;
                                 78                 :                : 
 1137 tgl@sss.pgh.pa.us          79                 :CBC        2273 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                 80                 :           2273 :     beentry->st_progress_param[index] += incr;
                                 81   [ -  +  -  + ]:           2273 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                 82                 :                : }
                                 83                 :                : 
                                 84                 :                : /*-----------
                                 85                 :                :  * pgstat_progress_parallel_incr_param() -
                                 86                 :                :  *
                                 87                 :                :  * A variant of pgstat_progress_incr_param to allow a worker to poke at
                                 88                 :                :  * a leader to do an incremental progress update.
                                 89                 :                :  *-----------
                                 90                 :                :  */
                                 91                 :                : void
 1029 msawada@postgresql.o       92                 :            125 : pgstat_progress_parallel_incr_param(int index, int64 incr)
                                 93                 :                : {
                                 94                 :                :     /*
                                 95                 :                :      * Parallel workers notify a leader through a PqMsg_Progress message to
                                 96                 :                :      * update progress, passing the progress index and incremented value.
                                 97                 :                :      * Leaders can just call pgstat_progress_incr_param directly.
                                 98                 :                :      */
                                 99         [ +  + ]:            125 :     if (IsParallelWorker())
                                100                 :                :     {
                                101                 :                :         static StringInfoData progress_message;
                                102                 :                : 
 1029 msawada@postgresql.o      103                 :GBC           6 :         initStringInfo(&progress_message);
                                104                 :                : 
  657 nathan@postgresql.or      105                 :              6 :         pq_beginmessage(&progress_message, PqMsg_Progress);
 1029 msawada@postgresql.o      106                 :              6 :         pq_sendint32(&progress_message, index);
                                107                 :              6 :         pq_sendint64(&progress_message, incr);
                                108                 :              6 :         pq_endmessage(&progress_message);
                                109                 :                :     }
                                110                 :                :     else
 1029 msawada@postgresql.o      111                 :CBC         119 :         pgstat_progress_incr_param(index, incr);
                                112                 :            125 : }
                                113                 :                : 
                                114                 :                : /*-----------
                                115                 :                :  * pgstat_progress_update_multi_param() -
                                116                 :                :  *
                                117                 :                :  * Update multiple members in st_progress_param[] of own backend entry.
                                118                 :                :  * This is atomic; readers won't see intermediate states.
                                119                 :                :  *-----------
                                120                 :                :  */
                                121                 :                : void
 1858 andres@anarazel.de        122                 :         677714 : pgstat_progress_update_multi_param(int nparam, const int *index,
                                123                 :                :                                    const int64 *val)
                                124                 :                : {
                                125                 :         677714 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                126                 :                :     int         i;
                                127                 :                : 
                                128   [ +  -  +  -  :         677714 :     if (!beentry || !pgstat_track_activities || nparam == 0)
                                              -  + ]
 1858 andres@anarazel.de        129                 :UBC           0 :         return;
                                130                 :                : 
 1858 andres@anarazel.de        131                 :CBC      677714 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                132                 :                : 
                                133         [ +  + ]:        1747679 :     for (i = 0; i < nparam; ++i)
                                134                 :                :     {
                                135   [ +  -  -  + ]:        1069965 :         Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
                                136                 :                : 
                                137                 :        1069965 :         beentry->st_progress_param[index[i]] = val[i];
                                138                 :                :     }
                                139                 :                : 
                                140   [ -  +  -  + ]:         677714 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                141                 :                : }
                                142                 :                : 
                                143                 :                : /*-----------
                                144                 :                :  * pgstat_progress_end_command() -
                                145                 :                :  *
                                146                 :                :  * Reset st_progress_command (and st_progress_command_target) in own backend
                                147                 :                :  * entry.  This signals the end of the command.
                                148                 :                :  *-----------
                                149                 :                :  */
                                150                 :                : void
                                151                 :          93438 : pgstat_progress_end_command(void)
                                152                 :                : {
                                153                 :          93438 :     volatile PgBackendStatus *beentry = MyBEEntry;
                                154                 :                : 
                                155   [ +  -  -  + ]:          93438 :     if (!beentry || !pgstat_track_activities)
 1858 andres@anarazel.de        156                 :UBC           0 :         return;
                                157                 :                : 
 1858 andres@anarazel.de        158         [ +  + ]:CBC       93438 :     if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
                                159                 :          39919 :         return;
                                160                 :                : 
                                161                 :          53519 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
                                162                 :          53519 :     beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
                                163                 :          53519 :     beentry->st_progress_command_target = InvalidOid;
                                164   [ -  +  -  + ]:          53519 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
                                165                 :                : }
        

Generated by: LCOV version 2.5.0-beta