@@ -120,9 +120,17 @@ static const struct config_enum_entry pgws_profile_queries_options[] =
120
120
{NULL , 0 , false}
121
121
};
122
122
123
+ /* GUC variables */
124
+ int pg_wait_sampling_historySize = 5000 ;
125
+ int pg_wait_sampling_historyPeriod = 10 ;
126
+ int pg_wait_sampling_profilePeriod = 10 ;
127
+ bool pg_wait_sampling_profilePid = true;
128
+ int pg_wait_sampling_profileQueries = PGWS_PROFILE_QUERIES_TOP ;
129
+ bool pg_wait_sampling_sampleCpu = true;
130
+
123
131
#define pgws_enabled (level ) \
124
- ((pgws_collector_hdr->profileQueries == PGWS_PROFILE_QUERIES_ALL) || \
125
- (pgws_collector_hdr->profileQueries == PGWS_PROFILE_QUERIES_TOP && (level) == 0))
132
+ ((pg_wait_sampling_profileQueries == PGWS_PROFILE_QUERIES_ALL) || \
133
+ (pg_wait_sampling_profileQueries == PGWS_PROFILE_QUERIES_TOP && (level) == 0))
126
134
127
135
/*
128
136
* Calculate max processes count.
@@ -206,30 +214,6 @@ pgws_shmem_size(void)
206
214
return size ;
207
215
}
208
216
209
- static bool
210
- shmem_int_guc_check_hook (int * newval , void * * extra , GucSource source )
211
- {
212
- if (UsedShmemSegAddr == NULL )
213
- return false;
214
- return true;
215
- }
216
-
217
- static bool
218
- shmem_enum_guc_check_hook (int * newval , void * * extra , GucSource source )
219
- {
220
- if (UsedShmemSegAddr == NULL )
221
- return false;
222
- return true;
223
- }
224
-
225
- static bool
226
- shmem_bool_guc_check_hook (bool * newval , void * * extra , GucSource source )
227
- {
228
- if (UsedShmemSegAddr == NULL )
229
- return false;
230
- return true;
231
- }
232
-
233
217
/*
234
218
* This union allows us to mix the numerous different types of structs
235
219
* that we are organizing.
@@ -244,117 +228,6 @@ typedef union
244
228
struct config_enum _enum ;
245
229
} mixedStruct ;
246
230
247
- /*
248
- * Setup new GUCs or modify existsing.
249
- */
250
- static void
251
- setup_gucs ()
252
- {
253
- struct config_generic * * guc_vars ;
254
- int numOpts ,
255
- i ;
256
- bool history_size_found = false,
257
- history_period_found = false,
258
- profile_period_found = false,
259
- profile_pid_found = false,
260
- profile_queries_found = false,
261
- sample_cpu_found = false;
262
-
263
- get_guc_variables_compat (& guc_vars , & numOpts );
264
-
265
- for (i = 0 ; i < numOpts ; i ++ )
266
- {
267
- mixedStruct * var = (mixedStruct * ) guc_vars [i ];
268
- const char * name = var -> generic .name ;
269
-
270
- if (var -> generic .flags & GUC_CUSTOM_PLACEHOLDER )
271
- continue ;
272
-
273
- if (!strcmp (name , "pg_wait_sampling.history_size" ))
274
- {
275
- history_size_found = true;
276
- var -> integer .variable = & pgws_collector_hdr -> historySize ;
277
- pgws_collector_hdr -> historySize = 5000 ;
278
- }
279
- else if (!strcmp (name , "pg_wait_sampling.history_period" ))
280
- {
281
- history_period_found = true;
282
- var -> integer .variable = & pgws_collector_hdr -> historyPeriod ;
283
- pgws_collector_hdr -> historyPeriod = 10 ;
284
- }
285
- else if (!strcmp (name , "pg_wait_sampling.profile_period" ))
286
- {
287
- profile_period_found = true;
288
- var -> integer .variable = & pgws_collector_hdr -> profilePeriod ;
289
- pgws_collector_hdr -> profilePeriod = 10 ;
290
- }
291
- else if (!strcmp (name , "pg_wait_sampling.profile_pid" ))
292
- {
293
- profile_pid_found = true;
294
- var -> _bool .variable = & pgws_collector_hdr -> profilePid ;
295
- pgws_collector_hdr -> profilePid = true;
296
- }
297
- else if (!strcmp (name , "pg_wait_sampling.profile_queries" ))
298
- {
299
- profile_queries_found = true;
300
- var -> _enum .variable = & pgws_collector_hdr -> profileQueries ;
301
- pgws_collector_hdr -> profileQueries = PGWS_PROFILE_QUERIES_TOP ;
302
- }
303
- else if (!strcmp (name , "pg_wait_sampling.sample_cpu" ))
304
- {
305
- sample_cpu_found = true;
306
- var -> _bool .variable = & pgws_collector_hdr -> sampleCpu ;
307
- pgws_collector_hdr -> sampleCpu = true;
308
- }
309
- }
310
-
311
- if (!history_size_found )
312
- DefineCustomIntVariable ("pg_wait_sampling.history_size" ,
313
- "Sets size of waits history." , NULL ,
314
- & pgws_collector_hdr -> historySize , 5000 , 100 , INT_MAX ,
315
- PGC_SUSET , 0 , shmem_int_guc_check_hook , NULL , NULL );
316
-
317
- if (!history_period_found )
318
- DefineCustomIntVariable ("pg_wait_sampling.history_period" ,
319
- "Sets period of waits history sampling." , NULL ,
320
- & pgws_collector_hdr -> historyPeriod , 10 , 1 , INT_MAX ,
321
- PGC_SUSET , 0 , shmem_int_guc_check_hook , NULL , NULL );
322
-
323
- if (!profile_period_found )
324
- DefineCustomIntVariable ("pg_wait_sampling.profile_period" ,
325
- "Sets period of waits profile sampling." , NULL ,
326
- & pgws_collector_hdr -> profilePeriod , 10 , 1 , INT_MAX ,
327
- PGC_SUSET , 0 , shmem_int_guc_check_hook , NULL , NULL );
328
-
329
- if (!profile_pid_found )
330
- DefineCustomBoolVariable ("pg_wait_sampling.profile_pid" ,
331
- "Sets whether profile should be collected per pid." , NULL ,
332
- & pgws_collector_hdr -> profilePid , true,
333
- PGC_SUSET , 0 , shmem_bool_guc_check_hook , NULL , NULL );
334
-
335
- if (!profile_queries_found )
336
- DefineCustomEnumVariable ("pg_wait_sampling.profile_queries" ,
337
- "Sets whether profile should be collected per query." , NULL ,
338
- & pgws_collector_hdr -> profileQueries , PGWS_PROFILE_QUERIES_TOP , pgws_profile_queries_options ,
339
- PGC_SUSET , 0 , shmem_enum_guc_check_hook , NULL , NULL );
340
-
341
- if (!sample_cpu_found )
342
- DefineCustomBoolVariable ("pg_wait_sampling.sample_cpu" ,
343
- "Sets whether not waiting backends should be sampled." , NULL ,
344
- & pgws_collector_hdr -> sampleCpu , true,
345
- PGC_SUSET , 0 , shmem_bool_guc_check_hook , NULL , NULL );
346
-
347
- if (history_size_found
348
- || history_period_found
349
- || profile_period_found
350
- || profile_pid_found
351
- || profile_queries_found
352
- || sample_cpu_found )
353
- {
354
- ProcessConfigFile (PGC_SIGHUP );
355
- }
356
- }
357
-
358
231
#if PG_VERSION_NUM >= 150000
359
232
/*
360
233
* shmem_request hook: request additional shared memory resources.
@@ -391,17 +264,12 @@ pgws_shmem_startup(void)
391
264
392
265
pgws_collector_hdr = shm_toc_allocate (toc , sizeof (CollectorShmqHeader ));
393
266
shm_toc_insert (toc , 0 , pgws_collector_hdr );
394
- /* needed to please check_GUC_init */
395
- pgws_collector_hdr -> profileQueries = PGWS_PROFILE_QUERIES_TOP ;
396
267
pgws_collector_mq = shm_toc_allocate (toc , COLLECTOR_QUEUE_SIZE );
397
268
shm_toc_insert (toc , 1 , pgws_collector_mq );
398
269
pgws_proc_queryids = shm_toc_allocate (toc ,
399
270
sizeof (uint64 ) * get_max_procs_count ());
400
271
shm_toc_insert (toc , 2 , pgws_proc_queryids );
401
272
MemSet (pgws_proc_queryids , 0 , sizeof (uint64 ) * get_max_procs_count ());
402
-
403
- /* Initialize GUC variables in shared memory */
404
- setup_gucs ();
405
273
}
406
274
else
407
275
{
@@ -482,6 +350,32 @@ _PG_init(void)
482
350
ExecutorEnd_hook = pgws_ExecutorEnd ;
483
351
prev_ProcessUtility = ProcessUtility_hook ;
484
352
ProcessUtility_hook = pgws_ProcessUtility ;
353
+
354
+ /* Define GUC variables */
355
+ DefineCustomIntVariable ("pg_wait_sampling.history_size" ,
356
+ "Sets size of waits history." , NULL ,
357
+ & pg_wait_sampling_historySize , 5000 , 100 , INT_MAX ,
358
+ PGC_SIGHUP , 0 , NULL , NULL , NULL );
359
+ DefineCustomIntVariable ("pg_wait_sampling.history_period" ,
360
+ "Sets period of waits history sampling." , NULL ,
361
+ & pg_wait_sampling_historyPeriod , 10 , 1 , INT_MAX ,
362
+ PGC_SIGHUP , 0 , NULL , NULL , NULL );
363
+ DefineCustomIntVariable ("pg_wait_sampling.profile_period" ,
364
+ "Sets period of waits profile sampling." , NULL ,
365
+ & pg_wait_sampling_profilePeriod , 10 , 1 , INT_MAX ,
366
+ PGC_SIGHUP , 0 , NULL , NULL , NULL );
367
+ DefineCustomBoolVariable ("pg_wait_sampling.profile_pid" ,
368
+ "Sets whether profile should be collected per pid." , NULL ,
369
+ & pg_wait_sampling_profilePid , true,
370
+ PGC_SIGHUP , 0 , NULL , NULL , NULL );
371
+ DefineCustomEnumVariable ("pg_wait_sampling.profile_queries" ,
372
+ "Sets whether profile should be collected per query." , NULL ,
373
+ & pg_wait_sampling_profileQueries , PGWS_PROFILE_QUERIES_TOP , pgws_profile_queries_options ,
374
+ PGC_SIGHUP , 0 , NULL , NULL , NULL );
375
+ DefineCustomBoolVariable ("pg_wait_sampling.sample_cpu" ,
376
+ "Sets whether not waiting backends should be sampled." , NULL ,
377
+ & pg_wait_sampling_sampleCpu , true,
378
+ PGC_SIGHUP , 0 , NULL , NULL , NULL );
485
379
}
486
380
487
381
/*
@@ -517,7 +411,7 @@ search_proc(int pid)
517
411
bool
518
412
pgws_should_sample_proc (PGPROC * proc )
519
413
{
520
- if (proc -> wait_event_info == 0 && !pgws_collector_hdr -> sampleCpu )
414
+ if (proc -> wait_event_info == 0 && !pg_wait_sampling_sampleCpu )
521
415
return false;
522
416
523
417
/*
@@ -829,7 +723,7 @@ pg_wait_sampling_get_profile(PG_FUNCTION_ARGS)
829
723
else
830
724
nulls [2 ] = true;
831
725
832
- if (pgws_collector_hdr -> profileQueries )
726
+ if (pg_wait_sampling_profileQueries )
833
727
values [3 ] = UInt64GetDatum (item -> queryId );
834
728
else
835
729
values [3 ] = (Datum ) 0 ;
0 commit comments