performance/MailOpenPerformanceTracker.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "performance/MailOpenPerformanceTracker.h" | ||
| 2 | |||
| 3 | #include <QApplication> | ||
| 4 | #include <QEvent> | ||
| 5 | #include <QTimer> | ||
| 6 | #include <QWidget> | ||
| 7 | |||
| 8 | #include <algorithm> | ||
| 9 | |||
| 10 | namespace MailJD::Performance { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | constexpr auto BodyPaintedMetric = "mail_open.input_to_body_painted.v1"; | ||
| 15 | constexpr auto EventLoopStallMetric = "mail_open.event_loop_stall_max.v1"; | ||
| 16 | |||
| 17 | } // namespace | ||
| 18 | |||
| 19 | 13733 | MailOpenPerformanceTracker &MailOpenPerformanceTracker::instance() { | |
| 20 |
4/7✓ Branch 2 → 3 taken 21 times.
✓ Branch 2 → 8 taken 13712 times.
✓ Branch 4 → 5 taken 21 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 21 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
|
13733 | static MailOpenPerformanceTracker tracker; |
| 21 | 13733 | return tracker; | |
| 22 | } | ||
| 23 | |||
| 24 | 21 | MailOpenPerformanceTracker::MailOpenPerformanceTracker(QObject *parent) | |
| 25 |
3/6✓ Branch 8 → 9 taken 21 times.
✓ Branch 9 → 10 taken 21 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 21 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
|
21 | : QObject(parent), m_stallTimer(new QTimer(this)) { |
| 26 |
1/1✓ Branch 13 → 14 taken 21 times.
|
21 | m_stallTimer->setTimerType(Qt::PreciseTimer); |
| 27 |
1/1✓ Branch 14 → 15 taken 21 times.
|
21 | m_stallTimer->setInterval(HeartbeatIntervalMs); |
| 28 |
1/1✓ Branch 15 → 16 taken 21 times.
|
21 | connect(m_stallTimer, &QTimer::timeout, this, [this]() { |
| 29 | ✗ | const qint64 now = PerformanceTrace::monotonicNowNs(); | |
| 30 | ✗ | const qint64 expected = | |
| 31 | ✗ | m_previousHeartbeatNs + | |
| 32 | static_cast<qint64>(HeartbeatIntervalMs) * 1000000; | ||
| 33 | ✗ | m_maxStallNs = std::max<qint64>(m_maxStallNs, now - expected); | |
| 34 | ✗ | m_previousHeartbeatNs = now; | |
| 35 | ✗ | }); | |
| 36 | 21 | } | |
| 37 | |||
| 38 | 32 | void MailOpenPerformanceTracker::ensureEventFilterInstalled() { | |
| 39 |
5/6✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 31 times.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 11 taken 31 times.
|
32 | if (!m_eventFilterInstalled && qApp) { |
| 40 | 1 | qApp->installEventFilter(this); | |
| 41 | 1 | m_eventFilterInstalled = true; | |
| 42 | } | ||
| 43 | 32 | } | |
| 44 | |||
| 45 | 1239 | bool MailOpenPerformanceTracker::isActive() const { | |
| 46 |
4/4✓ Branch 2 → 3 taken 1239 times.
✓ Branch 3 → 4 taken 1239 times.
✓ Branch 4 → 5 taken 34 times.
✓ Branch 4 → 13 taken 1205 times.
|
1307 | return PerformanceTrace::instance().isEnabled() && |
| 47 |
4/7✓ Branch 5 → 6 taken 34 times.
✓ Branch 6 → 7 taken 34 times.
✓ Branch 10 → 11 taken 34 times.
✓ Branch 11 → 12 taken 34 times.
✗ Branch 11 → 13 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
|
1307 | PerformanceTrace::instance().selectedScenario().startsWith( |
| 48 |
6/10✓ Branch 14 → 15 taken 34 times.
✓ Branch 14 → 16 taken 1205 times.
✓ Branch 16 → 17 taken 34 times.
✓ Branch 16 → 18 taken 1205 times.
✓ Branch 18 → 19 taken 34 times.
✓ Branch 18 → 20 taken 1205 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
|
2512 | QStringLiteral("MAIL_OPEN.")); |
| 49 | } | ||
| 50 | |||
| 51 | 1731 | Operation MailOpenPerformanceTracker::operationFor(const MailId &mailId) const { | |
| 52 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1731 times.
|
1731 | return matches(mailId) ? m_operation : Operation{}; |
| 53 | } | ||
| 54 | |||
| 55 | 6 | void MailOpenPerformanceTracker::watchPlainViewport(QWidget *viewport) { | |
| 56 | 6 | m_plainViewport = viewport; | |
| 57 |
2/2✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 1 time.
|
6 | if (isActive()) |
| 58 | 5 | ensureEventFilterInstalled(); | |
| 59 | 6 | } | |
| 60 | |||
| 61 | 4 | void MailOpenPerformanceTracker::watchWebView(QWidget *webView) { | |
| 62 | 4 | m_webView = webView; | |
| 63 |
2/2✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 1 time.
|
4 | if (isActive()) |
| 64 | 3 | ensureEventFilterInstalled(); | |
| 65 | 4 | } | |
| 66 | |||
| 67 | 48 | void MailOpenPerformanceTracker::reset() { | |
| 68 | 48 | m_stallTimer->stop(); | |
| 69 | 48 | m_operation = {}; | |
| 70 | 48 | m_mailId = {}; | |
| 71 | 48 | m_renderEligible = false; | |
| 72 | 48 | m_renderInProgress = false; | |
| 73 | 48 | m_waitingForPlainPaint = false; | |
| 74 | 48 | m_waitingForHtmlPaint = false; | |
| 75 | 48 | m_quickRevision = 0; | |
| 76 | 48 | m_bodyBytes = 0; | |
| 77 | 48 | m_attachmentCount = 0; | |
| 78 | 48 | m_inlineImageCount = 0; | |
| 79 | 48 | m_maxStallNs = 0; | |
| 80 | 48 | } | |
| 81 | |||
| 82 | 13493 | bool MailOpenPerformanceTracker::matches(const MailId &mailId) const { | |
| 83 |
4/4✓ Branch 3 → 4 taken 83 times.
✓ Branch 3 → 7 taken 13410 times.
✓ Branch 5 → 6 taken 71 times.
✓ Branch 5 → 7 taken 12 times.
|
13493 | return m_operation.isValid() && mailId == m_mailId; |
| 84 | } | ||
| 85 | |||
| 86 | 32 | bool MailOpenPerformanceTracker::matchesUi(qint64 folderId, qint64 uid) const { | |
| 87 |
1/2✓ Branch 4 → 5 taken 27 times.
✗ Branch 4 → 8 not taken.
|
59 | return m_operation.isValid() && m_renderInProgress && |
| 88 |
5/6✓ Branch 3 → 4 taken 27 times.
✓ Branch 3 → 8 taken 5 times.
✓ Branch 5 → 6 taken 27 times.
✗ Branch 5 → 8 not taken.
✓ Branch 6 → 7 taken 22 times.
✓ Branch 6 → 8 taken 5 times.
|
59 | m_mailId.folderId == folderId && m_mailId.uid == uid; |
| 89 | } | ||
| 90 | |||
| 91 | 77 | void MailOpenPerformanceTracker::startPhase(const QString &phase) { | |
| 92 |
1/2✓ Branch 3 → 4 taken 77 times.
✗ Branch 3 → 5 not taken.
|
77 | if (m_operation.isValid()) |
| 93 | 77 | m_operation.startPhase(phase); | |
| 94 | 77 | } | |
| 95 | |||
| 96 | 77 | void MailOpenPerformanceTracker::endPhase(const QString &phase) { | |
| 97 |
1/2✓ Branch 3 → 4 taken 77 times.
✗ Branch 3 → 5 not taken.
|
77 | if (m_operation.isValid()) |
| 98 | 77 | m_operation.endPhase(phase); | |
| 99 | 77 | } | |
| 100 | |||
| 101 | 1226 | void MailOpenPerformanceTracker::beginSelection(const MailId &mailId) { | |
| 102 |
5/6✓ Branch 3 → 4 taken 24 times.
✓ Branch 3 → 6 taken 1202 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 24 times.
✓ Branch 8 → 9 taken 1202 times.
✓ Branch 8 → 10 taken 24 times.
|
1226 | if (!isActive() || !mailId.isValid()) |
| 103 | 1202 | return; | |
| 104 | 24 | ensureEventFilterInstalled(); | |
| 105 |
2/2✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 14 taken 22 times.
|
24 | if (m_operation.isValid()) |
| 106 | 2 | finish(Outcome::Cancelled); | |
| 107 | 24 | reset(); | |
| 108 |
2/2✓ Branch 15 → 16 taken 24 times.
✓ Branch 16 → 17 taken 24 times.
|
24 | m_scenario = PerformanceTrace::instance().selectedScenario(); |
| 109 | 24 | m_mailId = mailId; | |
| 110 |
1/1✓ Branch 20 → 21 taken 24 times.
|
48 | m_operation = PerformanceTrace::instance().startMetric( |
| 111 |
2/2✓ Branch 22 → 23 taken 24 times.
✓ Branch 23 → 24 taken 24 times.
|
48 | m_scenario, QString::fromLatin1(BodyPaintedMetric)); |
| 112 |
1/1✓ Branch 30 → 31 taken 24 times.
|
24 | startPhase(QStringLiteral("selection")); |
| 113 | 24 | m_previousHeartbeatNs = PerformanceTrace::monotonicNowNs(); | |
| 114 | 24 | m_stallTimer->start(); | |
| 115 | } | ||
| 116 | |||
| 117 | 761 | void MailOpenPerformanceTracker::selectionLookupFinished(const MailId &mailId, | |
| 118 | bool found) { | ||
| 119 |
2/2✓ Branch 3 → 4 taken 747 times.
✓ Branch 3 → 5 taken 14 times.
|
761 | if (!matches(mailId)) |
| 120 | 747 | return; | |
| 121 |
1/1✓ Branch 8 → 9 taken 14 times.
|
14 | endPhase(QStringLiteral("selection")); |
| 122 |
2/2✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 13 times.
|
14 | if (!found) |
| 123 | 1 | finish(Outcome::Failed); | |
| 124 | } | ||
| 125 | |||
| 126 | 1229 | void MailOpenPerformanceTracker::cacheReadStarted(const MailId &mailId) { | |
| 127 |
2/2✓ Branch 3 → 4 taken 11 times.
✓ Branch 3 → 11 taken 1218 times.
|
1229 | if (matches(mailId)) |
| 128 |
1/1✓ Branch 7 → 8 taken 11 times.
|
11 | startPhase(QStringLiteral("cache_read")); |
| 129 | 1229 | } | |
| 130 | |||
| 131 | 345 | void MailOpenPerformanceTracker::sqlQueued(const MailId &mailId) { | |
| 132 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 344 times.
|
345 | if (matches(mailId)) |
| 133 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | startPhase(QStringLiteral("sql_queue")); |
| 134 | 345 | } | |
| 135 | |||
| 136 | 1130 | void MailOpenPerformanceTracker::sqlDispatched(const MailId &mailId) { | |
| 137 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 1129 times.
|
1130 | if (matches(mailId)) |
| 138 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | endPhase(QStringLiteral("sql_queue")); |
| 139 | 1130 | } | |
| 140 | |||
| 141 | 807 | void MailOpenPerformanceTracker::snapshotHandoff(const MailId &mailId) { | |
| 142 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 806 times.
|
807 | if (matches(mailId)) |
| 143 |
1/1✓ Branch 7 → 8 taken 1 time.
|
2 | m_operation.mark(QStringLiteral("snapshot_handoff")); |
| 144 | 807 | } | |
| 145 | |||
| 146 | 21 | bool MailOpenPerformanceTracker::selectedCacheStateMatches( | |
| 147 | bool hit, bool prefetchHit) const { | ||
| 148 |
3/3✓ Branch 5 → 6 taken 21 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 14 taken 20 times.
|
42 | if (m_scenario.contains(QStringLiteral(".prefetch-hit."))) |
| 149 |
2/4✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 12 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 1 time.
|
1 | return hit && prefetchHit; |
| 150 |
3/3✓ Branch 17 → 18 taken 20 times.
✓ Branch 20 → 21 taken 18 times.
✓ Branch 20 → 26 taken 2 times.
|
40 | if (m_scenario.contains(QStringLiteral(".body-hit."))) |
| 151 |
3/4✓ Branch 21 → 22 taken 16 times.
✓ Branch 21 → 24 taken 2 times.
✓ Branch 22 → 23 taken 16 times.
✗ Branch 22 → 24 not taken.
|
18 | return hit && !prefetchHit; |
| 152 |
2/3✓ Branch 29 → 30 taken 2 times.
✓ Branch 32 → 33 taken 2 times.
✗ Branch 32 → 34 not taken.
|
4 | if (m_scenario.contains(QStringLiteral(".body-miss."))) |
| 153 | 2 | return !hit; | |
| 154 | ✗ | return true; | |
| 155 | } | ||
| 156 | |||
| 157 | 768 | void MailOpenPerformanceTracker::cacheReadFinished(const MailId &mailId, | |
| 158 | bool hit, | ||
| 159 | bool prefetchHit) { | ||
| 160 |
2/2✓ Branch 3 → 4 taken 747 times.
✓ Branch 3 → 5 taken 21 times.
|
768 | if (!matches(mailId)) |
| 161 | 747 | return; | |
| 162 |
1/1✓ Branch 8 → 9 taken 21 times.
|
21 | endPhase(QStringLiteral("cache_read")); |
| 163 |
2/2✓ Branch 12 → 13 taken 4 times.
✓ Branch 12 → 15 taken 17 times.
|
21 | if (!selectedCacheStateMatches(hit, prefetchHit)) { |
| 164 | 4 | finish(Outcome::Failed); | |
| 165 | 4 | return; | |
| 166 | } | ||
| 167 | 17 | m_renderEligible = hit; | |
| 168 | } | ||
| 169 | |||
| 170 | 5 | void MailOpenPerformanceTracker::dispatchQueued(const MailId &mailId) { | |
| 171 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 4 times.
|
5 | if (matches(mailId)) |
| 172 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | startPhase(QStringLiteral("dispatch_wait")); |
| 173 | 5 | } | |
| 174 | |||
| 175 | 3 | void MailOpenPerformanceTracker::transportStarted(const MailId &mailId) { | |
| 176 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 1 time.
|
3 | if (!matches(mailId)) |
| 177 | 2 | return; | |
| 178 |
1/1✓ Branch 8 → 9 taken 1 time.
|
1 | endPhase(QStringLiteral("dispatch_wait")); |
| 179 |
1/1✓ Branch 14 → 15 taken 1 time.
|
1 | startPhase(QStringLiteral("select")); |
| 180 | } | ||
| 181 | |||
| 182 | 4 | void MailOpenPerformanceTracker::transportSelectionFinished( | |
| 183 | const MailId &mailId, bool success) { | ||
| 184 |
2/2✓ Branch 3 → 4 taken 3 times.
✓ Branch 3 → 5 taken 1 time.
|
4 | if (!matches(mailId)) |
| 185 | 3 | return; | |
| 186 |
1/1✓ Branch 8 → 9 taken 1 time.
|
1 | endPhase(QStringLiteral("select")); |
| 187 |
1/2✗ Branch 11 → 12 not taken.
✓ Branch 11 → 14 taken 1 time.
|
1 | if (!success) { |
| 188 | ✗ | finish(Outcome::Failed); | |
| 189 | ✗ | return; | |
| 190 | } | ||
| 191 |
1/1✓ Branch 17 → 18 taken 1 time.
|
1 | startPhase(QStringLiteral("fetch_transfer")); |
| 192 | } | ||
| 193 | |||
| 194 | 30 | void MailOpenPerformanceTracker::transportFinished(const MailId &mailId, | |
| 195 | bool success, | ||
| 196 | qint64 byteCount) { | ||
| 197 |
2/2✓ Branch 3 → 4 taken 29 times.
✓ Branch 3 → 5 taken 1 time.
|
30 | if (!matches(mailId)) |
| 198 | 29 | return; | |
| 199 |
1/1✓ Branch 8 → 9 taken 1 time.
|
1 | endPhase(QStringLiteral("fetch_transfer")); |
| 200 | 1 | m_bodyBytes = std::max<qint64>(0, byteCount); | |
| 201 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1 time.
|
1 | if (!success) |
| 202 | ✗ | finish(Outcome::Failed); | |
| 203 | } | ||
| 204 | |||
| 205 | 19 | void MailOpenPerformanceTracker::mimeParseStarted(const MailId &mailId) { | |
| 206 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 18 times.
|
19 | if (matches(mailId)) |
| 207 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | startPhase(QStringLiteral("mime_parse")); |
| 208 | 19 | } | |
| 209 | |||
| 210 | 18 | void MailOpenPerformanceTracker::mimeParseFinished(const MailId &mailId) { | |
| 211 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 17 times.
|
18 | if (matches(mailId)) |
| 212 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | endPhase(QStringLiteral("mime_parse")); |
| 213 | 18 | } | |
| 214 | |||
| 215 | 15 | void MailOpenPerformanceTracker::storeIndexStarted(const MailId &mailId) { | |
| 216 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 11 taken 14 times.
|
15 | if (matches(mailId)) |
| 217 |
1/1✓ Branch 7 → 8 taken 1 time.
|
1 | startPhase(QStringLiteral("store_index")); |
| 218 | 15 | } | |
| 219 | |||
| 220 | 12 | void MailOpenPerformanceTracker::storeIndexFinished(const MailId &mailId, | |
| 221 | int attachmentCount, | ||
| 222 | int inlineImageCount) { | ||
| 223 |
2/2✓ Branch 3 → 4 taken 11 times.
✓ Branch 3 → 5 taken 1 time.
|
12 | if (!matches(mailId)) |
| 224 | 11 | return; | |
| 225 |
1/1✓ Branch 8 → 9 taken 1 time.
|
1 | endPhase(QStringLiteral("store_index")); |
| 226 | 1 | m_attachmentCount = std::max(0, attachmentCount); | |
| 227 | 1 | m_inlineImageCount = std::max(0, inlineImageCount); | |
| 228 | 1 | m_renderEligible = true; | |
| 229 | } | ||
| 230 | |||
| 231 | 18 | bool MailOpenPerformanceTracker::renderStarted(qint64 folderId, qint64 uid, | |
| 232 | bool html, qint64 bodyBytes, | ||
| 233 | int attachmentCount, | ||
| 234 | int inlineImageCount) { | ||
| 235 |
2/2✓ Branch 4 → 5 taken 16 times.
✓ Branch 4 → 7 taken 1 time.
|
35 | if (!m_operation.isValid() || !m_renderEligible || |
| 236 |
6/8✓ Branch 3 → 4 taken 17 times.
✓ Branch 3 → 7 taken 1 time.
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 16 times.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 11 taken 16 times.
|
35 | m_mailId.folderId != folderId || m_mailId.uid != uid) |
| 237 | 2 | return false; | |
| 238 |
4/9✓ Branch 14 → 15 taken 16 times.
✓ Branch 15 → 16 taken 8 times.
✓ Branch 15 → 21 taken 8 times.
✓ Branch 29 → 30 taken 16 times.
✗ Branch 29 → 31 not taken.
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 65 not taken.
✗ Branch 67 → 68 not taken.
✗ Branch 67 → 69 not taken.
|
56 | const bool scenarioHtml = m_scenario.contains(QStringLiteral("html")) || |
| 239 |
7/13✓ Branch 19 → 20 taken 8 times.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 8 times.
✓ Branch 23 → 24 taken 8 times.
✓ Branch 23 → 25 taken 8 times.
✓ Branch 25 → 26 taken 8 times.
✓ Branch 25 → 27 taken 8 times.
✓ Branch 27 → 28 taken 16 times.
✗ Branch 27 → 29 not taken.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
|
32 | m_scenario.contains(QStringLiteral("inline_images")); |
| 240 |
2/2✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 34 taken 15 times.
|
16 | if (scenarioHtml != html) { |
| 241 | 1 | finish(Outcome::Failed); | |
| 242 | 1 | return false; | |
| 243 | } | ||
| 244 | 15 | m_bodyBytes = std::max(m_bodyBytes, std::max<qint64>(0, bodyBytes)); | |
| 245 | 15 | m_attachmentCount = std::max(0, attachmentCount); | |
| 246 | 15 | m_inlineImageCount = std::max(0, inlineImageCount); | |
| 247 |
2/2✓ Branch 38 → 39 taken 7 times.
✓ Branch 38 → 46 taken 8 times.
|
15 | if (html) |
| 248 |
1/1✓ Branch 42 → 43 taken 7 times.
|
7 | startPhase(QStringLiteral("inline_prepare")); |
| 249 | else | ||
| 250 |
1/1✓ Branch 49 → 50 taken 8 times.
|
8 | startPhase(QStringLiteral("render")); |
| 251 | 15 | m_renderInProgress = true; | |
| 252 | 15 | return true; | |
| 253 | } | ||
| 254 | |||
| 255 | 5 | void MailOpenPerformanceTracker::inlinePreparationFinished(qint64 folderId, | |
| 256 | qint64 uid) { | ||
| 257 |
2/2✓ Branch 3 → 4 taken 3 times.
✓ Branch 3 → 11 taken 2 times.
|
5 | if (matchesUi(folderId, uid)) |
| 258 |
1/1✓ Branch 7 → 8 taken 3 times.
|
3 | endPhase(QStringLiteral("inline_prepare")); |
| 259 | 5 | } | |
| 260 | |||
| 261 | 5 | void MailOpenPerformanceTracker::sanitizerStarted(qint64 folderId, | |
| 262 | qint64 uid) { | ||
| 263 |
2/2✓ Branch 3 → 4 taken 3 times.
✓ Branch 3 → 11 taken 2 times.
|
5 | if (matchesUi(folderId, uid)) |
| 264 |
1/1✓ Branch 7 → 8 taken 3 times.
|
3 | startPhase(QStringLiteral("sanitize")); |
| 265 | 5 | } | |
| 266 | |||
| 267 | 6 | void MailOpenPerformanceTracker::sanitizerFinished(qint64 folderId, qint64 uid, | |
| 268 | bool currentGeneration) { | ||
| 269 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 4 times.
|
6 | if (!matchesUi(folderId, uid)) |
| 270 | 2 | return; | |
| 271 |
1/1✓ Branch 8 → 9 taken 4 times.
|
4 | endPhase(QStringLiteral("sanitize")); |
| 272 |
2/2✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 14 taken 3 times.
|
4 | if (!currentGeneration) { |
| 273 | 1 | finish(Outcome::Cancelled); | |
| 274 | 1 | return; | |
| 275 | } | ||
| 276 |
1/1✓ Branch 17 → 18 taken 3 times.
|
3 | startPhase(QStringLiteral("webengine_load")); |
| 277 | } | ||
| 278 | |||
| 279 | 8 | void MailOpenPerformanceTracker::plainCommitted(qint64 folderId, qint64 uid) { | |
| 280 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 6 times.
|
8 | if (!matchesUi(folderId, uid)) |
| 281 | 2 | return; | |
| 282 |
1/1✓ Branch 8 → 9 taken 6 times.
|
6 | endPhase(QStringLiteral("render")); |
| 283 |
1/1✓ Branch 14 → 15 taken 6 times.
|
6 | startPhase(QStringLiteral("paint")); |
| 284 | 6 | m_waitingForPlainPaint = true; | |
| 285 |
1/2✓ Branch 18 → 19 taken 6 times.
✗ Branch 18 → 21 not taken.
|
6 | if (m_plainViewport) |
| 286 | 6 | m_plainViewport->update(); | |
| 287 | } | ||
| 288 | |||
| 289 | 789 | void MailOpenPerformanceTracker::quickDocumentCommitted(const MailId &mailId, quint64 revision) { | |
| 290 |
7/10✓ Branch 3 → 4 taken 5 times.
✓ Branch 3 → 7 taken 784 times.
✓ Branch 4 → 5 taken 5 times.
✗ Branch 4 → 7 not taken.
✓ Branch 5 → 6 taken 5 times.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 5 times.
✓ Branch 9 → 10 taken 784 times.
✓ Branch 9 → 11 taken 5 times.
|
789 | if (!matches(mailId) || !m_renderEligible || revision == 0 || m_quickRevision == revision) return; |
| 291 | // The native text render tail ends here (no-op for the HTML tail whose | ||
| 292 | // phases are owned by the Quick HTML reader). | ||
| 293 |
1/1✓ Branch 14 → 15 taken 5 times.
|
5 | endPhase(QStringLiteral("render")); |
| 294 |
3/3✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 25 taken 4 times.
✓ Branch 21 → 22 taken 1 time.
|
6 | if (m_quickRevision) endPhase(QStringLiteral("quick_frame")); |
| 295 | 5 | m_quickRevision = revision; | |
| 296 |
1/1✓ Branch 28 → 29 taken 5 times.
|
5 | startPhase(QStringLiteral("quick_frame")); |
| 297 | } | ||
| 298 | |||
| 299 | 5698 | void MailOpenPerformanceTracker::quickFramePresented(const MailId &mailId, quint64 revision) { | |
| 300 |
8/8✓ Branch 3 → 4 taken 7 times.
✓ Branch 3 → 6 taken 5691 times.
✓ Branch 4 → 5 taken 6 times.
✓ Branch 4 → 6 taken 1 time.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 7 taken 4 times.
✓ Branch 8 → 9 taken 5694 times.
✓ Branch 8 → 10 taken 4 times.
|
5698 | if (!matches(mailId) || !m_quickRevision || revision != m_quickRevision) return; |
| 301 |
1/1✓ Branch 13 → 14 taken 4 times.
|
4 | endPhase(QStringLiteral("quick_frame")); |
| 302 | 4 | finish(Outcome::Success); | |
| 303 | } | ||
| 304 | |||
| 305 | 8 | void MailOpenPerformanceTracker::webEngineLoadFinished( | |
| 306 | qint64 folderId, qint64 uid, bool success, bool currentGeneration) { | ||
| 307 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 6 times.
|
8 | if (!matchesUi(folderId, uid)) |
| 308 | 2 | return; | |
| 309 |
1/1✓ Branch 8 → 9 taken 6 times.
|
6 | endPhase(QStringLiteral("webengine_load")); |
| 310 |
4/4✓ Branch 11 → 12 taken 5 times.
✓ Branch 11 → 13 taken 1 time.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 18 taken 4 times.
|
6 | if (!success || !currentGeneration) { |
| 311 |
2/2✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 1 time.
|
2 | finish(currentGeneration ? Outcome::Failed : Outcome::Cancelled); |
| 312 | 2 | return; | |
| 313 | } | ||
| 314 |
1/1✓ Branch 21 → 22 taken 4 times.
|
4 | startPhase(QStringLiteral("paint")); |
| 315 | 4 | m_waitingForHtmlPaint = true; | |
| 316 |
2/2✓ Branch 25 → 26 taken 3 times.
✓ Branch 25 → 28 taken 1 time.
|
4 | if (m_webView) |
| 317 | 3 | m_webView->update(); | |
| 318 | } | ||
| 319 | |||
| 320 | 129 | void MailOpenPerformanceTracker::fail(const MailId &mailId) { | |
| 321 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 127 times.
|
129 | if (matches(mailId)) |
| 322 | 2 | finish(Outcome::Failed); | |
| 323 | 129 | } | |
| 324 | |||
| 325 | 3 | void MailOpenPerformanceTracker::rememberPrefetch(const MailId &mailId) { | |
| 326 |
6/6✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 7 taken 1 time.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 1 time.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 11 taken 2 times.
|
3 | if (isActive() && mailId.isValid()) |
| 327 |
1/1✓ Branch 9 → 10 taken 1 time.
|
1 | m_prefetchedBodies.insert(mailId); |
| 328 | 3 | } | |
| 329 | |||
| 330 | 634 | bool MailOpenPerformanceTracker::consumePrefetch(const MailId &mailId) { | |
| 331 | 634 | return m_prefetchedBodies.remove(mailId) > 0; | |
| 332 | } | ||
| 333 | |||
| 334 | 24 | void MailOpenPerformanceTracker::finish(Outcome outcome) { | |
| 335 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 24 times.
|
24 | if (!m_operation.isValid()) |
| 336 | ✗ | return; | |
| 337 | 24 | const qint64 now = PerformanceTrace::monotonicNowNs(); | |
| 338 | 24 | const qint64 expected = | |
| 339 | 24 | m_previousHeartbeatNs + | |
| 340 | static_cast<qint64>(HeartbeatIntervalMs) * 1000000; | ||
| 341 | 24 | m_maxStallNs = std::max<qint64>(m_maxStallNs, now - expected); | |
| 342 | 24 | m_stallTimer->stop(); | |
| 343 | 24 | PerformanceTrace::instance().markProcessEvent( | |
| 344 |
2/2✓ Branch 11 → 12 taken 24 times.
✓ Branch 12 → 13 taken 24 times.
|
24 | m_scenario, QString::fromLatin1(EventLoopStallMetric), now, |
| 345 | 24 | std::max<qint64>(0, m_maxStallNs)); | |
| 346 | 24 | m_operation.finish(outcome, m_attachmentCount, m_bodyBytes); | |
| 347 | 24 | reset(); | |
| 348 | } | ||
| 349 | |||
| 350 | 85 | bool MailOpenPerformanceTracker::eventFilter(QObject *watched, QEvent *event) { | |
| 351 |
6/7✓ Branch 3 → 4 taken 12 times.
✓ Branch 3 → 6 taken 73 times.
✓ Branch 4 → 5 taken 12 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 12 times.
✓ Branch 8 → 9 taken 73 times.
✓ Branch 8 → 11 taken 12 times.
|
85 | if (event->type() != QEvent::Paint || !m_operation.isValid()) |
| 352 |
1/1✓ Branch 9 → 10 taken 73 times.
|
73 | return QObject::eventFilter(watched, event); |
| 353 | 12 | const auto *widget = qobject_cast<QWidget *>(watched); | |
| 354 |
6/8✓ Branch 12 → 13 taken 4 times.
✓ Branch 12 → 22 taken 8 times.
✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 22 not taken.
✓ Branch 15 → 16 taken 4 times.
✗ Branch 15 → 22 not taken.
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 21 taken 2 times.
|
18 | const bool htmlSurface = m_waitingForHtmlPaint && m_webView && widget && |
| 355 |
3/3✓ Branch 19 → 20 taken 2 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 22 taken 1 time.
|
6 | (widget == m_webView || m_webView->isAncestorOf(widget)); |
| 356 |
7/8✓ Branch 23 → 24 taken 6 times.
✓ Branch 23 → 26 taken 6 times.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 6 times.
✓ Branch 26 → 27 taken 3 times.
✓ Branch 26 → 28 taken 3 times.
✓ Branch 29 → 30 taken 9 times.
✓ Branch 29 → 36 taken 3 times.
|
12 | if ((m_waitingForPlainPaint && watched == m_plainViewport) || htmlSurface) { |
| 357 | 9 | m_waitingForPlainPaint = false; | |
| 358 | 9 | m_waitingForHtmlPaint = false; | |
| 359 | // WebEngine paints through an embedded widget. Complete after that paint | ||
| 360 | // returns, and never let its queued completion finish a later selection. | ||
| 361 |
1/1✓ Branch 30 → 31 taken 9 times.
|
9 | const auto operationId = m_operation.id(); |
| 362 |
1/1✓ Branch 32 → 33 taken 9 times.
|
9 | QTimer::singleShot(0, this, [this, operationId] { |
| 363 |
10/12✓ Branch 2 → 3 taken 9 times.
✓ Branch 3 → 4 taken 8 times.
✓ Branch 3 → 7 taken 1 time.
✓ Branch 4 → 5 taken 8 times.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 7 times.
✓ Branch 9 → 10 taken 8 times.
✓ Branch 9 → 11 taken 1 time.
✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 13 taken 7 times.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
|
9 | if (!m_operation.isValid() || m_operation.id() != operationId) return; |
| 364 |
1/1✓ Branch 16 → 17 taken 7 times.
|
14 | endPhase(QStringLiteral("paint")); |
| 365 | 7 | finish(Outcome::Success); | |
| 366 | }); | ||
| 367 | 9 | } | |
| 368 |
1/1✓ Branch 36 → 37 taken 12 times.
|
12 | return QObject::eventFilter(watched, event); |
| 369 | } | ||
| 370 | |||
| 371 | } // namespace MailJD::Performance | ||
| 372 |