Skip to content

Code cleanup #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add some comments
Author: Oleg Tselebrovskiy
  • Loading branch information
Sergey Shinderuk committed Feb 20, 2025
commit 09463b6c041b0af7fec9cd01821e81567eb54d95
5 changes: 4 additions & 1 deletion collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ get_next_observation(History *observations)
{
HistoryItem *result;

/* Check for wraparound */
if (observations->index >= observations->count)
{
observations->index = 0;
Expand Down Expand Up @@ -217,6 +218,7 @@ send_history(History *observations, shm_mq_handle *mqh)
else
count = observations->index;

/* Send array size first since receive_array expects this */
mq_result = shm_mq_send_compat(mqh, sizeof(count), &count, false, true);
if (mq_result == SHM_MQ_DETACHED)
{
Expand Down Expand Up @@ -253,6 +255,7 @@ send_profile(HTAB *profile_hash, shm_mq_handle *mqh)
Size count = hash_get_num_entries(profile_hash);
shm_mq_result mq_result;

/* Send array size first since receive_array expects this */
mq_result = shm_mq_send_compat(mqh, sizeof(count), &count, false, true);
if (mq_result == SHM_MQ_DETACHED)
{
Expand Down Expand Up @@ -380,7 +383,7 @@ pgws_collector_main(Datum main_arg)
ProcessConfigFile(PGC_SIGHUP);
}

/* Wait calculate time to next sample for history or profile */
/* Calculate time to next sample for history or profile */
current_ts = GetCurrentTimestamp();

history_diff = millisecs_diff(history_ts, current_ts);
Expand Down
10 changes: 8 additions & 2 deletions pg_wait_sampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void _PG_init(void);

static bool shmem_initialized = false;

/* Hooks */
/* Hooks variables */
static ExecutorStart_hook_type prev_ExecutorStart = NULL;
static ExecutorRun_hook_type prev_ExecutorRun = NULL;
static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
Expand All @@ -65,6 +65,7 @@ static shm_mq *recv_mq = NULL;
static shm_mq_handle *recv_mqh = NULL;
static LOCKTAG queueTag;

/* Hook functions */
#if PG_VERSION_NUM >= 150000
static shmem_request_hook_type prev_shmem_request_hook = NULL;
#endif
Expand Down Expand Up @@ -126,7 +127,6 @@ static const struct config_enum_entry pgws_profile_queries_options[] =
{NULL, 0, false}
};

/* GUC variables */
int pgws_historySize = 5000;
int pgws_historyPeriod = 10;
int pgws_profilePeriod = 10;
Expand Down Expand Up @@ -253,6 +253,7 @@ pgws_shmem_startup(void)

if (!found)
{
/* Create shared objects */
toc = shm_toc_create(PG_WAIT_SAMPLING_MAGIC, pgws, segsize);

pgws_collector_hdr = shm_toc_allocate(toc, sizeof(CollectorShmqHeader));
Expand All @@ -266,6 +267,7 @@ pgws_shmem_startup(void)
}
else
{
/* Attach to existing shared objects */
toc = shm_toc_attach(PG_WAIT_SAMPLING_MAGIC, pgws);
pgws_collector_hdr = shm_toc_lookup(toc, 0, false);
pgws_collector_mq = shm_toc_lookup(toc, 1, false);
Expand Down Expand Up @@ -522,6 +524,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)

if (!PG_ARGISNULL(0))
{
/* pg_wait_sampling_get_current(pid int4) function */
HistoryItem *item;
PGPROC *proc;

Expand All @@ -535,6 +538,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
}
else
{
/* pg_wait_sampling_current view */
int procCount = ProcGlobal->allProcCount,
i,
j = 0;
Expand Down Expand Up @@ -600,6 +604,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
}
else
{
/* nothing left */
SRF_RETURN_DONE(funcctx);
}
}
Expand All @@ -621,6 +626,7 @@ pgws_init_lock_tag(LOCKTAG *tag, uint32 lock)
tag->locktag_lockmethodid = USER_LOCKMETHOD;
}

/* Get array (history or profile data) from shared memory */
static void *
receive_array(SHMRequest request, Size item_size, Size *count)
{
Expand Down