]> git.cworth.org Git - apitrace/commitdiff
Add code to report parsing/scanning progress.
authorZack Rusin <zack@kde.org>
Sun, 4 Sep 2011 20:14:22 +0000 (16:14 -0400)
committerZack Rusin <zack@kde.org>
Sun, 4 Sep 2011 20:14:22 +0000 (16:14 -0400)
trace_file.cpp
trace_file.hpp
trace_loader.cpp
trace_parser.hpp
trace_snappyfile.cpp
trace_snappyfile.hpp

index 91114b3290b0a56c09e46b125e59fc836d693ade..517e2219cf70fdd8924d9844dca7a0e14aaf9036 100644 (file)
@@ -113,6 +113,12 @@ bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode)
 {
     m_gzFile = gzopen(filename.c_str(),
                       (mode == File::Write) ? "wb" : "rb");
+
+    if (mode == File::Read && m_gzFile) {
+        m_endOffset = gzseek(m_gzFile, 0, SEEK_END);
+        gzrewind(m_gzFile);
+    }
+
     return m_gzFile != NULL;
 }
 
@@ -154,3 +160,8 @@ bool ZLibFile::rawSkip(size_t)
 {
     return false;
 }
+
+int ZLibFile::rawPercentRead()
+{
+    return 100 * (gztell(m_gzFile) / m_endOffset);
+}
index 6fdb9c3336fa9305b79ed2258eea7470d2040372..f6e77ae8b69802c88f96b8b31b48d6f3cd2c013c 100644 (file)
@@ -68,6 +68,7 @@ public:
     void flush(void);
     int getc();
     bool skip(size_t length);
+    int percentRead();
 
     virtual bool supportsOffsets() const = 0;
     virtual File::Offset currentOffset();
@@ -80,6 +81,7 @@ protected:
     virtual void rawClose() = 0;
     virtual void rawFlush() = 0;
     virtual bool rawSkip(size_t length) = 0;
+    virtual int rawPercentRead() = 0;
 
 protected:
     std::string m_filename;
@@ -129,6 +131,14 @@ inline bool File::read(void *buffer, size_t length)
     return rawRead(buffer, length);
 }
 
+inline int File::percentRead()
+{
+    if (!m_isOpened || m_mode != File::Read) {
+        return 0;
+    }
+    return rawPercentRead();
+}
+
 inline void File::close()
 {
     if (m_isOpened) {
@@ -176,8 +186,10 @@ protected:
     virtual void rawClose();
     virtual void rawFlush();
     virtual bool rawSkip(size_t length);
+    virtual int  rawPercentRead();
 private:
     void *m_gzFile;
+    double m_endOffset;
 };
 
 inline bool
index 5c287a92a621d52bf9643fa510d9a5f66892ae51..f91e09b00ef5ffe8a9575314c4848690ee7158a3 100644 (file)
@@ -56,6 +56,7 @@ bool Loader::open(const char *filename)
     int numOfFrames = 0;
     int numOfCalls = 0;
     unsigned callNum = 0;
+    int lastPercentReport = 0;
 
     startOffset = m_parser.currentOffset();
     callNum = m_parser.currentCallNumber();
@@ -72,6 +73,12 @@ bool Loader::open(const char *filename)
             m_frameOffsets[numOfFrames] = frameOffset;
             ++numOfFrames;
 
+            if (m_parser.percentRead() - lastPercentReport >= 5) {
+                std::cerr << "\tPercent scanned = "
+                          << m_parser.percentRead()
+                          << "..."<<std::endl;
+                lastPercentReport = m_parser.percentRead();
+            }
             startOffset = endOffset;
             callNum = m_parser.currentCallNumber();
             numOfCalls = 0;
index 1f87b6fed185c8959dd112a2aa4d2c3dce99f702..f50cf9aebe94c3e8b79cb06c83a7b196feb180c7 100644 (file)
@@ -112,6 +112,11 @@ public:
         next_call_no = num;
     }
 
+    int percentRead()
+    {
+        return file->percentRead();
+    }
+
     Call *scan_call();
 
 protected:
index 1794a829c6635c2a57a11b33e446958dc908fe54..4dbe42dc364264a8db0e717a1af17681b9af271e 100644 (file)
@@ -93,6 +93,10 @@ bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
 
     //read in the initial buffer if we're reading
     if (m_stream.is_open() && mode == File::Read) {
+        m_stream.seekg(0, std::ios::end);
+        m_endPos = m_stream.tellg();
+        m_stream.seekg(0, std::ios::beg);
+
         // read the snappy file identifier
         unsigned char byte1, byte2;
         m_stream >> byte1;
@@ -327,3 +331,8 @@ bool SnappyFile::rawSkip(size_t length)
 
     return true;
 }
+
+int SnappyFile::rawPercentRead()
+{
+    return 100 * (double(m_stream.tellg()) / double(m_endPos));
+}
index 469f29e13cbe561cd5416da8bafd3e2487bd3c61..33159ec73cc81eb4413158de707940a2c64c5211 100644 (file)
@@ -63,6 +63,7 @@ protected:
     virtual void rawClose();
     virtual void rawFlush();
     virtual bool rawSkip(size_t length);
+    virtual int rawPercentRead();
 
 private:
     inline size_t usedCacheSize() const
@@ -97,6 +98,7 @@ private:
     char *m_compressedCache;
 
     File::Offset m_currentOffset;
+    std::streampos m_endPos;
 };
 
 }