This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before this change, `ThreadTraceCollector` was exposed to the consumer of the hwtracer API. Calling `TraceCollector::thread_tracer()` would give back a fresh instance each time. This API would allow the user request multiple `ThreadTraceCollector`s on the same thread and start them all "collecting traces" concurrently. This leads to chaos as any given thread can only be traced at most once at a time. Until now we've swept this under the rug, warning the user not to do the naughty thing unless they want to invoke UB, but the API still allows it to happen. This change hides `ThreadTraceCollector`s from the public API entirely, leaving `TraceCollector`s to manage thread local instances of `ThreadTraceCollector`. The user now starts and stops trace collection of a thread with `TraceCollector::start_thread_collector()` and `TraceCollector::stop_thread_collector()`. `ThreadTraceCollector`s are still there behind the scenes, but the user no longer sees them and thus can't start two tracing the same thread any more. One subtle side-effect of this new API is that we can no longer automatically stop a running trace collector when the `ThreadTraceCollector` goes out of scope (via `Drop`). Since `ThreadTraceCollector`s are stored (and owned) by thread locals, they never really "fall out of scope", so the user must ensure they consistently stop trace collection before trying to re-trace the same thread. It may be tempting to stop the current thread's `ThreadTraceCollector` when a `TraceCollector` goes out of scope, but then we'd have to track which `TraceCollector` started the `ThreadTraceCollector` and only stop the collector if they match. This starts to sound pretty over the top, and I think the proposed API is already a lot better than what we had before. Further `TraceCollector::start_thread_collector()` will return a meaningful error message if the user has forgotten to stop a collector, so it shouldn't be hard to track down instances of this blunder. Fixes #101.
- Loading branch information
Showing
6 changed files
with
151 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.