diff options
author | Ulf Hermann <[email protected]> | 2014-06-12 14:33:05 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-06-12 18:13:45 +0200 |
commit | 4d68155848723a863e59d2ce99142b56c75ab3c6 (patch) | |
tree | 9471400f4f33c8aaa160f311874027f56606bc35 /src/qml/jsruntime | |
parent | 841f3e6ff78871e5d7fc90666f12756210c7435e (diff) |
Properly initialize heap profiler when starting profiling
Change-Id: Ia994464b2150dc9a9185280ae0e2f8c615393310
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4mm.cpp | 26 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4mm_p.h | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4profiling.cpp | 19 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4profiling_p.h | 3 |
5 files changed, 45 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 1eab157ecc..52a89eba51 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -453,7 +453,7 @@ void ExecutionEngine::enableDebugger() void ExecutionEngine::enableProfiler() { Q_ASSERT(!profiler); - profiler = new QV4::Profiling::Profiler(); + profiler = new QV4::Profiling::Profiler(this); } void ExecutionEngine::initRootContext() diff --git a/src/qml/jsruntime/qv4mm.cpp b/src/qml/jsruntime/qv4mm.cpp index 472fa4071a..f3374d48e6 100644 --- a/src/qml/jsruntime/qv4mm.cpp +++ b/src/qml/jsruntime/qv4mm.cpp @@ -451,9 +451,7 @@ void MemoryManager::runGC() mark(); sweep(); } else { - int totalMem = 0; - for (int i = 0; i < m_d->heapChunks.size(); ++i) - totalMem += m_d->heapChunks.at(i).memory.size(); + int totalMem = getAllocatedMem(); QTime t; t.start(); @@ -479,10 +477,10 @@ void MemoryManager::runGC() m_d->totalAlloc = 0; } -uint MemoryManager::getUsedMem() +size_t MemoryManager::getUsedMem() const { - uint usedMem = 0; - for (QVector<Data::Chunk>::iterator i = m_d->heapChunks.begin(), ei = m_d->heapChunks.end(); i != ei; ++i) { + size_t usedMem = 0; + for (QVector<Data::Chunk>::const_iterator i = m_d->heapChunks.begin(), ei = m_d->heapChunks.end(); i != ei; ++i) { char *chunkStart = reinterpret_cast<char *>(i->memory.base()); char *chunkEnd = chunkStart + i->memory.size() - i->chunkSize; for (char *chunk = chunkStart; chunk <= chunkEnd; chunk += i->chunkSize) { @@ -495,6 +493,22 @@ uint MemoryManager::getUsedMem() return usedMem; } +size_t MemoryManager::getAllocatedMem() const +{ + size_t total = 0; + for (int i = 0; i < m_d->heapChunks.size(); ++i) + total += m_d->heapChunks.at(i).memory.size(); + return total; +} + +size_t MemoryManager::getLargeItemsMem() const +{ + size_t total = 0; + for (const Data::LargeItem *i = m_d->largeItems; i != 0; i = i->next) + total += i->size; + return total; +} + MemoryManager::~MemoryManager() { PersistentValuePrivate *persistent = m_persistentValues; diff --git a/src/qml/jsruntime/qv4mm_p.h b/src/qml/jsruntime/qv4mm_p.h index 47020c12f0..bd41e94cfc 100644 --- a/src/qml/jsruntime/qv4mm_p.h +++ b/src/qml/jsruntime/qv4mm_p.h @@ -113,6 +113,10 @@ public: void registerDeletable(GCDeletable *d); + size_t getUsedMem() const; + size_t getAllocatedMem() const; + size_t getLargeItemsMem() const; + protected: /// expects size to be aligned // TODO: try to inline @@ -129,7 +133,6 @@ private: void mark(); void sweep(bool lastSweep = false); void sweep(char *chunkStart, std::size_t chunkSize, size_t size); - uint getUsedMem(); protected: QScopedPointer<Data> m_d; diff --git a/src/qml/jsruntime/qv4profiling.cpp b/src/qml/jsruntime/qv4profiling.cpp index f1c70c6b33..b70e9de1a0 100644 --- a/src/qml/jsruntime/qv4profiling.cpp +++ b/src/qml/jsruntime/qv4profiling.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qv4profiling_p.h" +#include "qv4mm_p.h" QT_BEGIN_NAMESPACE @@ -60,7 +61,7 @@ FunctionCallProperties FunctionCall::resolve() const } -Profiler::Profiler() : enabled(false) +Profiler::Profiler(QV4::ExecutionEngine *engine) : enabled(false), m_engine(engine) { static int metatype = qRegisterMetaType<QList<QV4::Profiling::FunctionCallProperties> >(); static int metatype2 = qRegisterMetaType<QList<QV4::Profiling::MemoryAllocationProperties> >(); @@ -96,6 +97,22 @@ void Profiler::startProfiling() { if (!enabled) { m_data.clear(); + m_memory_data.clear(); + + qint64 timestamp = m_timer.nsecsElapsed(); + MemoryAllocationProperties heap = {timestamp, + (qint64)m_engine->memoryManager->getAllocatedMem(), + HeapPage}; + m_memory_data.append(heap); + MemoryAllocationProperties small = {timestamp, + (qint64)m_engine->memoryManager->getUsedMem(), + SmallItem}; + m_memory_data.append(small); + MemoryAllocationProperties large = {timestamp, + (qint64)m_engine->memoryManager->getLargeItemsMem(), + LargeItem}; + m_memory_data.append(large); + enabled = true; } } diff --git a/src/qml/jsruntime/qv4profiling_p.h b/src/qml/jsruntime/qv4profiling_p.h index cafe36861d..525e23f0de 100644 --- a/src/qml/jsruntime/qv4profiling_p.h +++ b/src/qml/jsruntime/qv4profiling_p.h @@ -130,7 +130,7 @@ class Q_QML_EXPORT Profiler : public QObject { Q_OBJECT Q_DISABLE_COPY(Profiler) public: - Profiler(); + Profiler(QV4::ExecutionEngine *engine); size_t trackAlloc(size_t size, MemoryType type) { @@ -159,6 +159,7 @@ signals: const QList<QV4::Profiling::MemoryAllocationProperties> &); private: + QV4::ExecutionEngine *m_engine; QElapsedTimer m_timer; QVector<FunctionCall> m_data; QList<MemoryAllocationProperties> m_memory_data; |