V8Profiler: make the profiler run in the main thread
authorChristiaan Janssen <christiaan.janssen@nokia.com>
Wed, 30 Nov 2011 15:03:47 +0000 (16:03 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 30 Nov 2011 15:09:19 +0000 (16:09 +0100)
Change-Id: I31f126c4014ee2a5045ff6d66dcfef63ec869e98
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
src/declarative/debugger/qv8profilerservice.cpp
src/declarative/debugger/qv8profilerservice_p.h

index 6e844b4..cf6c04a 100644 (file)
@@ -84,7 +84,6 @@ class QV8ProfilerServicePrivate : public QDeclarativeDebugServicePrivate
 public:
     QV8ProfilerServicePrivate()
         :initialized(false)
-        , isolate(0)
     {
     }
 
@@ -96,7 +95,6 @@ public:
     QList<QV8ProfilerData> 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);
index f8d6417..c2b63bd 100644 (file)
@@ -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();