forked from epics-rip/exampleCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayPerformance.cpp
More file actions
151 lines (135 loc) · 4.24 KB
/
Copy patharrayPerformance.cpp
File metadata and controls
151 lines (135 loc) · 4.24 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* 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.08
*/
#include <epicsThread.h>
#include <pv/event.h>
#include <pv/standardPVField.h>
#include <pv/timeStamp.h>
#include <pv/pvTimeStamp.h>
#include <pv/pvDatabase.h>
#define epicsExportSharedSymbols
#include "pv/arrayPerformance.h"
namespace epics { namespace exampleCPP { namespace arrayPerformance {
using namespace std;
using namespace epics::pvData;
using namespace epics::pvDatabase;
ArrayPerformancePtr ArrayPerformance::create(
std::string const & recordName,
size_t size,
double delay)
{
PVStructurePtr pvStructure = getStandardPVField()->scalarArray(
pvLong,"value,timeStamp,alarm");
ArrayPerformancePtr arrayPerformance(
new ArrayPerformance(recordName,pvStructure,size,delay));
arrayPerformance->initPVRecord();
return arrayPerformance;
}
void ArrayPerformance::startThread()
{
thread = EpicsThreadPtr(new epicsThread(
*this,
"arrayPerformance",
epicsThreadGetStackSize(epicsThreadStackSmall),
epicsThreadPriorityLow));
thread->start();
}
ArrayPerformance::ArrayPerformance(
std::string const & recordName,
epics::pvData::PVStructurePtr const & pvStructure,
size_t size,
double delay)
: PVRecord(recordName,pvStructure),
size(size),
delay(delay)
{
}
void ArrayPerformance::process()
{
PVRecord::process();
}
void ArrayPerformance::stop()
{
runStop.signal();
runReturn.wait();
}
void ArrayPerformance::run()
{
PVStructurePtr pvStructure = PVRecord::getPVRecordStructure()->getPVStructure();
PVLongArrayPtr pvValue= pvStructure->getSubField<PVLongArray>("value");
TimeStamp timeStamp;
TimeStamp timeStampLast;
timeStampLast.getCurrent();
int nSinceLastReport = 0;
int64 value = 0;
while(true) {
if(runStop.tryWait()) {
runReturn.signal();
return;
}
if(delay>0.0) epicsThreadSleep(delay);
timeStamp.getCurrent();
double diff = TimeStamp::diff(timeStamp,timeStampLast);
if(diff>=1.0) {
ostringstream out;
out << "arrayPerformance value " << value;
out << " time " << diff ;
double iterations = nSinceLastReport;
iterations /= diff;
if(iterations>10.0e9) {
iterations /= 1e9;
out << " gigaIterations/sec " << iterations;
} else if(iterations>10.0e6) {
iterations /= 1e6;
out << " megaIterations/sec " << iterations;
} else if(iterations>10.0e3) {
iterations /= 1e3;
out << " kiloIterations/sec " << iterations;
} else {
out << " Iterations/sec " << iterations;
}
double elementSize = size;
double elementsPerSecond = elementSize*nSinceLastReport;
elementsPerSecond /= diff;
if(elementsPerSecond>10.0e9) {
elementsPerSecond /= 1e9;
out << " gigaElements/sec " << elementsPerSecond;
} else if(elementsPerSecond>10.0e6) {
elementsPerSecond /= 1e6;
out << " megaElements/sec " << elementsPerSecond;
} else if(elementsPerSecond>10.0e3) {
elementsPerSecond /= 1e3;
out << " kiloElements/sec " << elementsPerSecond;
} else {
out << " Elements/sec " << elementsPerSecond;
}
cout << out.str() << endl;
timeStampLast = timeStamp;
nSinceLastReport = 0;
}
++nSinceLastReport;
lock();
try {
if(getTraceLevel()>1) {
cout << "arrayPerformance size " << size;
cout << " value " << value +1 << endl;
}
shared_vector<int64> xxx(size,value++);
shared_vector<const int64> data(freeze(xxx));
beginGroupPut();
pvValue->replace(data);
process();
endGroupPut();
} catch(std::exception& e) {
unlock();
throw;
}
unlock();
}
}
}}}