From: Zack Rusin Date: Sat, 16 Apr 2011 15:56:19 +0000 (-0400) Subject: Reduce the memory usage by ~2gb on a 2.7 million calls trace X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=53484b27fe6e64dde4b27016869ef4c6c5e8c27f;p=apitrace Reduce the memory usage by ~2gb on a 2.7 million calls trace delete the parsed data from blobs and delay the creation of the static text until the item is actually shown (i.e. don't create glyph caches for items that will never be displayed!) --- diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index 32e78b5..4641807 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -242,10 +242,11 @@ void ApiArray::init(const Trace::Array *arr) QStaticText ApiTraceCall::staticText() const { - if (!m_staticText.text().isEmpty()) - return m_staticText; + if (m_staticText && !m_staticText->text().isEmpty()) + return *m_staticText; - QString richText = QString::fromLatin1("%1(").arg(m_name); + QString richText = QString::fromLatin1( + "%1(").arg(m_name); for (int i = 0; i < m_argNames.count(); ++i) { richText += QLatin1String(""); QString argText = apiVariantToString(m_argValues[i]); @@ -275,13 +276,14 @@ QStaticText ApiTraceCall::staticText() const richText += QLatin1String(""); } - m_staticText.setText(richText); + if (!m_staticText) + m_staticText = new QStaticText(richText); QTextOption opt; opt.setWrapMode(QTextOption::NoWrap); - m_staticText.setTextOption(opt); - m_staticText.prepare(); + m_staticText->setTextOption(opt); + m_staticText->prepare(); - return m_staticText; + return *m_staticText; } QString ApiTraceCall::toHtml() const @@ -352,19 +354,21 @@ QString ApiTraceCall::filterText() const QStaticText ApiTraceFrame::staticText() const { - if (!m_staticText.text().isEmpty()) - return m_staticText; + if (m_staticText && !m_staticText->text().isEmpty()) + return *m_staticText; QString richText = QString::fromLatin1("Frame %1").arg(number); - m_staticText.setText(richText); + if (!m_staticText) + m_staticText = new QStaticText(richText); + QTextOption opt; opt.setWrapMode(QTextOption::NoWrap); - m_staticText.setTextOption(opt); - m_staticText.prepare(); + m_staticText->setTextOption(opt); + m_staticText->prepare(); - return m_staticText; + return *m_staticText; } int ApiTraceCall::numChildren() const @@ -390,12 +394,14 @@ ApiTraceCall::ApiTraceCall() } ApiTraceEvent::ApiTraceEvent() - : m_type(ApiTraceEvent::None) + : m_type(ApiTraceEvent::None), + m_staticText(0) { } ApiTraceEvent::ApiTraceEvent(Type t) - : m_type(t) + : m_type(t), + m_staticText(0) { } @@ -594,6 +600,19 @@ ApiTraceCall::ApiTraceCall(const Trace::Call *call) VariantVisitor argVisitor; call->args[i]->visit(argVisitor); m_argValues += argVisitor.variant(); + + //XXX + //FIXME: this is a nasty hack. Trace::Blob's can't + // delete the contents in the destructor because + // the data is being used by other calls. we should + // use something like Boost's shared_ptr or + // Qt's QSharedPointer to handle it. + Trace::Blob *b = dynamic_cast(call->args[i]); + if (b && b->blob()) { + char *buf = (char*)b->blob(); + delete [] buf; + } + } } @@ -612,3 +631,8 @@ ApiTraceFrame * ApiTraceCall::parentFrame()const return m_parentFrame; } +ApiTraceEvent::~ApiTraceEvent() +{ + delete m_staticText; +} + diff --git a/gui/apitracecall.h b/gui/apitracecall.h index 1cabcec..e399bc6 100644 --- a/gui/apitracecall.h +++ b/gui/apitracecall.h @@ -135,6 +135,7 @@ public: public: ApiTraceEvent(); ApiTraceEvent(Type t); + virtual ~ApiTraceEvent(); Type type() const { return m_type; } @@ -148,6 +149,8 @@ public: protected: Type m_type; ApiTraceState m_state; + + mutable QStaticText *m_staticText; }; Q_DECLARE_METATYPE(ApiTraceEvent*); @@ -185,7 +188,6 @@ private: mutable QString m_richText; mutable QString m_filterText; - mutable QStaticText m_staticText; mutable bool m_hasBinaryData; mutable int m_binaryDataIndex; }; @@ -200,8 +202,6 @@ public: int numChildren() const; QStaticText staticText() const; -private: - mutable QStaticText m_staticText; }; Q_DECLARE_METATYPE(ApiTraceFrame*);