[Libreoffice-commits] online.git: loolwsd/TraceFile.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Aug 8 03:50:18 UTC 2016
loolwsd/TraceFile.hpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 57 insertions(+), 3 deletions(-)
New commits:
commit 4f57e43fdc79f87a6ba4c827dd78ed9e08177d7c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Jul 31 19:32:37 2016 -0400
loolstress: load trace file records
Change-Id: Id0f76c1848863f5910d4492b2d37c6b18d1b3871
Reviewed-on: https://gerrit.libreoffice.org/27961
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 cf51981..41f316d 100644
--- a/loolwsd/TraceFile.hpp
+++ b/loolwsd/TraceFile.hpp
@@ -61,10 +61,16 @@ class TraceFileRecord
public:
enum class Direction
{
+ Invalid,
Incoming,
Outgoing
};
+ TraceFileRecord() :
+ Dir(Direction::Invalid)
+ {
+ }
+
Direction Dir;
unsigned TimestampNs;
std::string Payload;
@@ -75,12 +81,43 @@ class TraceFileReader
public:
TraceFileReader(const std::string& path) :
_epochStart(Poco::Timestamp().epochMicroseconds()),
- _stream(path)
+ _stream(path),
+ _indexIn(-1),
+ _indexOut(-1)
{
+ readFile();
}
+ TraceFileRecord getNextRecord(const TraceFileRecord::Direction dir)
+ {
+ if (dir == TraceFileRecord::Direction::Incoming)
+ {
+ if (_indexIn < _records.size())
+ {
+ const TraceFileRecord rec = _records[_indexIn];
+ _indexIn = advance(_indexIn, dir);
+ return rec;
+ }
+ }
+ else
+ {
+ if (_indexOut < _records.size())
+ {
+ const TraceFileRecord rec = _records[_indexOut];
+ _indexOut = advance(_indexOut, dir);
+ return rec;
+ }
+ }
+
+ // Invalid.
+ return TraceFileRecord();
+ }
+
+private:
void readFile()
{
+ _records.clear();
+
std::string line;
while (std::getline(_stream, line) && !line.empty())
{
@@ -94,10 +131,12 @@ public:
_records.push_back(rec);
}
}
+
+ _indexIn = advance(-1, TraceFileRecord::Direction::Incoming);
+ _indexOut = advance(-1, TraceFileRecord::Direction::Outgoing);
}
-private:
- std::vector<std::string> split(const std::string& s, const char delim)
+ std::vector<std::string> split(const std::string& s, const char delim) const
{
std::stringstream ss(s);
std::string item;
@@ -113,10 +152,25 @@ private:
return v;
}
+ unsigned advance(unsigned index, const TraceFileRecord::Direction dir)
+ {
+ while (++index < _records.size())
+ {
+ if (_records[index].Dir == dir)
+ {
+ break;
+ }
+ }
+
+ return index;
+ }
+
private:
const Poco::Int64 _epochStart;
std::ifstream _stream;
std::vector<TraceFileRecord> _records;
+ unsigned _indexIn;
+ unsigned _indexOut;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list