Skip to content

Commit cf273de

Browse files
committed
Add stats to the caching proxy
1 parent ac4afcc commit cf273de

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

opencog/persist/proxy/CachingProxy.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void CachingProxy::init(void)
4949
// size and whatever other whizzy caching ideas we might want.
5050
void CachingProxy::open(void)
5151
{
52+
_nhits = 0;
53+
_nmisses = 0;
5254
ReadThruProxy::open();
5355
}
5456

@@ -80,40 +82,55 @@ void CachingProxy::getAtom(const Handle& h)
8082
{
8183
CHECK_OPEN;
8284

83-
if (h->haveValues()) return;
85+
if (h->haveValues()) { _nhits++; return; }
8486

87+
_nmisses ++;
8588
ReadThruProxy::getAtom(h);
8689
}
8790

8891
void CachingProxy::fetchIncomingSet(AtomSpace* as, const Handle& h)
8992
{
9093
CHECK_OPEN;
91-
if (0 < h->getIncomingSetSize(as)) return;
94+
if (0 < h->getIncomingSetSize(as)) { _nhits++; return; }
9295

96+
_nmisses ++;
9397
ReadThruProxy::fetchIncomingSet(as, h);
9498
}
9599

96100
void CachingProxy::fetchIncomingByType(AtomSpace* as, const Handle& h, Type t)
97101
{
98102
CHECK_OPEN;
99-
if (0 < h->getIncomingSetSizeByType(t, as)) return;
103+
if (0 < h->getIncomingSetSizeByType(t, as)) { _nhits++; return; }
100104

105+
_nmisses ++;
101106
ReadThruProxy::fetchIncomingByType(as, h, t);
102107
}
103108

104109
void CachingProxy::loadValue(const Handle& atom, const Handle& key)
105110
{
106111
CHECK_OPEN;
107-
if (nullptr != atom->getValue(key)) return;
112+
if (nullptr != atom->getValue(key)) { _nhits++; return; }
108113

114+
_nmisses ++;
109115
ReadThruProxy::loadValue(atom, key);
110116
}
111117

112118
// We're just going to be unconditional, here.
113119
void CachingProxy::loadType(AtomSpace* as, Type t)
114120
{
115121
CHECK_OPEN;
122+
_nmisses ++;
116123
ReadThruProxy::loadType(as, t);
117124
}
118125

126+
std::string CachingProxy::monitor(void)
127+
{
128+
std::string rpt;
129+
rpt += "Caching Proxy: ";
130+
rpt += "hits: " + std::to_string(_nhits);
131+
rpt += " misses: " + std::to_string(_nmisses);
132+
rpt += "\n";
133+
return rpt;
134+
}
135+
119136
DEFINE_NODE_FACTORY(CachingProxy, CACHING_PROXY_NODE)

opencog/persist/proxy/CachingProxy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class CachingProxy : public ReadThruProxy
3434
{
3535
private:
3636
void init(void);
37+
size_t _nhits;
38+
size_t _nmisses;
3739

3840
public:
3941
CachingProxy(const std::string&&);
@@ -54,6 +56,8 @@ class CachingProxy : public ReadThruProxy
5456
virtual void loadValue(const Handle& atom, const Handle& key);
5557
virtual void loadType(AtomSpace*, Type);
5658

59+
virtual std::string monitor(void);
60+
5761
public:
5862
static Handle factory(const Handle&);
5963
};

opencog/persist/proxy/WriteBufferProxy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class WriteBufferProxy : public WriteThruProxy
7373
// ----------------------------------------------------------------
7474
virtual void open(void);
7575
virtual void close(void);
76-
virtual bool connected(void) { return 0 < _targets.size(); }
7776

7877
protected:
7978
// ----------------------------------------------------------------

0 commit comments

Comments
 (0)