2016-07-30 21:22:28 -05:00
|
|
|
/* -*- 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.
|
2016-07-31 12:56:57 -05:00
|
|
|
class TraceFileWriter
|
2016-07-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-07-31 12:56:57 -05:00
|
|
|
TraceFileWriter(const std::string& path) :
|
2016-07-30 22:06:12 -05:00
|
|
|
_epochStart(Poco::Timestamp().epochMicroseconds()),
|
2016-07-30 21:22:28 -05:00
|
|
|
_stream(path, std::ios::out)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-31 12:56:57 -05:00
|
|
|
~TraceFileWriter()
|
2016-07-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
_stream.close();
|
|
|
|
}
|
|
|
|
|
2016-07-30 22:06:12 -05:00
|
|
|
void writeIncoming(const std::string& data)
|
2016-07-30 21:22:28 -05:00
|
|
|
{
|
2016-07-30 22:06:12 -05:00
|
|
|
std::unique_lock<std::mutex> lock(_mutex);
|
|
|
|
const Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - _epochStart;
|
|
|
|
_stream.write(">", 1);
|
|
|
|
_stream << usec;
|
|
|
|
_stream.write(">", 1);
|
2016-07-30 21:22:28 -05:00
|
|
|
_stream.write(data.c_str(), data.size());
|
2016-07-30 22:06:12 -05:00
|
|
|
_stream.write("\n", 1);
|
2016-07-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
2016-07-31 06:54:47 -05:00
|
|
|
void writeOutgoing(const std::string& data)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(_mutex);
|
|
|
|
const Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - _epochStart;
|
|
|
|
_stream.write("<", 1);
|
|
|
|
_stream << usec;
|
|
|
|
_stream.write("<", 1);
|
|
|
|
_stream.write(data.c_str(), data.size());
|
|
|
|
_stream.write("\n", 1);
|
|
|
|
}
|
|
|
|
|
2016-07-30 21:22:28 -05:00
|
|
|
private:
|
2016-07-30 22:06:12 -05:00
|
|
|
const Poco::Int64 _epochStart;
|
2016-07-30 21:22:28 -05:00
|
|
|
std::fstream _stream;
|
2016-07-30 22:06:12 -05:00
|
|
|
std::mutex _mutex;
|
2016-07-30 21:22:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|