7#include <QtCore/QJsonArray>
8#include <QtCore/QJsonObject>
9#include <QtCore/QString>
13#include <condition_variable>
18namespace Sonde::Detail {
39 static constexpr std::chrono::milliseconds
kTick{ 100 };
75 void arm(Settings settings, std::chrono::milliseconds duration);
85 static qint64
nowMs();
Samples the stack of the thread it is started on, from a thread of its own, while that thread is stal...
Definition stacksampler_p.h:28
const Settings m_defaults
Without arming.
Definition stacksampler_p.h:87
static constexpr std::chrono::milliseconds kTick
The interval of the watched thread's ticks.
Definition stacksampler_p.h:39
static qint64 nowMs()
Milliseconds on a steady clock.
Definition stacksampler.cpp:52
qint64 m_armedUntilMs
When an arming without a stall runs out.
Definition stacksampler_p.h:97
qint64 m_previousTickMs
The tick before the last (watched thread only).
Definition stacksampler_p.h:90
QString start()
Starts sampling the calling thread. Returns why it can't, or an empty string.
Definition stacksampler.cpp:59
std::thread m_thread
The sampler thread.
Definition stacksampler_p.h:107
void run()
The sampler thread.
Definition stacksampler.cpp:154
std::atomic< bool > m_running
Between start() and stop().
Definition stacksampler_p.h:88
StackSampler(Settings settings)
Samples with settings by default (the threshold is the stall source's).
Definition stacksampler.cpp:45
std::mutex m_mutex
Guards everything below.
Definition stacksampler_p.h:92
bool m_armed
arm() is in effect.
Definition stacksampler_p.h:95
std::map< qint64, Samples > m_stalls
At most the current stall and one ended.
Definition stacksampler_p.h:106
Settings m_armedSettings
The settings while armed.
Definition stacksampler_p.h:96
std::chrono::milliseconds effectiveThreshold() const
The threshold in effect: lower while armed with a lower one.
Definition stacksampler.cpp:103
Settings settingsAt(qint64 nowMs)
The settings in effect at nowMs (an arming that ran out is dropped).
Definition stacksampler.cpp:96
bool m_stopping
stop() was called.
Definition stacksampler_p.h:94
Stall takeEndedStall()
The samples taken since the tick before the last one, which is when the stall began; ends an arming t...
Definition stacksampler.cpp:122
void stop()
Stops sampling; returns once the sampler thread has ended.
Definition stacksampler.cpp:77
std::condition_variable m_wake
Wakes the sampler thread: stop, or armed.
Definition stacksampler_p.h:93
void tick()
The watched thread's tick: it is responsive now.
Definition stacksampler.cpp:90
std::atomic< qint64 > m_lastTickMs
When the watched thread last ticked.
Definition stacksampler_p.h:89
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.
Definition stacksampler.cpp:111
bool isRunning() const
Whether it is sampling.
Definition stacksampler_p.h:53
Stall currentStall() const
The samples of the stall in progress, if the watched thread is stalled now.
Definition stacksampler.cpp:141
One stall's samples, by the tick it began after.
Definition stacksampler_p.h:100
QJsonArray modules
As in Stall.
Definition stacksampler_p.h:102
int attempts
Samples tried, including any that failed.
Definition stacksampler_p.h:104
qint64 lastSampleMs
When the last was taken.
Definition stacksampler_p.h:103
QJsonArray samples
As in Stall.
Definition stacksampler_p.h:101
How samples are taken.
Definition stacksampler_p.h:32
std::chrono::milliseconds threshold
Stalled this long: take the first sample.
Definition stacksampler_p.h:33
int maxSamples
At most this many per stall.
Definition stacksampler_p.h:35
std::chrono::milliseconds interval
Then one every interval.
Definition stacksampler_p.h:34
The samples of the stall that just ended, taken by the watched thread when it reports the stall.
Definition stacksampler_p.h:61
QJsonArray samples
Each: "atMs" (into the stall) and "frames".
Definition stacksampler_p.h:62
bool isEmpty() const
Whether no sample was taken.
Definition stacksampler_p.h:65
QJsonArray modules
The modules the frames are in.
Definition stacksampler_p.h:63