PVData C++ 8.0.7
Loading...
Searching...
No Matches
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
56namespace epics {
57
59epicsShareFunc
60void registerRefCounter(const char *name, const size_t* counter);
61
63epicsShareFunc
64void unregisterRefCounter(const char *name, const size_t* counter);
65
67epicsShareFunc
68size_t readRefCounter(const char *name);
69
71class epicsShareClass RefSnapshot
72{
73public:
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
84private:
85 typedef std::map<std::string, Count> cnt_map_t;
86 cnt_map_t counts;
87public:
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
117epicsShareFunc
118std::ostream& operator<<(std::ostream& strm, const RefSnapshot& snap);
119
122class epicsShareClass RefMonitor
123{
124 struct Impl;
125 Impl *impl;
126public:
127 RefMonitor();
128 virtual ~RefMonitor();
129
130 void start(double period=10.0);
131 void stop();
132 bool running() const;
133
135 void current();
136protected:
139 virtual void show(const RefSnapshot& snap, bool complete=false);
140};
141
142} // namespace epics
143
144extern "C" {
145#endif /* __cplusplus */
146
150char* epicsRefSnapshotCurrent();
151
152#ifdef __cplusplus
153}
154#endif /* __cplusplus */
155
156#endif // REFTRACK_H
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator-(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
size_t start() const
gslice_array< _Tp > operator[](const gslice &__s)
valarray< size_t > size() const
void swap(any &__x, any &__y) noexcept
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
constexpr auto begin(_Container &__cont) -> decltype(__cont.begin())
constexpr auto end(_Container &__cont) -> decltype(__cont.end())
constexpr bool operator==(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const _CharT *__rhs)
epics
Definition convert.h:21