add instanceSnapshot()

This commit is contained in:
Michael Davidsaver
2020-03-24 17:41:46 -07:00
parent d064afb5bb
commit edadc31f96
14 changed files with 162 additions and 0 deletions
+3
View File
@@ -7,6 +7,7 @@
#include <pvxs/log.h>
#include <pvxs/nt.h>
#include "utilpvt.h"
#include "clientimpl.h"
namespace pvxs {
@@ -124,6 +125,8 @@ struct GPROp : public OperationBase
Done,
} state = Connecting;
INST_COUNTER(GPROp);
GPROp(operation_t op, const std::shared_ptr<Channel>& chan)
:OperationBase (op, chan)
{}
+6
View File
@@ -86,6 +86,8 @@ struct Connection : public ConnBase, public std::enable_shared_from_this<Connect
uint32_t nextIOID = 0u;
INST_COUNTER(Connection);
Connection(const std::shared_ptr<Context::Pvt>& context, const SockAddr &peerAddr);
virtual ~Connection();
@@ -148,6 +150,8 @@ struct Channel {
// points to storage of Connection::opByIOID
std::map<uint32_t, RequestInfo*> opByIOID;
INST_COUNTER(Channel);
Channel(const std::shared_ptr<Context::Pvt>& context, const std::string& name, uint32_t cid);
~Channel();
@@ -205,6 +209,8 @@ struct Context::Pvt
const evevent beaconCleaner;
INST_COUNTER(ClientPvt);
Pvt(const Config& conf);
~Pvt();
+2
View File
@@ -28,6 +28,8 @@ struct InfoOp : public OperationBase
Done,
} state = Connecting;
INST_COUNTER(InfoOp);
explicit InfoOp(const std::shared_ptr<Channel>& chan)
:OperationBase(Info, chan)
{}
+2
View File
@@ -64,6 +64,8 @@ struct SubscriptionImpl : public OperationBase, public Subscription
std::deque<Entry> queue;
uint32_t window =0u, unack =0u;
INST_COUNTER(SubscriptionImpl);
SubscriptionImpl(operation_t op, const std::shared_ptr<Channel>& chan)
:OperationBase (op, chan)
,channelName(chan->name)
+2
View File
@@ -140,6 +140,8 @@ struct StructTop {
// empty, or the field of a structure which encloses this.
std::weak_ptr<FieldStorage> enclosing;
INST_COUNTER(StructTop);
};
using Type = std::shared_ptr<const FieldDesc>;
+5
View File
@@ -7,6 +7,7 @@
#ifndef PVXS_UTIL_H
#define PVXS_UTIL_H
#include <map>
#include <functional>
#include <ostream>
#include <type_traits>
@@ -104,6 +105,10 @@ public:
#endif // !defined(__rtems__) && !defined(vxWorks)
//! return a snapshot of internal instance counters
PVXS_API
std::map<std::string, size_t> instanceSnapshot();
} // namespace pvxs
#endif // PVXS_UTIL_H
+10
View File
@@ -69,6 +69,8 @@ struct ServerChannelControl : public server::ChannelControl
const std::weak_ptr<server::Server::Pvt> server;
const std::weak_ptr<ServerChan> chan;
INST_COUNTER(ServerChannelControl);
};
struct ServerChan
@@ -91,6 +93,8 @@ struct ServerChan
std::map<uint32_t, std::shared_ptr<ServerOp> > opByIOID; // our subset of ServerConn::opByIOID
INST_COUNTER(ServerChan);
ServerChan(const std::shared_ptr<ServerConn>& conn, uint32_t sid, uint32_t cid, const std::string& name);
ServerChan(const ServerChan&) = delete;
ServerChan& operator=(const ServerChan&) = delete;
@@ -110,6 +114,8 @@ struct ServerConn : public ConnBase, public std::enable_shared_from_this<ServerC
std::list<std::function<void()>> backlog;
INST_COUNTER(ServerConn);
ServerConn(ServIface* iface, evutil_socket_t sock, struct sockaddr *peer, int socklen);
ServerConn(const ServerConn&) = delete;
ServerConn& operator=(const ServerConn&) = delete;
@@ -174,6 +180,8 @@ struct ServerSource : public server::Source
const Value info;
INST_COUNTER(ServerSource);
ServerSource(server::Server::Pvt* serv);
virtual void onSearch(Search &op) override final;
@@ -229,6 +237,8 @@ struct Server::Pvt
Stopping,
} state;
INST_COUNTER(ServerPvt);
Pvt(const Config& conf);
~Pvt();
+6
View File
@@ -136,6 +136,8 @@ struct ServerGPR : public ServerOp
std::function<void(std::unique_ptr<server::ExecOp>&&, Value&&)> onPut;
std::function<void(std::unique_ptr<server::ExecOp>&&)> onGet;
INST_COUNTER(ServerGPR);
};
@@ -246,6 +248,8 @@ struct ServerGPRConnect : public server::ConnectOp
const std::weak_ptr<server::Server::Pvt> server;
const std::weak_ptr<ServerGPR> op;
INST_COUNTER(ServerGPRConnect);
};
struct ServerGPRExec : public server::ExecOp
@@ -323,6 +327,8 @@ struct ServerGPRExec : public server::ExecOp
const std::weak_ptr<server::Server::Pvt> server;
const std::weak_ptr<ServerGPR> op;
INST_COUNTER(ServerGPRExec);
};
} // namespace
+4
View File
@@ -48,6 +48,8 @@ struct ServerIntrospect : public ServerOp
conn->opByIOID.erase(ioid);
ch->opByIOID.erase(ioid);
}
INST_COUNTER(ServerIntrospect);
};
struct ServerIntrospectControl : public server::ConnectOp
@@ -125,6 +127,8 @@ struct ServerIntrospectControl : public server::ConnectOp
const std::weak_ptr<server::Server::Pvt> server;
const std::weak_ptr<ServerIntrospect> op;
INST_COUNTER(ServerIntrospectControl);
};
} // namespace
+6
View File
@@ -55,6 +55,8 @@ struct MonitorOp : public ServerOp,
std::deque<Value> queue;
INST_COUNTER(MonitorOp);
// caller must hold lock.
// only used after State==Idle
static
@@ -319,6 +321,8 @@ struct ServerMonitorControl : public server::MonitorControlOp
const std::weak_ptr<server::Server::Pvt> server;
const std::weak_ptr<MonitorOp> op;
INST_COUNTER(ServerMonitorControl);
};
struct ServerMonitorSetup : public server::MonitorSetupOp
@@ -411,6 +415,8 @@ struct ServerMonitorSetup : public server::MonitorSetupOp
const std::weak_ptr<server::Server::Pvt> server;
const std::weak_ptr<MonitorOp> op;
INST_COUNTER(ServerMonitorSetup);
};
+2
View File
@@ -45,6 +45,8 @@ struct SharedPV::Impl : public std::enable_shared_from_this<Impl>
std::set<std::shared_ptr<MonitorControlOp>> subscribers;
Value current;
INST_COUNTER(SharedPVImpl);
};
SharedPV SharedPV::buildMailbox()
+3
View File
@@ -86,6 +86,9 @@ class PVXS_API UDPListener
std::shared_ptr<UDPCollector> collector;
const SockAddr dest;
bool active;
INST_COUNTER(UDPListener);
friend struct UDPCollector;
friend struct UDPManager;
+70
View File
@@ -58,6 +58,76 @@ void cleanup_for_valgrind()
impl::UDPManager::cleanup();
}
#define CASE(KLASS) std::atomic<size_t> cnt_ ## KLASS{}
CASE(StructTop);
CASE(UDPListener);
CASE(GPROp);
CASE(Connection);
CASE(Channel);
CASE(ClientPvt);
CASE(InfoOp);
CASE(SubScriptionImpl);
CASE(ServerChannelControl);
CASE(ServerChan);
CASE(ServerConn);
CASE(ServerSource);
CASE(ServerPvt);
CASE(ServerIntrospect);
CASE(ServerIntrospectControl);
CASE(ServerGPR);
CASE(ServerGPRConnect);
CASE(ServerGPRExec);
CASE(MonitorOp);
CASE(ServerMonitorControl);
CASE(ServerMonitorSetup);
CASE(SharedPVImpl);
CASE(SubscriptionImpl);
#undef CASE
std::map<std::string, size_t> instanceSnapshot()
{
std::map<std::string, size_t> ret;
#define CASE(KLASS) ret[#KLASS] = cnt_ ## KLASS .load(std::memory_order_relaxed)
CASE(StructTop);
CASE(UDPListener);
CASE(GPROp);
CASE(Connection);
CASE(Channel);
CASE(ClientPvt);
CASE(InfoOp);
CASE(SubScriptionImpl);
CASE(ServerChannelControl);
CASE(ServerChan);
CASE(ServerConn);
CASE(ServerSource);
CASE(ServerPvt);
CASE(ServerIntrospect);
CASE(ServerIntrospectControl);
CASE(ServerGPR);
CASE(ServerGPRConnect);
CASE(ServerGPRExec);
CASE(MonitorOp);
CASE(ServerMonitorControl);
CASE(ServerMonitorSetup);
CASE(SharedPVImpl);
CASE(SubscriptionImpl);
#undef CASE
return ret;
}
std::ostream& operator<<(std::ostream& strm, ArrayType code)
{
switch(code) {
+41
View File
@@ -13,6 +13,7 @@
# include <pthread.h>
#endif
#include <atomic>
#include <memory>
#include <string>
#include <sstream>
@@ -233,6 +234,46 @@ public:
PVXS_API
std::ostream& operator<<(std::ostream& strm, const SockAddr& addr);
template<std::atomic<size_t>* Cnt>
struct InstCounter
{
InstCounter() {(*Cnt).fetch_add(1, std::memory_order_relaxed);}
~InstCounter() {(*Cnt).fetch_sub(1, std::memory_order_relaxed);}
};
#define INST_COUNTER(KLASS) InstCounter<&cnt_ ## KLASS> instances
#define CASE(KLASS) extern std::atomic<size_t> cnt_ ## KLASS
CASE(StructTop);
CASE(UDPListener);
CASE(GPROp);
CASE(Connection);
CASE(Channel);
CASE(ClientPvt);
CASE(InfoOp);
CASE(SubScriptionImpl);
CASE(ServerChannelControl);
CASE(ServerChan);
CASE(ServerConn);
CASE(ServerSource);
CASE(ServerPvt);
CASE(ServerIntrospect);
CASE(ServerIntrospectControl);
CASE(ServerGPR);
CASE(ServerGPRConnect);
CASE(ServerGPRExec);
CASE(MonitorOp);
CASE(ServerMonitorControl);
CASE(ServerMonitorSetup);
CASE(SharedPVImpl);
CASE(SubscriptionImpl);
#undef CASE
} // namespace pvxs
#endif // UTILPVT_H