aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Ionascu <stanislav.ionascu@nokia.com>2010-12-09 13:52:17 +0200
committerStanislav Ionascu <stanislav.ionascu@nokia.com>2011-01-14 16:04:58 +0200
commit5dbd7cefd9d4ba5550b74a80c5d6447286986c6e (patch)
treea08247505f59d10a26a0090f51fa47775eb4c945
parente67969e65298dcd45ad36135f02f01fc65ae07ae (diff)
Fixes: NB#210125 - Meegotouch should output warning message when style reloading happens
RevBy: Sergiy Dubovik, Armin Berres, Peter Penz Details: The recursive reload of styles is a time consuming operation and should be avoided. -performance-debug will output warnings on routines that affect application startup and runtime performance.
-rw-r--r--src/corelib/core/core.pri2
-rw-r--r--src/corelib/core/mcomponentdata.cpp34
-rw-r--r--src/corelib/core/mdebug.cpp106
-rw-r--r--src/corelib/core/mdebug.h57
-rw-r--r--src/corelib/core/msyslogclient.cpp31
-rw-r--r--src/corelib/core/msyslogclient.h5
-rw-r--r--src/corelib/widgets/core/mwidgetview.cpp4
7 files changed, 223 insertions, 16 deletions
diff --git a/src/corelib/core/core.pri b/src/corelib/core/core.pri
index bf502615..441d666f 100644
--- a/src/corelib/core/core.pri
+++ b/src/corelib/core/core.pri
@@ -80,6 +80,7 @@ SOURCES += \
$$CORE_SRC_DIR/msyslogclient.cpp \
$$CORE_SRC_DIR/mgraphicssystemhelper.cpp \
$$CORE_SRC_DIR/mdynamicpropertywatcher.cpp \
+ $$CORE_SRC_DIR/mdebug.cpp \
contains(DEFINES, HAVE_DBUS) {
SOURCES += \
@@ -97,4 +98,3 @@ contains(DEFINES, HAVE_GCONF) {
} else {
SOURCES += $$CORE_SRC_DIR/mgconfitem_stub.cpp
}
-
diff --git a/src/corelib/core/mcomponentdata.cpp b/src/corelib/core/mcomponentdata.cpp
index 610b21dc..3eb7f741 100644
--- a/src/corelib/core/mcomponentdata.cpp
+++ b/src/corelib/core/mcomponentdata.cpp
@@ -68,6 +68,7 @@ namespace
QStringList g_debug_prefixes;
bool g_has_debug_whitelist(false);
bool g_has_debug_blacklist(false);
+ bool g_show_performance_messages(false);
#ifdef __arm__
QtMsgType g_debug_level(QtCriticalMsg);
#else
@@ -110,6 +111,27 @@ bool mRedirectOutput(const QString &filename)
return debugingOutput != 0;
}
+void m_output_message(const char* msg)
+{
+ FILE *out = debugingOutput;
+ if (!out) {
+ out = stderr;
+ }
+ fprintf(out, "%s\n", msg);
+}
+
+void mMessageHandler(int type, const char *msg)
+{
+ switch (type) {
+ case MDebug::Performance:
+ if (g_show_performance_messages)
+ m_output_message(msg);
+ break;
+ default:
+ break;
+ };
+}
+
void mMessageHandler(QtMsgType type, const char *msg)
{
if (type < g_debug_level)
@@ -138,11 +160,7 @@ void mMessageHandler(QtMsgType type, const char *msg)
}
}
- FILE *out = debugingOutput;
- if (!out) {
- out = stderr;
- }
- fprintf(out, "%s\n", msg);
+ m_output_message(msg);
if (g_syslogSocket) {
g_syslogSocket->sendMsg(type, msg);
@@ -292,6 +310,7 @@ void MComponentDataPrivate::debugInit(bool levelSet)
} else if (!syslogServer.isEmpty()) {
initSyslogConnection(syslogServer);
}
+ MDebug::installMessageHandler(mMessageHandler);
}
MComponentData *MComponentData::instance()
@@ -299,7 +318,7 @@ MComponentData *MComponentData::instance()
return self;
}
-MComponentData* MComponentData::createInstance(int &argc, char **argv, const QString &appIdentifier /*= QString()*/, MApplicationService *service /*= 0*/)
+MComponentData* MComponentData::createInstance(int &argc, char **argv, const QString &appIdentifier, MApplicationService *service)
{
if(!self) {
self = new MComponentData(argc, argv, appIdentifier, service);
@@ -627,6 +646,8 @@ void MComponentDataPrivate::parseArguments(int &argc, char **argv,
argv[0]);
exit(EXIT_FAILURE);
}
+ } else if (s == "-performance-debug") {
+ g_show_performance_messages = true;
} else if (s == "-syslog-server") {
if (i < (argc -1)) {
i++;
@@ -713,6 +734,7 @@ void MComponentDataPrivate::parseArguments(int &argc, char **argv,
<< " [-output-level debug|warning|critical] Only show messages of given output level or above\n"
<< " [-output-prefix <prefix>] Only show debug messages that start with the given prefix\n"
<< " [-no-output-prefix <prefix>] Only show debug messages that do not start with the given prefix\n"
+ << " [-performance-debug] Show debug messages affecting performance\n"
<< " [-syslog-server <server>] Log debug output to a local or remote syslog server instance.\n"
<< " To send messages over the network, specify server as udp://hostname[:port].\n"
<< " To log locally, use the keyword 'local', which is an alias for file:///dev/log,\n"
diff --git a/src/corelib/core/mdebug.cpp b/src/corelib/core/mdebug.cpp
new file mode 100644
index 00000000..44d79ed9
--- /dev/null
+++ b/src/corelib/core/mdebug.cpp
@@ -0,0 +1,106 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include "mdebug.h"
+#include "mwidgetcontroller.h"
+
+#include <QTextStream>
+
+namespace {
+ MDebug::MMsgHandler handler(0);
+}
+
+MDebug::MDebug(int type)
+ : stream(new Stream(type))
+{
+}
+
+MDebug::MDebug(const MDebug &debug)
+ : stream(debug.stream)
+{
+ ++stream->ref;
+}
+
+MDebug::~MDebug()
+{
+ flush();
+}
+
+void MDebug::installMessageHandler(MMsgHandler handler)
+{
+ ::handler = handler;
+}
+
+void MDebug::flush()
+{
+ if (!--stream->ref) {
+ if (stream->output) {
+ switch (stream->type) {
+ case Debug:
+ case Warning:
+ case Critical:
+ case Fatal:
+ case System:
+ qt_message_output(convertMsgType(stream->type), stream->buffer.toLocal8Bit().constData());
+ break;
+ case Performance:
+ case User:
+ default:
+ if (handler)
+ handler(stream->type, stream->buffer.toLocal8Bit().constData());
+ };
+ }
+ delete stream;
+ }
+}
+
+QtMsgType MDebug::convertMsgType(int type)
+{
+ switch(type) {
+ case Debug:
+ return QtDebugMsg;
+ case Warning:
+ return QtWarningMsg;
+ case Critical:
+ return QtCriticalMsg;
+ case Fatal:
+ return QtFatalMsg;
+ case System:
+ return QtSystemMsg;
+ }
+
+ return QtDebugMsg;
+}
+
+MDebug &MDebug::operator <<(const QString &string)
+{
+ stream->ts << string << ' ';
+ return *this;
+}
+
+MDebug &MDebug::operator <<(const MWidgetController *controller)
+{
+ stream->ts << controller->metaObject()->className() << "(styleName = \"" + controller->styleName() << ", parent = ";
+ if (controller->parentWidget())
+ stream->ts << controller->parentWidget()->metaObject()->className();
+ else
+ stream->ts << "NULL";
+ stream->ts << ") ";
+ return *this;
+}
diff --git a/src/corelib/core/mdebug.h b/src/corelib/core/mdebug.h
index 4bffd2ea..09faaec2 100644
--- a/src/corelib/core/mdebug.h
+++ b/src/corelib/core/mdebug.h
@@ -22,6 +22,55 @@
#include <QDebug>
+//! \internal
+
+class MWidgetController;
+
+class MDebug
+{
+public:
+ typedef void (*MMsgHandler)(int, const char *);
+
+ enum Type {
+ Debug,
+ Warning,
+ Fatal,
+ Critical,
+ System,
+ Performance,
+
+ User = 0xFF
+ };
+
+ MDebug(int type = Debug);
+ MDebug(const MDebug &debug);
+ ~MDebug();
+
+ MDebug &operator<<(const QString &string);
+ MDebug &operator<<(const MWidgetController *controller);
+
+ static void installMessageHandler(MMsgHandler handler);
+ static MMsgHandler messageHandler();
+
+private:
+ void flush();
+ QtMsgType convertMsgType(int type);
+
+ struct Stream {
+ Stream(int type) : ts(&buffer, QIODevice::WriteOnly), ref(1), type(type), output(true) {}
+
+ QTextStream ts;
+ QString buffer;
+ int ref;
+ int type;
+ bool output;
+ };
+
+ Stream *stream;
+};
+
+//! \internal_end
+
/*!
* \brief Redirects all debugging output from qDebug, qWarning, qCritical and qFatal
* to specified file.
@@ -67,6 +116,7 @@ inline QDebug mDebugStream(const QString &module)
* as QString to categorize the output.
*
* \sa mDebug(const QString &)
+ * \sa mPerformanceWarning(const QString &)
*/
inline QDebug mWarningStream(const QString &module)
{
@@ -77,5 +127,12 @@ inline QDebug mWarningStream(const QString &module)
#define mWarning(x) mWarningStream(x)
#endif // QT_NO_WARNING_OUTPUT
+#define mPerformanceWarning(x) mPerformanceWarningStream(x)
+
+inline MDebug mPerformanceWarningStream(const QString &module)
+{
+ return MDebug(MDebug::Performance) << qPrintable(QString("%1:").arg(module));
+}
+
#endif
diff --git a/src/corelib/core/msyslogclient.cpp b/src/corelib/core/msyslogclient.cpp
index 21189fc3..b88e30f2 100644
--- a/src/corelib/core/msyslogclient.cpp
+++ b/src/corelib/core/msyslogclient.cpp
@@ -141,6 +141,28 @@ bool MSyslogClientSocket::connectToServer(const QUrl &url)
qint64 MSyslogClientSocket::sendMsg(QtMsgType type, const char *msg)
{
+ // we log to facility 'user' (1)
+ QString syslogMsg = QString("<%1>%2: %3")
+ .arg((1 << 3) + severityMap[type])
+ .arg(syslogId())
+ .arg(msg);
+
+ return m_socket->write(syslogMsg.toUtf8().data());
+}
+
+qint64 MSyslogClientSocket::sendMsg(const char *msg)
+{
+ // we log to facility 'user' (1)
+ QString syslogMsg = QString("<%1>%2: %3")
+ .arg((1 << 3) + severityMap[QtDebugMsg])
+ .arg(syslogId())
+ .arg(msg);
+
+ return m_socket->write(syslogMsg.toUtf8().data());
+}
+
+const QString &MSyslogClientSocket::syslogId()
+{
// generate identifier
if (m_syslogId.isEmpty()) {
if (!MApplication::binaryName().isEmpty()) {
@@ -150,12 +172,5 @@ qint64 MSyslogClientSocket::sendMsg(QtMsgType type, const char *msg)
}
}
- // we log to facility 'user' (1)
- QString syslogMsg = QString("<%1>%2: %3")
- .arg((1 << 3) + severityMap[type])
- .arg(m_syslogId)
- .arg(msg);
-
- return m_socket->write(syslogMsg.toUtf8().data());
+ return m_syslogId;
}
-
diff --git a/src/corelib/core/msyslogclient.h b/src/corelib/core/msyslogclient.h
index 8a0e976d..ec847e3a 100644
--- a/src/corelib/core/msyslogclient.h
+++ b/src/corelib/core/msyslogclient.h
@@ -33,9 +33,14 @@ class MSyslogClientSocket
virtual ~MSyslogClientSocket();
bool connectToServer(const QUrl &url);
void close();
+
qint64 sendMsg(QtMsgType type, const char * data);
+ qint64 sendMsg(const char * data);
+
+ const QString &syslogId();
private:
+
QMap<QtMsgType, int> severityMap;
QIODevice * m_socket;
QString m_syslogId;
diff --git a/src/corelib/widgets/core/mwidgetview.cpp b/src/corelib/widgets/core/mwidgetview.cpp
index ce63d099..c691a091 100644
--- a/src/corelib/widgets/core/mwidgetview.cpp
+++ b/src/corelib/widgets/core/mwidgetview.cpp
@@ -33,6 +33,8 @@
#include "mapplicationwindow.h"
#include "mclassfactory.h"
+#include "mdebug.h"
+
#include <QGestureEvent>
#include <QTapAndHoldGesture>
#include <QPanGesture>
@@ -432,6 +434,7 @@ void MWidgetView::notifyItemChange(QGraphicsItem::GraphicsItemChange change, con
style().setParent(parent);
if (value.value<QGraphicsItem*>() != NULL) {
+ mPerformanceWarning("MWidgetView::reloadChildItemsStyles") << "Styles are recursively reloaded due to parent change :" << d->controller;
d->reloadChildItemsStyles(d->controller);
applyStyle();
}
@@ -539,7 +542,6 @@ void MWidgetView::resizeEvent(QGraphicsSceneResizeEvent *event)
Q_UNUSED(event);
}
-
void MWidgetView::changeEvent(QEvent *event)
{
// styles can depend on right-to-left e.g. left and right margins