Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::StallEventSource Class Reference

Reports when the event loop of its thread was blocked, as events from source "stalls". More...

#include <stalleventsource.h>

Inheritance diagram for Sonde::StallEventSource:
Sonde::EventSource

Public Member Functions

 StallEventSource (std::chrono::milliseconds threshold=std::chrono::milliseconds(250), QObject *parent=nullptr)
 Starts watching the current thread; stalls longer than threshold are reported.
 ~StallEventSource () override
 Stops watching.
std::chrono::milliseconds threshold () const
 The shortest stall reported.
void setBackgroundCheck (std::function< bool()> inBackground)
 Sets a check for "the application is in the background".
Public Member Functions inherited from Sonde::EventSource
 EventSource (QString name, QString description={ }, QObject *parent=nullptr)
 Creates a source called name (used in filters and resource URIs), described by description in the events tools' descriptions.
 ~EventSource () override
 Destroys the source; the server forgets it.
QString name () const
 The source's name.
QString description () const
 Human-readable description shown in tool descriptions.
void emitEvent (LogLevel level, const QString &message, const QString &category={ }, const QJsonObject &data={ })
 Emits an event.
void eventOccurred (const Sonde::Event &event)
 An event was emitted (sequence is still 0; the server assigns it).

Private Attributes

PrivatePtr< StallEventSourcePrivate > d
 Implementation.

Friends

class StallEventSourcePrivate

Detailed Description

Reports when the event loop of its thread was blocked, as events from source "stalls".

A timer ticks every 100 ms and measures how late each tick is. A tick more than the threshold late means the thread did something else for that long (a long computation, blocking I/O, a synchronous network call), or the process was paused (in a debugger, or by the system). The event is emitted once the thread is back, since nothing can be reported while it is blocked; while it is blocked, Sonde itself can't answer either. So this is the evidence afterwards that the UI froze, and for how long:

warning stalls: The main thread was blocked for about 1840 ms {"blockedMs": 1840}

While a server it was added to listens, a thread of Sonde's also takes samples of the blocked thread's call stack during the stall, and the event carries them, so it says where the thread was, not only that it was blocked (design 0016). Server::setStackSampling() and the SONDE_STACK_SAMPLES environment variable turn that off.

installStandardTools() adds one with the default threshold.

Member Function Documentation

◆ setBackgroundCheck()

void Sonde::StallEventSource::setBackgroundCheck ( std::function< bool()> inBackground)

Sets a check for "the application is in the background".

Stalls seen while it returns true are reported at info level, with a note: the system may delay a background application's timers on purpose (macOS App Nap, timer coalescing), which looks like a block but isn't one. installStandardTools() sets one from QGuiApplication::applicationState().


The documentation for this class was generated from the following files: