[Libreoffice-commits] online.git: loolwsd/LOOLStress.cpp loolwsd/TraceFile.hpp
loolwsd/LOOLStress.cpp | 159 ++--- loolwsd/TraceFile.hpp | 14 ++-- 2 files changed, 94 insertions(+), 79 deletions(-) New commits: commit f9ec1bade3325fc4c3505b60ef63665d32e38739 Author: Ashod NakashianDate: Thu Aug 4 12:17:22 2016 -0400 loolstress: time-accurate replay Change-Id: I1aff521f042c61916ef6ddfc50c2fe06c41b29ee Reviewed-on: https://gerrit.libreoffice.org/27968 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLStress.cpp b/loolwsd/LOOLStress.cpp index f60aa55..f042901 100644 --- a/loolwsd/LOOLStress.cpp +++ b/loolwsd/LOOLStress.cpp @@ -124,108 +124,119 @@ public: void run() override { -const auto epochStart(std::chrono::steady_clock::now()); try { -for (;;) +doRun(); +} +catch (const Poco::Exception ) +{ +std::cerr << "Error: " << e.name() << ' ' + << e.message() << std::endl; +} +} + +private: + +void doRun() +{ +auto epochFile(_traceFile.getEpoch()); +auto epochCurrent(std::chrono::steady_clock::now()); +for (;;) +{ +const auto rec = _traceFile.getNextRecord(); +if (rec.Dir == TraceFileRecord::Direction::Invalid) { -const auto rec = _traceFile.getNextRecord(); -if (rec.Dir == TraceFileRecord::Direction::Invalid) -{ -// End of trace file. -break; -} +// End of trace file. +break; +} -const auto delta = (epochStart - std::chrono::steady_clock::now()); -const auto delay = rec.TimestampNs - std::chrono::duration_cast(delta).count(); -if (delay > 0) -{ - std::this_thread::sleep_for(std::chrono::microseconds(delay)); -} +const auto deltaCurrent = std::chrono::duration_cast(std::chrono::steady_clock::now() - epochCurrent).count(); +const auto deltaFile = rec.TimestampNs - epochFile; +const auto delay = deltaFile - deltaCurrent; +if (delay > 0) +{ +std::this_thread::sleep_for(std::chrono::microseconds(delay)); +} -if (rec.Dir == TraceFileRecord::Direction::Event) -{ -// Meta info about about an event. -static const std::string NewSession("NewSession: "); -static const std::string EndSession("EndSession: "); +if (rec.Dir == TraceFileRecord::Direction::Event) +{ +// Meta info about about an event. +static const std::string NewSession("NewSession: "); +static const std::string EndSession("EndSession: "); -if (rec.Payload.find(NewSession) == 0) +if (rec.Payload.find(NewSession) == 0) +{ +const auto& uri = rec.Payload.substr(NewSession.size()); +auto it = Sessions.find(uri); +if (it != Sessions.end()) { -const auto& uri = rec.Payload.substr(NewSession.size()); -auto it = Sessions.find(uri); -if (it != Sessions.end()) +// Add a new session. +if (it->second.find(rec.SessionId) != it->second.end()) { -// Add a new session. -if (it->second.find(rec.SessionId) != it->second.end()) -{ -std::cerr << "ERROR: session [" << rec.SessionId << "] already exists on doc [" << uri << "]\n"; -} -else -{ -it->second.emplace(rec.SessionId, Connection::create(_app._serverURI, uri, rec.SessionId)); -} +std::cerr << "ERROR: session [" << rec.SessionId << "] already exists on doc [" << uri << "]\n"; } else { -std::cerr << "New Document: " << uri << "\n"; -ChildToDoc.emplace(rec.Pid, uri); -Sessions[uri].emplace(rec.SessionId, Connection::create(_app._serverURI, uri, rec.SessionId)); +it->second.emplace(rec.SessionId, Connection::create(_app._serverURI, uri, rec.SessionId)); } } -else if (rec.Payload.find(EndSession) == 0) +
[Libreoffice-commits] online.git: loolwsd/LOOLStress.cpp loolwsd/TraceFile.hpp
loolwsd/LOOLStress.cpp |4 ++- loolwsd/TraceFile.hpp | 55 +++-- 2 files changed, 56 insertions(+), 3 deletions(-) New commits: commit 4d7c2e4002b51d4a1347a5178103612df2985ddc Author: Ashod NakashianDate: 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 Tested-by: Ashod Nakashian 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 #include +#include #include +#include /// 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 split(const std::string& s, const char delim) +{ +std::stringstream ss(s); +std::string item; +std::vector 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 _records; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLStress.cpp loolwsd/TraceFile.hpp
loolwsd/LOOLStress.cpp | 14 +- loolwsd/TraceFile.hpp | 17 - 2 files changed, 21 insertions(+), 10 deletions(-) New commits: commit b394ad89d87ef207f6b26d96134b345a8cf07112 Author: Ashod NakashianDate: Sun Jul 31 14:17:52 2016 -0400 loolstress: TraceFileReader class added Change-Id: I81d508bb794ca56f647d0eb5b9dd27585100fe07 Reviewed-on: https://gerrit.libreoffice.org/27959 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLStress.cpp b/loolwsd/LOOLStress.cpp index 6232128..6bda492 100644 --- a/loolwsd/LOOLStress.cpp +++ b/loolwsd/LOOLStress.cpp @@ -16,14 +16,9 @@ #include #include -#include #include -#include -#include #include #include -#include -#include #include #include #include @@ -39,14 +34,15 @@ #include #include +#include +#include + #include "Common.hpp" #include "LOOLProtocol.hpp" +#include "TraceFile.hpp" #include "Util.hpp" #include "test/helpers.hpp" -#include -#include - /// Stress testing and performance/scalability benchmarking tool. class Stress: public Poco::Util::Application @@ -115,7 +111,7 @@ public: private: Stress& _app; -std::string _traceFilePath; +TraceFileReader _traceFile; }; Stress::Stress() : diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp index 8c61d1f..73713e6 100644 --- a/loolwsd/TraceFile.hpp +++ b/loolwsd/TraceFile.hpp @@ -7,8 +7,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include #include +#include +#include /// Dumps commands and notification trace. class TraceFileWriter @@ -53,4 +54,18 @@ private: std::mutex _mutex; }; +class TraceFileReader +{ +public: +TraceFileReader(const std::string& path) : +_epochStart(Poco::Timestamp().epochMicroseconds()), +_stream(path, std::ios::in) +{ +} + +private: +const Poco::Int64 _epochStart; +std::fstream _stream; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits