LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - backend_progress.c (source / functions) Coverage Total Hit UNC LBC UIC UBC GBC GIC GNC CBC EUB ECB
Current: Differential Code Coverage HEAD vs 15 Lines: 88.6 % 44 39 1 1 1 2 1 12 7 19 2 19
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 5 5 2 1 2 3
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /* ----------
       2                 :  * backend_progress.c
       3                 :  *
       4                 :  *  Command progress reporting infrastructure.
       5                 :  *
       6                 :  *  Copyright (c) 2001-2023, PostgreSQL Global Development Group
       7                 :  *
       8                 :  *  src/backend/utils/activity/backend_progress.c
       9                 :  * ----------
      10                 :  */
      11                 : #include "postgres.h"
      12                 : 
      13                 : #include "port/atomics.h"     /* for memory barriers */
      14                 : #include "utils/backend_progress.h"
      15                 : #include "utils/backend_status.h"
      16                 : 
      17                 : 
      18                 : /*-----------
      19                 :  * pgstat_progress_start_command() -
      20                 :  *
      21                 :  * Set st_progress_command (and st_progress_command_target) in own backend
      22                 :  * entry.  Also, zero-initialize st_progress_param array.
      23                 :  *-----------
      24                 :  */
      25                 : void
      26 CBC      111253 : pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
      27                 : {
      28          111253 :     volatile PgBackendStatus *beentry = MyBEEntry;
      29                 : 
      30          111253 :     if (!beentry || !pgstat_track_activities)
      31 UBC           0 :         return;
      32                 : 
      33 CBC      111253 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      34          111253 :     beentry->st_progress_command = cmdtype;
      35          111253 :     beentry->st_progress_command_target = relid;
      36         2336313 :     MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
      37          111253 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
      38                 : }
      39                 : 
      40                 : /*-----------
      41                 :  * pgstat_progress_update_param() -
      42                 :  *
      43                 :  * Update index'th member in st_progress_param[] of own backend entry.
      44                 :  *-----------
      45                 :  */
      46                 : void
      47        17287934 : pgstat_progress_update_param(int index, int64 val)
      48                 : {
      49        17287934 :     volatile PgBackendStatus *beentry = MyBEEntry;
      50                 : 
      51        17287934 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
      52                 : 
      53        17287934 :     if (!beentry || !pgstat_track_activities)
      54 UBC           0 :         return;
      55                 : 
      56 CBC    17287934 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      57        17287934 :     beentry->st_progress_param[index] = val;
      58        17287934 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
      59                 : }
      60                 : 
      61                 : /*-----------
      62                 :  * pgstat_progress_incr_param() -
      63                 :  *
      64                 :  * Increment index'th member in st_progress_param[] of own backend entry.
      65                 :  *-----------
      66                 :  */
      67                 : void
      68 GNC        1076 : pgstat_progress_incr_param(int index, int64 incr)
      69                 : {
      70            1076 :     volatile PgBackendStatus *beentry = MyBEEntry;
      71                 : 
      72            1076 :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
      73                 : 
      74            1076 :     if (!beentry || !pgstat_track_activities)
      75 UNC           0 :         return;
      76                 : 
      77 GNC        1076 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      78            1076 :     beentry->st_progress_param[index] += incr;
      79            1076 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
      80                 : }
      81                 : 
      82                 : /*-----------
      83                 :  * pgstat_progress_update_multi_param() -
      84                 :  *
      85                 :  * Update multiple members in st_progress_param[] of own backend entry.
      86                 :  * This is atomic; readers won't see intermediate states.
      87                 :  *-----------
      88                 :  */
      89 ECB             : void
      90 GIC      565952 : pgstat_progress_update_multi_param(int nparam, const int *index,
      91 ECB             :                                    const int64 *val)
      92                 : {
      93 CBC      565952 :     volatile PgBackendStatus *beentry = MyBEEntry;
      94                 :     int         i;
      95 ECB             : 
      96 GBC      565952 :     if (!beentry || !pgstat_track_activities || nparam == 0)
      97 UIC           0 :         return;
      98 ECB             : 
      99 CBC      565952 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
     100 ECB             : 
     101 GIC     1793227 :     for (i = 0; i < nparam; ++i)
     102                 :     {
     103         1227275 :         Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
     104                 : 
     105         1227275 :         beentry->st_progress_param[index[i]] = val[i];
     106                 :     }
     107                 : 
     108          565952 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
     109                 : }
     110                 : 
     111 ECB             : /*-----------
     112                 :  * pgstat_progress_end_command() -
     113                 :  *
     114                 :  * Reset st_progress_command (and st_progress_command_target) in own backend
     115                 :  * entry.  This signals the end of the command.
     116                 :  *-----------
     117                 :  */
     118 EUB             : void
     119 GIC      134832 : pgstat_progress_end_command(void)
     120 ECB             : {
     121 GIC      134832 :     volatile PgBackendStatus *beentry = MyBEEntry;
     122 ECB             : 
     123 GIC      134832 :     if (!beentry || !pgstat_track_activities)
     124 LBC           0 :         return;
     125                 : 
     126 CBC      134832 :     if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
     127 GIC       24212 :         return;
     128                 : 
     129 CBC      110620 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
     130 GIC      110620 :     beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
     131          110620 :     beentry->st_progress_command_target = InvalidOid;
     132          110620 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
     133                 : }
        

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