@@ -563,9 +563,9 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
563
563
* depending on build options. Might want to separate that out from COSTS
564
564
* at a later stage.
565
565
*/
566
- if (queryDesc -> estate -> es_jit && es -> costs &&
567
- queryDesc -> estate -> es_jit -> created_functions > 0 )
568
- ExplainPrintJIT ( es , queryDesc );
566
+ if (es -> costs )
567
+ ExplainPrintJIT ( es , queryDesc -> estate -> es_jit_flags ,
568
+ queryDesc -> estate -> es_jit_combined_instr , -1 );
569
569
570
570
/*
571
571
* Close down the query and free resources. Include time for this in the
@@ -691,78 +691,90 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
691
691
/*
692
692
* ExplainPrintJIT -
693
693
* Append information about JITing to es->str.
694
+ *
695
+ * Can be used to print the JIT instrumentation of the backend (worker_num =
696
+ * -1) or that of a specific worker (worker_num = ...).
694
697
*/
695
698
void
696
- ExplainPrintJIT (ExplainState * es , QueryDesc * queryDesc )
699
+ ExplainPrintJIT (ExplainState * es , int jit_flags ,
700
+ JitInstrumentation * ji , int worker_num )
697
701
{
698
- JitContext * jc = queryDesc -> estate -> es_jit ;
699
702
instr_time total_time ;
703
+ bool for_workers = (worker_num >= 0 );
704
+
705
+ /* don't print information if no JITing happened */
706
+ if (!ji || ji -> created_functions == 0 )
707
+ return ;
700
708
701
709
/* calculate total time */
702
710
INSTR_TIME_SET_ZERO (total_time );
703
- INSTR_TIME_ADD (total_time , jc -> generation_counter );
704
- INSTR_TIME_ADD (total_time , jc -> inlining_counter );
705
- INSTR_TIME_ADD (total_time , jc -> optimization_counter );
706
- INSTR_TIME_ADD (total_time , jc -> emission_counter );
711
+ INSTR_TIME_ADD (total_time , ji -> generation_counter );
712
+ INSTR_TIME_ADD (total_time , ji -> inlining_counter );
713
+ INSTR_TIME_ADD (total_time , ji -> optimization_counter );
714
+ INSTR_TIME_ADD (total_time , ji -> emission_counter );
707
715
708
716
ExplainOpenGroup ("JIT" , "JIT" , true, es );
709
717
710
718
/* for higher density, open code the text output format */
711
719
if (es -> format == EXPLAIN_FORMAT_TEXT )
712
720
{
713
721
appendStringInfoSpaces (es -> str , es -> indent * 2 );
714
- appendStringInfo (es -> str , "JIT:\n" );
722
+ if (for_workers )
723
+ appendStringInfo (es -> str , "JIT for worker %u:\n" , worker_num );
724
+ else
725
+ appendStringInfo (es -> str , "JIT:\n" );
715
726
es -> indent += 1 ;
716
727
717
- ExplainPropertyInteger ("Functions" , NULL , jc -> created_functions , es );
728
+ ExplainPropertyInteger ("Functions" , NULL , ji -> created_functions , es );
718
729
719
730
appendStringInfoSpaces (es -> str , es -> indent * 2 );
720
731
appendStringInfo (es -> str , "Options: %s %s, %s %s, %s %s, %s %s\n" ,
721
- "Inlining" , jc -> flags & PGJIT_INLINE ? "true" : "false" ,
722
- "Optimization" , jc -> flags & PGJIT_OPT3 ? "true" : "false" ,
723
- "Expressions" , jc -> flags & PGJIT_EXPR ? "true" : "false" ,
724
- "Deforming" , jc -> flags & PGJIT_DEFORM ? "true" : "false" );
732
+ "Inlining" , jit_flags & PGJIT_INLINE ? "true" : "false" ,
733
+ "Optimization" , jit_flags & PGJIT_OPT3 ? "true" : "false" ,
734
+ "Expressions" , jit_flags & PGJIT_EXPR ? "true" : "false" ,
735
+ "Deforming" , jit_flags & PGJIT_DEFORM ? "true" : "false" );
725
736
726
737
if (es -> analyze && es -> timing )
727
738
{
728
739
appendStringInfoSpaces (es -> str , es -> indent * 2 );
729
740
appendStringInfo (es -> str ,
730
741
"Timing: %s %.3f ms, %s %.3f ms, %s %.3f ms, %s %.3f ms, %s %.3f ms\n" ,
731
- "Generation" , 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> generation_counter ),
732
- "Inlining" , 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> inlining_counter ),
733
- "Optimization" , 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> optimization_counter ),
734
- "Emission" , 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> emission_counter ),
742
+ "Generation" , 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> generation_counter ),
743
+ "Inlining" , 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> inlining_counter ),
744
+ "Optimization" , 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> optimization_counter ),
745
+ "Emission" , 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> emission_counter ),
735
746
"Total" , 1000.0 * INSTR_TIME_GET_DOUBLE (total_time ));
736
747
}
737
748
738
749
es -> indent -= 1 ;
739
750
}
740
751
else
741
752
{
742
- ExplainPropertyInteger ("Functions" , NULL , jc -> created_functions , es );
753
+ ExplainPropertyInteger ("Worker Number" , NULL , worker_num , es );
754
+ ExplainPropertyInteger ("Functions" , NULL , ji -> created_functions , es );
743
755
744
756
ExplainOpenGroup ("Options" , "Options" , true, es );
745
- ExplainPropertyBool ("Inlining" , jc -> flags & PGJIT_INLINE , es );
746
- ExplainPropertyBool ("Optimization" , jc -> flags & PGJIT_OPT3 , es );
747
- ExplainPropertyBool ("Expressions" , jc -> flags & PGJIT_EXPR , es );
748
- ExplainPropertyBool ("Deforming" , jc -> flags & PGJIT_DEFORM , es );
757
+ ExplainPropertyBool ("Inlining" , jit_flags & PGJIT_INLINE , es );
758
+ ExplainPropertyBool ("Optimization" , jit_flags & PGJIT_OPT3 , es );
759
+ ExplainPropertyBool ("Expressions" , jit_flags & PGJIT_EXPR , es );
760
+ ExplainPropertyBool ("Deforming" , jit_flags & PGJIT_DEFORM , es );
749
761
ExplainCloseGroup ("Options" , "Options" , true, es );
750
762
751
763
if (es -> analyze && es -> timing )
752
764
{
753
765
ExplainOpenGroup ("Timing" , "Timing" , true, es );
754
766
755
767
ExplainPropertyFloat ("Generation" , "ms" ,
756
- 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> generation_counter ),
768
+ 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> generation_counter ),
757
769
3 , es );
758
770
ExplainPropertyFloat ("Inlining" , "ms" ,
759
- 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> inlining_counter ),
771
+ 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> inlining_counter ),
760
772
3 , es );
761
773
ExplainPropertyFloat ("Optimization" , "ms" ,
762
- 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> optimization_counter ),
774
+ 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> optimization_counter ),
763
775
3 , es );
764
776
ExplainPropertyFloat ("Emission" , "ms" ,
765
- 1000.0 * INSTR_TIME_GET_DOUBLE (jc -> emission_counter ),
777
+ 1000.0 * INSTR_TIME_GET_DOUBLE (ji -> emission_counter ),
766
778
3 , es );
767
779
ExplainPropertyFloat ("Total" , "ms" ,
768
780
1000.0 * INSTR_TIME_GET_DOUBLE (total_time ),
@@ -1554,6 +1566,25 @@ ExplainNode(PlanState *planstate, List *ancestors,
1554
1566
ExplainPropertyInteger ("Workers Launched" , NULL ,
1555
1567
nworkers , es );
1556
1568
}
1569
+
1570
+ /*
1571
+ * Print per-worker Jit instrumentation. Use same conditions
1572
+ * as for the leader's JIT instrumentation, see comment there.
1573
+ */
1574
+ if (es -> costs && es -> verbose &&
1575
+ outerPlanState (planstate )-> worker_jit_instrument )
1576
+ {
1577
+ PlanState * child = outerPlanState (planstate );
1578
+ int n ;
1579
+ SharedJitInstrumentation * w = child -> worker_jit_instrument ;
1580
+
1581
+ for (n = 0 ; n < w -> num_workers ; ++ n )
1582
+ {
1583
+ ExplainPrintJIT (es , child -> state -> es_jit_flags ,
1584
+ & w -> jit_instr [n ], n );
1585
+ }
1586
+ }
1587
+
1557
1588
if (gather -> single_copy || es -> format != EXPLAIN_FORMAT_TEXT )
1558
1589
ExplainPropertyBool ("Single Copy" , gather -> single_copy , es );
1559
1590
}
0 commit comments