[Libreoffice-commits] online.git: loolwsd/TraceFile.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Aug 22 04:20:53 UTC 2016
loolwsd/TraceFile.hpp | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
New commits:
commit 3469fd95377456fdd2ff7d3a71d4f74f898021e9
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Wed Aug 17 19:41:58 2016 -0400
loolstress: seemingly support plain text and .gz trace files
Change-Id: I6eb6c8f0b6476c8d0af7bf90ccf15712df0dbbd5
Reviewed-on: https://gerrit.libreoffice.org/28285
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp
index 8b25252..576121f 100644
--- a/loolwsd/TraceFile.hpp
+++ b/loolwsd/TraceFile.hpp
@@ -14,6 +14,7 @@
#include <vector>
#include <Poco/DeflatingStream.h>
+#include <Poco/InflatingStream.h>
#include "Util.hpp"
@@ -135,8 +136,10 @@ class TraceFileReader
{
public:
TraceFileReader(const std::string& path) :
+ _compressed(path.size() > 2 && path.substr(path.size() - 2) == "gz"),
_epochStart(0),
- _stream(path),
+ _stream(path, _compressed ? std::ios::binary : std::ios::in),
+ _inflater(_stream, Poco::InflatingStreamBuf::STREAM_GZIP),
_index(0),
_indexIn(-1),
_indexOut(-1)
@@ -144,6 +147,11 @@ public:
readFile();
}
+ ~TraceFileReader()
+ {
+ _stream.close();
+ }
+
Poco::Int64 getEpoch() const { return _epochStart; }
TraceFileRecord getNextRecord()
@@ -188,8 +196,22 @@ private:
_records.clear();
std::string line;
- while (std::getline(_stream, line) && !line.empty())
+ for (;;)
{
+ if (_compressed)
+ {
+ std::getline(_inflater, line);
+ }
+ else
+ {
+ std::getline(_stream, line);
+ }
+
+ if (line.empty())
+ {
+ break;
+ }
+
const auto v = split(line, line[0]);
if (v.size() == 4)
{
@@ -253,8 +275,10 @@ private:
}
private:
+ const bool _compressed;
Poco::Int64 _epochStart;
std::ifstream _stream;
+ Poco::InflatingInputStream _inflater;
std::vector<TraceFileRecord> _records;
unsigned _index;
unsigned _indexIn;
More information about the Libreoffice-commits
mailing list