performance/NavigationPerformanceTracker.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "performance/NavigationPerformanceTracker.h" | ||
| 2 | |||
| 3 | #include <QApplication> | ||
| 4 | #include <QEvent> | ||
| 5 | #include <QWidget> | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | |||
| 9 | namespace MailJD::Performance { | ||
| 10 | |||
| 11 | namespace { | ||
| 12 | constexpr auto SearchMetric = "search.input_to_results_painted.v1"; | ||
| 13 | constexpr auto FilterMetric = "filter.input_to_results_painted.v1"; | ||
| 14 | constexpr auto ScrollMetric = "scroll.input_to_paint.v1"; | ||
| 15 | constexpr auto ThreadMetric = "thread.input_to_painted.v1"; | ||
| 16 | constexpr auto TabMetric = "tab.input_to_painted.v1"; | ||
| 17 | } // namespace | ||
| 18 | |||
| 19 | 28 | NavigationPerformanceTracker &NavigationPerformanceTracker::instance() { | |
| 20 |
4/7✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 8 taken 27 times.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
|
28 | static NavigationPerformanceTracker tracker; |
| 21 | 28 | return tracker; | |
| 22 | } | ||
| 23 | |||
| 24 | 1 | NavigationPerformanceTracker::NavigationPerformanceTracker(QObject *parent) | |
| 25 | 1 | : QObject(parent) {} | |
| 26 | |||
| 27 | 65 | bool NavigationPerformanceTracker::isActive() const { | |
| 28 |
4/4✓ Branch 2 → 3 taken 65 times.
✓ Branch 3 → 4 taken 65 times.
✓ Branch 4 → 5 taken 59 times.
✓ Branch 4 → 13 taken 6 times.
|
183 | return PerformanceTrace::instance().isEnabled() && |
| 29 |
4/7✓ Branch 5 → 6 taken 59 times.
✓ Branch 6 → 7 taken 59 times.
✓ Branch 10 → 11 taken 59 times.
✓ Branch 11 → 12 taken 59 times.
✗ Branch 11 → 13 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
|
183 | PerformanceTrace::instance().selectedScenario().startsWith( |
| 30 |
6/10✓ Branch 14 → 15 taken 59 times.
✓ Branch 14 → 16 taken 6 times.
✓ Branch 16 → 17 taken 59 times.
✓ Branch 16 → 18 taken 6 times.
✓ Branch 18 → 19 taken 59 times.
✓ Branch 18 → 20 taken 6 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
|
189 | QStringLiteral("SEARCH_LIST.")); |
| 31 | } | ||
| 32 | |||
| 33 | 54 | void NavigationPerformanceTracker::ensureEventFilterInstalled() { | |
| 34 |
5/6✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 53 times.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 11 taken 53 times.
|
54 | if (!m_eventFilterInstalled && qApp) { |
| 35 | 1 | qApp->installEventFilter(this); | |
| 36 | 1 | m_eventFilterInstalled = true; | |
| 37 | } | ||
| 38 | 54 | } | |
| 39 | |||
| 40 | 27 | void NavigationPerformanceTracker::watchListViewport(QWidget *viewport) { | |
| 41 | 27 | m_listViewport = viewport; | |
| 42 |
2/2✓ Branch 4 → 5 taken 26 times.
✓ Branch 4 → 6 taken 1 time.
|
27 | if (isActive()) |
| 43 | 26 | ensureEventFilterInstalled(); | |
| 44 | 27 | } | |
| 45 | |||
| 46 | 38 | void NavigationPerformanceTracker::begin( | |
| 47 | const QString &metric, const QStringList &operations) { | ||
| 48 |
3/3✓ Branch 2 → 3 taken 38 times.
✓ Branch 3 → 4 taken 5 times.
✓ Branch 3 → 5 taken 33 times.
|
38 | if (!isActive()) |
| 49 | 10 | return; | |
| 50 | const QString selected = | ||
| 51 |
2/2✓ Branch 5 → 6 taken 33 times.
✓ Branch 6 → 7 taken 33 times.
|
33 | PerformanceTrace::instance().selectedScenario(); |
| 52 |
1/1✓ Branch 9 → 10 taken 33 times.
|
33 | const bool matches = std::any_of( |
| 53 | operations.cbegin(), operations.cend(), | ||
| 54 | 112 | [&selected](const QString &operation) { | |
| 55 |
2/2✓ Branch 8 → 9 taken 112 times.
✓ Branch 10 → 11 taken 112 times.
|
448 | return selected.contains(QStringLiteral(".") + operation + |
| 56 |
1/1✓ Branch 9 → 10 taken 112 times.
|
448 | QStringLiteral(".")); |
| 57 | }); | ||
| 58 |
2/2✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 12 taken 28 times.
|
33 | if (!matches) |
| 59 | 5 | return; | |
| 60 |
3/3✓ Branch 12 → 13 taken 28 times.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 27 times.
|
28 | if (m_operation.isValid()) |
| 61 |
1/1✓ Branch 14 → 15 taken 1 time.
|
1 | finish(Outcome::Cancelled); |
| 62 |
1/1✓ Branch 15 → 16 taken 28 times.
|
28 | ensureEventFilterInstalled(); |
| 63 | 28 | m_scenario = selected; | |
| 64 | 28 | m_itemCount = -1; | |
| 65 | 28 | m_paintPending = false; | |
| 66 |
1/1✓ Branch 17 → 18 taken 28 times.
|
28 | m_targetViewport = nullptr; |
| 67 |
2/2✓ Branch 18 → 19 taken 28 times.
✓ Branch 19 → 20 taken 28 times.
|
28 | m_operation = PerformanceTrace::instance().startMetric(m_scenario, metric); |
| 68 |
1/1✓ Branch 25 → 26 taken 28 times.
|
56 | m_operation.startPhase(QStringLiteral("input")); |
| 69 |
1/1✓ Branch 31 → 32 taken 28 times.
|
56 | m_operation.endPhase(QStringLiteral("input")); |
| 70 | 33 | } | |
| 71 | |||
| 72 | 12 | void NavigationPerformanceTracker::beginSearch() { | |
| 73 |
4/6✓ Branch 31 → 32 taken 12 times.
✓ Branch 32 → 33 taken 12 times.
✓ Branch 36 → 37 taken 108 times.
✓ Branch 36 → 38 taken 12 times.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
|
120 | begin(QString::fromLatin1(SearchMetric), |
| 74 | 12 | {QStringLiteral("fts"), QStringLiteral("like_fallback"), | |
| 75 | 12 | QStringLiteral("trigram"), QStringLiteral("sender_facet"), | |
| 76 | 12 | QStringLiteral("folder_facet"), QStringLiteral("date_facet"), | |
| 77 | 12 | QStringLiteral("label_facet"), QStringLiteral("server_search"), | |
| 78 | 12 | QStringLiteral("server_cancel")}); | |
| 79 | 132 | } | |
| 80 | |||
| 81 | 6 | void NavigationPerformanceTracker::beginFilter() { | |
| 82 |
4/6✓ Branch 10 → 11 taken 6 times.
✓ Branch 11 → 12 taken 6 times.
✓ Branch 15 → 16 taken 12 times.
✓ Branch 15 → 17 taken 6 times.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
|
18 | begin(QString::fromLatin1(FilterMetric), |
| 83 | ✗ | {QStringLiteral("quick_filter_type"), | |
| 84 | 6 | QStringLiteral("quick_filter_clear")}); | |
| 85 | 24 | } | |
| 86 | |||
| 87 | 6 | void NavigationPerformanceTracker::beginScroll() { | |
| 88 |
4/6✓ Branch 16 → 17 taken 6 times.
✓ Branch 17 → 18 taken 6 times.
✓ Branch 21 → 22 taken 24 times.
✓ Branch 21 → 23 taken 6 times.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
|
30 | begin(QString::fromLatin1(ScrollMetric), |
| 89 | 6 | {QStringLiteral("scroll_wheel"), QStringLiteral("scroll_bar"), | |
| 90 | 6 | QStringLiteral("scroll_page"), | |
| 91 | 6 | QStringLiteral("scroll_keyboard")}); | |
| 92 | 36 | } | |
| 93 | |||
| 94 | 6 | void NavigationPerformanceTracker::beginThread() { | |
| 95 |
4/6✓ Branch 16 → 17 taken 6 times.
✓ Branch 17 → 18 taken 6 times.
✓ Branch 21 → 22 taken 24 times.
✓ Branch 21 → 23 taken 6 times.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
|
30 | begin(QString::fromLatin1(ThreadMetric), |
| 96 | ✗ | {QStringLiteral("thread_toggle"), | |
| 97 | 6 | QStringLiteral("thread_rebuild"), | |
| 98 | 6 | QStringLiteral("thread_expand"), | |
| 99 | 6 | QStringLiteral("thread_collapse")}); | |
| 100 | 36 | } | |
| 101 | |||
| 102 | 8 | void NavigationPerformanceTracker::beginTab() { | |
| 103 |
4/6✓ Branch 19 → 20 taken 8 times.
✓ Branch 20 → 21 taken 8 times.
✓ Branch 24 → 25 taken 40 times.
✓ Branch 24 → 26 taken 8 times.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
|
48 | begin(QString::fromLatin1(TabMetric), |
| 104 | 8 | {QStringLiteral("tab_open"), QStringLiteral("tab_switch"), | |
| 105 | 8 | QStringLiteral("tab_restore"), QStringLiteral("tab_close"), | |
| 106 | 8 | QStringLiteral("tab_reorder")}); | |
| 107 | 56 | } | |
| 108 | |||
| 109 | 26 | void NavigationPerformanceTracker::phaseStarted(const QString &phase) { | |
| 110 |
2/2✓ Branch 3 → 4 taken 25 times.
✓ Branch 3 → 5 taken 1 time.
|
26 | if (m_operation.isValid()) |
| 111 | 25 | m_operation.startPhase(phase); | |
| 112 | 26 | } | |
| 113 | |||
| 114 | 26 | void NavigationPerformanceTracker::phaseFinished(const QString &phase, | |
| 115 | int itemCount) { | ||
| 116 |
2/2✓ Branch 3 → 4 taken 25 times.
✓ Branch 3 → 5 taken 1 time.
|
26 | if (m_operation.isValid()) |
| 117 | 25 | m_operation.endPhase(phase, itemCount); | |
| 118 | 26 | } | |
| 119 | |||
| 120 | 29 | void NavigationPerformanceTracker::committed(QWidget *viewport, | |
| 121 | int itemCount) { | ||
| 122 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 27 times.
|
29 | if (!m_operation.isValid()) |
| 123 | 2 | return; | |
| 124 | 27 | m_targetViewport = viewport; | |
| 125 | 27 | m_itemCount = itemCount; | |
| 126 |
1/1✓ Branch 9 → 10 taken 27 times.
|
54 | m_operation.startPhase(QStringLiteral("paint")); |
| 127 | 27 | m_paintPending = true; | |
| 128 |
1/2✓ Branch 12 → 13 taken 27 times.
✗ Branch 12 → 14 not taken.
|
27 | if (viewport) |
| 129 | 27 | viewport->update(); | |
| 130 | } | ||
| 131 | |||
| 132 | 27 | void NavigationPerformanceTracker::listCommitted(int itemCount) { | |
| 133 | 27 | committed(m_listViewport, itemCount); | |
| 134 | 27 | } | |
| 135 | |||
| 136 | 2 | void NavigationPerformanceTracker::tabCommitted(QWidget *content, | |
| 137 | int itemCount) { | ||
| 138 | 2 | committed(content, itemCount); | |
| 139 | 2 | } | |
| 140 | |||
| 141 | 30 | void NavigationPerformanceTracker::finish(Outcome outcome) { | |
| 142 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 28 times.
|
30 | if (!m_operation.isValid()) |
| 143 | 2 | return; | |
| 144 | 28 | m_operation.finish(outcome, m_itemCount); | |
| 145 | 28 | m_operation = {}; | |
| 146 | 28 | m_paintPending = false; | |
| 147 | 28 | m_targetViewport = nullptr; | |
| 148 | } | ||
| 149 | |||
| 150 | 9 | void NavigationPerformanceTracker::fail() { finish(Outcome::Failed); } | |
| 151 | |||
| 152 | 9 | void NavigationPerformanceTracker::cancel() { finish(Outcome::Cancelled); } | |
| 153 | |||
| 154 | 142 | bool NavigationPerformanceTracker::eventFilter(QObject *watched, | |
| 155 | QEvent *event) { | ||
| 156 |
7/8✓ Branch 2 → 3 taken 35 times.
✓ Branch 2 → 8 taken 107 times.
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 8 taken 24 times.
✓ Branch 6 → 7 taken 11 times.
✗ Branch 6 → 8 not taken.
✓ Branch 9 → 10 taken 11 times.
✓ Branch 9 → 17 taken 131 times.
|
153 | if (m_paintPending && watched == m_targetViewport && |
| 157 | 11 | event->type() == QEvent::Paint) { | |
| 158 |
1/1✓ Branch 13 → 14 taken 11 times.
|
22 | m_operation.endPhase(QStringLiteral("paint"), m_itemCount); |
| 159 | 11 | finish(Outcome::Success); | |
| 160 | } | ||
| 161 | 142 | return QObject::eventFilter(watched, event); | |
| 162 | } | ||
| 163 | |||
| 164 | } // namespace MailJD::Performance | ||
| 165 |