forked from epics-rip/exampleCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongArrayMonitor.cpp
More file actions
127 lines (115 loc) · 3.64 KB
/
Copy pathlongArrayMonitor.cpp
File metadata and controls
127 lines (115 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/**
* @author mrk
* @date 2013.08.09
*/
#include <epicsThread.h>
#include <pv/event.h>
#include <pv/standardPVField.h>
#include <pv/nt.h>
#include <pv/pvTimeStamp.h>
#include <pv/pvAlarm.h>
#include <pv/pvControl.h>
#include <pv/pvDisplay.h>
#include <pv/pvDatabase.h>
#include <pv/pvaClient.h>
#define epicsExportSharedSymbols
#include "pv/longArrayMonitor.h"
namespace epics { namespace exampleCPP { namespace arrayPerformance {
using namespace std;
using namespace epics::pvData;
using namespace epics::pvAccess;
using namespace epics::pvaClient;
using namespace std;
LongArrayMonitor::LongArrayMonitor(
string const & channelName,
int queueSize)
:
channelName(channelName),
queueSize(queueSize)
{
thread = EpicsThreadPtr(new epicsThread(
*this,
"longArrayMonitor",
epicsThreadGetStackSize(epicsThreadStackSmall),
epicsThreadPriorityLow));
thread->start();
}
void LongArrayMonitor::stop()
{
runStop.signal();
runReturn.wait();
}
void LongArrayMonitor::run()
{
PvaClientPtr pva(PvaClient::get("pva"));
string request("record[queueSize=");
char buff[20];
sprintf(buff,"%d",queueSize);
request += buff;
request += "]field(value,timeStamp,alarm)";
PvaClientMonitorPtr monitor = pva->channel(channelName)->monitor(request);
TimeStamp timeStamp;
TimeStamp timeStampLast;
timeStampLast.getCurrent();
long nElements = 0;
long nSinceLastReport = 0;
int64 first = 0;
int64 last = 0;
while(true) {
if(runStop.tryWait()) {
runReturn.signal();
return;
}
if(!monitor->waitEvent(0.0)) {
cout << "waitEvent returned false. Why???" << endl;
continue;
}
PvaClientMonitorDataPtr pvaData = monitor->getData();
PVStructurePtr pvStructure = pvaData->getPVStructure();
PVLongArrayPtr pvValue = pvStructure->getSubField<PVLongArray>("value");
size_t len = pvValue->getLength();
if(len>0) {
shared_vector<const int64> data = pvValue->view();
first = data[0];
last = data[len-1];
if(first!=last) cout << "error first=" << first << " last=" << last << endl;
} else {
cout << "len is 0" << endl;
}
nElements += len;
timeStamp.getCurrent();
double diff = TimeStamp::diff(timeStamp,timeStampLast);
if(diff>=1.0) {
ostringstream out;
out << " monitors/sec " << nSinceLastReport << " ";
if(len>0) out << "first " << first << " last " << last ;
out << " changed " << *pvaData->getChangedBitSet();
out << " overrun " << *pvaData->getOverrunBitSet();
double elementsPerSec = nElements;
elementsPerSec /= diff;
if(elementsPerSec>10.0e9) {
elementsPerSec /= 1e9;
out << " gigaElements/sec " << elementsPerSec;
} else if(elementsPerSec>10.0e6) {
elementsPerSec /= 1e6;
out << " megaElements/sec " << elementsPerSec;
} else if(elementsPerSec>10.0e3) {
elementsPerSec /= 1e3;
out << " kiloElements/sec " << elementsPerSec;
} else {
out << " Elements/sec " << elementsPerSec;
}
cout << out.str() << endl;
timeStampLast = timeStamp;
nSinceLastReport = 0;
nElements = 0;
}
++nSinceLastReport;
monitor->releaseEvent();
}
}
}}}