ChimeraTK-DeviceAccess  03.18.00
testAccessorPerformance.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
4 #include "Device.h"
5 #include "Utilities.h"
6 #include <sys/time.h>
7 
8 #include <fstream>
9 #include <iostream>
10 
11 using namespace ChimeraTK;
12 
13 /*
14  *
15  * Usage: ( cd tests ; ../bin/testAccessorPerformance [<NumberOfIterations>] )
16  *
17  * <NumberOfIterations> is the number of iterations used for block access tests.
18  * Single word access tests will use 100000 times the given number of
19  * iterations. If omitted, the number of iterations defaults to 10 (which is
20  * acceptable also on slower machines in debug build mode).
21  *
22  */
23 int main(int argc, char** argv) {
24  struct timeval tv;
25  int64_t t0, tdur;
26 
27  setDMapFilePath("dummies.dmap");
28 
29  Device device;
30  device.open("PERFTEST");
31 
32  int niterBlock;
33  if(argc <= 1) {
34  niterBlock = 10;
35  }
36  else {
37  niterBlock = atoi(argv[1]);
38  }
39 
40  int64_t sum = 0;
41 
42  std::ofstream fresult("performance_test.txt", std::ofstream::out);
43 
44  std::cout << " **************************************************************"
45  "*************"
46  << std::endl;
47  std::cout << " Tests with the OneDRegisterAccessor:" << std::endl;
48 
49  auto acc1D = device.getOneDRegisterAccessor<int>("ADC/AREA_DMA_VIA_DMA");
50  gettimeofday(&tv, nullptr);
51  t0 = tv.tv_sec * 1000000 + tv.tv_usec;
52  std::cout << " reading block ";
53  for(int i = 0; i < niterBlock; ++i) {
54  acc1D.read();
55  sum += acc1D[i];
56  }
57  gettimeofday(&tv, nullptr);
58  tdur = (tv.tv_sec * 1000000 + tv.tv_usec) - t0;
59  std::cout << "took " << static_cast<double>(tdur) / 1000. / niterBlock << " ms per block" << std::endl;
60  fresult << "1D_COOKEDus=" << std::round(static_cast<double>(tdur) / niterBlock) << std::endl;
61 
62  auto acc1Draw = device.getOneDRegisterAccessor<int>("ADC/AREA_DMA_VIA_DMA", 0, 0, {AccessMode::raw});
63  gettimeofday(&tv, nullptr);
64  t0 = tv.tv_sec * 1000000 + tv.tv_usec;
65  std::cout << " raw-reading block ";
66  for(int i = 0; i < niterBlock; ++i) {
67  acc1Draw.read();
68  sum += acc1Draw[i];
69  }
70  gettimeofday(&tv, nullptr);
71  tdur = (tv.tv_sec * 1000000 + tv.tv_usec) - t0;
72  std::cout << "took " << static_cast<double>(tdur) / 1000. / niterBlock << " ms per block" << std::endl;
73  fresult << "1D_RAWus=" << std::round(static_cast<double>(tdur) / niterBlock) << std::endl;
74 
75  std::cout << " **************************************************************"
76  "*************"
77  << std::endl;
78  std::cout << " Sum of all read data: " << sum << std::endl;
79 
80  fresult.close();
81 
82  return 0;
83 }
ChimeraTK::AccessMode::raw
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...
device
ctk::Device device
Definition: testExceptionDummyDevice.cc:18
ChimeraTK::Device::getOneDRegisterAccessor
OneDRegisterAccessor< UserType > getOneDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfWords=0, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a OneDRegisterAccessor object for the given register.
Definition: Device.h:273
Utilities.h
Device.h
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
main
int main(int argc, char **argv)
Definition: testAccessorPerformance.cpp:23
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327
ChimeraTK
Definition: DummyBackend.h:16