|
52 | 52 | #include "common/hashfn.h"
|
53 | 53 | #include "executor/instrument.h"
|
54 | 54 | #include "funcapi.h"
|
| 55 | +#include "jit/jit.h" |
55 | 56 | #include "mb/pg_wchar.h"
|
56 | 57 | #include "miscadmin.h"
|
57 | 58 | #include "optimizer/planner.h"
|
@@ -188,6 +189,17 @@ typedef struct Counters
|
188 | 189 | int64 wal_records; /* # of WAL records generated */
|
189 | 190 | int64 wal_fpi; /* # of WAL full page images generated */
|
190 | 191 | uint64 wal_bytes; /* total amount of WAL generated in bytes */
|
| 192 | + int64 jit_functions; /* total number of JIT functions emitted */ |
| 193 | + double jit_generation_time; /* total time to generate jit code */ |
| 194 | + int64 jit_inlining_count; /* number of times inlining time has been |
| 195 | + * > 0 */ |
| 196 | + double jit_inlining_time; /* total time to inline jit code */ |
| 197 | + int64 jit_optimization_count; /* number of times optimization time |
| 198 | + * has been > 0 */ |
| 199 | + double jit_optimization_time; /* total time to optimize jit code */ |
| 200 | + int64 jit_emission_count; /* number of times emission time has been |
| 201 | + * > 0 */ |
| 202 | + double jit_emission_time; /* total time to emit jit code */ |
191 | 203 | } Counters;
|
192 | 204 |
|
193 | 205 | /*
|
@@ -330,6 +342,7 @@ static void pgss_store(const char *query, uint64 queryId,
|
330 | 342 | double total_time, uint64 rows,
|
331 | 343 | const BufferUsage *bufusage,
|
332 | 344 | const WalUsage *walusage,
|
| 345 | + const struct JitInstrumentation *jitusage, |
333 | 346 | JumbleState *jstate);
|
334 | 347 | static void pg_stat_statements_internal(FunctionCallInfo fcinfo,
|
335 | 348 | pgssVersion api_version,
|
@@ -854,6 +867,7 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
|
854 | 867 | 0,
|
855 | 868 | NULL,
|
856 | 869 | NULL,
|
| 870 | + NULL, |
857 | 871 | jstate);
|
858 | 872 | }
|
859 | 873 |
|
@@ -938,6 +952,7 @@ pgss_planner(Query *parse,
|
938 | 952 | 0,
|
939 | 953 | &bufusage,
|
940 | 954 | &walusage,
|
| 955 | + NULL, |
941 | 956 | NULL);
|
942 | 957 | }
|
943 | 958 | else
|
@@ -1056,6 +1071,7 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
|
1056 | 1071 | queryDesc->estate->es_processed,
|
1057 | 1072 | &queryDesc->totaltime->bufusage,
|
1058 | 1073 | &queryDesc->totaltime->walusage,
|
| 1074 | + queryDesc->estate->es_jit ? &queryDesc->estate->es_jit->instr : NULL, |
1059 | 1075 | NULL);
|
1060 | 1076 | }
|
1061 | 1077 |
|
@@ -1173,6 +1189,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
|
1173 | 1189 | rows,
|
1174 | 1190 | &bufusage,
|
1175 | 1191 | &walusage,
|
| 1192 | + NULL, |
1176 | 1193 | NULL);
|
1177 | 1194 | }
|
1178 | 1195 | else
|
@@ -1206,6 +1223,7 @@ pgss_store(const char *query, uint64 queryId,
|
1206 | 1223 | double total_time, uint64 rows,
|
1207 | 1224 | const BufferUsage *bufusage,
|
1208 | 1225 | const WalUsage *walusage,
|
| 1226 | + const struct JitInstrumentation *jitusage, |
1209 | 1227 | JumbleState *jstate)
|
1210 | 1228 | {
|
1211 | 1229 | pgssHashKey key;
|
@@ -1375,6 +1393,23 @@ pgss_store(const char *query, uint64 queryId,
|
1375 | 1393 | e->counters.wal_records += walusage->wal_records;
|
1376 | 1394 | e->counters.wal_fpi += walusage->wal_fpi;
|
1377 | 1395 | e->counters.wal_bytes += walusage->wal_bytes;
|
| 1396 | + if (jitusage) |
| 1397 | + { |
| 1398 | + e->counters.jit_functions += jitusage->created_functions; |
| 1399 | + e->counters.jit_generation_time += INSTR_TIME_GET_MILLISEC(jitusage->generation_counter); |
| 1400 | + |
| 1401 | + if (INSTR_TIME_GET_MILLISEC(jitusage->inlining_counter)) |
| 1402 | + e->counters.jit_inlining_count++; |
| 1403 | + e->counters.jit_inlining_time += INSTR_TIME_GET_MILLISEC(jitusage->inlining_counter); |
| 1404 | + |
| 1405 | + if (INSTR_TIME_GET_MILLISEC(jitusage->optimization_counter)) |
| 1406 | + e->counters.jit_optimization_count++; |
| 1407 | + e->counters.jit_optimization_time += INSTR_TIME_GET_MILLISEC(jitusage->optimization_counter); |
| 1408 | + |
| 1409 | + if (INSTR_TIME_GET_MILLISEC(jitusage->emission_counter)) |
| 1410 | + e->counters.jit_emission_count++; |
| 1411 | + e->counters.jit_emission_time += INSTR_TIME_GET_MILLISEC(jitusage->emission_counter); |
| 1412 | + } |
1378 | 1413 |
|
1379 | 1414 | SpinLockRelease(&e->mutex);
|
1380 | 1415 | }
|
@@ -1424,8 +1459,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
|
1424 | 1459 | #define PG_STAT_STATEMENTS_COLS_V1_3 23
|
1425 | 1460 | #define PG_STAT_STATEMENTS_COLS_V1_8 32
|
1426 | 1461 | #define PG_STAT_STATEMENTS_COLS_V1_9 33
|
1427 |
| -#define PG_STAT_STATEMENTS_COLS_V1_10 35 |
1428 |
| -#define PG_STAT_STATEMENTS_COLS 35 /* maximum of above */ |
| 1462 | +#define PG_STAT_STATEMENTS_COLS_V1_10 43 |
| 1463 | +#define PG_STAT_STATEMENTS_COLS 43 /* maximum of above */ |
1429 | 1464 |
|
1430 | 1465 | /*
|
1431 | 1466 | * Retrieve statement statistics.
|
@@ -1786,6 +1821,17 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
|
1786 | 1821 | Int32GetDatum(-1));
|
1787 | 1822 | values[i++] = wal_bytes;
|
1788 | 1823 | }
|
| 1824 | + if (api_version >= PGSS_V1_10) |
| 1825 | + { |
| 1826 | + values[i++] = Int64GetDatumFast(tmp.jit_functions); |
| 1827 | + values[i++] = Float8GetDatumFast(tmp.jit_generation_time); |
| 1828 | + values[i++] = Int64GetDatumFast(tmp.jit_inlining_count); |
| 1829 | + values[i++] = Float8GetDatumFast(tmp.jit_inlining_time); |
| 1830 | + values[i++] = Int64GetDatumFast(tmp.jit_optimization_count); |
| 1831 | + values[i++] = Float8GetDatumFast(tmp.jit_optimization_time); |
| 1832 | + values[i++] = Int64GetDatumFast(tmp.jit_emission_count); |
| 1833 | + values[i++] = Float8GetDatumFast(tmp.jit_emission_time); |
| 1834 | + } |
1789 | 1835 |
|
1790 | 1836 | Assert(i == (api_version == PGSS_V1_0 ? PG_STAT_STATEMENTS_COLS_V1_0 :
|
1791 | 1837 | api_version == PGSS_V1_1 ? PG_STAT_STATEMENTS_COLS_V1_1 :
|
|
0 commit comments