summaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2020-02-04 11:11:35 +0000
committerHåvard Pettersen <havardpe@oath.com>2020-02-04 12:07:48 +0000
commitb0f12f2e14682e322bd8e43500378fe0ffd4a6ae (patch)
tree2286079f856c2b6b2f0160f013917bbd173888b9 /fnet
parent83f21ba4f707c9c8d9360e2bf52860ab939aaf9b (diff)
track the total number of connection objects
Diffstat (limited to 'fnet')
-rw-r--r--fnet/src/vespa/fnet/connection.cpp5
-rw-r--r--fnet/src/vespa/fnet/connection.h10
2 files changed, 14 insertions, 1 deletions
diff --git a/fnet/src/vespa/fnet/connection.cpp b/fnet/src/vespa/fnet/connection.cpp
index 74a7d19387c..bf29cc29c18 100644
--- a/fnet/src/vespa/fnet/connection.cpp
+++ b/fnet/src/vespa/fnet/connection.cpp
@@ -13,6 +13,8 @@
#include <vespa/log/log.h>
LOG_SETUP(".fnet");
+std::atomic<uint64_t> FNET_Connection::_num_connections = 0;
+
namespace {
class SyncPacket : public FNET_DummyPacket {
private:
@@ -489,6 +491,7 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner,
_cleanup(nullptr)
{
assert(_socket && (_socket->get_fd() >= 0));
+ ++_num_connections;
}
@@ -526,6 +529,7 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner,
_adminChannel = admin.get();
_channels.Register(admin.release());
}
+ ++_num_connections;
}
@@ -536,6 +540,7 @@ FNET_Connection::~FNET_Connection()
delete _adminChannel;
}
assert(_cleanup == nullptr);
+ --_num_connections;
}
diff --git a/fnet/src/vespa/fnet/connection.h b/fnet/src/vespa/fnet/connection.h
index 760b1b96d4d..c9c49c5151a 100644
--- a/fnet/src/vespa/fnet/connection.h
+++ b/fnet/src/vespa/fnet/connection.h
@@ -10,6 +10,7 @@
#include <vespa/vespalib/net/socket_handle.h>
#include <vespa/vespalib/net/async_resolver.h>
#include <vespa/vespalib/net/crypto_socket.h>
+#include <atomic>
class FNET_IPacketStreamer;
class FNET_IServerAdapter;
@@ -111,6 +112,8 @@ private:
FNET_IConnectionCleanupHandler *_cleanup; // cleanup handler
+ static std::atomic<uint64_t> _num_connections; // total number of connections
+
FNET_Connection(const FNET_Connection &);
FNET_Connection &operator=(const FNET_Connection &);
@@ -517,5 +520,10 @@ public:
*/
uint32_t getInputBufferSize() const { return _input.GetBufSize(); }
+ /**
+ * @return the total number of connection objects
+ **/
+ static uint64_t get_num_connections() {
+ return _num_connections.load(std::memory_order_relaxed);
+ }
};
-