more changes for arrayPerformance; added vectorPerformanceMain.cpp
This commit is contained in:
@@ -12,6 +12,11 @@ longArrayMonitorMain_SRCS += longArrayMonitorMain.cpp
|
||||
longArrayMonitorMain_LIBS += pvDatabase pvAccess pvData Com
|
||||
longArrayMonitorMain_LIBS += pvDatabaseExample
|
||||
|
||||
PROD_HOST += vectorPerformanceMain
|
||||
vectorPerformanceMain_SRCS += vectorPerformanceMain.cpp
|
||||
vectorPerformanceMain_LIBS += pvDatabase pvAccess pvData Com
|
||||
vectorPerformanceMain_LIBS += pvDatabaseExample
|
||||
|
||||
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/*vectorPerformanceMain.cpp */
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2013.09.02
|
||||
*/
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <epicsThread.h>
|
||||
#include <pv/timeStamp.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
|
||||
class VectorPerformanceThread;
|
||||
typedef std::tr1::shared_ptr<VectorPerformanceThread> VectorPerformanceThreadPtr;
|
||||
|
||||
class VectorPerformanceThread :
|
||||
public epicsThreadRunable
|
||||
{
|
||||
public:
|
||||
VectorPerformanceThread(int threadNumber,size_t size,double delay);
|
||||
virtual ~VectorPerformanceThread(){};
|
||||
void init();
|
||||
void start();
|
||||
virtual void run();
|
||||
void destroy();
|
||||
private:
|
||||
bool isDestroyed;
|
||||
bool runReturned;
|
||||
int threadNumber;
|
||||
size_t size;
|
||||
epics::pvData::int64 value;
|
||||
double delay;
|
||||
Mutex mutex;
|
||||
std::vector<int64> vector;
|
||||
std::auto_ptr<epicsThread> thread;
|
||||
};
|
||||
|
||||
VectorPerformanceThread::VectorPerformanceThread(
|
||||
int threadNumber,size_t size,double delay)
|
||||
:
|
||||
isDestroyed(false),
|
||||
runReturned(false),
|
||||
threadNumber(threadNumber),
|
||||
size(size),
|
||||
value(0),
|
||||
delay(delay)
|
||||
{}
|
||||
|
||||
void VectorPerformanceThread::init()
|
||||
{
|
||||
vector.resize(size);
|
||||
thread = std::auto_ptr<epicsThread>(new epicsThread(
|
||||
*this,
|
||||
"vectorPerform",
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
epicsThreadPriorityHigh));
|
||||
}
|
||||
|
||||
void VectorPerformanceThread::start()
|
||||
{
|
||||
thread->start();
|
||||
}
|
||||
|
||||
void VectorPerformanceThread::destroy()
|
||||
{
|
||||
Lock lock(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
while(true) {
|
||||
if(runReturned) break;
|
||||
lock.unlock();
|
||||
epicsThreadSleep(.01);
|
||||
lock.lock();
|
||||
}
|
||||
thread->exitWait();
|
||||
thread.reset();
|
||||
}
|
||||
|
||||
|
||||
void VectorPerformanceThread::run()
|
||||
{
|
||||
TimeStamp timeStamp;
|
||||
TimeStamp timeStampLast;
|
||||
timeStampLast.getCurrent();
|
||||
int nSinceLastReport = 0;
|
||||
while(true) {
|
||||
if(delay>0.0) epicsThreadSleep(delay);
|
||||
{
|
||||
Lock lock(mutex);
|
||||
if(isDestroyed) {
|
||||
cout << " found isDestroyed " << threadNumber << endl;
|
||||
runReturned = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
timeStamp.getCurrent();
|
||||
double diff = TimeStamp::diff(timeStamp,timeStampLast);
|
||||
if(diff>=1.0) {
|
||||
cout << "thread" << threadNumber;
|
||||
cout << " value " << value;
|
||||
cout << " time " << diff;
|
||||
double iterations = nSinceLastReport;
|
||||
iterations /= diff;
|
||||
cout << " iterations/sec " << iterations;
|
||||
double elementSize = size;
|
||||
double elementsPerSecond = elementSize*nSinceLastReport;
|
||||
elementsPerSecond /= diff;
|
||||
elementsPerSecond /= 1e6;
|
||||
cout << " elements/sec " << elementsPerSecond << "million" << endl;
|
||||
cout.flush();
|
||||
timeStampLast = timeStamp;
|
||||
nSinceLastReport = 0;
|
||||
}
|
||||
++nSinceLastReport;
|
||||
++value;
|
||||
for(size_t i=0; i<size; ++i) vector[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
size_t size = 50000000;
|
||||
double delay = .01;
|
||||
size_t nThread = 1;
|
||||
if(argc==2 && String(argv[1])==String("-help")) {
|
||||
cout << "vectorPerformanceMain size delay nThread" << endl;
|
||||
cout << "default" << endl;
|
||||
cout << "vectorPerformance ";
|
||||
cout << size << " ";
|
||||
cout << delay << " ";
|
||||
cout << nThread << " ";
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
if(argc>1) size = strtoul(argv[1],0,0);
|
||||
if(argc>2) delay = atof(argv[2]);
|
||||
if(argc>3) nThread = strtoul(argv[3],0,0);
|
||||
cout << "vectorPerformance ";
|
||||
cout << size << " ";
|
||||
cout << delay << " ";
|
||||
cout << nThread << " ";
|
||||
cout << endl;
|
||||
cout << "vectorPerformance\n";
|
||||
std::vector<VectorPerformanceThreadPtr> threads;
|
||||
for(size_t i=0; i<nThread; ++i) {
|
||||
threads.push_back(
|
||||
VectorPerformanceThreadPtr(
|
||||
new VectorPerformanceThread(i,size,delay)));
|
||||
}
|
||||
epicsThreadSleep(.1);
|
||||
for(size_t i=0; i<nThread; ++i) {
|
||||
threads[i]->init();
|
||||
}
|
||||
for(size_t i=0; i<nThread; ++i) {
|
||||
threads[i]->start();
|
||||
}
|
||||
string str;
|
||||
while(true) {
|
||||
cout << "Type exit to stop: \n";
|
||||
getline(cin,str);
|
||||
if(str.compare("exit")==0) break;
|
||||
|
||||
}
|
||||
for(size_t i=0; i<nThread; ++i) {
|
||||
cout << "" << i << " calling destroy" << endl;
|
||||
threads[i]->destroy();
|
||||
threads[i].reset();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* @author mrk
|
||||
* @date 2013.08.08
|
||||
*/
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/arrayPerformance.h>
|
||||
|
||||
@@ -18,6 +19,7 @@ using std::tr1::static_pointer_cast;
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::ostringstream;
|
||||
|
||||
ArrayPerformancePtr ArrayPerformance::create(
|
||||
epics::pvData::String const & recordName,
|
||||
@@ -87,7 +89,8 @@ ArrayPerformanceThread::ArrayPerformanceThread(ArrayPerformancePtr const & array
|
||||
arrayPerformance(arrayPerformance),
|
||||
isDestroyed(false),
|
||||
runReturned(false),
|
||||
threadName("arrayPerformance")
|
||||
threadName("arrayPerformance"),
|
||||
value(0)
|
||||
{}
|
||||
|
||||
void ArrayPerformanceThread::init()
|
||||
@@ -138,17 +141,18 @@ void ArrayPerformanceThread::run()
|
||||
timeStamp.getCurrent();
|
||||
double diff = TimeStamp::diff(timeStamp,timeStampLast);
|
||||
if(diff>=1.0) {
|
||||
cout << "arrayPerformance value " << value;
|
||||
cout << " time " << diff;
|
||||
ostringstream out;
|
||||
out << "arrayPerformance value " << value;
|
||||
out << " time " << diff;
|
||||
double iterations = nSinceLastReport;
|
||||
iterations /= diff;
|
||||
cout << " iterations/sec " << iterations;
|
||||
out << " iterations/sec " << iterations;
|
||||
double elementSize = arrayPerformance->size;
|
||||
double elementsPerSecond = elementSize*nSinceLastReport;
|
||||
elementsPerSecond /= diff;
|
||||
elementsPerSecond /= 1e6;
|
||||
cout << " elements/sec " << elementsPerSecond << "million" << endl;
|
||||
cout.flush();
|
||||
out << " elements/sec " << elementsPerSecond << "million";
|
||||
cout << out.str() << endl;
|
||||
timeStampLast = timeStamp;
|
||||
nSinceLastReport = 0;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ private:
|
||||
bool runReturned;
|
||||
epics::pvData::String threadName;
|
||||
Event event;
|
||||
Mutex mutex;
|
||||
std::auto_ptr<epicsThread> thread;
|
||||
};
|
||||
|
||||
@@ -163,9 +164,14 @@ void LAMMonitorRequester::run()
|
||||
return;
|
||||
}
|
||||
while(true) {
|
||||
MonitorElementPtr monitorElement = longArrayMonitor->monitor->poll();
|
||||
MonitorElementPtr monitorElement;
|
||||
PVStructurePtr pvStructure;
|
||||
{
|
||||
Lock xx(mutex);
|
||||
monitorElement = longArrayMonitor->monitor->poll();
|
||||
if(monitorElement!=NULL) pvStructure = monitorElement->pvStructurePtr;
|
||||
}
|
||||
if(monitorElement==NULL) break;
|
||||
PVStructurePtr pvStructure = monitorElement->pvStructurePtr;
|
||||
pvTimeStamp.attach(pvStructure->getSubField("timeStamp"));
|
||||
pvTimeStamp.get(timeStamp);
|
||||
pvValue = dynamic_pointer_cast<PVLongArray>(pvStructure->getSubField("value"));
|
||||
|
||||
Reference in New Issue
Block a user