Fix V8 heap snapshot in profiler service
authorMikko Harju <mikko.a.harju@nokia.com>
Wed, 12 Oct 2011 06:41:10 +0000 (09:41 +0300)
committerQt by Nokia <qt-info@nokia.com>
Wed, 12 Oct 2011 11:43:04 +0000 (13:43 +0200)
Fixes the message parsing (use the option also for heap snapshot
commands).

Do not directly serialize the snapshot to the QByteArray under
QDataStream.

Change-Id: I3ad15a2debd6c2f912854610b6434744e0acd788
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
src/declarative/debugger/qv8profilerservice.cpp

index 0afa4fa..9195729 100644 (file)
@@ -160,14 +160,12 @@ void QV8ProfilerService::messageReceived(const QByteArray &message)
     }
 
     if (command == "V8SNAPSHOT") {
-            QByteArray snapshotType;
-            ds >> snapshotType;
-
-            if (snapshotType == "full")
-                d->takeSnapshot(v8::HeapSnapshot::kFull);
-        } else if (command == "deletesnapshots") {
+        if (option == "full")
+            d->takeSnapshot(v8::HeapSnapshot::kFull);
+        else if (option == "delete") {
             v8::HeapProfiler::DeleteAllSnapshots();
         }
+    }
 
     QDeclarativeDebugService::messageReceived(message);
 }
@@ -218,14 +216,14 @@ void QV8ProfilerServicePrivate::takeSnapshot(v8::HeapSnapshot::Type snapshotType
     v8::HandleScope scope;
     v8::Local<v8::String> title = v8::String::New("");
 
+    QByteArray jsonSnapshot;
+    ByteArrayOutputStream bos(&jsonSnapshot);
     const v8::HeapSnapshot *snapshot = v8::HeapProfiler::TakeSnapshot(title, snapshotType);
+    snapshot->Serialize(&bos, v8::HeapSnapshot::kJSON);
 
     QByteArray data;
     QDataStream ds(&data, QIODevice::WriteOnly);
-    ds << (int)QV8ProfilerService::V8Snapshot;
-
-    ByteArrayOutputStream bos(&data);
-    snapshot->Serialize(&bos, v8::HeapSnapshot::kJSON);
+    ds << (int)QV8ProfilerService::V8Snapshot << jsonSnapshot;
 
     q->sendMessage(data);
 }