| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include <QCoreApplication>
- #include <iostream>
- #include <thread>
- #include <QFile>
- QFile gFile;
- bool gbFile = false;
- int gnFile = 0;
- const int GNT = 1000;
- #include "modulecomm.h"
- void * mpa;
- void * mpb;
- void ListenTopic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- {
- static double favglatency = 0;
- static int ncount = 0;
- static long long latcount = 0;
- // std::cout<<"size is "<<nSize<<std::endl;
- int64_t recvtime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- int64_t sendtime;
- memcpy(&sendtime,strdata,sizeof(int64_t));
- long long latance = QDateTime::currentMSecsSinceEpoch() - dt->toMSecsSinceEpoch();
- latcount = latance + latcount;
- ncount++;
- double flatency = recvtime - sendtime;
- flatency = flatency/1000.0;
- char strout[1000];
- snprintf(strout,1000,"%d\t%f\n",gnFile,flatency);
- if(gnFile < GNT)favglatency = favglatency + flatency;
- if(gnFile<GNT)
- {
- if(gbFile)
- {
- gFile.write(strout,strnlen(strout,1000));
- }
- }
- else
- {
- if(gbFile)
- {
- if(gnFile == GNT)
- {
- favglatency = favglatency /GNT;
- snprintf(strout,1000,"avg %f",favglatency);
- gFile.write(strout,strnlen(strout,1000));
- gFile.close();
- }
- }
- }
- gnFile++;
- qDebug("latency is %6.3f",flatency);
- // std::cout<<"lat is "<<latance<<std::endl;
- std::cout<<ncount<<"\t"<<latance<<"\t"<<latcount/ncount<<std::endl;
- }
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- // iv::modulecomm::RegisterRecv("test1",ListenTopic);
- gFile.setFileName("/home/yuchuli/ddstest.txt");
- if(gFile.open(QIODevice::ReadWrite))
- {
- gbFile = true;
- }
- int i;
- for(i=0;i<1;i++)
- {
- // std::thread *px = new std::thread(testdata,i);
- char strname[256];
- snprintf(strname,255,"tests%d",i);
- iv::modulecomm::RegisterRecv(strname,ListenTopic);
- }
- return a.exec();
- }
|