Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okbob/plpgsql_check
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed May 15, 2022
2 parents 48648b6 + 83cf31f commit efe7a5d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/plpgsql_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ void _PG_fini(void);

#endif

#if PG_VERSION_NUM >= 150000
shmem_request_hook_type prev_shmem_request_hook = NULL;
#endif
shmem_startup_hook_type prev_shmem_startup_hook = NULL;

bool plpgsql_check_regress_test_mode;
Expand Down Expand Up @@ -305,14 +308,25 @@ _PG_init(void)
PGC_POSTMASTER, 0,
NULL, NULL, NULL);

#if PG_VERSION_NUM < 150000
/*
* If you change code here, don't forget to also report the
* modifications in plpgsql_check_profiler_shmem_request() for pg15 and
* later.
*/
RequestAddinShmemSpace(plpgsql_check_shmem_size());

RequestNamedLWLockTranche("plpgsql_check profiler", 1);
RequestNamedLWLockTranche("plpgsql_check fstats", 1);
#endif

/*
* Install hooks.
*/
#if PG_VERSION_NUM >= 150000
prev_shmem_startup_hook = shmem_request_hook;
shmem_request_hook = plpgsql_check_profiler_shmem_request;
#endif
prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = plpgsql_check_profiler_shmem_startup;
}
Expand All @@ -334,6 +348,9 @@ _PG_init(void)
void
_PG_fini(void)
{
#if PG_VERSION_NUM >= 150000
shmem_request_hook = prev_shmem_request_hook;
#endif
shmem_startup_hook = prev_shmem_startup_hook;

/* Be more correct, and clean rendezvous variable */
Expand All @@ -343,4 +360,4 @@ _PG_fini(void)
fmgr_hook = plpgsql_check_next_fmgr_hook;
}

#endif
#endif
6 changes: 6 additions & 0 deletions src/plpgsql_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ extern int plpgsql_check_profiler_max_shared_chunks;
extern needs_fmgr_hook_type plpgsql_check_next_needs_fmgr_hook;
extern fmgr_hook_type plpgsql_check_next_fmgr_hook;

#if PG_VERSION_NUM >= 150000
extern void plpgsql_check_profiler_shmem_request(void);
#endif
extern void plpgsql_check_profiler_shmem_startup(void);

extern Size plpgsql_check_shmem_size(void);
Expand Down Expand Up @@ -386,6 +389,9 @@ extern bool plpgsql_check_runtime_pragma_vector_changed;
* functions from plpgsql_check.c
*/

#if PG_VERSION_NUM >= 150000
extern shmem_request_hook_type prev_shmem_request_hook;
#endif
extern shmem_startup_hook_type prev_shmem_startup_hook;

extern PLpgSQL_plugin **plpgsql_check_plugin_var_ptr;
Expand Down
20 changes: 20 additions & 0 deletions src/profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,26 @@ plpgsql_check_shmem_size(void)
return num_bytes;
}

/*
* Request additional shared memory resources.
*
* If you change code here, don't forget to also report the modifications in
* _PG_init() for pg14 and below.
*/
#if PG_VERSION_NUM >= 150000
void
plpgsql_check_profiler_shmem_request(void)
{
if (prev_shmem_request_hook)
prev_shmem_request_hook();

RequestAddinShmemSpace(plpgsql_check_shmem_size());

RequestNamedLWLockTranche("plpgsql_check profiler", 1);
RequestNamedLWLockTranche("plpgsql_check fstats", 1);
}
#endif

/*
* Initialize shared memory used like permanent profile storage.
* No other parts use shared memory, so this code is completly here.
Expand Down

0 comments on commit efe7a5d

Please sign in to comment.