]> git.cworth.org Git - apitrace/commitdiff
Fix memory usage in the on-demand-loading.
authorZack Rusin <zack@kde.org>
Thu, 1 Sep 2011 15:33:51 +0000 (11:33 -0400)
committerZack Rusin <zack@kde.org>
Thu, 1 Sep 2011 15:33:51 +0000 (11:33 -0400)
just store offsets to the first call in a frame in the loader

trace_loader.cpp
trace_loader.hpp
trace_parser.cpp
trace_parser.hpp

index 254d2cb0af61fdfe1b68692fb99e54fcdd50741b..228553b242d3fe4cc4cfe8f0298a62490512b3a8 100644 (file)
@@ -30,13 +30,14 @@ int Loader::numberOfFrames() const
     return m_frameOffsets.size();
 }
 
-int Loader::numberOfCallsInFrame(int frameIdx)
+int Loader::numberOfCallsInFrame(int frameIdx) const
 {
     if (frameIdx > m_frameOffsets.size()) {
         return 0;
     }
-
-    return m_frameOffsets[frameIdx].numberOfCalls;
+    FrameOffsets::const_iterator itr =
+        m_frameOffsets.find(frameIdx);
+    return itr->second.numberOfCalls;
 }
 
 bool Loader::open(const char *filename)
@@ -55,8 +56,10 @@ bool Loader::open(const char *filename)
     File::Offset startOffset;
     int numOfFrames = 0;
     int numOfCalls = 0;
+    unsigned callNum = 0;
 
     startOffset = m_parser.currentOffset();
+    callNum = m_parser.currentCallNumber();
 
     while ((call = m_parser.parse_call())) {
 
@@ -64,13 +67,15 @@ bool Loader::open(const char *filename)
 
         if (isCallAFrameMarker(call)) {
             File::Offset endOffset = m_parser.currentOffset();
-            FrameOffset frameOffset(startOffset, endOffset);
-
+            FrameOffset frameOffset(startOffset);
             frameOffset.numberOfCalls = numOfCalls;
+            frameOffset.callNumber = callNum;
+
             m_frameOffsets[numOfFrames] = frameOffset;
             ++numOfFrames;
 
             startOffset = endOffset;
+            callNum = m_parser.currentCallNumber();
             numOfCalls = 0;
         }
         //call->dump(std::cout, color);
@@ -111,8 +116,10 @@ std::vector<Trace::Call *> Loader::frame(int idx)
 {
     int numOfCalls = numberOfCallsInFrame(idx);
     if (numOfCalls) {
+        const FrameOffset &frameOffset = m_frameOffsets[idx];
         std::vector<Trace::Call*> calls(numOfCalls);
-        m_parser.setCurrentOffset(m_frameOffsets[idx].start);
+        m_parser.setCurrentOffset(frameOffset.start);
+        m_parser.setCurrentCallNumber(frameOffset.callNumber);
 
         Trace::Call *call;
         int parsedCalls = 0;
index 7b746b951ffdd849e23ff6bc2f667a3131d2fe72..26567000323f525baff7928fe5e4b552d429f43f 100644 (file)
@@ -30,7 +30,7 @@ public:
     void setFrameMarker(Loader::FrameMarker marker);
 
     int numberOfFrames() const;
-    int numberOfCallsInFrame(int frameIdx);
+    int numberOfCallsInFrame(int frameIdx) const;
 
     bool open(const char *filename);
     void close();
@@ -42,16 +42,14 @@ private:
         FrameOffset()
             : numberOfCalls(0)
         {}
-        FrameOffset(const File::Offset &s,
-                    const File::Offset &e)
+        FrameOffset(const File::Offset &s)
             : start(s),
-              end(e),
               numberOfCalls(0)
         {}
 
         File::Offset start;
-        File::Offset end;
         int numberOfCalls;
+        unsigned callNumber;
     };
     bool isCallAFrameMarker(const Trace::Call *call) const;
 
@@ -62,7 +60,8 @@ private:
     std::map<int, Trace::Frame*> m_frameCache;
     std::queue<Trace::Frame*> m_loadedFrames;
 
-    std::map<int, FrameOffset> m_frameOffsets;
+    typedef std::map<int, FrameOffset> FrameOffsets;
+    FrameOffsets m_frameOffsets;
 
     Trace::File *file;
 };
index abed4f51f37cab0543e0183b3fd97655ec9043a2..66d56a66bbbb2abf2d524665f9f4e88e1f894071 100644 (file)
@@ -174,13 +174,8 @@ void Parser::parse_enter(void) {
 
     Call *call = new Call(sig);
 
-    if (hasCallBeenParsed(offset)) {
-        call->no = callNumForOffset(offset);
-    } else {
-        call->no = next_call_no++;
-        m_callNumOffsets.insert(
-                    std::pair<File::Offset, unsigned>(offset, call->no));
-    }
+
+    call->no = next_call_no++;
 
     if (parse_call_details(call)) {
         calls.push_back(call);
@@ -532,16 +527,4 @@ inline bool Parser::bitmaskWithSignature(const File::Offset &offset) const
     return m_bitmaskSigOffsets.find(offset) != m_bitmaskSigOffsets.end();
 }
 
-bool Parser::hasCallBeenParsed(const File::Offset &offset) const
-{
-    return m_callNumOffsets.find(offset) != m_callNumOffsets.end();
-}
-
-unsigned Parser::callNumForOffset(const File::Offset &offset) const
-{
-    CallNumOffsets::const_iterator itr = m_callNumOffsets.find(offset);
-    assert(itr != m_callNumOffsets.end());
-    return itr->second;
-}
-
 } /* namespace Trace */
index a9f11f78949213e00d0dca9b8623c6330f63d489..f340da0e72613573aa5ea6d61e0e029779672e29 100644 (file)
@@ -84,7 +84,7 @@ public:
 
     bool supportsOffsets() const
     {
-        return file-supportsOffsets();
+        return file->supportsOffsets();
     }
 
     File::Offset currentOffset()
@@ -101,8 +101,16 @@ public:
     bool structWithSignature(const File::Offset &offset) const;
     bool enumWithSignature(const File::Offset &offset) const;
     bool bitmaskWithSignature(const File::Offset &offset) const;
-    bool hasCallBeenParsed(const File::Offset &offset) const;
-    unsigned callNumForOffset(const File::Offset &offset) const;
+
+    unsigned currentCallNumber() const
+    {
+        return next_call_no;
+    }
+
+    void setCurrentCallNumber(unsigned num)
+    {
+        next_call_no = num;
+    }
 
 protected:
     void parse_enter(void);