From 7701b58ad06f9e99d291e0e3468096dc3ab4dd00 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 2 Jan 2014 16:49:32 +0100 Subject: Remove redundant copies of enabled flag in QML profiler Task-number: QTBUG-35315 Change-Id: Idd35a330531722cb3d4e0d3e95cb3be6e5697688 Reviewed-by: Michael Brasser --- src/qml/debugger/qqmlprofilerservice.cpp | 102 ++++++++----------------------- src/qml/debugger/qqmlprofilerservice_p.h | 72 +++++++--------------- src/qml/qml/qqmlvme.cpp | 34 +++++------ 3 files changed, 63 insertions(+), 145 deletions(-) (limited to 'src') diff --git a/src/qml/debugger/qqmlprofilerservice.cpp b/src/qml/debugger/qqmlprofilerservice.cpp index b83de937c6..3c066bd380 100644 --- a/src/qml/debugger/qqmlprofilerservice.cpp +++ b/src/qml/debugger/qqmlprofilerservice.cpp @@ -431,58 +431,29 @@ void QQmlProfilerService::messageReceived(const QByteArray &message) */ void QQmlVmeProfiler::Data::clear() { - url = QUrl(); + url.clear(); line = 0; column = 0; - typeName = QString(); -} - -/*! - * \brief QQmlVmeProfiler::start Start profiler and set data - * \param url URL of file being executed - * \param line Curent line in file - * \param column Current column in file - * \param typeName Type of object be created - * Stops the profiler previously running in the foreground if there is one, then starts a - * new one and sets it up with the data given. - * Preconditions: Profiling must be enabled. - */ -void QQmlVmeProfiler::start(const QUrl &url, int line, int column, const QString &typeName) -{ - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - if (enabled) { - switchRange(); - updateLocation(url, line, column); - updateTypeName(typeName); - } + typeName.clear(); } /*! * \brief QQmlVmeProfiler::start Start profiler without data * Clears the current range data, then stops the profiler previously running in the * foreground if any, then starts a new one. - * Preconditions: Profiling must be enabled. */ -void QQmlVmeProfiler::start() +bool QQmlVmeProfiler::start() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - if (enabled) { + if (QQmlProfilerService::enabled) { currentRange.clear(); - switchRange(); + if (running) + QQmlProfilerService::instance->endRange(QQmlProfilerService::Creating); + else + running = true; + QQmlProfilerService::instance->startRange(QQmlProfilerService::Creating); + return true; } -} - -/*! - * \brief QQmlVmeProfiler::switchRange Switch foreground profilers - * Stops the current profiler if any, and starts a new one. - */ -void QQmlVmeProfiler::switchRange() -{ - if (running) - QQmlProfilerService::instance->endRange(QQmlProfilerService::Creating); - else - running = true; - QQmlProfilerService::instance->startRange(QQmlProfilerService::Creating); + return false; } /*! @@ -491,13 +462,10 @@ void QQmlVmeProfiler::switchRange() * \param line line Curent line in file * \param column column Current column in file * Updates the current profiler's location information. - * Preconditions: Profiling must be enabled and a profiler must be running in the foreground. */ void QQmlVmeProfiler::updateLocation(const QUrl &url, int line, int column) { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - Q_ASSERT_X(running, Q_FUNC_INFO, "trying to update location on stopped profiler"); - if (enabled && running) { + if (QQmlProfilerService::enabled && running) { currentRange.url = url; currentRange.line = line; currentRange.column = column; @@ -510,13 +478,10 @@ void QQmlVmeProfiler::updateLocation(const QUrl &url, int line, int column) * \brief QQmlVmeProfiler::updateTypeName Update current type information * \param typeName Type of object being created * Updates the current profiler's type information. - * Preconditions: Profiling must be enabled and a profiler must be running in the foreground. */ void QQmlVmeProfiler::updateTypeName(const QString &typeName) { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - Q_ASSERT_X(running, Q_FUNC_INFO, "trying to update typeName on stopped profiler"); - if (enabled && running) { + if (QQmlProfilerService::enabled && running) { currentRange.typeName = typeName; QQmlProfilerService::instance->rangeData(QQmlProfilerService::Creating, typeName); } @@ -526,14 +491,10 @@ void QQmlVmeProfiler::updateTypeName(const QString &typeName) * \brief QQmlVmeProfiler::pop Pops a paused profiler from the stack and restarts it * Stops the currently running profiler, if any, then retrieves an old one from the stack * of paused profilers and starts that. - * Preconditions: Profiling must be enabled and there must be at least one profiler on the - * stack. */ void QQmlVmeProfiler::pop() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - Q_ASSERT_X(ranges.count() > 0, Q_FUNC_INFO, "trying to pop an invalid profiler"); - if (enabled && ranges.count() > 0) { + if (QQmlProfilerService::enabled && ranges.count() > 0) { start(); currentRange = ranges.pop(); QQmlProfilerService::instance->rangeLocation( @@ -547,13 +508,10 @@ void QQmlVmeProfiler::pop() * Pushes the currently running profiler on the stack of paused profilers. Note: The profiler * isn't paused here. That's a separate step. If it's never paused, but pop()'ed later that * won't do any harm, though. - * Preconditions: Profiling must be enabled and a profiler must be running in the foreground. */ void QQmlVmeProfiler::push() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - Q_ASSERT_X(running, Q_FUNC_INFO, "trying to push stopped profiler"); - if (enabled && running) + if (QQmlProfilerService::enabled && running) ranges.push(currentRange); } @@ -561,29 +519,26 @@ void QQmlVmeProfiler::push() * \brief QQmlVmeProfiler::clear Stop all running profilers and clear all data. * Stops the currently running (foreground and background) profilers and removes all saved * data about paused profilers. - * Precondtions: Profiling must be enabled. */ void QQmlVmeProfiler::clear() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - if (enabled) { - stop(); - ranges.clear(); + stop(); + ranges.clear(); + if (QQmlProfilerService::enabled) { for (int i = 0; i < backgroundRanges.count(); ++i) { QQmlProfilerService::instance->endRange(QQmlProfilerService::Creating); } - backgroundRanges.clear(); } + backgroundRanges.clear(); + running = false; } /*! * \brief QQmlVmeProfiler::stop Stop profiler running in the foreground, if any. - * Precondition: Profiling must be enabled. */ void QQmlVmeProfiler::stop() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - if (enabled && running) { + if (QQmlProfilerService::enabled && running) { QQmlProfilerService::instance->endRange(QQmlProfilerService::Creating); currentRange.clear(); running = false; @@ -595,13 +550,10 @@ void QQmlVmeProfiler::stop() * Push the profiler currently running in the foreground to the background so that it * won't be stopped by stop() or start(). There can be multiple profilers in the background. * You can retrieve them in reverse order by calling foreground(). - * Precondition: Profiling must be enabled and a profiler must be running in the foreground. */ void QQmlVmeProfiler::background() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - Q_ASSERT_X(running, Q_FUNC_INFO, "trying to push stopped profiler to the background."); - if (enabled && running) { + if (QQmlProfilerService::enabled && running) { backgroundRanges.push(currentRange); running = false; } @@ -611,18 +563,16 @@ void QQmlVmeProfiler::background() * \brief QQmlVmeProfiler::foreground Retrieve a profiler from the background * Stop the profiler currently running in the foreground, if any and put the next profiler * from the background in its place. - * Preconditions: Profiling must be enabled and there must be at least one profiler in the - * background. */ -void QQmlVmeProfiler::foreground() +bool QQmlVmeProfiler::foreground() { - Q_ASSERT_X(enabled, Q_FUNC_INFO, "method called although profiler is not enabled."); - Q_ASSERT_X(backgroundRanges.count() > 0, Q_FUNC_INFO, "trying to foreground stopped profiler."); - if (enabled && backgroundRanges.count() > 0) { + if (QQmlProfilerService::enabled && backgroundRanges.count() > 0) { stop(); currentRange = backgroundRanges.pop(); running = true; + return true; } + return false; } QT_END_NAMESPACE diff --git a/src/qml/debugger/qqmlprofilerservice_p.h b/src/qml/debugger/qqmlprofilerservice_p.h index 5959a526bb..86807eacec 100644 --- a/src/qml/debugger/qqmlprofilerservice_p.h +++ b/src/qml/debugger/qqmlprofilerservice_p.h @@ -237,32 +237,25 @@ private: struct QQmlBindingProfiler { QQmlBindingProfiler(const QString &url, int line, int column, QQmlProfilerService::BindingType bindingType) { - QQmlProfilerService *instance = QQmlProfilerService::instance; - enabled = instance ? instance->profilingEnabled() : false; - if (enabled) { - instance->startRange(QQmlProfilerService::Binding, bindingType); - instance->rangeLocation(QQmlProfilerService::Binding, url, line, column); + if (QQmlProfilerService::enabled) { + QQmlProfilerService::instance->startRange(QQmlProfilerService::Binding, bindingType); + QQmlProfilerService::instance->rangeLocation(QQmlProfilerService::Binding, url, line, column); } } ~QQmlBindingProfiler() { - if (enabled) + if (QQmlProfilerService::enabled) QQmlProfilerService::instance->endRange(QQmlProfilerService::Binding); } - - bool enabled; }; struct QQmlHandlingSignalProfiler { QQmlHandlingSignalProfiler(QQmlBoundSignalExpression *expression) { - enabled = QQmlProfilerService::instance - ? QQmlProfilerService::instance->profilingEnabled() : false; - if (enabled) { - QQmlProfilerService *service = QQmlProfilerService::instance; - service->startRange(QQmlProfilerService::HandlingSignal); - service->rangeLocation(QQmlProfilerService::HandlingSignal, + if (QQmlProfilerService::enabled) { + QQmlProfilerService::instance->startRange(QQmlProfilerService::HandlingSignal); + QQmlProfilerService::instance->rangeLocation(QQmlProfilerService::HandlingSignal, expression->sourceFile(), expression->lineNumber(), expression->columnNumber()); } @@ -270,38 +263,30 @@ struct QQmlHandlingSignalProfiler { ~QQmlHandlingSignalProfiler() { - if (enabled) + if (QQmlProfilerService::enabled) QQmlProfilerService::instance->endRange(QQmlProfilerService::HandlingSignal); } - - bool enabled; }; struct QQmlCompilingProfiler { QQmlCompilingProfiler(const QString &name) { - QQmlProfilerService *instance = QQmlProfilerService::instance; - enabled = instance ? - instance->profilingEnabled() : false; - if (enabled) { - instance->startRange(QQmlProfilerService::Compiling); - instance->rangeLocation(QQmlProfilerService::Compiling, name, 1, 1); - instance->rangeData(QQmlProfilerService::Compiling, name); + if (QQmlProfilerService::enabled) { + QQmlProfilerService::instance->startRange(QQmlProfilerService::Compiling); + QQmlProfilerService::instance->rangeLocation(QQmlProfilerService::Compiling, name, 1, 1); + QQmlProfilerService::instance->rangeData(QQmlProfilerService::Compiling, name); } } ~QQmlCompilingProfiler() { - if (enabled) + if (QQmlProfilerService::enabled) QQmlProfilerService::instance->endRange(QQmlProfilerService::Compiling); } - - bool enabled; }; struct QQmlVmeProfiler { public: - const bool enabled; struct Data { Data() : line(0), column(0) {} @@ -313,20 +298,18 @@ public: }; QQmlVmeProfiler() : - enabled(QQmlProfilerService::instance ? QQmlProfilerService::instance->profilingEnabled() : false), running(false) {} ~QQmlVmeProfiler() { - if (enabled) + if (QQmlProfilerService::enabled) clear(); } void clear(); - void start(const QUrl &url, int line, int column, const QString &typeName); - void start(); + bool start(); void stop(); void updateLocation(const QUrl &url, int line, int column); @@ -336,10 +319,9 @@ public: void push(); void background(); - void foreground(); + bool foreground(); private: - void switchRange(); Data currentRange; QStack ranges; @@ -348,46 +330,36 @@ private: }; struct QQmlPixmapProfiler { - QQmlPixmapProfiler() { - QQmlProfilerService *instance = QQmlProfilerService::instance; - enabled = instance ? - instance->profilingEnabled() : false; - } - - ~QQmlPixmapProfiler() {} - void startLoading(const QUrl &pixmapUrl) { - if (enabled) { + if (QQmlProfilerService::enabled) { QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingStarted, pixmapUrl); } } void finishLoading(const QUrl &pixmapUrl) { - if (enabled) { + if (QQmlProfilerService::enabled) { QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingFinished, pixmapUrl); } } void errorLoading(const QUrl &pixmapUrl) { - if (enabled) { + if (QQmlProfilerService::enabled) { QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingError, pixmapUrl); } } void cacheCountChanged(const QUrl &pixmapUrl, int cacheCount) { - if (enabled) { + if (QQmlProfilerService::enabled) { QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapCacheCountChanged, pixmapUrl, cacheCount); } } void referenceCountChanged(const QUrl &pixmapUrl, int referenceCount) { - if (enabled) { + if (QQmlProfilerService::enabled) { QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapReferenceCountChanged, pixmapUrl, referenceCount); } } void setSize(const QUrl &pixmapUrl, const QSize &size) { - if (enabled && size.width() > 0) { + if (QQmlProfilerService::enabled && size.width() > 0) { QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapSizeKnown, pixmapUrl, size.width(), size.height()); } } - - bool enabled; }; QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp index ad1e9d862e..1881b554ed 100644 --- a/src/qml/qml/qqmlvme.cpp +++ b/src/qml/qml/qqmlvme.cpp @@ -503,8 +503,7 @@ QObject *QQmlVME::run(QList *errors, const QQmlCompiledData::TypeReference &type = TYPES.at(instr.type); Q_ASSERT(type.component); - if (profiler.enabled) { - profiler.start(); + if (profiler.start()) { profiler.updateTypeName(type.component->name); profiler.background(); } @@ -530,10 +529,8 @@ QObject *QQmlVME::run(QList *errors, QML_END_INSTR(CreateQMLObject) QML_BEGIN_INSTR(CompleteQMLObject) - if (profiler.enabled) { - profiler.foreground(); + if (profiler.foreground()) profiler.updateLocation(CTXT->url, instr.line, instr.column); - } QObject *o = objects.top(); Q_ASSERT(o); @@ -577,8 +574,10 @@ QObject *QQmlVME::run(QList *errors, QML_BEGIN_INSTR(CreateCppObject) const QQmlCompiledData::TypeReference &type = TYPES.at(instr.type); Q_ASSERT(type.type); - if (profiler.enabled) - profiler.start(CTXT->url, instr.line, instr.column, type.type->qmlTypeName()); + if (profiler.start()) { + profiler.updateLocation(CTXT->url, instr.line, instr.column); + profiler.updateTypeName(type.type->qmlTypeName()); + } QObject *o = 0; void *memory = 0; @@ -651,8 +650,10 @@ QObject *QQmlVME::run(QList *errors, QML_BEGIN_INSTR(CreateSimpleObject) const QQmlCompiledData::TypeReference &ref = TYPES.at(instr.type); - if (profiler.enabled) - profiler.start(CTXT->url, instr.line, instr.column, ref.type->qmlTypeName()); + if (profiler.start()) { + profiler.updateLocation(CTXT->url, instr.line, instr.column); + profiler.updateTypeName(ref.type->qmlTypeName()); + } QObject *o = (QObject *)operator new(instr.typeSize + sizeof(QQmlData)); ::memset(static_cast(o), 0, instr.typeSize + sizeof(QQmlData)); instr.create(o); @@ -832,8 +833,7 @@ QObject *QQmlVME::run(QList *errors, QML_END_INSTR(StoreScriptString) QML_BEGIN_INSTR(BeginObject) - if (profiler.enabled) - profiler.push(); + profiler.push(); QObject *target = objects.top(); QQmlParserStatus *status = reinterpret_cast(reinterpret_cast(target) + instr.castValue); parserStatus.push(status); @@ -1091,8 +1091,7 @@ normalExit: objects.deallocate(); lists.deallocate(); states.clear(); - if (profiler.enabled) - profiler.stop(); + profiler.stop(); return rv; } @@ -1130,8 +1129,7 @@ void QQmlVME::reset() states.clear(); rootContext = 0; creationContext = 0; - if (profiler.enabled) - profiler.clear(); + profiler.clear(); } #ifdef QML_THREADED_VME_INTERPRETER @@ -1191,8 +1189,7 @@ QQmlContextData *QQmlVME::complete(const Interrupt &interrupt) if (componentCompleteEnabled()) { // the qml designer does the component complete later QQmlTrace trace("VME Component Complete"); while (!parserStatus.isEmpty()) { - if (profiler.enabled) - profiler.pop(); + profiler.pop(); QQmlParserStatus *status = parserStatus.pop(); #ifdef QML_ENABLE_TRACE QQmlData *data = parserStatusData.pop(); @@ -1212,8 +1209,7 @@ QQmlContextData *QQmlVME::complete(const Interrupt &interrupt) return 0; } parserStatus.deallocate(); - if (profiler.enabled) - profiler.clear(); + profiler.clear(); } { -- cgit v1.2.3