[Libreoffice-commits] online.git: net/Socket.cpp net/Socket.hpp
Michael Meeks
michael.meeks at collabora.com
Fri May 26 15:36:54 UTC 2017
net/Socket.cpp | 4 +++-
net/Socket.hpp | 16 +++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
New commits:
commit c224413a9d013a4253ed66fccb8ee40dc01be8f8
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri May 26 15:50:08 2017 +0100
Track bytes recv'd and sent on StreamSockets.
Dump on USR1 as part of our state.
Change-Id: I4c6b87c19bca768402c9b0b8e26f16336e007749
diff --git a/net/Socket.cpp b/net/Socket.cpp
index 06afce83..13424cd3 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -181,6 +181,7 @@ void WebSocketHandler::dumpState(std::ostream& os)
<< std::setw(5) << 1.0*_pingTimeUs/1000 << "ms ";
if (_wsPayload.size() > 0)
dump_hex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload);
+ os << "\n";
}
void StreamSocket::dumpState(std::ostream& os)
@@ -188,7 +189,8 @@ void StreamSocket::dumpState(std::ostream& os)
int timeoutMaxMs = SocketPoll::DefaultPollTimeoutMs;
int events = getPollEvents(std::chrono::steady_clock::now(), timeoutMaxMs);
os << "\t" << getFD() << "\t" << events << "\t"
- << _inBuffer.size() << "\t" << _outBuffer.size() << "\t";
+ << _inBuffer.size() << "\t" << _outBuffer.size() << "\t"
+ << " r: " << _bytesRecvd << "\t w: " << _bytesSent << "\t";
_socketHandler->dumpState(os);
if (_inBuffer.size() > 0)
dump_hex(os, "\t\tinBuffer:\n", "\t\t", _inBuffer);
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 88e24f05..a7cc426d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -31,6 +31,7 @@
#include <mutex>
#include <sstream>
#include <thread>
+#include <atomic>
#include "common/Common.hpp"
#include "common/Log.hpp"
@@ -691,7 +692,9 @@ public:
Socket(fd),
_socketHandler(std::move(socketHandler)),
_closed(false),
- _shutdownSignalled(false)
+ _shutdownSignalled(false),
+ _bytesSent(0),
+ _bytesRecvd(0)
{
LOG_DBG("StreamSocket ctor #" << fd);
@@ -785,6 +788,7 @@ public:
if (len > 0)
{
assert (len <= ssize_t(sizeof(buf)));
+ _bytesRecvd += len;
_inBuffer.insert(_inBuffer.end(), &buf[0], &buf[len]);
}
// else poll will handle errors.
@@ -915,6 +919,7 @@ protected:
if (len > 0)
{
+ _bytesSent += len;
_outBuffer.erase(_outBuffer.begin(), _outBuffer.begin() + len);
}
else
@@ -942,6 +947,12 @@ protected:
void dumpState(std::ostream& os) override;
+ void getStats(uint64_t &sent, uint64_t &recv)
+ {
+ sent = _bytesSent;
+ recv = _bytesRecvd;
+ }
+
protected:
/// Client handling the actual data.
std::shared_ptr<SocketHandlerInterface> _socketHandler;
@@ -955,6 +966,9 @@ protected:
std::vector< char > _inBuffer;
std::vector< char > _outBuffer;
+ std::atomic<uint64_t> _bytesSent;
+ std::atomic<uint64_t> _bytesRecvd;
+
// To be able to access _inBuffer and _outBuffer.
// TODO we probably need accessors to the _inBuffer & _outBuffer
// instead of this many friends...
More information about the Libreoffice-commits
mailing list