Skip to content
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

Shut down profiler thread when no more threads are being sampled #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mbUSC
Copy link

@mbUSC mbUSC commented Apr 18, 2024

Solves #227

Copy link
Contributor

@camelid camelid left a comment

Choose a reason for hiding this comment

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

Hi @mbUSC, thanks for your PR! The overall approach looks good, but you need to use atomics to avoid data races.

@@ -223,6 +227,7 @@ class profiler {
spinlock _latency_points_lock; //< Spinlock that protects the latency points map

static_map<pid_t, thread_state> _thread_states; //< Map from thread IDs to thread-local state
uint64_t _num_threads_running; //< Number of threads that are currently being sampled
Copy link
Contributor

@camelid camelid Jun 26, 2024

Choose a reason for hiding this comment

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

This should be atomic since it's shared across threads. uint64_t is also inconsistent with the other integer sizes used here.

Suggested change
uint64_t _num_threads_running; //< Number of threads that are currently being sampled
std::atomic<size_t> _num_threads_running; //< Number of threads that are currently being sampled

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.

None yet

2 participants