[Libreoffice-commits] online.git: loolwsd/LOOLStress.cpp loolwsd/TraceFile.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Aug 8 03:49:56 UTC 2016
loolwsd/LOOLStress.cpp | 4 ++-
loolwsd/TraceFile.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 56 insertions(+), 3 deletions(-)
New commits:
commit 4d7c2e4002b51d4a1347a5178103612df2985ddc
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Jul 31 18:06:01 2016 -0400
loolstress: parse trace file
Change-Id: I04964744a74d3a025e310d7ec52f5d1f5b6d100d
Reviewed-on: https://gerrit.libreoffice.org/27960
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLStress.cpp b/loolwsd/LOOLStress.cpp
index 6bda492..ef06135 100644
--- a/loolwsd/LOOLStress.cpp
+++ b/loolwsd/LOOLStress.cpp
@@ -79,12 +79,14 @@ class Worker: public Runnable
public:
Worker(Stress& app, const std::string& traceFilePath) :
- _app(app), _traceFilePath(traceFilePath)
+ _app(app), _traceFile(traceFilePath)
{
}
void run() override
{
+ _traceFile.readFile();
+
std::cerr << "Connecting to server: " << _app._serverURI << "\n";
Poco::URI uri(_app._serverURI);
diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp
index 73713e6..cf51981 100644
--- a/loolwsd/TraceFile.hpp
+++ b/loolwsd/TraceFile.hpp
@@ -9,7 +9,9 @@
#include <fstream>
#include <mutex>
+#include <sstream>
#include <string>
+#include <vector>
/// Dumps commands and notification trace.
class TraceFileWriter
@@ -54,18 +56,67 @@ private:
std::mutex _mutex;
};
+class TraceFileRecord
+{
+public:
+ enum class Direction
+ {
+ Incoming,
+ Outgoing
+ };
+
+ Direction Dir;
+ unsigned TimestampNs;
+ std::string Payload;
+};
+
class TraceFileReader
{
public:
TraceFileReader(const std::string& path) :
_epochStart(Poco::Timestamp().epochMicroseconds()),
- _stream(path, std::ios::in)
+ _stream(path)
{
}
+ void readFile()
+ {
+ std::string line;
+ while (std::getline(_stream, line) && !line.empty())
+ {
+ const auto v = split(line, line[0]);
+ if (v.size() == 2)
+ {
+ TraceFileRecord rec;
+ rec.Dir = (line[0] == '>' ? TraceFileRecord::Direction::Incoming : TraceFileRecord::Direction::Outgoing);
+ rec.TimestampNs = std::atoi(v[0].c_str());
+ rec.Payload = v[1];
+ _records.push_back(rec);
+ }
+ }
+ }
+
+private:
+ std::vector<std::string> split(const std::string& s, const char delim)
+ {
+ std::stringstream ss(s);
+ std::string item;
+ std::vector<std::string> v;
+ while (std::getline(ss, item, delim))
+ {
+ if (!item.empty())
+ {
+ v.push_back(item);
+ }
+ }
+
+ return v;
+ }
+
private:
const Poco::Int64 _epochStart;
- std::fstream _stream;
+ std::ifstream _stream;
+ std::vector<TraceFileRecord> _records;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list