PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
reftrack.h
1 /*
2  * Copyright information and license terms for this software can be
3  * found in the file LICENSE that is included with the distribution
4  */
5 #ifndef REFTRACK_H
6 #define REFTRACK_H
7 
40 #ifdef __cplusplus
41 
42 #include <map>
43 #include <string>
44 #include <ostream>
45 
46 #include <stdlib.h>
47 
48 #include <epicsVersion.h>
49 #include <epicsAtomic.h>
50 
51 #define REFTRACE_INCREMENT(counter) ::epics::atomic::increment(counter)
52 #define REFTRACE_DECREMENT(counter) ::epics::atomic::decrement(counter)
53 
54 #include <shareLib.h>
55 
56 namespace epics {
57 
59 epicsShareFunc
60 void registerRefCounter(const char *name, const size_t* counter);
61 
63 epicsShareFunc
64 void unregisterRefCounter(const char *name, const size_t* counter);
65 
67 epicsShareFunc
68 size_t readRefCounter(const char *name);
69 
71 class epicsShareClass RefSnapshot
72 {
73 public:
75  struct Count {
76  size_t current;
77  long delta;
78  Count() :current(0u), delta(0) {}
79  explicit Count(size_t c, long d) :current(c), delta(d) {}
80  bool operator==(const Count& o) const
81  { return current==o.current && delta==o.delta; }
82  };
83 
84 private:
85  typedef std::map<std::string, Count> cnt_map_t;
86  cnt_map_t counts;
87 public:
88  typedef cnt_map_t::const_iterator iterator;
89  typedef cnt_map_t::const_iterator const_iterator;
90 
95  void update();
96 
97  const Count& operator[](const std::string& name) const;
98 
99  iterator begin() const { return counts.begin(); }
100  iterator end() const { return counts.end(); }
101  size_t size() const { return counts.size(); }
102 
103  inline void swap(RefSnapshot& o)
104  {
105  counts.swap(o.counts);
106  }
107 
113  RefSnapshot operator-(const RefSnapshot& rhs) const;
114 };
115 
117 epicsShareFunc
118 std::ostream& operator<<(std::ostream& strm, const RefSnapshot& snap);
119 
122 class epicsShareClass RefMonitor
123 {
124  struct Impl;
125  Impl *impl;
126 public:
127  RefMonitor();
128  virtual ~RefMonitor();
129 
130  void start(double period=10.0);
131  void stop();
132  bool running() const;
133 
135  void current();
136 protected:
139  virtual void show(const RefSnapshot& snap, bool complete=false);
140 };
141 
142 } // namespace epics
143 
144 extern "C" {
145 #endif /* __cplusplus */
146 
150 char* epicsRefSnapshotCurrent();
151 
152 #ifdef __cplusplus
153 }
154 #endif /* __cplusplus */
155 
156 #endif // REFTRACK_H
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::bernoulli_distribution &__x)
constexpr complex< _Tp > operator-(const complex< _Tp > &__x)
valarray< size_t > size() const
directory_iterator end(directory_iterator) noexcept
size_t start() const
directory_iterator begin(directory_iterator __iter) noexcept
gslice_array< _Tp > operator[](const gslice &__s)
void swap(any &__x, any &__y) noexcept
constexpr bool operator==(const allocator< _T1 > &, const allocator< _T2 > &) noexcept