LCOV - code coverage report
Current view: top level - src/backend/utils/activity - backend_progress.c (source / functions) Hit Total Coverage
Test: PostgreSQL 15devel Lines: 34 34 100.0 %
Date: 2021-09-17 16:07:28 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* ----------
       2             :  * progress.c
       3             :  *
       4             :  *  Command progress reporting infrastructure.
       5             :  *
       6             :  *  Copyright (c) 2001-2021, PostgreSQL Global Development Group
       7             :  *
       8             :  *  src/backend/postmaster/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      163068 : pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
      27             : {
      28      163068 :     volatile PgBackendStatus *beentry = MyBEEntry;
      29             : 
      30      163068 :     if (!beentry || !pgstat_track_activities)
      31       53586 :         return;
      32             : 
      33      109482 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      34      109482 :     beentry->st_progress_command = cmdtype;
      35      109482 :     beentry->st_progress_command_target = relid;
      36     2299122 :     MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
      37      109482 :     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    26121442 : pgstat_progress_update_param(int index, int64 val)
      48             : {
      49    26121442 :     volatile PgBackendStatus *beentry = MyBEEntry;
      50             : 
      51             :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
      52             : 
      53    26121442 :     if (!beentry || !pgstat_track_activities)
      54    10836738 :         return;
      55             : 
      56    15284704 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      57    15284704 :     beentry->st_progress_param[index] = val;
      58    15284704 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
      59             : }
      60             : 
      61             : /*-----------
      62             :  * pgstat_progress_update_multi_param() -
      63             :  *
      64             :  * Update multiple members in st_progress_param[] of own backend entry.
      65             :  * This is atomic; readers won't see intermediate states.
      66             :  *-----------
      67             :  */
      68             : void
      69      744432 : pgstat_progress_update_multi_param(int nparam, const int *index,
      70             :                                    const int64 *val)
      71             : {
      72      744432 :     volatile PgBackendStatus *beentry = MyBEEntry;
      73             :     int         i;
      74             : 
      75      744432 :     if (!beentry || !pgstat_track_activities || nparam == 0)
      76      138316 :         return;
      77             : 
      78      606116 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      79             : 
      80     1665802 :     for (i = 0; i < nparam; ++i)
      81             :     {
      82             :         Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
      83             : 
      84     1059686 :         beentry->st_progress_param[index[i]] = val[i];
      85             :     }
      86             : 
      87      606116 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
      88             : }
      89             : 
      90             : /*-----------
      91             :  * pgstat_progress_end_command() -
      92             :  *
      93             :  * Reset st_progress_command (and st_progress_command_target) in own backend
      94             :  * entry.  This signals the end of the command.
      95             :  *-----------
      96             :  */
      97             : void
      98      191540 : pgstat_progress_end_command(void)
      99             : {
     100      191540 :     volatile PgBackendStatus *beentry = MyBEEntry;
     101             : 
     102      191540 :     if (!beentry || !pgstat_track_activities)
     103       53586 :         return;
     104             : 
     105      137954 :     if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
     106       29066 :         return;
     107             : 
     108      108888 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
     109      108888 :     beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
     110      108888 :     beentry->st_progress_command_target = InvalidOid;
     111      108888 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
     112             : }

Generated by: LCOV version 1.13