ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
7#include <sys/time.h>
8
9#include <fstream>
10#include <iostream>
11
12using namespace ChimeraTK;
13
14/*
15 *
16 * Usage: ( cd tests ; ../bin/testAccessorPerformance [<NumberOfIterations>] )
17 *
18 * <NumberOfIterations> is the number of iterations used for block access tests.
19 * Single word access tests will use 100000 times the given number of
20 * iterations. If omitted, the number of iterations defaults to 10 (which is
21 * acceptable also on slower machines in debug build mode).
22 *
23 */
24int main(int argc, char** argv) {
25 struct timeval tv;
26 int64_t t0, tdur;
27
28 setDMapFilePath("dummies.dmap");
29
31 device.open("PERFTEST");
32
33 int niterBlock;
34 if(argc <= 1) {
35 niterBlock = 10;
36 }
37 else {
38 niterBlock = atoi(argv[1]);
39 }
40
41 int64_t sum = 0;
42
43 std::ofstream fresult("performance_test.txt", std::ofstream::out);
44
45 std::cout << " **************************************************************"
46 "*************"
47 << std::endl;
48 std::cout << " Tests with the OneDRegisterAccessor:" << std::endl;
49
50 auto acc1D = device.getOneDRegisterAccessor<int>("ADC/AREA_DMA_VIA_DMA");
51 gettimeofday(&tv, nullptr);
52 t0 = tv.tv_sec * 1000000 + tv.tv_usec;
53 std::cout << " reading block ";
54 for(int i = 0; i < niterBlock; ++i) {
55 acc1D.read();
56 sum += acc1D[i];
57 }
58 gettimeofday(&tv, nullptr);
59 tdur = (tv.tv_sec * 1000000 + tv.tv_usec) - t0;
60 std::cout << "took " << static_cast<double>(tdur) / 1000. / niterBlock << " ms per block" << std::endl;
61 fresult << "1D_COOKEDus=" << std::round(static_cast<double>(tdur) / niterBlock) << std::endl;
62
63 auto acc1Draw = device.getOneDRegisterAccessor<int>("ADC/AREA_DMA_VIA_DMA", 0, 0, {AccessMode::raw});
64 gettimeofday(&tv, nullptr);
65 t0 = tv.tv_sec * 1000000 + tv.tv_usec;
66 std::cout << " raw-reading block ";
67 for(int i = 0; i < niterBlock; ++i) {
68 acc1Draw.read();
69 sum += acc1Draw[i];
70 }
71 gettimeofday(&tv, nullptr);
72 tdur = (tv.tv_sec * 1000000 + tv.tv_usec) - t0;
73 std::cout << "took " << static_cast<double>(tdur) / 1000. / niterBlock << " ms per block" << std::endl;
74 fresult << "1D_RAWus=" << std::round(static_cast<double>(tdur) / niterBlock) << std::endl;
75
76 std::cout << " **************************************************************"
77 "*************"
78 << std::endl;
79 std::cout << " Sum of all read data: " << sum << std::endl;
80
81 fresult.close();
82
83 return 0;
84}
int main()
Class allows to read/write registers from device.
Definition Device.h:39
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:276
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
ctk::Device device