]> granicus.if.org Git - postgresql/commitdiff
Add EXPLAIN support for JIT.
authorAndres Freund <andres@anarazel.de>
Wed, 28 Mar 2018 20:26:51 +0000 (13:26 -0700)
committerAndres Freund <andres@anarazel.de>
Wed, 28 Mar 2018 20:26:51 +0000 (13:26 -0700)
This just shows a few details about JITing, e.g. how many functions
have been JITed, and how long that took.  To avoid noise in regression
tests with functions sometimes being JITed in --with-llvm builds,
disable display when COSTS OFF is specified.

Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de

src/backend/commands/explain.c
src/include/commands/explain.h

index c38d178cd9f16e8a39469a5f6c8a1a57ac7b7423..8a58672a94e3477034f97b38916b6f19362d9786 100644 (file)
@@ -21,6 +21,7 @@
 #include "commands/prepare.h"
 #include "executor/nodeHash.h"
 #include "foreign/fdwapi.h"
+#include "jit/jit.h"
 #include "nodes/extensible.h"
 #include "nodes/nodeFuncs.h"
 #include "optimizer/clauses.h"
@@ -556,6 +557,16 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
        if (es->analyze)
                ExplainPrintTriggers(es, queryDesc);
 
+       /*
+        * Print info about JITing. Tied to es->costs because we don't want to
+        * display this in regression tests, as it'd cause output differences
+        * depending on build options.  Might want to separate that out from COSTS
+        * at a later stage.
+        */
+       if (queryDesc->estate->es_jit && es->costs &&
+               queryDesc->estate->es_jit->created_functions > 0)
+               ExplainPrintJIT(es, queryDesc);
+
        /*
         * Close down the query and free resources.  Include time for this in the
         * total execution time (although it should be pretty minimal).
@@ -677,6 +688,54 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
        ExplainCloseGroup("Triggers", "Triggers", false, es);
 }
 
+/*
+ * ExplainPrintJIT -
+ *       Append information about JITing to es->str.
+ */
+void
+ExplainPrintJIT(ExplainState *es, QueryDesc *queryDesc)
+{
+       JitContext *jc = queryDesc->estate->es_jit;
+
+       ExplainOpenGroup("JIT", "JIT", true, es);
+
+       if (es->format == EXPLAIN_FORMAT_TEXT)
+       {
+               es->indent += 1;
+               appendStringInfo(es->str, "JIT:\n");
+       }
+
+       ExplainPropertyInteger("Functions", NULL, jc->created_functions, es);
+       if (es->analyze && es->timing)
+               ExplainPropertyFloat("Generation Time", "ms",
+                                                        1000.0 * INSTR_TIME_GET_DOUBLE(jc->generation_counter),
+                                                        3, es);
+
+       ExplainPropertyBool("Inlining", jc->flags & PGJIT_INLINE, es);
+
+       if (es->analyze && es->timing)
+               ExplainPropertyFloat("Inlining Time", "ms",
+                                                        1000.0 * INSTR_TIME_GET_DOUBLE(jc->inlining_counter),
+                                                        3, es);
+
+       ExplainPropertyBool("Optimization", jc->flags & PGJIT_OPT3, es);
+       if (es->analyze && es->timing)
+               ExplainPropertyFloat("Optimization Time", "ms",
+                                                        1000.0 * INSTR_TIME_GET_DOUBLE(jc->optimization_counter),
+                                                        3, es);
+
+       if (es->analyze && es->timing)
+               ExplainPropertyFloat("Emission Time", "ms",
+                                                        1000.0 * INSTR_TIME_GET_DOUBLE(jc->emission_counter),
+                                                        3, es);
+
+       ExplainCloseGroup("JIT", "JIT", true, es);
+       if (es->format == EXPLAIN_FORMAT_TEXT)
+       {
+               es->indent -= 1;
+       }
+}
+
 /*
  * ExplainQueryText -
  *       add a "Query Text" node that contains the actual text of the query
index 6d3d94cae260a7305e13cba8e1d8099f0e8d4b4f..9b75baae6e68cde6471070064b36f89532e94e15 100644 (file)
@@ -81,6 +81,8 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
 extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
 
+extern void ExplainPrintJIT(ExplainState *es, QueryDesc *queryDesc);
+
 extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
 
 extern void ExplainBeginOutput(ExplainState *es);