loolwsd/LOOLWSD.cpp | 3 +- loolwsd/TraceFile.hpp | 47 +++++++++++++++++++++++++++++----------- loolwsd/loolwsd.xml.in | 2 - loolwsd/test/TileCacheTests.cpp | 2 + 4 files changed, 40 insertions(+), 14 deletions(-)
New commits: commit 807b3c2e55226a1555cf9c0c1ec41d5150f7b59a Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sat Aug 6 21:23:57 2016 -0400 loolstress: support trace file compression Compression to .gz is supported and is controlled via the XML configuration. Change-Id: If26fad2c0b5f3c4ffd93362608644dc917172a41 Reviewed-on: https://gerrit.libreoffice.org/27975 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 0a994aa..c9ce709 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1418,7 +1418,8 @@ void LOOLWSD::initialize(Application& self) } } - TraceDumper.reset(new TraceFileWriter(path, recordOutgoing, filters)); + const auto compress = getConfigValue<bool>(conf, "trace.path[@compress]", false); + TraceDumper.reset(new TraceFileWriter(path, recordOutgoing, compress, filters)); Log::info("Command trace dumping enabled to file: " + path); } diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp index dec080c..eee746f 100644 --- a/loolwsd/TraceFile.hpp +++ b/loolwsd/TraceFile.hpp @@ -13,6 +13,8 @@ #include <string> #include <vector> +#include <Poco/DeflatingStream.h> + #include "Util.hpp" /// Dumps commands and notification trace. @@ -42,11 +44,14 @@ public: class TraceFileWriter { public: - TraceFileWriter(const std::string& path, const bool recordOugoing, const std::vector<std::string>& filters) : + TraceFileWriter(const std::string& path, const bool recordOugoing, const bool compress, + const std::vector<std::string>& filters) : _epochStart(Poco::Timestamp().epochMicroseconds()), _recordOutgoing(recordOugoing), + _compress(compress), _filter(true), - _stream(path, std::ios::out) + _stream(path, compress ? std::ios::binary : std::ios::out), + _deflater(_stream, Poco::DeflatingStreamBuf::STREAM_GZIP) { for (const auto& f : filters) { @@ -56,6 +61,7 @@ public: ~TraceFileWriter() { + _deflater.close(); _stream.close(); } @@ -85,22 +91,39 @@ private: { std::unique_lock<std::mutex> lock(_mutex); const Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - _epochStart; - _stream.write(&delim, 1); - _stream << usec; - _stream.write(&delim, 1); - _stream << pId; - _stream.write(&delim, 1); - _stream << sessionId; - _stream.write(&delim, 1); - _stream.write(data.c_str(), data.size()); - _stream.write("\n", 1); + if (_compress) + { + _deflater.write(&delim, 1); + _deflater << usec; + _deflater.write(&delim, 1); + _deflater << pId; + _deflater.write(&delim, 1); + _deflater << sessionId; + _deflater.write(&delim, 1); + _deflater.write(data.c_str(), data.size()); + _deflater.write("\n", 1); + } + else + { + _stream.write(&delim, 1); + _stream << usec; + _stream.write(&delim, 1); + _stream << pId; + _stream.write(&delim, 1); + _stream << sessionId; + _stream.write(&delim, 1); + _stream.write(data.c_str(), data.size()); + _stream.write("\n", 1); + } } private: const Poco::Int64 _epochStart; const bool _recordOutgoing; + const bool _compress; Util::RegexListMatcher _filter; - std::fstream _stream; + std::ofstream _stream; + Poco::DeflatingOutputStream _deflater; std::mutex _mutex; }; diff --git a/loolwsd/loolwsd.xml.in b/loolwsd/loolwsd.xml.in index 6acfdf6..d05724f 100644 --- a/loolwsd/loolwsd.xml.in +++ b/loolwsd/loolwsd.xml.in @@ -24,7 +24,7 @@ </logging> <trace desc="Dump commands and notifications for replay" enable="true"> - <path desc="Output file path">/tmp/dump</path> + <path desc="Output file path" compress="true">/tmp/looltrace.gz</path> <filter> <message desc="Regex pattern of messages to exlcude">tile.*</message> </filter> diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp index d4b0a4f..54177d4 100644 --- a/loolwsd/test/TileCacheTests.cpp +++ b/loolwsd/test/TileCacheTests.cpp @@ -419,11 +419,13 @@ void TileCacheTests::checkBlackTiles(Poco::Net::WebSocket& socket, const int /*p const auto tile = getResponseMessage(socket, "tile:", "checkBlackTiles "); const std::string firstLine = LOOLProtocol::getFirstLine(tile); + #if 0 std::fstream outStream("/tmp/black.png", std::ios::out); outStream.write(tile.data() + firstLine.size() + 1, tile.size() - firstLine.size() - 1); outStream.close(); #endif + std::stringstream streamTile; std::copy(tile.begin() + firstLine.size() + 1, tile.end(), std::ostream_iterator<char>(streamTile)); checkBlackTile(streamTile); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits