added event thread executor timeFunction showConstructDestruct timeStamp
This commit is contained in:
@@ -6,6 +6,10 @@ PROD_HOST += testLinkedList
|
||||
testLinkedList_SRCS += testLinkedList.cpp
|
||||
testLinkedList_LIBS += pvMisc Com
|
||||
|
||||
PROD_HOST += testThread
|
||||
testThread_SRCS += testThread.cpp
|
||||
testThread_LIBS += pvMisc Com
|
||||
|
||||
PROD_HOST += testBitSet
|
||||
testBitSet_SRCS += testBitSet.cpp
|
||||
testBitSet_LIBS += pvMisc Com
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* * testLinkedList.cpp
|
||||
* *
|
||||
* * Created on: 2010.11
|
||||
* * Author: Marty Kraimer
|
||||
* */
|
||||
* testLinkedList.cpp
|
||||
*
|
||||
* Created on: 2010.11
|
||||
* Author: Marty Kraimer
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
@@ -12,13 +12,12 @@
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
|
||||
#include <epicsTime.h>
|
||||
#include <epicsAssert.h>
|
||||
|
||||
#include "lock.h"
|
||||
#include "timeStamp.h"
|
||||
#include "linkedList.h"
|
||||
#include "pvIntrospect.h"
|
||||
#include "pvData.h"
|
||||
#include "showConstructDestruct.h"
|
||||
|
||||
|
||||
using namespace epics::pvData;
|
||||
@@ -271,8 +270,8 @@ static void testOrderedQueue(FILE * fd ) {
|
||||
}
|
||||
|
||||
static void testTime(FILE *auxFd) {
|
||||
epicsTimeStamp startTime;
|
||||
epicsTimeStamp endTime;
|
||||
TimeStamp startTime(0,0);
|
||||
TimeStamp endTime(0,0);
|
||||
int numNodes = 1000;
|
||||
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
@@ -282,15 +281,15 @@ static void testTime(FILE *auxFd) {
|
||||
}
|
||||
fprintf(auxFd,"\nTime test\n");
|
||||
int ntimes = 1000;
|
||||
epicsTimeGetCurrent(&startTime);
|
||||
startTime.getCurrent();
|
||||
for(int i=0; i<ntimes; i++) {
|
||||
for(int j=0;j<numNodes;j++) basicList->addTail(basics[j]->node);
|
||||
BasicListNode *basicNode = basicList->removeHead();
|
||||
while(basicNode!=0) basicNode = basicList->removeHead();
|
||||
}
|
||||
epicsTimeGetCurrent(&endTime);
|
||||
double diff = epicsTimeDiffInSeconds(&endTime,&startTime);
|
||||
diff *= 1000.0;
|
||||
endTime.getCurrent();
|
||||
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
|
||||
diff /= 1000.0;
|
||||
fprintf(auxFd,"diff %f milliSeconds\n",diff);
|
||||
diff = diff/1000.0; // convert from milliseconds to seconds
|
||||
diff = diff/ntimes; // seconds per outer loop
|
||||
@@ -304,8 +303,8 @@ static void testTime(FILE *auxFd) {
|
||||
}
|
||||
|
||||
static void testTimeLocked(FILE *auxFd) {
|
||||
epicsTimeStamp startTime;
|
||||
epicsTimeStamp endTime;
|
||||
TimeStamp startTime(0,0);
|
||||
TimeStamp endTime(0,0);
|
||||
Mutex *mutex = new Mutex();
|
||||
int numNodes = 1000;
|
||||
|
||||
@@ -316,7 +315,7 @@ static void testTimeLocked(FILE *auxFd) {
|
||||
}
|
||||
fprintf(auxFd,"\nTime test locked\n");
|
||||
int ntimes = 1000;
|
||||
epicsTimeGetCurrent(&startTime);
|
||||
startTime.getCurrent();
|
||||
for(int i=0; i<ntimes; i++) {
|
||||
for(int j=0;j<numNodes;j++) {
|
||||
Lock xx(mutex);
|
||||
@@ -332,8 +331,8 @@ static void testTimeLocked(FILE *auxFd) {
|
||||
basicNode = basicList->removeHead();
|
||||
}
|
||||
}
|
||||
epicsTimeGetCurrent(&endTime);
|
||||
double diff = epicsTimeDiffInSeconds(&endTime,&startTime);
|
||||
endTime.getCurrent();
|
||||
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
|
||||
diff *= 1000.0;
|
||||
fprintf(auxFd,"diff %f milliSeconds\n",diff);
|
||||
diff = diff/1000.0; // convert from milliseconds to seconds
|
||||
@@ -349,8 +348,8 @@ static void testTimeLocked(FILE *auxFd) {
|
||||
|
||||
typedef std::list<Basic *> stdList;
|
||||
static void testArrayListTime(FILE *auxFd) {
|
||||
epicsTimeStamp startTime;
|
||||
epicsTimeStamp endTime;
|
||||
TimeStamp startTime(0,0);
|
||||
TimeStamp endTime(0,0);
|
||||
int numNodes = 1000;
|
||||
|
||||
stdList basicList;
|
||||
@@ -360,7 +359,7 @@ static void testArrayListTime(FILE *auxFd) {
|
||||
}
|
||||
fprintf(auxFd,"\nTime ArrayList test\n");
|
||||
int ntimes = 1000;
|
||||
epicsTimeGetCurrent(&startTime);
|
||||
startTime.getCurrent();
|
||||
for(int i=0; i<ntimes; i++) {
|
||||
for(int j=0;j<numNodes;j++) basicList.push_back(basics[j]);
|
||||
while(basicList.size()>0) {
|
||||
@@ -368,8 +367,8 @@ static void testArrayListTime(FILE *auxFd) {
|
||||
basicList.pop_front();
|
||||
}
|
||||
}
|
||||
epicsTimeGetCurrent(&endTime);
|
||||
double diff = epicsTimeDiffInSeconds(&endTime,&startTime);
|
||||
endTime.getCurrent();
|
||||
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
|
||||
diff *= 1000.0;
|
||||
fprintf(auxFd,"diff %f milliSeconds\n",diff);
|
||||
diff = diff/1000.0; // convert from milliseconds to seconds
|
||||
@@ -382,8 +381,8 @@ static void testArrayListTime(FILE *auxFd) {
|
||||
}
|
||||
|
||||
static void testArrayListTimeLocked(FILE *auxFd) {
|
||||
epicsTimeStamp startTime;
|
||||
epicsTimeStamp endTime;
|
||||
TimeStamp startTime(0,0);
|
||||
TimeStamp endTime(0,0);
|
||||
int numNodes = 1000;
|
||||
Mutex *mutex = new Mutex();
|
||||
|
||||
@@ -394,7 +393,7 @@ static void testArrayListTimeLocked(FILE *auxFd) {
|
||||
}
|
||||
fprintf(auxFd,"\nTime ArrayList test locked\n");
|
||||
int ntimes = 1000;
|
||||
epicsTimeGetCurrent(&startTime);
|
||||
startTime.getCurrent();
|
||||
for(int i=0; i<ntimes; i++) {
|
||||
for(int j=0;j<numNodes;j++) {
|
||||
Lock xx(mutex);
|
||||
@@ -406,8 +405,8 @@ static void testArrayListTimeLocked(FILE *auxFd) {
|
||||
basicList.pop_front();
|
||||
}
|
||||
}
|
||||
epicsTimeGetCurrent(&endTime);
|
||||
double diff = epicsTimeDiffInSeconds(&endTime,&startTime);
|
||||
endTime.getCurrent();
|
||||
double diff = TimeStamp::diffInSeconds(&endTime,&startTime);
|
||||
diff *= 1000.0;
|
||||
fprintf(auxFd,"diff %f milliSeconds\n",diff);
|
||||
diff = diff/1000.0; // convert from milliseconds to seconds
|
||||
@@ -442,16 +441,7 @@ int main(int argc, char *argv[]) {
|
||||
testTimeLocked(auxFd);
|
||||
testArrayListTime(auxFd);
|
||||
testArrayListTimeLocked(auxFd);
|
||||
int totalConstructList = LinkedListVoid::getTotalConstruct();
|
||||
int totalDestructList = LinkedListVoid::getTotalDestruct();
|
||||
int totalConstructListNode = LinkedListVoidNode::getTotalConstruct();
|
||||
int totalDestructListNode = LinkedListVoidNode::getTotalDestruct();
|
||||
fprintf(fd,"totalConstructList %d totalDestructList %d",
|
||||
totalConstructList,totalDestructList);
|
||||
fprintf(fd," totalConstructListNode %d totalDestructListNode %d\n",
|
||||
totalConstructListNode,totalDestructListNode);
|
||||
assert(totalConstructList==totalDestructList);
|
||||
assert(totalConstructListNode==totalDestructListNode);
|
||||
getShowConstructDestruct()->constuctDestructTotals(fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* testThread.cpp
|
||||
*
|
||||
* Created on: 2010.11
|
||||
* Author: Marty Kraimer
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
|
||||
#include "event.h"
|
||||
#include "thread.h"
|
||||
#include "executor.h"
|
||||
#include "showConstructDestruct.h"
|
||||
#include "timeFunction.h"
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
|
||||
class Basic : public Command {
|
||||
public:
|
||||
Basic(Executor *executor);
|
||||
~Basic();
|
||||
void run();
|
||||
virtual void command();
|
||||
private:
|
||||
Executor *executor;
|
||||
ExecutorNode *executorNode;
|
||||
Event *wait;
|
||||
};
|
||||
|
||||
Basic::Basic(Executor *executor)
|
||||
: executor(executor),
|
||||
executorNode(executor->createNode(this)),
|
||||
wait(new Event(eventEmpty))
|
||||
{
|
||||
}
|
||||
|
||||
Basic::~Basic() {
|
||||
delete wait;
|
||||
}
|
||||
|
||||
void Basic::run()
|
||||
{
|
||||
executor->execute(executorNode);
|
||||
bool result = wait->wait();
|
||||
if(result==false) printf("basic::run wait returned true\n");
|
||||
}
|
||||
|
||||
void Basic::command()
|
||||
{
|
||||
wait->signal();
|
||||
}
|
||||
|
||||
|
||||
static void testBasic(FILE *fd) {
|
||||
Executor *executor = new Executor(String("basic"),middlePriority);
|
||||
Basic *basic = new Basic(executor);
|
||||
basic->run();
|
||||
delete basic;
|
||||
String buf("");
|
||||
Thread::showThreads(&buf);
|
||||
fprintf(fd,"threads\n%s\n",buf.c_str());
|
||||
executor->destroy();
|
||||
}
|
||||
|
||||
class MyFunc : public TimeFunctionRequester {
|
||||
public:
|
||||
MyFunc(Basic *basic)
|
||||
: basic(basic)
|
||||
{}
|
||||
virtual void function()
|
||||
{
|
||||
basic->run();
|
||||
}
|
||||
private:
|
||||
Basic *basic;
|
||||
};
|
||||
|
||||
static void testThreadContext(FILE *fd,FILE *auxFd) {
|
||||
Executor *executor = new Executor(String("basic"),middlePriority);
|
||||
Basic *basic = new Basic(executor);
|
||||
MyFunc myFunc(basic);
|
||||
TimeFunction timeFunction(&myFunc);
|
||||
double perCall = timeFunction.timeCall();
|
||||
perCall *= 1e6;
|
||||
fprintf(auxFd,"time per call %f microseconds\n",perCall);
|
||||
delete basic;
|
||||
executor->destroy();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
if(argc>1) fileName = argv[1];
|
||||
FILE * fd = stdout;
|
||||
if(fileName!=0 && fileName[0]!=0) {
|
||||
fd = fopen(fileName,"w+");
|
||||
}
|
||||
char *auxFileName = 0;
|
||||
if(argc>2) auxFileName = argv[2];
|
||||
FILE *auxFd = stdout;
|
||||
if(auxFileName!=0 && auxFileName[0]!=0) {
|
||||
auxFd = fopen(auxFileName,"w+");
|
||||
}
|
||||
testBasic(fd);
|
||||
testThreadContext(fd,auxFd);
|
||||
getShowConstructDestruct()->constuctDestructTotals(fd);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user