forked from qt-creator/qt-creator
QmlProfiler: Methods for dispatching events by feature
When announcing features models have to provide functions that handle events for those features now. The model manager gets a function to dispatch events to the models that subscribe to them. Change-Id: I3fd80443a68ba264a513d8d53ed473cf072f1dc7 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
@@ -51,7 +51,12 @@ FlameGraphModel::FlameGraphModel(QmlProfilerModelManager *modelManager,
|
||||
m_modelId = modelManager->registerModelProxy();
|
||||
|
||||
m_acceptedTypes << Compiling << Creating << Binding << HandlingSignal << Javascript;
|
||||
modelManager->announceFeatures(m_modelId, Constants::QML_JS_RANGE_FEATURES);
|
||||
modelManager->announceFeatures(Constants::QML_JS_RANGE_FEATURES,
|
||||
[this](const QmlEvent &event, const QmlEventType &type) {
|
||||
loadEvent(event, type);
|
||||
}, [this](){
|
||||
finalize();
|
||||
});
|
||||
}
|
||||
|
||||
void FlameGraphModel::clear()
|
||||
|
@@ -33,7 +33,8 @@ namespace Internal {
|
||||
MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) :
|
||||
QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent)
|
||||
{
|
||||
announceFeatures((1ULL << mainFeature()) | Constants::QML_JS_RANGE_FEATURES);
|
||||
// Announce additional features. The base class already announces the main feature.
|
||||
announceFeatures(Constants::QML_JS_RANGE_FEATURES);
|
||||
}
|
||||
|
||||
int MemoryUsageModel::rowMaxValue(int rowNumber) const
|
||||
|
@@ -46,6 +46,33 @@ struct QmlEventType {
|
||||
Message message;
|
||||
RangeType rangeType;
|
||||
int detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
|
||||
|
||||
ProfileFeature feature() const
|
||||
{
|
||||
switch (message) {
|
||||
case Event: {
|
||||
switch (detailType) {
|
||||
case Mouse:
|
||||
case Key:
|
||||
return ProfileInputEvents;
|
||||
case AnimationFrame:
|
||||
return ProfileAnimations;
|
||||
default:
|
||||
return MaximumProfileFeature;
|
||||
}
|
||||
}
|
||||
case PixmapCacheEvent:
|
||||
return ProfilePixmapCache;
|
||||
case SceneGraphFrame:
|
||||
return ProfileSceneGraph;
|
||||
case MemoryAllocation:
|
||||
return ProfileMemory;
|
||||
case DebugMessage:
|
||||
return ProfileDebugMessages;
|
||||
default:
|
||||
return featureFromRangeType(rangeType);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
QDataStream &operator>>(QDataStream &stream, QmlEventType &type);
|
||||
|
@@ -136,6 +136,9 @@ public:
|
||||
quint64 availableFeatures;
|
||||
quint64 visibleFeatures;
|
||||
quint64 recordedFeatures;
|
||||
|
||||
QHash<ProfileFeature, QVector<EventLoader> > eventLoaders;
|
||||
QVector<Finalizer> finalizers;
|
||||
};
|
||||
|
||||
|
||||
@@ -182,9 +185,15 @@ int QmlProfilerModelManager::registerModelProxy()
|
||||
return d->numRegisteredModels++;
|
||||
}
|
||||
|
||||
void QmlProfilerModelManager::announceFeatures(int proxyId, quint64 features)
|
||||
void QmlProfilerModelManager::dispatch(const QmlEvent &event, const QmlEventType &type)
|
||||
{
|
||||
foreach (const EventLoader &loader, d->eventLoaders[type.feature()])
|
||||
loader(event, type);
|
||||
}
|
||||
|
||||
void QmlProfilerModelManager::announceFeatures(quint64 features, EventLoader eventLoader,
|
||||
Finalizer finalizer)
|
||||
{
|
||||
Q_UNUSED(proxyId); // Will use that later to optimize the event dispatching on loading.
|
||||
if ((features & d->availableFeatures) != features) {
|
||||
d->availableFeatures |= features;
|
||||
emit availableFeaturesChanged(d->availableFeatures);
|
||||
@@ -193,6 +202,13 @@ void QmlProfilerModelManager::announceFeatures(int proxyId, quint64 features)
|
||||
d->visibleFeatures |= features;
|
||||
emit visibleFeaturesChanged(d->visibleFeatures);
|
||||
}
|
||||
|
||||
for (int feature = 0; feature != MaximumProfileFeature; ++feature) {
|
||||
if (features & (1 << feature))
|
||||
d->eventLoaders[static_cast<ProfileFeature>(feature)].append(eventLoader);
|
||||
}
|
||||
|
||||
d->finalizers.append(finalizer);
|
||||
}
|
||||
|
||||
quint64 QmlProfilerModelManager::availableFeatures() const
|
||||
|
@@ -28,10 +28,13 @@
|
||||
#include "qmlprofiler_global.h"
|
||||
#include "qmlprofilereventtypes.h"
|
||||
#include "qmleventlocation.h"
|
||||
#include "qmlevent.h"
|
||||
#include "qmleventtype.h"
|
||||
|
||||
#include <utils/fileinprojectfinder.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
|
||||
namespace QmlProfiler {
|
||||
class QmlProfilerModelManager;
|
||||
@@ -80,6 +83,9 @@ public:
|
||||
Done
|
||||
};
|
||||
|
||||
typedef std::function<void(const QmlEvent &, const QmlEventType &)> EventLoader;
|
||||
typedef std::function<void()> Finalizer;
|
||||
|
||||
explicit QmlProfilerModelManager(Utils::FileInProjectFinder *finder, QObject *parent = 0);
|
||||
~QmlProfilerModelManager();
|
||||
|
||||
@@ -91,7 +97,10 @@ public:
|
||||
bool isEmpty() const;
|
||||
|
||||
int registerModelProxy();
|
||||
void announceFeatures(int proxyId, quint64 features);
|
||||
void announceFeatures(quint64 features, EventLoader eventLoader, Finalizer finalizer);
|
||||
|
||||
void dispatch(const QmlEvent &event, const QmlEventType &type);
|
||||
|
||||
quint64 availableFeatures() const;
|
||||
quint64 visibleFeatures() const;
|
||||
void setVisibleFeatures(quint64 features);
|
||||
|
@@ -65,7 +65,12 @@ QmlProfilerStatisticsModel::QmlProfilerStatisticsModel(QmlProfilerModelManager *
|
||||
|
||||
d->acceptedTypes << Compiling << Creating << Binding << HandlingSignal << Javascript;
|
||||
|
||||
modelManager->announceFeatures(d->modelId, Constants::QML_JS_RANGE_FEATURES);
|
||||
modelManager->announceFeatures(Constants::QML_JS_RANGE_FEATURES,
|
||||
[this](const QmlEvent &event, const QmlEventType &type) {
|
||||
loadEvent(event, type);
|
||||
}, [this]() {
|
||||
finalize();
|
||||
});
|
||||
}
|
||||
|
||||
QmlProfilerStatisticsModel::~QmlProfilerStatisticsModel()
|
||||
|
@@ -80,9 +80,14 @@ QmlProfilerModelManager *QmlProfilerTimelineModel::modelManager() const
|
||||
return m_modelManager;
|
||||
}
|
||||
|
||||
void QmlProfilerTimelineModel::announceFeatures(quint64 features) const
|
||||
void QmlProfilerTimelineModel::announceFeatures(quint64 features)
|
||||
{
|
||||
m_modelManager->announceFeatures(modelId(), features);
|
||||
m_modelManager->announceFeatures(
|
||||
features, [this](const QmlEvent &event, const QmlEventType &type) {
|
||||
loadEvent(event, type);
|
||||
}, [this]() {
|
||||
finalize();
|
||||
});
|
||||
}
|
||||
|
||||
void QmlProfilerTimelineModel::dataChanged()
|
||||
|
@@ -64,7 +64,7 @@ private slots:
|
||||
void onVisibleFeaturesChanged(quint64 features);
|
||||
|
||||
protected:
|
||||
void announceFeatures(quint64 features) const;
|
||||
void announceFeatures(quint64 features);
|
||||
|
||||
private:
|
||||
const Message m_message;
|
||||
|
Reference in New Issue
Block a user