diff options
author | Mikko Harju <mikko.a.harju@nokia.com> | 2011-12-08 13:24:12 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-12 02:04:53 +0100 |
commit | 18ce33ecd994666d42e438c4aa62302c72465458 (patch) | |
tree | cda4a43bc5721e9c0b0916b46ca10df1ea63d0a0 /src/declarative/debugger | |
parent | d0dc58b8c300682b92fa018e04193ffccd79ef15 (diff) |
QmlProfiler: stream snapshots to reduce memory footprint
Taking a V8 heap snapshot with QV8ProfilerService created multiple
copies of the snapshot data, causing overhead of several megabytes.
This patch changes the snapshot protocol to stream the contents over
the debugger connection.
Change-Id: I90054210233d52dd02aa838201f9b024d578fcea
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src/declarative/debugger')
-rw-r--r-- | src/declarative/debugger/qv8profilerservice.cpp | 24 | ||||
-rw-r--r-- | src/declarative/debugger/qv8profilerservice_p.h | 3 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/declarative/debugger/qv8profilerservice.cpp b/src/declarative/debugger/qv8profilerservice.cpp index cf6c04a3e1..7cbd336e17 100644 --- a/src/declarative/debugger/qv8profilerservice.cpp +++ b/src/declarative/debugger/qv8profilerservice.cpp @@ -50,18 +50,20 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QV8ProfilerService, v8ProfilerInstance) -class ByteArrayOutputStream : public v8::OutputStream +class DebugServiceOutputStream : public v8::OutputStream { - QByteArray *_buffer; + QDeclarativeDebugService &_service; public: - ByteArrayOutputStream(QByteArray *buffer) + DebugServiceOutputStream(QDeclarativeDebugService &service) : v8::OutputStream(), - _buffer(buffer) {} + _service(service) {} void EndOfStream() {} - WriteResult WriteAsciiChunk(char *data, int size) + WriteResult WriteAsciiChunk(char *rawData, int size) { - QByteArray b(data, size); - _buffer->append(b); + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << QV8ProfilerService::V8SnapshotChunk << QByteArray(rawData, size); + _service.sendMessage(data); return kContinue; } }; @@ -223,14 +225,14 @@ void QV8ProfilerServicePrivate::takeSnapshot(v8::HeapSnapshot::Type snapshotType v8::HandleScope scope; v8::Local<v8::String> title = v8::String::New(""); - QByteArray jsonSnapshot; - ByteArrayOutputStream bos(&jsonSnapshot); + DebugServiceOutputStream outputStream(*q); const v8::HeapSnapshot *snapshot = v8::HeapProfiler::TakeSnapshot(title, snapshotType); - snapshot->Serialize(&bos, v8::HeapSnapshot::kJSON); + snapshot->Serialize(&outputStream, v8::HeapSnapshot::kJSON); + //indicate completion QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); - ds << (int)QV8ProfilerService::V8Snapshot << jsonSnapshot; + ds << (int)QV8ProfilerService::V8SnapshotComplete; q->sendMessage(data); } diff --git a/src/declarative/debugger/qv8profilerservice_p.h b/src/declarative/debugger/qv8profilerservice_p.h index c2b63bd74a..7868659c63 100644 --- a/src/declarative/debugger/qv8profilerservice_p.h +++ b/src/declarative/debugger/qv8profilerservice_p.h @@ -84,7 +84,8 @@ public: enum MessageType { V8Entry, V8Complete, - V8Snapshot, + V8SnapshotChunk, + V8SnapshotComplete, V8MaximumMessage }; |