LCOV - code coverage report
Current view: top level - src/backend/utils/activity - backend_progress.c (source / functions) Hit Total Coverage
Test: PostgreSQL 16devel Lines: 30 34 88.2 %
Date: 2022-08-17 04:10:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* ----------
       2             :  * backend_progress.c
       3             :  *
       4             :  *  Command progress reporting infrastructure.
       5             :  *
       6             :  *  Copyright (c) 2001-2022, 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      203436 : pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
      27             : {
      28      203436 :     volatile PgBackendStatus *beentry = MyBEEntry;
      29             : 
      30      203436 :     if (!beentry || !pgstat_track_activities)
      31           0 :         return;
      32             : 
      33      203436 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      34      203436 :     beentry->st_progress_command = cmdtype;
      35      203436 :     beentry->st_progress_command_target = relid;
      36     4272156 :     MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
      37      203436 :     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    34659642 : pgstat_progress_update_param(int index, int64 val)
      48             : {
      49    34659642 :     volatile PgBackendStatus *beentry = MyBEEntry;
      50             : 
      51             :     Assert(index >= 0 && index < PGSTAT_NUM_PROGRESS_PARAM);
      52             : 
      53    34659642 :     if (!beentry || !pgstat_track_activities)
      54           0 :         return;
      55             : 
      56    34659642 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      57    34659642 :     beentry->st_progress_param[index] = val;
      58    34659642 :     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      945984 : pgstat_progress_update_multi_param(int nparam, const int *index,
      70             :                                    const int64 *val)
      71             : {
      72      945984 :     volatile PgBackendStatus *beentry = MyBEEntry;
      73             :     int         i;
      74             : 
      75      945984 :     if (!beentry || !pgstat_track_activities || nparam == 0)
      76           0 :         return;
      77             : 
      78      945984 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
      79             : 
      80     3027948 :     for (i = 0; i < nparam; ++i)
      81             :     {
      82             :         Assert(index[i] >= 0 && index[i] < PGSTAT_NUM_PROGRESS_PARAM);
      83             : 
      84     2081964 :         beentry->st_progress_param[index[i]] = val[i];
      85             :     }
      86             : 
      87      945984 :     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      248486 : pgstat_progress_end_command(void)
      99             : {
     100      248486 :     volatile PgBackendStatus *beentry = MyBEEntry;
     101             : 
     102      248486 :     if (!beentry || !pgstat_track_activities)
     103           0 :         return;
     104             : 
     105      248486 :     if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
     106       46270 :         return;
     107             : 
     108      202216 :     PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
     109      202216 :     beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
     110      202216 :     beentry->st_progress_command_target = InvalidOid;
     111      202216 :     PGSTAT_END_WRITE_ACTIVITY(beentry);
     112             : }

Generated by: LCOV version 1.14