*** pgsql/contrib/auto_explain/auto_explain.c 2009/01/01 17:23:31 1.2 --- pgsql/contrib/auto_explain/auto_explain.c 2009/01/02 01:16:02 1.3 *************** *** 6,12 **** * Copyright (c) 2008-2009, PostgreSQL Global Development Group * * IDENTIFICATION ! * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.1 2008/11/19 02:59:28 tgl Exp $ * *------------------------------------------------------------------------- */ --- 6,12 ---- * Copyright (c) 2008-2009, PostgreSQL Global Development Group * * IDENTIFICATION ! * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.2 2009/01/01 17:23:31 momjian Exp $ * *------------------------------------------------------------------------- */ *************** *** 18,30 **** PG_MODULE_MAGIC; - #define GUCNAME(name) ("explain." name) - /* GUC variables */ ! static int explain_log_min_duration = -1; /* msec or -1 */ ! static bool explain_log_analyze = false; ! static bool explain_log_verbose = false; ! static bool explain_log_nested = false; /* Current nesting depth of ExecutorRun calls */ static int nesting_level = 0; --- 18,28 ---- PG_MODULE_MAGIC; /* GUC variables */ ! static int auto_explain_log_min_duration = -1; /* msec or -1 */ ! static bool auto_explain_log_analyze = false; ! static bool auto_explain_log_verbose = false; ! static bool auto_explain_log_nested_statements = false; /* Current nesting depth of ExecutorRun calls */ static int nesting_level = 0; *************** static ExecutorRun_hook_type prev_Execut *** 35,42 **** static ExecutorEnd_hook_type prev_ExecutorEnd = NULL; #define auto_explain_enabled() \ ! (explain_log_min_duration >= 0 && \ ! (nesting_level == 0 || explain_log_nested)) void _PG_init(void); void _PG_fini(void); --- 33,40 ---- static ExecutorEnd_hook_type prev_ExecutorEnd = NULL; #define auto_explain_enabled() \ ! (auto_explain_log_min_duration >= 0 && \ ! (nesting_level == 0 || auto_explain_log_nested_statements)) void _PG_init(void); void _PG_fini(void); *************** void *** 55,64 **** _PG_init(void) { /* Define custom GUC variables. */ ! DefineCustomIntVariable(GUCNAME("log_min_duration"), "Sets the minimum execution time above which plans will be logged.", "Zero prints all plans. -1 turns this feature off.", ! &explain_log_min_duration, -1, -1, INT_MAX / 1000, PGC_SUSET, --- 53,62 ---- _PG_init(void) { /* Define custom GUC variables. */ ! DefineCustomIntVariable("auto_explain.log_min_duration", "Sets the minimum execution time above which plans will be logged.", "Zero prints all plans. -1 turns this feature off.", ! &auto_explain_log_min_duration, -1, -1, INT_MAX / 1000, PGC_SUSET, *************** _PG_init(void) *** 66,95 **** NULL, NULL); ! DefineCustomBoolVariable(GUCNAME("log_analyze"), "Use EXPLAIN ANALYZE for plan logging.", NULL, ! &explain_log_analyze, false, PGC_SUSET, 0, NULL, NULL); ! DefineCustomBoolVariable(GUCNAME("log_verbose"), "Use EXPLAIN VERBOSE for plan logging.", NULL, ! &explain_log_verbose, false, PGC_SUSET, 0, NULL, NULL); ! DefineCustomBoolVariable(GUCNAME("log_nested_statements"), "Log nested statements.", NULL, ! &explain_log_nested, false, PGC_SUSET, 0, --- 64,93 ---- NULL, NULL); ! DefineCustomBoolVariable("auto_explain.log_analyze", "Use EXPLAIN ANALYZE for plan logging.", NULL, ! &auto_explain_log_analyze, false, PGC_SUSET, 0, NULL, NULL); ! DefineCustomBoolVariable("auto_explain.log_verbose", "Use EXPLAIN VERBOSE for plan logging.", NULL, ! &auto_explain_log_verbose, false, PGC_SUSET, 0, NULL, NULL); ! DefineCustomBoolVariable("auto_explain.log_nested_statements", "Log nested statements.", NULL, ! &auto_explain_log_nested_statements, false, PGC_SUSET, 0, *************** explain_ExecutorStart(QueryDesc *queryDe *** 126,132 **** if (auto_explain_enabled()) { /* Enable per-node instrumentation iff log_analyze is required. */ ! if (explain_log_analyze && (eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0) queryDesc->doInstrument = true; } --- 124,130 ---- if (auto_explain_enabled()) { /* Enable per-node instrumentation iff log_analyze is required. */ ! if (auto_explain_log_analyze && (eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0) queryDesc->doInstrument = true; } *************** explain_ExecutorEnd(QueryDesc *queryDesc *** 194,207 **** /* Log plan if duration is exceeded. */ msec = queryDesc->totaltime->total * 1000.0; ! if (msec >= explain_log_min_duration) { StringInfoData buf; initStringInfo(&buf); ExplainPrintPlan(&buf, queryDesc, ! queryDesc->doInstrument && explain_log_analyze, ! explain_log_verbose); /* Remove last line break */ if (buf.len > 0 && buf.data[buf.len - 1] == '\n') --- 192,205 ---- /* Log plan if duration is exceeded. */ msec = queryDesc->totaltime->total * 1000.0; ! if (msec >= auto_explain_log_min_duration) { StringInfoData buf; initStringInfo(&buf); ExplainPrintPlan(&buf, queryDesc, ! queryDesc->doInstrument && auto_explain_log_analyze, ! auto_explain_log_verbose); /* Remove last line break */ if (buf.len > 0 && buf.data[buf.len - 1] == '\n')