diff --git a/src/client/client.cpp b/src/client/client.cpp index b83c17d..8d014a1 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -8,10 +8,11 @@ #include #include +#include #define epicsExportSharedSymbols #include "pv/logger.h" -#include "pva/client.h" +#include "clientpvt.h" #include "pv/pvAccess.h" #include "pv/configuration.h" @@ -34,7 +35,10 @@ struct ClientChannel::Impl : public pva::ChannelRequester typedef std::vector listeners_t; listeners_t listeners; - virtual ~Impl() {} + static size_t num_instances; + + Impl() {REFTRACE_INCREMENT(num_instances);} + virtual ~Impl() {REFTRACE_DECREMENT(num_instances);} virtual std::string getRequesterName() OVERRIDE FINAL { return "ClientChannel::Impl"; } @@ -68,6 +72,8 @@ struct ClientChannel::Impl : public pva::ChannelRequester } }; +size_t ClientChannel::Impl::num_instances; + ClientChannel::Options::Options() :priority(0) ,address() @@ -151,12 +157,29 @@ void ClientChannel::removeConnectListener(ConnectCallback* cb) } } +static +void register_reftrack() +{ + static volatile int done; + if(done) return; + done = 1; + // done is an optimization, duplicate calls to registerRef* are no-ops + pvac::detail::registerRefTrack(); + pvac::detail::registerRefTrackGet(); + pvac::detail::registerRefTrackMonitor(); + pvac::detail::registerRefTrackRPC(); +} + std::tr1::shared_ptr ClientChannel::getChannel() { return impl->channel; } struct ClientProvider::Impl { + static size_t num_instances; + Impl() {register_reftrack(); REFTRACE_INCREMENT(num_instances);} + ~Impl() {REFTRACE_DECREMENT(num_instances);} + pva::ChannelProvider::shared_pointer provider; epicsMutex mutex; @@ -164,6 +187,8 @@ struct ClientProvider::Impl channels_t channels; }; +size_t ClientProvider::Impl::num_instances; + ClientProvider::ClientProvider(const std::string& providerName, const std::tr1::shared_ptr& conf) :impl(new Impl) @@ -240,4 +265,14 @@ void ClientProvider::disconnect() impl->channels.clear(); } +namespace detail { + +void registerRefTrack() +{ + epics::registerRefCounter("pvac::ClientChannel::Impl", &ClientChannel::Impl::num_instances); + epics::registerRefCounter("pvac::ClientProvider::Impl", &ClientProvider::Impl::num_instances); +} + +} + } //namespace pvac diff --git a/src/client/clientGet.cpp b/src/client/clientGet.cpp index 25f4d10..7711ef6 100644 --- a/src/client/clientGet.cpp +++ b/src/client/clientGet.cpp @@ -10,10 +10,11 @@ #include #include #include +#include #define epicsExportSharedSymbols #include "pv/logger.h" -#include "pva/client.h" +#include "clientpvt.h" #include "pv/pvAccess.h" namespace pvd = epics::pvData; @@ -35,9 +36,13 @@ struct GetPutter : public pva::ChannelPutRequester, pvac::ClientChannel::PutCallback *putcb; pvac::GetEvent event; - GetPutter(pvac::ClientChannel::GetCallback* cb) :started(false), getcb(cb), putcb(0) {} - GetPutter(pvac::ClientChannel::PutCallback* cb) :started(false), getcb(0), putcb(cb) {} - virtual ~GetPutter() {cancel();} + static size_t num_instances; + + GetPutter(pvac::ClientChannel::GetCallback* cb) :started(false), getcb(cb), putcb(0) + {REFTRACE_INCREMENT(num_instances);} + GetPutter(pvac::ClientChannel::PutCallback* cb) :started(false), getcb(0), putcb(cb) + {REFTRACE_INCREMENT(num_instances);} + virtual ~GetPutter() {cancel();REFTRACE_DECREMENT(num_instances);} void callEvent(Guard& G, pvac::GetEvent::event_t evt = pvac::GetEvent::Fail) { @@ -172,6 +177,8 @@ struct GetPutter : public pva::ChannelPutRequester, } }; +size_t GetPutter::num_instances; + } //namespace namespace pvac { @@ -213,4 +220,13 @@ ClientChannel::put(PutCallback* cb, } +namespace detail { + +void registerRefTrackGet() +{ + epics::registerRefCounter("pvac::GetPutter", &GetPutter::num_instances); +} + +} + }//namespace pvac diff --git a/src/client/clientMonitor.cpp b/src/client/clientMonitor.cpp index 69dc98a..ce256d7 100644 --- a/src/client/clientMonitor.cpp +++ b/src/client/clientMonitor.cpp @@ -9,10 +9,11 @@ #include #include #include +#include #define epicsExportSharedSymbols #include "pv/logger.h" -#include "pva/client.h" +#include "clientpvt.h" #include "pv/pvAccess.h" namespace pvd = epics::pvData; @@ -34,13 +35,15 @@ struct Monitor::Impl : public pva::MonitorRequester pva::MonitorElement::Ref last; + static size_t num_instances; + Impl(ClientChannel::MonitorCallback* cb) :started(false) ,done(false) ,seenEmpty(false) ,cb(cb) - {} - virtual ~Impl() {cancel();} + {REFTRACE_INCREMENT(num_instances);} + virtual ~Impl() {cancel();REFTRACE_DECREMENT(num_instances);} void callEvent(Guard& G, MonitorEvent::event_t evt = MonitorEvent::Fail) { @@ -160,6 +163,8 @@ struct Monitor::Impl : public pva::MonitorRequester } }; +size_t Monitor::Impl::num_instances; + Monitor::Monitor(const std::tr1::shared_ptr& impl) :impl(impl) {} @@ -224,4 +229,13 @@ ClientChannel::monitor(MonitorCallback *cb, return Monitor(ret); } +namespace detail { + +void registerRefTrackMonitor() +{ + epics::registerRefCounter("pvac::Monitor::Impl", &Monitor::Impl::num_instances); +} + +} + }//namespace pvac diff --git a/src/client/clientRPC.cpp b/src/client/clientRPC.cpp index a10ac55..0b86220 100644 --- a/src/client/clientRPC.cpp +++ b/src/client/clientRPC.cpp @@ -8,6 +8,7 @@ #include #include +#include #define epicsExportSharedSymbols #include "pv/logger.h" @@ -34,9 +35,12 @@ struct RPCer : public pva::ChannelRPCRequester, pvd::PVStructure::const_shared_pointer args; + static size_t num_instances; + RPCer(pvac::ClientChannel::GetCallback* cb, - const pvd::PVStructure::const_shared_pointer& args) :started(false), cb(cb), args(args) {} - virtual ~RPCer() {cancel();} + const pvd::PVStructure::const_shared_pointer& args) :started(false), cb(cb), args(args) + {REFTRACE_INCREMENT(num_instances);} + virtual ~RPCer() {cancel();REFTRACE_DECREMENT(num_instances);} void callEvent(Guard& G, pvac::GetEvent::event_t evt = pvac::GetEvent::Fail) { @@ -136,6 +140,8 @@ struct RPCer : public pva::ChannelRPCRequester, } }; +size_t RPCer::num_instances; + }//namespace namespace pvac { @@ -159,4 +165,13 @@ ClientChannel::rpc(GetCallback* cb, return Operation(ret); } +namespace detail { + +void registerRefTrackRPC() +{ + epics::registerRefCounter("pvac::RPCer", &RPCer::num_instances); +} + +} + }//namespace pvac diff --git a/src/client/clientpvt.h b/src/client/clientpvt.h new file mode 100644 index 0000000..eaa86ee --- /dev/null +++ b/src/client/clientpvt.h @@ -0,0 +1,15 @@ +#ifndef CLIENTPVT_H +#define CLIENTPVT_H + +#include + +namespace pvac{namespace detail{ + +void registerRefTrack(); +void registerRefTrackGet(); +void registerRefTrackMonitor(); +void registerRefTrackRPC(); + +}} // namespace pvac::detail + +#endif // CLIENTPVT_H diff --git a/src/client/pva/client.h b/src/client/pva/client.h index 2c76ed2..08998b3 100644 --- a/src/client/pva/client.h +++ b/src/client/pva/client.h @@ -179,6 +179,7 @@ struct Timeout : public std::runtime_error namespace detail { class PutBuilder; +void registerRefTrack(); } /** Represents a single channel @@ -195,6 +196,7 @@ class epicsShareClass ClientChannel struct Impl; std::tr1::shared_ptr impl; friend class ClientProvider; + friend void detail::registerRefTrack(); ClientChannel(const std::tr1::shared_ptr& i) :impl(i) {} public: @@ -395,6 +397,7 @@ class epicsShareClass ClientProvider { struct Impl; std::tr1::shared_ptr impl; + friend void detail::registerRefTrack(); public: /** Use named provider.