]> git.cworth.org Git - apitrace/commitdiff
Reduce the memory usage by ~2gb on a 2.7 million calls trace
authorZack Rusin <zack@kde.org>
Sat, 16 Apr 2011 15:56:19 +0000 (11:56 -0400)
committerZack Rusin <zack@kde.org>
Sat, 16 Apr 2011 15:56:19 +0000 (11:56 -0400)
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!)

gui/apitracecall.cpp
gui/apitracecall.h

index 32e78b5d3b928aae7eef01904eb948610e93051b..464180705d9d344a70a86453c721b0c9d5f6431d 100644 (file)
@@ -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("<span style=\"font-weight:bold\">%1</span>(").arg(m_name);
+    QString richText = QString::fromLatin1(
+        "<span style=\"font-weight:bold\">%1</span>(").arg(m_name);
     for (int i = 0; i < m_argNames.count(); ++i) {
         richText += QLatin1String("<span style=\"color:#0000ff\">");
         QString argText = apiVariantToString(m_argValues[i]);
@@ -275,13 +276,14 @@ QStaticText ApiTraceCall::staticText() const
         richText += QLatin1String("</span>");
     }
 
-    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("<span style=\"font-weight:bold\">Frame %1</span>").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<Trace::Blob*>(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;
+}
+
index 1cabceca33d4a52bb7af3d76be099ea6ed5fe509..e399bc62f8d8809a337ed11e40a4fe340e82fa57 100644 (file)
@@ -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*);