From 01479573b98747b39833ab09e2cd9ee618ad2a0f Mon Sep 17 00:00:00 2001 From: Christiaan Janssen Date: Wed, 30 Nov 2011 16:03:47 +0100 Subject: [PATCH] V8Profiler: make the profiler run in the main thread Change-Id: I31f126c4014ee2a5045ff6d66dcfef63ec869e98 Reviewed-by: Kai Koehne --- src/declarative/debugger/qv8profilerservice.cpp | 31 +++++++++++++------------ src/declarative/debugger/qv8profilerservice_p.h | 3 +++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/declarative/debugger/qv8profilerservice.cpp b/src/declarative/debugger/qv8profilerservice.cpp index 6e844b4..cf6c04a 100644 --- a/src/declarative/debugger/qv8profilerservice.cpp +++ b/src/declarative/debugger/qv8profilerservice.cpp @@ -84,7 +84,6 @@ class QV8ProfilerServicePrivate : public QDeclarativeDebugServicePrivate public: QV8ProfilerServicePrivate() :initialized(false) - , isolate(0) { } @@ -96,7 +95,6 @@ public: QList m_data; bool initialized; - v8::Isolate *isolate; }; QV8ProfilerService::QV8ProfilerService(QObject *parent) @@ -136,30 +134,22 @@ void QV8ProfilerService::messageReceived(const QByteArray &message) QByteArray title; ds >> command >> option; - if (!d->isolate) { - d->isolate = v8::Isolate::New(); - v8::Isolate::Scope scope(d->isolate); - v8::V8::Initialize(); - } - - v8::Isolate::Scope scope(d->isolate); - if (command == "V8PROFILER") { ds >> title; if (option == "start") { - startProfiling(QString::fromUtf8(title)); + QMetaObject::invokeMethod(this, "startProfiling", Qt::QueuedConnection, Q_ARG(QString, QString::fromUtf8(title))); } else if (option == "stop") { - stopProfiling(QString::fromUtf8(title)); - sendProfilingData(); + QMetaObject::invokeMethod(this, "stopProfiling", Qt::QueuedConnection, Q_ARG(QString, QString::fromUtf8(title))); + QMetaObject::invokeMethod(this, "sendProfilingData", Qt::QueuedConnection); } d->initialized = true; } if (command == "V8SNAPSHOT") { if (option == "full") - d->takeSnapshot(v8::HeapSnapshot::kFull); + QMetaObject::invokeMethod(this, "takeSnapshot", Qt::QueuedConnection); else if (option == "delete") { - v8::HeapProfiler::DeleteAllSnapshots(); + QMetaObject::invokeMethod(this, "deleteSnapshots", Qt::QueuedConnection); } } @@ -188,6 +178,17 @@ void QV8ProfilerService::stopProfiling(const QString &title) } } +void QV8ProfilerService::takeSnapshot() +{ + Q_D(QV8ProfilerService); + d->takeSnapshot(v8::HeapSnapshot::kFull); +} + +void QV8ProfilerService::deleteSnapshots() +{ + v8::HeapProfiler::DeleteAllSnapshots(); +} + void QV8ProfilerService::sendProfilingData() { Q_D(QV8ProfilerService); diff --git a/src/declarative/debugger/qv8profilerservice_p.h b/src/declarative/debugger/qv8profilerservice_p.h index f8d6417..c2b63bd 100644 --- a/src/declarative/debugger/qv8profilerservice_p.h +++ b/src/declarative/debugger/qv8profilerservice_p.h @@ -95,8 +95,11 @@ public: static QV8ProfilerService *instance(); static void initialize(); +public slots: void startProfiling(const QString &title); void stopProfiling(const QString &title); + void takeSnapshot(); + void deleteSnapshots(); void sendProfilingData(); -- 2.7.4