PostgreSQL Source Code  git master
backend_progress.c
Go to the documentation of this file.
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
27 {
28  volatile PgBackendStatus *beentry = MyBEEntry;
29 
30  if (!beentry || !pgstat_track_activities)
31  return;
32 
34  beentry->st_progress_command = cmdtype;
35  beentry->st_progress_command_target = relid;
36  MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
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
48 {
49  volatile PgBackendStatus *beentry = MyBEEntry;
50 
52 
53  if (!beentry || !pgstat_track_activities)
54  return;
55 
57  beentry->st_progress_param[index] = val;
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
69 {
70  volatile PgBackendStatus *beentry = MyBEEntry;
71 
73 
74  if (!beentry || !pgstat_track_activities)
75  return;
76 
78  beentry->st_progress_param[index] += incr;
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 void
91  const int64 *val)
92 {
93  volatile PgBackendStatus *beentry = MyBEEntry;
94  int i;
95 
96  if (!beentry || !pgstat_track_activities || nparam == 0)
97  return;
98 
100 
101  for (i = 0; i < nparam; ++i)
102  {
104 
105  beentry->st_progress_param[index[i]] = val[i];
106  }
107 
108  PGSTAT_END_WRITE_ACTIVITY(beentry);
109 }
110 
111 /*-----------
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 void
120 {
121  volatile PgBackendStatus *beentry = MyBEEntry;
122 
123  if (!beentry || !pgstat_track_activities)
124  return;
125 
127  return;
128 
132  PGSTAT_END_WRITE_ACTIVITY(beentry);
133 }
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void pgstat_progress_incr_param(int index, int64 incr)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void pgstat_progress_end_command(void)
#define PGSTAT_NUM_PROGRESS_PARAM
ProgressCommandType
@ PROGRESS_COMMAND_INVALID
PgBackendStatus * MyBEEntry
bool pgstat_track_activities
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
#define MemSet(start, val, len)
Definition: c.h:1004
long val
Definition: informix.c:664
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
ProgressCommandType st_progress_command
int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]
Oid st_progress_command_target
Definition: type.h:95