|
Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
|
Samples the stack of the thread it is started on, from a thread of its own, while that thread is stalled. More...
#include <stacksampler_p.h>
Classes | |
| struct | Settings |
| How samples are taken. More... | |
| struct | Stall |
| The samples of the stall that just ended, taken by the watched thread when it reports the stall. More... | |
| struct | Samples |
| One stall's samples, by the tick it began after. More... | |
Public Member Functions | |
| StackSampler (Settings settings) | |
Samples with settings by default (the threshold is the stall source's). | |
| ~StackSampler () | |
| Stops sampling. | |
| StackSampler (const StackSampler &)=delete | |
| StackSampler & | operator= (const StackSampler &)=delete |
| QString | start () |
| Starts sampling the calling thread. Returns why it can't, or an empty string. | |
| void | stop () |
| Stops sampling; returns once the sampler thread has ended. | |
| bool | isRunning () const |
| Whether it is sampling. | |
| void | tick () |
| The watched thread's tick: it is responsive now. | |
| Stall | takeEndedStall () |
| The samples taken since the tick before the last one, which is when the stall began; ends an arming that has samples. | |
| Stall | currentStall () const |
| The samples of the stall in progress, if the watched thread is stalled now. | |
| void | arm (Settings settings, std::chrono::milliseconds duration) |
Samples the next stall, or the stalls of the next duration, with settings instead of the defaults. | |
| std::chrono::milliseconds | effectiveThreshold () const |
| The threshold in effect: lower while armed with a lower one. | |
Static Public Attributes | |
| static constexpr std::chrono::milliseconds | kTick { 100 } |
| The interval of the watched thread's ticks. | |
Private Member Functions | |
| void | run () |
| The sampler thread. | |
| Settings | settingsAt (qint64 nowMs) |
The settings in effect at nowMs (an arming that ran out is dropped). | |
Static Private Member Functions | |
| static qint64 | nowMs () |
| Milliseconds on a steady clock. | |
Private Attributes | |
| const Settings | m_defaults |
| Without arming. | |
| std::atomic< bool > | m_running { false } |
| Between start() and stop(). | |
| std::atomic< qint64 > | m_lastTickMs { 0 } |
| When the watched thread last ticked. | |
| qint64 | m_previousTickMs = 0 |
| The tick before the last (watched thread only). | |
| std::mutex | m_mutex |
| Guards everything below. | |
| std::condition_variable | m_wake |
| Wakes the sampler thread: stop, or armed. | |
| bool | m_stopping = false |
| stop() was called. | |
| bool | m_armed = false |
| arm() is in effect. | |
| Settings | m_armedSettings |
| The settings while armed. | |
| qint64 | m_armedUntilMs = 0 |
| When an arming without a stall runs out. | |
| std::map< qint64, Samples > | m_stalls |
| At most the current stall and one ended. | |
| std::thread | m_thread |
| The sampler thread. | |
Samples the stack of the thread it is started on, from a thread of its own, while that thread is stalled.
Thread-safe: the watched thread ticks it and takes the samples of a stall that ended; any thread may read the stall in progress or arm it.
The watched thread calls tick() at every turn of its event loop's timer (every kTick). When no tick has come for kTick plus the threshold, the thread is stalled: the sampler takes a sample, then one every interval, up to the cap.
| void Sonde::Detail::StackSampler::arm | ( | Settings | settings, |
| std::chrono::milliseconds | duration ) |
Samples the next stall, or the stalls of the next duration, with settings instead of the defaults.
Replaces an earlier arming.