Qt: log icon and window timings to find the icon lag on the phone

Each icon request logs its key and how long it took (ultra.icon), each icon
logs when it shows, and the app state, scene graph and first frames are
logged too, so logcat shows where the time goes when icons appear late.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiQsCq11CwCPnKPp9D
This commit is contained in:
Claude committed 2026-11-04 16:19:45 +00:00
1 parent 5b09f66a78
commit 35b4c44168
4 files changed
+24

No files matched your search

@@ -219,6 +219,7 @@ public class HomeActivity extends QtActivity {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
Log.i("ultra", "onStart");
widgetHost.startListening(); widgetHost.startListening();
Updater.check(this, false); Updater.check(this, false);
} }
@@ -226,6 +227,7 @@ public class HomeActivity extends QtActivity {
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
Log.i("ultra", "onStop");
widgetHost.stopListening(); widgetHost.stopListening();
} }
+1
View File
@@ -25,6 +25,7 @@ Item {
mipmap: true mipmap: true
sourceSize.width: Math.ceil(root.size * Screen.devicePixelRatio) sourceSize.width: Math.ceil(root.size * Screen.devicePixelRatio)
sourceSize.height: Math.ceil(root.size * Screen.devicePixelRatio) sourceSize.height: Math.ceil(root.size * Screen.devicePixelRatio)
onStatusChanged: if (status === Image.Ready || status === Image.Error) console.info("ultra.icon shown", root.key, status === Image.Ready)
source: root.key ? "image://icon/" + encodeURIComponent(root.key) + "?" + root.generation : "" source: root.key ? "image://icon/" + encodeURIComponent(root.key) + "?" + root.generation : ""
} }
} }
+9
View File
@@ -3,6 +3,11 @@
#include <QColor> #include <QColor>
#include <QPainter> #include <QPainter>
#include <QUrl> #include <QUrl>
#include <QElapsedTimer>
#include <QLoggingCategory>
#include <QThread>
Q_LOGGING_CATEGORY(lcIcon, "ultra.icon")
#include <cmath> #include <cmath>
@@ -17,6 +22,8 @@ QImage IconProvider::requestImage(const QString &id, QSize *size, const QSize &r
if (q >= 0) key.truncate(q); if (q >= 0) key.truncate(q);
key = QUrl::fromPercentEncoding(key.toUtf8()); key = QUrl::fromPercentEncoding(key.toUtf8());
const int px = requested.width() > 0 ? requested.width() : 144; const int px = requested.width() > 0 ? requested.width() : 144;
QElapsedTimer took;
took.start();
QImage img; QImage img;
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
// Premultiplied RGBA, side x side, straight from an Android bitmap. // Premultiplied RGBA, side x side, straight from an Android bitmap.
@@ -54,5 +61,7 @@ QImage IconProvider::requestImage(const QString &id, QSize *size, const QSize &r
p.drawText(QRectF(0, 0, px, px), Qt::AlignCenter, name.left(1).toUpper()); p.drawText(QRectF(0, 0, px, px), Qt::AlignCenter, name.left(1).toUpper());
#endif #endif
if (size) *size = img.size(); if (size) *size = img.size();
// Timing, to find what holds icons up on a phone: adb logcat -s ultrahome:*
qCInfo(lcIcon, "icon %s %dpx %lldms%s", qPrintable(key), px, took.elapsed(), img.isNull() ? " (none)" : "");
return img; return img;
} }
+12
View File
@@ -28,5 +28,17 @@ int main(int argc, char *argv[]) {
[] { QCoreApplication::exit(1); }, Qt::QueuedConnection); [] { QCoreApplication::exit(1); }, Qt::QueuedConnection);
engine.loadFromModule("Launcher", "Main"); engine.loadFromModule("Launcher", "Main");
if (engine.rootObjects().isEmpty()) return 1; if (engine.rootObjects().isEmpty()) return 1;
// Timing of the window's lifecycle, next to the icon timings (category ultra.icon).
QObject::connect(&app, &QGuiApplication::applicationStateChanged, [](Qt::ApplicationState s) {
qInfo("ultra.state %d", int(s));
});
if (auto *win = qobject_cast<QQuickWindow *>(engine.rootObjects().first())) {
QObject::connect(win, &QQuickWindow::sceneGraphInitialized, [] { qInfo("ultra.sg initialized"); });
QObject::connect(win, &QQuickWindow::sceneGraphInvalidated, [] { qInfo("ultra.sg invalidated"); });
QObject::connect(win, &QQuickWindow::frameSwapped, win, [win] {
static int n = 0;
if (n++ < 3) qInfo("ultra.sg frame %d", n);
});
}
return app.exec(); return app.exec();
} }