Skip to content

Commit 1f0c6a9

Browse files
committed
Add EXPLAIN support for JIT.
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
1 parent 9370462 commit 1f0c6a9

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/backend/commands/explain.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "commands/prepare.h"
2222
#include "executor/nodeHash.h"
2323
#include "foreign/fdwapi.h"
24+
#include "jit/jit.h"
2425
#include "nodes/extensible.h"
2526
#include "nodes/nodeFuncs.h"
2627
#include "optimizer/clauses.h"
@@ -556,6 +557,16 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
556557
if (es->analyze)
557558
ExplainPrintTriggers(es, queryDesc);
558559

560+
/*
561+
* Print info about JITing. Tied to es->costs because we don't want to
562+
* display this in regression tests, as it'd cause output differences
563+
* depending on build options. Might want to separate that out from COSTS
564+
* at a later stage.
565+
*/
566+
if (queryDesc->estate->es_jit && es->costs &&
567+
queryDesc->estate->es_jit->created_functions > 0)
568+
ExplainPrintJIT(es, queryDesc);
569+
559570
/*
560571
* Close down the query and free resources. Include time for this in the
561572
* total execution time (although it should be pretty minimal).
@@ -677,6 +688,54 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
677688
ExplainCloseGroup("Triggers", "Triggers", false, es);
678689
}
679690

691+
/*
692+
* ExplainPrintJIT -
693+
* Append information about JITing to es->str.
694+
*/
695+
void
696+
ExplainPrintJIT(ExplainState *es, QueryDesc *queryDesc)
697+
{
698+
JitContext *jc = queryDesc->estate->es_jit;
699+
700+
ExplainOpenGroup("JIT", "JIT", true, es);
701+
702+
if (es->format == EXPLAIN_FORMAT_TEXT)
703+
{
704+
es->indent += 1;
705+
appendStringInfo(es->str, "JIT:\n");
706+
}
707+
708+
ExplainPropertyInteger("Functions", NULL, jc->created_functions, es);
709+
if (es->analyze && es->timing)
710+
ExplainPropertyFloat("Generation Time", "ms",
711+
1000.0 * INSTR_TIME_GET_DOUBLE(jc->generation_counter),
712+
3, es);
713+
714+
ExplainPropertyBool("Inlining", jc->flags & PGJIT_INLINE, es);
715+
716+
if (es->analyze && es->timing)
717+
ExplainPropertyFloat("Inlining Time", "ms",
718+
1000.0 * INSTR_TIME_GET_DOUBLE(jc->inlining_counter),
719+
3, es);
720+
721+
ExplainPropertyBool("Optimization", jc->flags & PGJIT_OPT3, es);
722+
if (es->analyze && es->timing)
723+
ExplainPropertyFloat("Optimization Time", "ms",
724+
1000.0 * INSTR_TIME_GET_DOUBLE(jc->optimization_counter),
725+
3, es);
726+
727+
if (es->analyze && es->timing)
728+
ExplainPropertyFloat("Emission Time", "ms",
729+
1000.0 * INSTR_TIME_GET_DOUBLE(jc->emission_counter),
730+
3, es);
731+
732+
ExplainCloseGroup("JIT", "JIT", true, es);
733+
if (es->format == EXPLAIN_FORMAT_TEXT)
734+
{
735+
es->indent -= 1;
736+
}
737+
}
738+
680739
/*
681740
* ExplainQueryText -
682741
* add a "Query Text" node that contains the actual text of the query

src/include/commands/explain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
8181
extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
8282
extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
8383

84+
extern void ExplainPrintJIT(ExplainState *es, QueryDesc *queryDesc);
85+
8486
extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
8587

8688
extern void ExplainBeginOutput(ExplainState *es);

0 commit comments

Comments
 (0)