Commit c975f80d authored by Kai Koehne's avatar Kai Koehne Committed by Qt by Nokia

QmlProfiler: Make sure there's minimal overhead when not enabled

Do expensive operations directly in the constructor, guarded by
and if (enabled). Also assert if the methods where this isn't feasible
are called altough debugging hasn't been enabled.

Change-Id: Ieaa3c71730042a88af2270203ea747af42ba5c58
Reviewed-by: default avatarAaron Kennedy <aaron.kennedy@nokia.com>
parent 587a1ce1
......@@ -54,12 +54,15 @@
//
#include <private/qqmldebugservice_p.h>
#include <QtQml/qtqmlglobal.h>
#include "qqmlexpression.h"
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qmutex.h>
#include <QtCore/qvector.h>
#include <QtCore/qstringbuilder.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
......@@ -198,36 +201,26 @@ struct QQmlBindingProfiler {
};
struct QQmlHandlingSignalProfiler {
QQmlHandlingSignalProfiler()
QQmlHandlingSignalProfiler(const QMetaMethod &signal, QQmlExpression *expression)
{
enabled = QQmlProfilerService::instance
? QQmlProfilerService::instance->profilingEnabled() : false;
if (enabled) {
QQmlProfilerService::instance->startRange(
QQmlProfilerService::HandlingSignal);
QQmlProfilerService *service = QQmlProfilerService::instance;
service->startRange(QQmlProfilerService::HandlingSignal);
service->rangeData(QQmlProfilerService::HandlingSignal,
QLatin1String(signal.signature()) + QLatin1String(": ")
+ expression->expression());
service->rangeLocation(QQmlProfilerService::HandlingSignal,
expression->sourceFile(), expression->lineNumber(),
expression->columnNumber());
}
}
void setSignalInfo(const QString &name, const QString &expression)
{
if (enabled)
QQmlProfilerService::instance->rangeData(
QQmlProfilerService::HandlingSignal,
name % QLatin1String(": ") % expression);
}
void setLocation(const QString &file, int line, int column)
{
if (enabled)
QQmlProfilerService::instance->rangeLocation(
QQmlProfilerService::HandlingSignal, file, line, column);
}
~QQmlHandlingSignalProfiler()
{
if (enabled)
QQmlProfilerService::instance->endRange(
QQmlProfilerService::HandlingSignal);
QQmlProfilerService::instance->endRange(QQmlProfilerService::HandlingSignal);
}
bool enabled;
......@@ -236,22 +229,23 @@ struct QQmlHandlingSignalProfiler {
struct QQmlObjectCreatingProfiler {
QQmlObjectCreatingProfiler()
{
QQmlProfilerService *instance = QQmlProfilerService::instance;
enabled = instance ?
instance->profilingEnabled() : false;
if (enabled)
instance->startRange(QQmlProfilerService::Creating);
enabled = QQmlProfilerService::instance
? QQmlProfilerService::instance->profilingEnabled() : false;
if (enabled) {
QQmlProfilerService *service = QQmlProfilerService::instance;
service->startRange(QQmlProfilerService::Creating);
}
}
void setTypeName(const QString &typeName)
{
if (enabled)
QQmlProfilerService::instance->rangeData(
QQmlProfilerService::Creating, typeName);
Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled.");
QQmlProfilerService::instance->rangeData(QQmlProfilerService::Creating, typeName);
}
void setLocation(const QUrl &url, int line, int column)
{
Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled.");
if (enabled)
QQmlProfilerService::instance->rangeLocation(
QQmlProfilerService::Creating, url, line, column);
......
......@@ -174,13 +174,7 @@ int QQmlBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a)
if (QQmlDebugService::isDebuggingEnabled())
QV8DebugService::instance()->signalEmitted(QString::fromAscii(m_signal.signature()));
QQmlHandlingSignalProfiler prof;
if (prof.enabled) {
prof.setSignalInfo(QString::fromLatin1(m_signal.signature()),
m_expression->expression());
prof.setLocation(m_expression->sourceFile(), m_expression->lineNumber(),
m_expression->columnNumber());
}
QQmlHandlingSignalProfiler prof(m_signal, m_expression);
m_isEvaluating = true;
if (!m_paramsValid) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment