Skip to content

PGPRO-6601: Add prefix to global variables and functions. #58

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 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 20 additions & 20 deletions collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void handle_sigterm(SIGNAL_ARGS);
* Register background worker for collecting waits history.
*/
void
register_wait_collector(void)
pgws_register_wait_collector(void)
{
BackgroundWorker worker;

Expand All @@ -48,7 +48,7 @@ register_wait_collector(void)
worker.bgw_restart_time = 1;
worker.bgw_notify_pid = 0;
snprintf(worker.bgw_library_name, BGW_MAXLEN, "pg_wait_sampling");
snprintf(worker.bgw_function_name, BGW_MAXLEN, CppAsString(collector_main));
snprintf(worker.bgw_function_name, BGW_MAXLEN, CppAsString(pgws_collector_main));
snprintf(worker.bgw_name, BGW_MAXLEN, "pg_wait_sampling collector");
worker.bgw_main_arg = (Datum) 0;
RegisterBackgroundWorker(&worker);
Expand All @@ -57,7 +57,7 @@ register_wait_collector(void)
/*
* Allocate memory for waits history.
*/
void
static void
alloc_history(History *observations, int count)
{
observations->items = (HistoryItem *) palloc0(sizeof(HistoryItem) * count);
Expand Down Expand Up @@ -151,7 +151,7 @@ probe_waits(History *observations, HTAB *profile_hash,
TimestampTz ts = GetCurrentTimestamp();

/* Realloc waits history if needed */
newSize = collector_hdr->historySize;
newSize = pgws_collector_hdr->historySize;
if (observations->count != newSize)
realloc_history(observations, newSize);

Expand All @@ -173,8 +173,8 @@ probe_waits(History *observations, HTAB *profile_hash,
item.pid = proc->pid;
item.wait_event_info = proc->wait_event_info;

if (collector_hdr->profileQueries)
item.queryId = proc_queryids[i];
if (pgws_collector_hdr->profileQueries)
item.queryId = pgws_proc_queryids[i];
else
item.queryId = 0;

Expand Down Expand Up @@ -292,7 +292,7 @@ make_profile_hash()
hash_ctl.hash = tag_hash;
hash_ctl.hcxt = TopMemoryContext;

if (collector_hdr->profileQueries)
if (pgws_collector_hdr->profileQueries)
hash_ctl.keysize = offsetof(ProfileItem, count);
else
hash_ctl.keysize = offsetof(ProfileItem, queryId);
Expand Down Expand Up @@ -321,7 +321,7 @@ millisecs_diff(TimestampTz tz1, TimestampTz tz2)
* Main routine of wait history collector.
*/
void
collector_main(Datum main_arg)
pgws_collector_main(Datum main_arg)
{
HTAB *profile_hash = NULL;
History observations;
Expand Down Expand Up @@ -358,13 +358,13 @@ collector_main(Datum main_arg)
pgstat_report_appname("pg_wait_sampling collector");

profile_hash = make_profile_hash();
collector_hdr->latch = &MyProc->procLatch;
pgws_collector_hdr->latch = &MyProc->procLatch;

CurrentResourceOwner = ResourceOwnerCreate(NULL, "pg_wait_sampling collector");
collector_context = AllocSetContextCreate(TopMemoryContext,
"pg_wait_sampling context", ALLOCSET_DEFAULT_SIZES);
old_context = MemoryContextSwitchTo(collector_context);
alloc_history(&observations, collector_hdr->historySize);
alloc_history(&observations, pgws_collector_hdr->historySize);
MemoryContextSwitchTo(old_context);

ereport(LOG, (errmsg("pg_wait_sampling collector started")));
Expand All @@ -391,16 +391,16 @@ collector_main(Datum main_arg)

history_diff = millisecs_diff(history_ts, current_ts);
profile_diff = millisecs_diff(profile_ts, current_ts);
history_period = collector_hdr->historyPeriod;
profile_period = collector_hdr->profilePeriod;
history_period = pgws_collector_hdr->historyPeriod;
profile_period = pgws_collector_hdr->profilePeriod;

write_history = (history_diff >= (int64)history_period);
write_profile = (profile_diff >= (int64)profile_period);

if (write_history || write_profile)
{
probe_waits(&observations, profile_hash,
write_history, write_profile, collector_hdr->profilePid);
write_history, write_profile, pgws_collector_hdr->profilePid);

if (write_history)
{
Expand Down Expand Up @@ -439,24 +439,24 @@ collector_main(Datum main_arg)
ResetLatch(&MyProc->procLatch);

/* Handle request if any */
if (collector_hdr->request != NO_REQUEST)
if (pgws_collector_hdr->request != NO_REQUEST)
{
LOCKTAG tag;
SHMRequest request;

init_lock_tag(&tag, PGWS_COLLECTOR_LOCK);
pgws_init_lock_tag(&tag, PGWS_COLLECTOR_LOCK);

LockAcquire(&tag, ExclusiveLock, false, false);
request = collector_hdr->request;
collector_hdr->request = NO_REQUEST;
request = pgws_collector_hdr->request;
pgws_collector_hdr->request = NO_REQUEST;

if (request == HISTORY_REQUEST || request == PROFILE_REQUEST)
{
shm_mq_result mq_result;

/* Send history or profile */
shm_mq_set_sender(collector_mq, MyProc);
mqh = shm_mq_attach(collector_mq, NULL, NULL);
shm_mq_set_sender(pgws_collector_mq, MyProc);
mqh = shm_mq_attach(pgws_collector_mq, NULL, NULL);
mq_result = shm_mq_wait_for_attach(mqh);
switch (mq_result)
{
Expand All @@ -482,7 +482,7 @@ collector_main(Datum main_arg)
default:
AssertState(false);
}
shm_mq_detach_compat(mqh, collector_mq);
shm_mq_detach_compat(mqh, pgws_collector_mq);
}
else if (request == PROFILE_RESET)
{
Expand Down
Loading