PostgreSQL Source Code  git master
backend_progress.c
Go to the documentation of this file.
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
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_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
70  const int64 *val)
71 {
72  volatile PgBackendStatus *beentry = MyBEEntry;
73  int i;
74 
75  if (!beentry || !pgstat_track_activities || nparam == 0)
76  return;
77 
79 
80  for (i = 0; i < nparam; ++i)
81  {
83 
84  beentry->st_progress_param[index[i]] = val[i];
85  }
86 
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
99 {
100  volatile PgBackendStatus *beentry = MyBEEntry;
101 
102  if (!beentry || !pgstat_track_activities)
103  return;
104 
106  return;
107 
111  PGSTAT_END_WRITE_ACTIVITY(beentry);
112 }
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
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:1008
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:90