Ejemplo n.º 1
0
void
_PG_init(void)
{
	if (!process_shared_preload_libraries_in_progress)
		return;

	RequestAddinShmemSpace(getMemstatSize());
	RequestNamedLWLockTranche("memstat", PROCARRAY_MAXPROCS);

	prev_ExecutorStart = ExecutorStart_hook;
	ExecutorStart_hook = collectLocalMemoryStats;

	prev_shmem_startup_hook = shmem_startup_hook;
	shmem_startup_hook = allocShmem;

	DefineCustomIntVariable("memstat.period",
							"Sets period to collect memory statistics",
							"zero means collecting after each query",
							&ticPeriod,
							10,
							0, 60*60*24*31,
							PGC_SUSET, GUC_UNIT_S,
							NULL, NULL, NULL);
}
Ejemplo n.º 2
0
/*
 * Module load callback
 */
void
_PG_init(void)
{

	/*
	 * In order to create our shared memory area, we have to be loaded via
	 * shared_preload_libraries.  If not, fall out without hooking into any of
	 * the main system.  (We don't throw error here because it seems useful to
	 * allow the query_histogram functions to be created even when the
	 * module isn't active.  The functions must protect themselves against
	 * being called then, however.)
	 */
	if (!process_shared_preload_libraries_in_progress)
		return;

	/* Define custom GUC variables. */
	DefineCustomBoolVariable("query_histogram.dynamic",
							  "Dynamic histogram may be modified on the fly.",
							 NULL,
							 &default_histogram_dynamic,
							 false,
							 PGC_BACKEND,
							 0,
							 NULL,
							 NULL,
							 NULL);

	/* Define custom GUC variables. */
	DefineCustomBoolVariable("query_histogram.track_utility",
							  "Selects whether utility commands are tracked.",
							 NULL,
							 &default_histogram_utility,
							 true,
							 PGC_SUSET,
							 0,
							 NULL,
							 &set_histogram_track_utility,
							 &show_histogram_track_utility);

	DefineCustomIntVariable("query_histogram.bin_count",
						 "Sets the number of bins of the histogram.",
						 "Zero disables collecting the histogram.",
							&default_histogram_bins,
							100,
							0, 1000,
							PGC_SUSET,
							0,
							NULL,
							&set_histogram_bins_count_hook,
							&show_histogram_bins_count_hook);

	DefineCustomIntVariable("query_histogram.bin_width",
						 "Sets the width of the histogram bin.",
							NULL,
							&default_histogram_step,
							100,
							1, 1000,
							PGC_SUSET,
							GUC_UNIT_MS,
							NULL,
							&set_histogram_bins_width_hook,
							&show_histogram_bins_width_hook);

	DefineCustomIntVariable("query_histogram.sample_pct",
						 "What portion of the queries should be sampled (in percent).",
							NULL,
							&default_histogram_sample_pct,
							5,
							1, 100,
							PGC_SUSET,
							0,
							NULL,
							&set_histogram_sample_hook,
							&show_histogram_sample_hook);

	DefineCustomEnumVariable("query_histogram.histogram_type",
							 "Type of the histogram (how the bin width is computed).",
							 NULL,
							 &default_histogram_type,
							 HISTOGRAM_LINEAR,
							 histogram_type_options,
							 PGC_SUSET,
							 0,
							 NULL,
							 &set_histogram_type_hook,
							 &show_histogram_type_hook);

	EmitWarningsOnPlaceholders("query_histogram");

	/*
	 * Request additional shared resources.  (These are no-ops if we're not in
	 * the postmaster process.)  We'll allocate or attach to the shared
	 * resources in histogram_shmem_startup().
	 */
	RequestAddinShmemSpace(get_histogram_size());
	RequestNamedLWLockTranche("query_histogram", 1);

	/* Install hooks. */
	prev_shmem_startup_hook = shmem_startup_hook;
	shmem_startup_hook = histogram_shmem_startup;

	prev_ExecutorStart = ExecutorStart_hook;
	ExecutorStart_hook = histogram_ExecutorStart;
	prev_ExecutorRun = ExecutorRun_hook;
	ExecutorRun_hook = histogram_ExecutorRun;
	prev_ExecutorFinish = ExecutorFinish_hook;
	ExecutorFinish_hook = histogram_ExecutorFinish;
	prev_ExecutorEnd = ExecutorEnd_hook;
	ExecutorEnd_hook = histogram_ExecutorEnd;
	prev_ProcessUtility = ProcessUtility_hook;
	ProcessUtility_hook = queryhist_ProcessUtility;
}