Skip to content

Commit d4d9dad

Browse files
author
Alexander Korotkov
committed
pg_wait_sampling.profile_pid setting to collect profile in not per-proccess manner.
1 parent 354c23b commit d4d9dad

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@ GUCs.
109109
| pg_wait_sampling.history_size | int4 | Size of history in-memory ring buffer | 5000 |
110110
| pg_wait_sampling.history_period | int4 | Period for history sampling in milliseconds | 10 |
111111
| pg_wait_sampling.profile_period | int4 | Period for profile sampling in milliseconds | 10 |
112+
| pg_wait_sampling.profile_pid | int4 | Whether profile should be per pid | true |
112113

113-
These GUCs are allowed to be changed by superuser. Also, they are placed into
114-
shared memory. Thus, they could be changed from any backend and affects worker
114+
If pg\_wait\_sampling.profile\_pid is set to false, sampling profile wouldn't be
115+
collected in per-process manner. In this case the value of pid could would
116+
be always zero and corresponding row contain samples among all the processes.
117+
118+
These GUCs are allowed to be changed by superuser. Also, they are placed into
119+
shared memory. Thus, they could be changed from any backend and affects worker
115120
runtime.
116121

122+
117123
See
118124
[PostgreSQL documentation](http://www.postgresql.org/docs/devel/static/monitoring-stats.html#WAIT-EVENT-TABLE)
119125
for list of possible wait events.

collector.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ get_next_observation(History *observations)
138138
*/
139139
static void
140140
probe_waits(History *observations, HTAB *profile_hash,
141-
bool write_history, bool write_profile)
141+
bool write_history, bool write_profile, bool profile_pid)
142142
{
143143
int i,
144144
newSize;
@@ -178,6 +178,9 @@ probe_waits(History *observations, HTAB *profile_hash,
178178
ProfileItem *profileItem;
179179
bool found;
180180

181+
if (!profile_pid)
182+
item.pid = 0;
183+
181184
profileItem = (ProfileItem *) hash_search(profile_hash, &item, HASH_ENTER, &found);
182185
if (found)
183186
profileItem->count++;
@@ -325,7 +328,7 @@ collector_main(Datum main_arg)
325328
if (write_history || write_profile)
326329
{
327330
probe_waits(&observations, profile_hash,
328-
write_history, write_profile);
331+
write_history, write_profile, collector_hdr->profilePid);
329332

330333
if (write_history)
331334
{

pg_wait_sampling.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ shmem_int_guc_check_hook(int *newval, void **extra, GucSource source)
7575
return true;
7676
}
7777

78+
static bool
79+
shmem_bool_guc_check_hook(bool *newval, void **extra, GucSource source)
80+
{
81+
if (UsedShmemSegAddr == NULL)
82+
return false;
83+
return true;
84+
}
85+
7886
/*
7987
* This union allows us to mix the numerous different types of structs
8088
* that we are organizing.
@@ -100,7 +108,8 @@ setup_gucs()
100108
i;
101109
bool history_size_found = false,
102110
history_period_found = false,
103-
profile_period_found = false;
111+
profile_period_found = false,
112+
profile_pid_found = false;
104113

105114
guc_vars = get_guc_variables();
106115
numOpts = GetNumConfigOptions();
@@ -131,6 +140,12 @@ setup_gucs()
131140
var->integer.variable = &collector_hdr->profilePeriod;
132141
collector_hdr->profilePeriod = 10;
133142
}
143+
else if (!strcmp(name, "pg_wait_sampling.profile_pid"))
144+
{
145+
profile_pid_found = true;
146+
var->_bool.variable = &collector_hdr->profilePid;
147+
collector_hdr->profilePid = true;
148+
}
134149
}
135150

136151
if (!history_size_found)
@@ -151,7 +166,14 @@ setup_gucs()
151166
&collector_hdr->profilePeriod, 10, 1, INT_MAX,
152167
PGC_SUSET, 0, shmem_int_guc_check_hook, NULL, NULL);
153168

154-
if (history_size_found || history_period_found || profile_period_found)
169+
if (!profile_pid_found)
170+
DefineCustomBoolVariable("pg_wait_sampling.profile_pid",
171+
"Sets whether profile should be collected per pid.", NULL,
172+
&collector_hdr->profilePid, true,
173+
PGC_SUSET, 0, shmem_bool_guc_check_hook, NULL, NULL);
174+
175+
if (history_size_found || history_period_found
176+
|| profile_period_found || profile_pid_found)
155177
ProcessConfigFile(PGC_SIGHUP);
156178
}
157179

pg_wait_sampling.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct
6262
int historySize;
6363
int historyPeriod;
6464
int profilePeriod;
65+
bool profilePid;
6566
} CollectorShmqHeader;
6667

6768
/* pg_wait_sampling.c */

0 commit comments

Comments
 (0)