Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

ants
Copy link
Contributor

@ants ants commented Jun 12, 2024

To not count dead backends as still running on the CPU we need to detect that the backend is dead. Starting from PG17 proc->pid is reset in ProcKill, before this we can check if the process latch is disowned. Not nice to be poking around in latch internals like this, but all alternatives seem to involve scanning bestatus array and correlating pids.

Verified that the latch disown mechanism works on at least PostgreSQL 12-16.

Also makes sense to exclude ourselves as we will always be on CPU while looking at wait events.

Resolves #10

To not count dead backends as still running on the CPU we need to
detect that the backend is dead. Starting from PG17 proc->pid is reset
in ProcKill, before this we can check if the process latch is disowned.
Not nice to be poking around in latch internals like this, but all
alternatives seem to involve scanning bestatus array and correlating
pids.

Also makes sense to exclude ourselves as we will always be on CPU while
looking at wait events.
@ants
Copy link
Contributor Author

ants commented Jun 12, 2024

Should I add a GUC to turn this functionality on and off?

@shinderuk shinderuk self-requested a review June 13, 2024 07:32
@shinderuk
Copy link
Contributor

Thanks for working on this! I did some tests with pgbench and the results look good. Yes, I think we need a GUC to turn this on. Also the pg_wait_sampling_current view needs to be patched similarly.

Defaults to false meaning previous behavior is retained. Update
pg_wait_sampling_current view to respect this flag.
@ants
Copy link
Contributor Author

ants commented Jun 14, 2024

Added a sample_cpu GUC and updated the pg_wait_sampling_current view. GUC defaults to false for backwards compatibility. What is the preference on this? I think most people would want to see the events, so maybe it should default to true?

Copy link
Contributor

@shinderuk shinderuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Looks good, except for a couple minor things.

Why not turn sample_cpu = on by default? Mainly for backward compatibility. I'm afraid that blank event_type in the profile would puzzle unprepared users or break UI. Also, turning it on could overflow the history buffer with new rows requiring adjustment of history_size. Anyway, I'm not sure which default is more useful for a regular user. Does it make sense?

@shinderuk shinderuk merged commit 12c0f7d into postgrespro:master Jun 17, 2024
1 check passed
@egor-rogov
Copy link

Thank you guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No information about "no wait" state
3 participants