loolwsd/LOOLWSD.cpp    |    9 +++++++++
 loolwsd/LOOLWSD.hpp    |   11 +++++++++++
 loolwsd/TraceFile.hpp  |   36 ++++++++++++++++++++++++++++++++++++
 loolwsd/loolwsd.xml.in |    4 ++++
 4 files changed, 60 insertions(+)

New commits:
commit 8b9b3289556ae2d69bd7f6a6a49f38be0dc90c71
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Sat Jul 30 22:22:28 2016 -0400

    loolwsd: add support for dumping command trace
    
    Change-Id: I4121ce74653d243149be09de46581cbe0aae0438
    Reviewed-on: https://gerrit.libreoffice.org/27953
    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 009a34d..cb0cb19 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1265,6 +1265,7 @@ static std::string UnitTestLibrary;
 unsigned int LOOLWSD::NumPreSpawnedChildren = 0;
 std::atomic<unsigned> LOOLWSD::NumDocBrokers;
 std::atomic<unsigned> LOOLWSD::NumConnections;
+std::unique_ptr<TraceFile> LOOLWSD::TraceDumper;
 
 class AppConfigMap : public Poco::Util::MapConfiguration
 {
@@ -1393,6 +1394,14 @@ void LOOLWSD::initialize(Application& self)
                                                     
std::to_string(MAX_CONNECTIONS) :
                                                     std::string("unlimited")) 
<< Log::end;
 
+    // Command Tracing.
+    if (getConfigValue<bool>(conf, "trace[@enable]", false))
+    {
+        const auto& path = getConfigValue<std::string>(conf, "trace.path", "");
+        TraceDumper.reset(new TraceFile(path));
+        Log::info("Command trace dumping enabled to file: " + path);
+    }
+
     StorageBase::initialize();
 
     ServerApplication::initialize(self);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 4a3898c..eed6b70 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -23,6 +23,7 @@
 #include "Auth.hpp"
 #include "Common.hpp"
 #include "DocumentBroker.hpp"
+#include "TraceFile.hpp"
 #include "Util.hpp"
 
 class LOOLWSD: public Poco::Util::ServerApplication
@@ -46,6 +47,7 @@ public:
     static std::string LOKitVersion;
     static std::atomic<unsigned> NumDocBrokers;
     static std::atomic<unsigned> NumConnections;
+    static std::unique_ptr<TraceFile> TraceDumper;
 
     static
     std::string GenSessionId()
@@ -59,6 +61,15 @@ public:
         return LOOLWSD::SSLEnabled.get();
     }
 
+    static
+    void dumpTrace(const std::string& data)
+    {
+        if (TraceDumper)
+        {
+            TraceDumper->write(data);
+        }
+    }
+
 protected:
     void initialize(Poco::Util::Application& self) override;
     void uninitialize() override;
diff --git a/loolwsd/TraceFile.hpp b/loolwsd/TraceFile.hpp
new file mode 100644
index 0000000..c1c01d7
--- /dev/null
+++ b/loolwsd/TraceFile.hpp
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <string>
+#include <fstream>
+
+/// Dumps commands and notification trace.
+class TraceFile
+{
+public:
+    TraceFile(const std::string& path) :
+        _stream(path, std::ios::out)
+    {
+    }
+
+    ~TraceFile()
+    {
+        _stream.close();
+    }
+
+    void write(const std::string& data)
+    {
+        _stream.write(data.c_str(), data.size());
+    }
+
+private:
+    std::fstream _stream;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/loolwsd.xml.in b/loolwsd/loolwsd.xml.in
index 15153c8..f5916e6 100644
--- a/loolwsd/loolwsd.xml.in
+++ b/loolwsd/loolwsd.xml.in
@@ -23,6 +23,10 @@
         <level type="string" desc="Can be 0-8, or none (turns off logging), 
fatal, critical, error, warning, notice, information, debug, trace" 
default="trace">trace</level>
     </logging>
 
+    <trace desc="Dump commands and notifications for replay" enable="true">
+        <path desc="Output file path">/tmp/dump</path>
+    </trace>
+
     <ssl desc="SSL settings">
         <enable type="bool" default="true">true</enable>
         <cert_file_path desc="Path to the cert file" 
relative="false">/etc/loolwsd/cert.pem</cert_file_path>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to