Skip to content

Commit ba7eb76

Browse files
erthalionhackorum
authored andcommitted
Add jit provider's version into the pgsql_version
If jit provider is available and initialized, add its version string into the pgsql_version output. This should help to get more relevant information in bug reports about JIT.
1 parent 72a6dad commit ba7eb76

5 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/backend/jit/jit.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,16 @@ InstrJitAgg(JitInstrumentation *dst, JitInstrumentation *add)
189189
INSTR_TIME_ADD(dst->optimization_counter, add->optimization_counter);
190190
INSTR_TIME_ADD(dst->emission_counter, add->emission_counter);
191191
}
192+
193+
/*
194+
* Return JIT provider's version string for troubleshooting purposes.
195+
*/
196+
const char *
197+
jit_get_version(bool *available)
198+
{
199+
if (provider_init())
200+
return provider.get_version(available);
201+
202+
*available = false;
203+
return "";
204+
}

src/backend/jit/llvm/llvmjit.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ _PG_jit_provider_init(JitProviderCallbacks *cb)
154154
cb->reset_after_error = llvm_reset_after_error;
155155
cb->release_context = llvm_release_context;
156156
cb->compile_expr = llvm_compile_expr;
157+
cb->get_version = llvm_version;
157158
}
158159

159160

@@ -1287,3 +1288,19 @@ ResOwnerReleaseJitContext(Datum res)
12871288
context->resowner = NULL;
12881289
jit_release_context(&context->base);
12891290
}
1291+
1292+
const char *
1293+
llvm_version(bool *available)
1294+
{
1295+
#if LLVM_VERSION_MAJOR > 15
1296+
unsigned int major, minor, patch;
1297+
1298+
LLVMGetVersion(&major, &minor, &patch);
1299+
1300+
*available = true;
1301+
return (const char*) psprintf("llvm: %d.%d.%d", major, minor, patch);
1302+
#else
1303+
*available = false;
1304+
return "";
1305+
#endif
1306+
}

src/backend/utils/adt/version.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,23 @@
1515
#include "postgres.h"
1616

1717
#include "utils/builtins.h"
18+
#include "jit/jit.h"
1819

1920

2021
Datum
2122
pgsql_version(PG_FUNCTION_ARGS)
2223
{
23-
PG_RETURN_TEXT_P(cstring_to_text(PG_VERSION_STR));
24+
bool jit_available = false;
25+
const char *jit_version = jit_get_version(&jit_available);
26+
27+
/* Add jit provides's version string if available. */
28+
if (jit_available)
29+
{
30+
PG_RETURN_TEXT_P(cstring_to_text(psprintf("%s, %s", PG_VERSION_STR,
31+
jit_version)));
32+
}
33+
else
34+
{
35+
PG_RETURN_TEXT_P(cstring_to_text(PG_VERSION_STR));
36+
}
2437
}

src/include/jit/jit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ typedef void (*JitProviderResetAfterErrorCB) (void);
7070
typedef void (*JitProviderReleaseContextCB) (JitContext *context);
7171
struct ExprState;
7272
typedef bool (*JitProviderCompileExprCB) (struct ExprState *state);
73+
typedef const char* (*JitProviderVersion) (bool *available);
7374

7475
struct JitProviderCallbacks
7576
{
7677
JitProviderResetAfterErrorCB reset_after_error;
7778
JitProviderReleaseContextCB release_context;
7879
JitProviderCompileExprCB compile_expr;
80+
JitProviderVersion get_version;
7981
};
8082

8183

@@ -102,5 +104,11 @@ extern void jit_release_context(JitContext *context);
102104
extern bool jit_compile_expr(struct ExprState *state);
103105
extern void InstrJitAgg(JitInstrumentation *dst, JitInstrumentation *add);
104106

107+
/*
108+
* Get the provider's version string. The flag indicating availability is
109+
* passed as an argument, and will be set accordingly if it's not possible to
110+
* get the version.
111+
*/
112+
extern const char *jit_get_version(bool *available);
105113

106114
#endif /* JIT_H */

src/include/jit/llvmjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r);
145145
extern LLVMOrcObjectLayerRef LLVMOrcCreateRTDyldObjectLinkingLayerWithSafeSectionMemoryManager(LLVMOrcExecutionSessionRef ES);
146146
#endif
147147

148+
extern const char* llvm_version(bool *available);
149+
148150
#ifdef __cplusplus
149151
} /* extern "C" */
150152
#endif

0 commit comments

Comments
 (0)