From 2b1bd4f71daba2570525eb63aa7b3b66e27259a7 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Sun, 4 Sep 2011 16:14:22 -0400 Subject: [PATCH] Add code to report parsing/scanning progress. --- trace_file.cpp | 11 +++++++++++ trace_file.hpp | 12 ++++++++++++ trace_loader.cpp | 7 +++++++ trace_parser.hpp | 5 +++++ trace_snappyfile.cpp | 9 +++++++++ trace_snappyfile.hpp | 2 ++ 6 files changed, 46 insertions(+) diff --git a/trace_file.cpp b/trace_file.cpp index 91114b3..517e221 100644 --- a/trace_file.cpp +++ b/trace_file.cpp @@ -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); +} diff --git a/trace_file.hpp b/trace_file.hpp index 6fdb9c3..f6e77ae 100644 --- a/trace_file.hpp +++ b/trace_file.hpp @@ -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 diff --git a/trace_loader.cpp b/trace_loader.cpp index 5c287a9..f91e09b 100644 --- a/trace_loader.cpp +++ b/trace_loader.cpp @@ -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() + << "..."<percentRead(); + } + Call *scan_call(); protected: diff --git a/trace_snappyfile.cpp b/trace_snappyfile.cpp index 1794a82..4dbe42d 100644 --- a/trace_snappyfile.cpp +++ b/trace_snappyfile.cpp @@ -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)); +} diff --git a/trace_snappyfile.hpp b/trace_snappyfile.hpp index 469f29e..33159ec 100644 --- a/trace_snappyfile.hpp +++ b/trace_snappyfile.hpp @@ -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; }; } -- 2.45.2