diff --git a/src/client/pv/pvAccess.h b/src/client/pv/pvAccess.h index 5e2630c..1515a4e 100644 --- a/src/client/pv/pvAccess.h +++ b/src/client/pv/pvAccess.h @@ -1056,7 +1056,10 @@ public: POINTER_DEFINITIONS(ChannelRequester); typedef Channel operation_type; - virtual ~ChannelRequester() {} + static size_t num_instances; + + ChannelRequester(); + virtual ~ChannelRequester(); /** * The request made with ChannelProvider::createChannel() is satisfied. diff --git a/src/client/pvAccess.cpp b/src/client/pvAccess.cpp index 731b752..c585ffb 100644 --- a/src/client/pvAccess.cpp +++ b/src/client/pvAccess.cpp @@ -4,6 +4,8 @@ * in file LICENSE that is included with this distribution. */ +#include + #define epicsExportSharedSymbols #include @@ -118,6 +120,19 @@ ChannelArray::shared_pointer Channel::createChannelArray( return ret; } + +size_t ChannelRequester::num_instances; + +ChannelRequester::ChannelRequester() +{ + REFTRACE_INCREMENT(num_instances); +} + +ChannelRequester::~ChannelRequester() +{ + REFTRACE_DECREMENT(num_instances); +} + std::string DefaultChannelRequester::getRequesterName() { return "DefaultChannelRequester"; } void DefaultChannelRequester::channelCreated(const epics::pvData::Status& status, Channel::shared_pointer const & channel) diff --git a/src/factory/ChannelAccessFactory.cpp b/src/factory/ChannelAccessFactory.cpp index 5b4a4f1..20caa5c 100644 --- a/src/factory/ChannelAccessFactory.cpp +++ b/src/factory/ChannelAccessFactory.cpp @@ -12,10 +12,13 @@ #include #include #include +#include #define epicsExportSharedSymbols #include #include +#include "pv/codec.h" +#include using namespace epics::pvData; using std::string; @@ -156,6 +159,9 @@ epicsThreadOnceId providerRegOnce = EPICS_THREAD_ONCE_INIT; void providerRegInit(void*) { providerRegGbl = new providerRegGbl_t; + registerRefCounter("ServerContext (PVA)", &ServerContextImpl::num_instances); + registerRefCounter("BlockingTCPTransportCodec", &detail::BlockingTCPTransportCodec::num_instances); + registerRefCounter("ChannelRequester", &ChannelRequester::num_instances); } } // namespace diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index da7cc12..14208dc 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #define epicsExportSharedSymbols #include @@ -1001,6 +1002,8 @@ bool AbstractCodec::directDeserialize(ByteBuffer *existingBuffer, char* deserial BlockingTCPTransportCodec::~BlockingTCPTransportCodec() { + REFTRACE_DECREMENT(num_instances); + waitJoin(); } @@ -1138,6 +1141,7 @@ void BlockingTCPTransportCodec::sendBufferFull(int tries) { // // +size_t BlockingTCPTransportCodec::num_instances; BlockingTCPTransportCodec::BlockingTCPTransportCodec(bool serverFlag, const Context::shared_pointer &context, SOCKET channel, const ResponseHandler::shared_pointer &responseHandler, @@ -1163,6 +1167,8 @@ BlockingTCPTransportCodec::BlockingTCPTransportCodec(bool serverFlag, const Cont ,_remoteTransportRevision(0), _priority(priority) ,_verified(false) { + REFTRACE_INCREMENT(num_instances); + _isOpen.getAndSet(true); // get remote address diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index afa082c..42162d2 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -302,6 +302,8 @@ public: POINTER_DEFINITIONS(BlockingTCPTransportCodec); + static size_t num_instances; + BlockingTCPTransportCodec( bool serverFlag, Context::shared_pointer const & context, diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index ad733e1..68ac87b 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #define epicsExportSharedSymbols #include @@ -165,6 +166,9 @@ protected: return std::tr1::static_pointer_cast(P); } public: + static size_t num_instances; + static size_t num_active; + template static typename std::tr1::shared_ptr @@ -180,6 +184,7 @@ public: const_cast(internal->m_this_internal) = internal; const_cast(internal->m_this_external) = external; internal->activate(); + REFTRACE_INCREMENT(num_active); return external; } protected: @@ -197,9 +202,13 @@ protected: m_destroyed(false), m_initialized(false), m_subscribed() - {} + { + REFTRACE_INCREMENT(num_instances); + } - virtual ~BaseRequestImpl() {} + virtual ~BaseRequestImpl() { + REFTRACE_DECREMENT(num_instances); + } virtual void activate() { // register response request @@ -344,6 +353,8 @@ public: } } + + REFTRACE_DECREMENT(num_active); } virtual void timeout() OVERRIDE FINAL { @@ -396,6 +407,8 @@ public: }; +size_t BaseRequestImpl::num_instances; +size_t BaseRequestImpl::num_active; PVDataCreatePtr BaseRequestImpl::pvDataCreate = getPVDataCreate(); @@ -3248,6 +3261,11 @@ private: */ ServerGUID m_guid; + public: + static size_t num_instances; + static size_t num_active; + private: + /** * Constructor. * @param context @@ -3275,6 +3293,7 @@ private: m_serverChannelID(0xFFFFFFFF), m_issueCreateMessage(true) { + REFTRACE_INCREMENT(num_instances); PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(channel); } @@ -3285,6 +3304,8 @@ private: // connect connect(); + + REFTRACE_INCREMENT(num_active); } public: @@ -3307,11 +3328,15 @@ private: virtual ~InternalChannelImpl() { + REFTRACE_DECREMENT(num_instances); + PVACCESS_REFCOUNT_MONITOR_DESTRUCT(channel); } virtual void destroy() OVERRIDE FINAL { + REFTRACE_DECREMENT(num_active); + destroy(false); } @@ -4035,6 +4060,7 @@ public: public: + static size_t num_instances; InternalClientContextImpl(const Configuration::shared_pointer& conf) : m_addressList(""), m_autoAddressList(true), m_connectionTimeout(30.0f), m_beaconPeriod(15.0f), @@ -4049,6 +4075,8 @@ public: m_configuration(conf), m_flushStrategy(DELAYED) { + REFTRACE_INCREMENT(num_instances); + PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(remoteClientContext); MB_INIT; if(!m_configuration) m_configuration = ConfigurationFactory::getConfiguration("pvAccess-client"); @@ -4148,6 +4176,7 @@ public: virtual ~InternalClientContextImpl() { + REFTRACE_DECREMENT(num_instances); PVACCESS_REFCOUNT_MONITOR_DESTRUCT(remoteClientContext); } @@ -4716,6 +4745,10 @@ private: FlushStrategy m_flushStrategy; }; +size_t InternalClientContextImpl::num_instances; +size_t InternalClientContextImpl::InternalChannelImpl::num_instances; +size_t InternalClientContextImpl::InternalChannelImpl::num_active; + PVACCESS_REFCOUNT_MONITOR_DEFINE(channelGetField); class ChannelGetFieldRequestImpl : @@ -4908,6 +4941,11 @@ namespace pvAccess { ChannelProvider::shared_pointer createClientProvider(const Configuration::shared_pointer& conf) { + registerRefCounter("InternalClientContextImpl", &InternalClientContextImpl::num_instances); + registerRefCounter("InternalChannelImpl", &InternalClientContextImpl::InternalChannelImpl::num_instances); + registerRefCounter("InternalChannelImpl (Active)", &InternalClientContextImpl::InternalChannelImpl::num_active); + registerRefCounter("BaseRequestImpl", &BaseRequestImpl::num_instances); + registerRefCounter("BaseRequestImpl (Active)", &BaseRequestImpl::num_active); InternalClientContextImpl::shared_pointer internal(new InternalClientContextImpl(conf)), external(internal.get(), epics::pvAccess::Destroyable::cleaner(internal)); const_cast(internal->m_external_this) = external; diff --git a/src/server/pv/serverContextImpl.h b/src/server/pv/serverContextImpl.h index 1d63d47..c7addf9 100644 --- a/src/server/pv/serverContextImpl.h +++ b/src/server/pv/serverContextImpl.h @@ -32,6 +32,8 @@ public: typedef std::tr1::shared_ptr shared_pointer; typedef std::tr1::shared_ptr const_shared_pointer; + static size_t num_instances; + ServerContextImpl(); virtual ~ServerContextImpl(); diff --git a/src/server/serverContext.cpp b/src/server/serverContext.cpp index 08331f7..73fcb0e 100644 --- a/src/server/serverContext.cpp +++ b/src/server/serverContext.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #define epicsExportSharedSymbols #include @@ -27,6 +28,8 @@ namespace pvAccess { const Version ServerContextImpl::VERSION("pvAccess Server", "cpp", EPICS_PVA_MAJOR_VERSION, EPICS_PVA_MINOR_VERSION, EPICS_PVA_MAINTENANCE_VERSION, EPICS_PVA_DEVELOPMENT_FLAG); +size_t ServerContextImpl::num_instances; + ServerContextImpl::ServerContextImpl(): _beaconAddressList(), _ignoreAddressList(), @@ -43,6 +46,8 @@ ServerContextImpl::ServerContextImpl(): _beaconServerStatusProvider(), _startTime() { + REFTRACE_INCREMENT(num_instances); + epicsTimeGetCurrent(&_startTime); // TODO maybe there is a better place for this (when there will be some factory) @@ -63,6 +68,7 @@ ServerContextImpl::~ServerContextImpl() { std::cerr<<"Error in: ServerContextImpl::dispose: "<