main.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <QCoreApplication>
  2. #include <iostream>
  3. #include <thread>
  4. #include <QFile>
  5. QFile gFile;
  6. bool gbFile = false;
  7. int gnFile = 0;
  8. const int GNT = 1000;
  9. #include "modulecomm.h"
  10. void * mpa;
  11. void * mpb;
  12. void ListenTopic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  13. {
  14. static double favglatency = 0;
  15. static int ncount = 0;
  16. static long long latcount = 0;
  17. // std::cout<<"size is "<<nSize<<std::endl;
  18. int64_t recvtime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  19. int64_t sendtime;
  20. memcpy(&sendtime,strdata,sizeof(int64_t));
  21. long long latance = QDateTime::currentMSecsSinceEpoch() - dt->toMSecsSinceEpoch();
  22. latcount = latance + latcount;
  23. ncount++;
  24. double flatency = recvtime - sendtime;
  25. flatency = flatency/1000.0;
  26. char strout[1000];
  27. snprintf(strout,1000,"%d\t%f\n",gnFile,flatency);
  28. if(gnFile < GNT)favglatency = favglatency + flatency;
  29. if(gnFile<GNT)
  30. {
  31. if(gbFile)
  32. {
  33. gFile.write(strout,strnlen(strout,1000));
  34. }
  35. }
  36. else
  37. {
  38. if(gbFile)
  39. {
  40. if(gnFile == GNT)
  41. {
  42. favglatency = favglatency /GNT;
  43. snprintf(strout,1000,"avg %f",favglatency);
  44. gFile.write(strout,strnlen(strout,1000));
  45. gFile.close();
  46. }
  47. }
  48. }
  49. gnFile++;
  50. qDebug("latency is %6.3f",flatency);
  51. // std::cout<<"lat is "<<latance<<std::endl;
  52. std::cout<<ncount<<"\t"<<latance<<"\t"<<latcount/ncount<<std::endl;
  53. }
  54. int main(int argc, char *argv[])
  55. {
  56. QCoreApplication a(argc, argv);
  57. // iv::modulecomm::RegisterRecv("test1",ListenTopic);
  58. gFile.setFileName("/home/yuchuli/ddstest.txt");
  59. if(gFile.open(QIODevice::ReadWrite))
  60. {
  61. gbFile = true;
  62. }
  63. int i;
  64. for(i=0;i<1;i++)
  65. {
  66. // std::thread *px = new std::thread(testdata,i);
  67. char strname[256];
  68. snprintf(strname,255,"tests%d",i);
  69. iv::modulecomm::RegisterRecv(strname,ListenTopic);
  70. }
  71. return a.exec();
  72. }