μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tools.hpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23 Marc Magrans de Abril, CERN
24 email: marc.magrans.de.abril <AT> cern.ch
25
26 Andrew Rose, Imperial College, London
27 email: awr01 <AT> imperial.ac.uk
28
29 Tom Williams, Rutherford Appleton Laboratory, Oxfordshire
30 email: tom.williams <AT> cern.ch
31
32---------------------------------------------------------------------------
33*/
34
35#ifndef _uhal_tests_tools_hpp_
36#define _uhal_tests_tools_hpp_
37
38
39#include <chrono>
40#include <iostream>
41#include <map>
42#include <memory>
43#include <stdint.h>
44#include <string>
45#include <sys/time.h>
46#include <thread>
47
49#include "uhal/HwInterface.hpp"
51
52
53
54namespace uhal {
55namespace tests {
56
57class DummyHardwareInterface;
58
60public:
63
64 void setReplyDelay (const std::chrono::microseconds& aDelay);
65
66private:
67 std::unique_ptr<DummyHardwareInterface> mHw;
68 std::thread mHwThread;
69};
70
71
73class Timer
74{
75public:
76
78 {
79 gettimeofday ( &m_start, NULL );
80 }
81
84 {
85 timeval now;
86 gettimeofday ( &now, NULL );
87 time_t sec = now.tv_sec - m_start.tv_sec;
88 suseconds_t usec = now.tv_usec - m_start.tv_usec;
89 return static_cast<double> ( sec + usec/1000000. );
90 }
91
92private:
93 timeval m_start;
94
95}; /* End of class Timer */
96
97
98double measureReadLatency(ClientInterface& aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
99
100double measureReadLatency(const std::vector<ClientInterface*>& aClients, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
101
102double measureWriteLatency(ClientInterface& aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
103
104double measureWriteLatency(const std::vector<ClientInterface*>& aClients, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
105
106double measureFileReadLatency(const std::string& aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose);
107
108double measureFileWriteLatency(const std::string& aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose);
109
110} // end ns tests
111} // end ns uhal
112
113#endif
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
Common abstract base class for IPbus 1.3 and 2.0 dummy hardware.
void setReplyDelay(const std::chrono::microseconds &aDelay)
Definition: tools.cpp:62
std::unique_ptr< DummyHardwareInterface > mHw
Definition: tools.hpp:67
A very simple timer.
Definition: tools.hpp:74
double elapsedSeconds()
Returns number of elapsed seconds since the timer was instantiated.
Definition: tools.hpp:83
timeval m_start
Definition: tools.hpp:93
None tests(nox.Session session)
Definition: noxfile.py:19
double measureFileWriteLatency(const std::string &aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose)
Definition: tools.cpp:170
double measureReadLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
Definition: tools.cpp:68
double measureFileReadLatency(const std::string &aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose)
Definition: tools.cpp:145
double measureWriteLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
Definition: tools.cpp:105
@ sec
seconds past the minute formatted as two digits e.g.
@ usec
microseconds past the second formatted as exactly six digits e.g.