aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristiaan Janssen <christiaan.janssen@digia.com>2012-10-24 16:09:29 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-30 13:07:16 +0200
commit107444f7c479ed6a1a3d2c42b026ebc9c1fe4b29 (patch)
tree1b2d5de24ac315fc1e57beeb38d0fed141fafab6 /src
parent3b0a9b27fec09cdab4cde7bfc41578c8c17a8832 (diff)
QmlProfiler: Pixmap Cache
Change-Id: Ibc237bb162c24030438b89d54fa8802ee66b080a Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/debugger/qqmlprofilerservice.cpp33
-rw-r--r--src/qml/debugger/qqmlprofilerservice_p.h66
-rw-r--r--src/quick/util/qquickpixmapcache.cpp24
3 files changed, 118 insertions, 5 deletions
diff --git a/src/qml/debugger/qqmlprofilerservice.cpp b/src/qml/debugger/qqmlprofilerservice.cpp
index cb85fc0e1f..e016b2fdb5 100644
--- a/src/qml/debugger/qqmlprofilerservice.cpp
+++ b/src/qml/debugger/qqmlprofilerservice.cpp
@@ -76,6 +76,15 @@ QByteArray QQmlProfilerData::toByteArray() const
if (messageType == (int)QQmlProfilerService::Event &&
detailType == (int)QQmlProfilerService::AnimationFrame)
ds << framerate << animationcount;
+ if (messageType == (int)QQmlProfilerService::PixmapCacheEvent) {
+ ds << detailData;
+ switch (detailType) {
+ case QQmlProfilerService::PixmapSizeKnown: ds << line << column; break;
+ case QQmlProfilerService::PixmapReferenceCountChanged: ds << animationcount; break;
+ case QQmlProfilerService::PixmapCacheCountChanged: ds << animationcount; break;
+ default: break;
+ }
+ }
return data;
}
@@ -238,6 +247,30 @@ void QQmlProfilerService::endRange(RangeType range)
processMessage(rd);
}
+void QQmlProfilerService::pixmapEventImpl(PixmapEventType eventType, const QUrl &url)
+{
+ // assuming enabled checked by caller
+ QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)PixmapCacheEvent, (int)eventType,
+ url.toString(), -1, -1, -1, -1, -1};
+ processMessage(rd);
+}
+
+void QQmlProfilerService::pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int width, int height)
+{
+ // assuming enabled checked by caller
+ QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)PixmapCacheEvent, (int)eventType,
+ url.toString(), width, height, -1, -1, -1};
+ processMessage(rd);
+}
+
+void QQmlProfilerService::pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int count)
+{
+ // assuming enabled checked by caller
+ QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)PixmapCacheEvent, (int)eventType,
+ url.toString(), -1, -1, -1, count, -1};
+ processMessage(rd);
+}
+
void QQmlProfilerService::animationFrameImpl(qint64 delta)
{
Q_ASSERT(QQmlDebugService::isDebuggingEnabled());
diff --git a/src/qml/debugger/qqmlprofilerservice_p.h b/src/qml/debugger/qqmlprofilerservice_p.h
index a50fb5ea08..30eb2ebbf4 100644
--- a/src/qml/debugger/qqmlprofilerservice_p.h
+++ b/src/qml/debugger/qqmlprofilerservice_p.h
@@ -74,10 +74,10 @@ struct Q_AUTOTEST_EXPORT QQmlProfilerData
//###
QString detailData; //used by RangeData and RangeLocation
- int line; //used by RangeLocation
- int column; //used by RangeLocation
+ int line; //used by RangeLocation, also as "width" for pixmaps
+ int column; //used by RangeLocation, also as "height" for pixmaps
int framerate; //used by animation events
- int animationcount; //used by animation events
+ int animationcount; //used by animation events, also as "cache/reference count" for pixmaps
int bindingType;
QByteArray toByteArray() const;
@@ -99,6 +99,7 @@ public:
RangeLocation,
RangeEnd,
Complete, // end of transmission
+ PixmapCacheEvent,
MaximumMessage
};
@@ -132,6 +133,17 @@ public:
MaximumBindingType
};
+ enum PixmapEventType {
+ PixmapSizeKnown,
+ PixmapReferenceCountChanged,
+ PixmapCacheCountChanged,
+ PixmapLoadingStarted,
+ PixmapLoadingFinished,
+ PixmapLoadingError,
+
+ MaximumPixmapEventType
+ };
+
static void initialize();
static bool startProfiling();
@@ -163,6 +175,10 @@ private:
void rangeLocation(RangeType, const QUrl &, int, int);
void endRange(RangeType);
+ // overloading depending on parameters
+ void pixmapEventImpl(PixmapEventType eventType, const QUrl &url);
+ void pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int width, int height);
+ void pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int count);
bool profilingEnabled();
void setProfilingEnabled(bool enable);
@@ -183,6 +199,7 @@ private:
friend struct QQmlHandlingSignalProfiler;
friend struct QQmlObjectCreatingProfiler;
friend struct QQmlCompilingProfiler;
+ friend struct QQmlPixmapProfiler;
};
//
@@ -288,6 +305,49 @@ struct QQmlCompilingProfiler {
bool enabled;
};
+struct QQmlPixmapProfiler {
+ QQmlPixmapProfiler() {
+ QQmlProfilerService *instance = QQmlProfilerService::instance;
+ enabled = instance ?
+ instance->profilingEnabled() : false;
+ }
+
+ ~QQmlPixmapProfiler() {}
+
+ void startLoading(const QUrl &pixmapUrl) {
+ if (enabled) {
+ QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingStarted, pixmapUrl);
+ }
+ }
+ void finishLoading(const QUrl &pixmapUrl) {
+ if (enabled) {
+ QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingFinished, pixmapUrl);
+ }
+ }
+ void errorLoading(const QUrl &pixmapUrl) {
+ if (enabled) {
+ QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingError, pixmapUrl);
+ }
+ }
+ void cacheCountChanged(const QUrl &pixmapUrl, int cacheCount) {
+ if (enabled) {
+ QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapCacheCountChanged, pixmapUrl, cacheCount);
+ }
+ }
+ void referenceCountChanged(const QUrl &pixmapUrl, int referenceCount) {
+ if (enabled) {
+ QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapReferenceCountChanged, pixmapUrl, referenceCount);
+ }
+ }
+ void setSize(const QUrl &pixmapUrl, int width, int height) {
+ if (enabled) {
+ QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapSizeKnown, pixmapUrl, width, height);
+ }
+ }
+
+ bool enabled;
+};
+
QT_END_NAMESPACE
#endif // QQMLPROFILERSERVICE_P_H
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index c5968c2bc1..9cf8c5812d 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -71,6 +71,8 @@
#include <QQmlFile>
#include <QMetaMethod>
+#include <private/qqmlprofilerservice_p.h>
+
#define IMAGEREQUEST_MAX_REQUEST_COUNT 8
#define IMAGEREQUEST_MAX_REDIRECT_RECURSION 16
#define CACHE_EXPIRE_TIME 30
@@ -890,11 +892,15 @@ bool QQuickPixmapReply::event(QEvent *event)
if (data) {
Event *de = static_cast<Event *>(event);
data->pixmapStatus = (de->error == NoError) ? QQuickPixmap::Ready : QQuickPixmap::Error;
-
+ QQmlPixmapProfiler pixmapProfiler;
if (data->pixmapStatus == QQuickPixmap::Ready) {
+ pixmapProfiler.finishLoading(data->url);
data->textureFactory = de->textureFactory;
data->implicitSize = de->implicitSize;
+ if (data->implicitSize.width() > 0)
+ pixmapProfiler.setSize(url, data->implicitSize.width(), data->implicitSize.height());
} else {
+ pixmapProfiler.errorLoading(data->url);
data->errorString = de->errorString;
data->removeFromCache(); // We don't continue to cache error'd pixmaps
}
@@ -920,6 +926,7 @@ int QQuickPixmapData::cost() const
void QQuickPixmapData::addref()
{
++refCount;
+ QQmlPixmapProfiler().referenceCountChanged(url, refCount);
if (prevUnreferencedPtr)
pixmapStore()->referencePixmap(this);
}
@@ -928,6 +935,7 @@ void QQuickPixmapData::release()
{
Q_ASSERT(refCount > 0);
--refCount;
+ QQmlPixmapProfiler().referenceCountChanged(url, refCount);
if (refCount == 0) {
if (reply) {
QQuickPixmapReply *cancelReply = reply;
@@ -958,6 +966,10 @@ void QQuickPixmapData::addToCache()
QQuickPixmapKey key = { &url, &requestSize };
pixmapStore()->m_cache.insert(key, this);
inCache = true;
+ QQmlPixmapProfiler pixmapProfiler;
+ pixmapProfiler.cacheCountChanged(url, pixmapStore()->m_cache.count());
+ if (implicitSize.width() > 0)
+ pixmapProfiler.setSize(url, implicitSize.width(), implicitSize.height());
}
}
@@ -965,6 +977,7 @@ void QQuickPixmapData::removeFromCache()
{
if (inCache) {
QQuickPixmapKey key = { &url, &requestSize };
+ QQmlPixmapProfiler().cacheCountChanged(url, pixmapStore()->m_cache.count());
pixmapStore()->m_cache.remove(key);
inCache = false;
}
@@ -1238,14 +1251,21 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
if (!(options & QQuickPixmap::Asynchronous)) {
bool ok = false;
+ QQmlPixmapProfiler pixmapProfiler;
+ pixmapProfiler.startLoading(url);
d = createPixmapDataSync(this, engine, url, requestSize, &ok);
if (ok) {
+ pixmapProfiler.finishLoading(url);
+ if (d->implicitSize.width() > 0)
+ QQmlPixmapProfiler().setSize(url, d->implicitSize.width(), d->implicitSize.height());
if (options & QQuickPixmap::Cache)
d->addToCache();
return;
}
- if (d) // loadable, but encountered error while loading
+ if (d) { // loadable, but encountered error while loading
+ pixmapProfiler.errorLoading(url);
return;
+ }
}
if (!engine)