From 2063a3069b990075b5a2b578467e6c5e41e9fd01 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 30 Aug 2017 13:06:21 -0500 Subject: [PATCH] add reftrack iocsh --- src/ioc/Makefile | 1 + src/ioc/PVAServerRegister.dbd | 1 + src/ioc/reftrackioc.cpp | 90 +++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/ioc/reftrackioc.cpp diff --git a/src/ioc/Makefile b/src/ioc/Makefile index 7972bea..16b1349 100644 --- a/src/ioc/Makefile +++ b/src/ioc/Makefile @@ -14,5 +14,6 @@ DBD += PVAClientRegister.dbd pvAccessIOC_SRCS += PVAServerRegister.cpp pvAccessIOC_SRCS += PVAClientRegister.cpp +pvAccessIOC_SRCS += reftrackioc.cpp include $(TOP)/configure/RULES diff --git a/src/ioc/PVAServerRegister.dbd b/src/ioc/PVAServerRegister.dbd index f8627bd..b065342 100644 --- a/src/ioc/PVAServerRegister.dbd +++ b/src/ioc/PVAServerRegister.dbd @@ -1 +1,2 @@ registrar("registerStartPVAServer") +registrar("refTrackRegistrar") diff --git a/src/ioc/reftrackioc.cpp b/src/ioc/reftrackioc.cpp new file mode 100644 index 0000000..979b4a6 --- /dev/null +++ b/src/ioc/reftrackioc.cpp @@ -0,0 +1,90 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * EPICS pvData is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + +#include + +#include +#include + +#include + +#include + +namespace { + +void showRefs(const epics::RefSnapshot& snap, int lvl, bool delta) +{ + for(epics::RefSnapshot::const_iterator it = snap.begin(), end = snap.end(); + it != end; ++it) + { + if(it->second.current==0 && it->second.delta==0 && lvl<=0) continue; + if(delta && it->second.delta==0 && lvl<=0) continue; + if(delta) { + printf(" %s : %zu (delta %zd)\n", + it->first.c_str(), it->second.current, it->second.delta); + } else { + printf(" %s : %zu\n", it->first.c_str(), it->second.current); + } + } +} + +#define CATCH() catch(std::exception& e){printf("Error %s\n", e.what());} + +void refshow(int lvl) +{ + try { + epics::RefSnapshot snap; + snap.update(); + + showRefs(snap, lvl, false); + }CATCH() +} + +// No locking. assume only interactive iocsh use +static epics::RefSnapshot savedSnap; + +void refsave() +{ + try { + epics::RefSnapshot snap; + snap.update(); + + savedSnap.swap(snap); + }CATCH() +} + +void refdiff(int lvl) +{ + epics::RefSnapshot snap; + snap.update(); + + showRefs(snap-savedSnap, lvl, true); +} + +static epics::RefMonitor gblmon; + +void refmon(double period, int lvl) +{ + if(period==0) { + gblmon.stop(); + } else if(period>0) { + gblmon.start(period); + } +} + +void refTrackRegistrar() +{ + epics::iocshRegister("refshow", "detail level"); + epics::iocshRegister<&refsave>("refsave"); + epics::iocshRegister("refdiff", "detail level"); + epics::iocshRegister("refmon", "update period", "detail level"); +} + +} // namespace + +extern "C" { + epicsExportRegistrar(refTrackRegistrar); +}