Skip to content

Track on CPU events too #74

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 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ in-memory hash table.
The work of wait event statistics collector worker is controlled by following
GUCs.

| Parameter name | Data type | Description | Default value |
| ----------------------------------- | --------- | ------------------------------------------- | ------------: |
| pg_wait_sampling.history_size | int4 | Size of history in-memory ring buffer | 5000 |
| pg_wait_sampling.history_period | int4 | Period for history sampling in milliseconds | 10 |
| pg_wait_sampling.profile_period | int4 | Period for profile sampling in milliseconds | 10 |
| pg_wait_sampling.profile_pid | bool | Whether profile should be per pid | true |
| pg_wait_sampling.profile_queries | bool | Whether profile should be per query | true |
| Parameter name | Data type | Description | Default value |
|----------------------------------| --------- |---------------------------------------------|--------------:|
| pg_wait_sampling.history_size | int4 | Size of history in-memory ring buffer | 5000 |
| pg_wait_sampling.history_period | int4 | Period for history sampling in milliseconds | 10 |
| pg_wait_sampling.profile_period | int4 | Period for profile sampling in milliseconds | 10 |
| pg_wait_sampling.profile_pid | bool | Whether profile should be per pid | true |
| pg_wait_sampling.profile_queries | bool | Whether profile should be per query | true |
| pg_wait_sampling.sample_cpu | bool | Whether on CPU backends should be sampled | false |

If `pg_wait_sampling.profile_pid` is set to false, sampling profile wouldn't be
collected in per-process manner. In this case the value of pid could would
Expand All @@ -148,6 +149,10 @@ be always zero and corresponding row contain samples among all the processes.
While `pg_wait_sampling.profile_queries` is set to false `queryid` field in
views will be zero.

If `pg_wait_sampling.sample_cpu` is set to true hen processes that are not
waiting on anything are also sampled. The wait event columns for such processes
will be NULL.

These GUCs are allowed to be changed by superuser. Also, they are placed into
shared memory. Thus, they could be changed from any backend and affects worker
runtime.
Expand Down
4 changes: 2 additions & 2 deletions collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ probe_waits(History *observations, HTAB *profile_hash,
*observation;
PGPROC *proc = &ProcGlobal->allProcs[i];

if (proc->pid == 0)
if (proc->wait_event_info == 0 && !pgws_collector_hdr->sampleCpu)
continue;

if (proc->wait_event_info == 0)
if (proc->pid == 0 || proc->procLatch.owner_pid == 0 || proc->pid == MyProcPid)
continue;

/* Collect next wait event sample */
Expand Down
20 changes: 17 additions & 3 deletions pg_wait_sampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ setup_gucs()
history_period_found = false,
profile_period_found = false,
profile_pid_found = false,
profile_queries_found = false;
profile_queries_found = false,
sample_cpu_found = false;

get_guc_variables_compat(&guc_vars, &numOpts);

Expand Down Expand Up @@ -240,6 +241,12 @@ setup_gucs()
var->_bool.variable = &pgws_collector_hdr->profileQueries;
pgws_collector_hdr->profileQueries = true;
}
else if (!strcmp(name, "pg_wait_sampling.sample_cpu"))
{
sample_cpu_found = true;
var->_bool.variable = &pgws_collector_hdr->sampleCpu;
pgws_collector_hdr->sampleCpu = false;
}
}

if (!history_size_found)
Expand Down Expand Up @@ -272,11 +279,18 @@ setup_gucs()
&pgws_collector_hdr->profileQueries, true,
PGC_SUSET, 0, shmem_bool_guc_check_hook, NULL, NULL);

if (!sample_cpu_found)
DefineCustomBoolVariable("pg_wait_sampling.sample_cpu",
"Sets whether not waiting backends should be sampled.", NULL,
&pgws_collector_hdr->sampleCpu, false,
PGC_SUSET, 0, shmem_bool_guc_check_hook, NULL, NULL);

if (history_size_found
|| history_period_found
|| profile_period_found
|| profile_pid_found
|| profile_queries_found)
|| profile_queries_found
|| sample_cpu_found)
{
ProcessConfigFile(PGC_SIGHUP);
}
Expand Down Expand Up @@ -501,7 +515,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
{
PGPROC *proc = &ProcGlobal->allProcs[i];

if (proc != NULL && proc->pid != 0 && proc->wait_event_info)
if (proc != NULL && proc->pid != 0 && (proc->wait_event_info || pgws_collector_hdr->sampleCpu))
{
params->items[j].pid = proc->pid;
params->items[j].wait_event_info = proc->wait_event_info;
Expand Down
1 change: 1 addition & 0 deletions pg_wait_sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef struct
int profilePeriod;
bool profilePid;
bool profileQueries;
bool sampleCpu;
} CollectorShmqHeader;

/* pg_wait_sampling.c */
Expand Down