μHAL (v2.6.5)
Part of the IPbus software repository
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 <iostream>
40 #include <map>
41 #include <stdint.h>
42 #include <string>
43 #include <sys/time.h>
44 
45 #include <boost/scoped_ptr.hpp>
46 #include <boost/thread/thread.hpp>
47 
49 #include "uhal/HwInterface.hpp"
51 
52 
53 
54 namespace uhal {
55 namespace tests {
56 
57 class DummyHardwareInterface;
58 
60 public:
63 
64  void setReplyDelay (const boost::chrono::microseconds& aDelay);
65 
66 private:
67  boost::scoped_ptr<DummyHardwareInterface> mHw;
68  boost::thread mHwThread;
69 };
70 
71 
73 class Timer
74 {
75 public:
76 
77  Timer() :m_start()
78  {
79  gettimeofday ( &m_start, NULL );
80  }
81 
83  double elapsedSeconds()
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 
92 private:
93  timeval m_start;
94 
95 }; /* End of class Timer */
96 
97 
98 double measureReadLatency(ClientInterface& aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
99 
100 double measureReadLatency(const std::vector<ClientInterface*>& aClients, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
101 
102 double measureWriteLatency(ClientInterface& aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
103 
104 double measureWriteLatency(const std::vector<ClientInterface*>& aClients, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose);
105 
106 double measureFileReadLatency(const std::string& aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose);
107 
108 double 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
A very simple timer.
Definition: tools.hpp:73
DummyHardwareRunner(DummyHardwareInterface *aHw)
Definition: tools.cpp:49
double measureFileReadLatency(const std::string &aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose)
Definition: tools.cpp:159
double measureReadLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
Definition: tools.cpp:67
boost::scoped_ptr< DummyHardwareInterface > mHw
Definition: tools.hpp:67
double measureWriteLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
Definition: tools.cpp:111
Common abstract base class for IPbus 1.3 and 2.0 dummy hardware.
void setReplyDelay(const boost::chrono::microseconds &aDelay)
Definition: tools.cpp:61
seconds past the minute formatted as two digits e.g.
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
microseconds past the second formatted as exactly six digits e.g.
double measureFileWriteLatency(const std::string &aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose)
Definition: tools.cpp:184
double elapsedSeconds()
Returns number of elapsed seconds since the timer was instantiated.
Definition: tools.hpp:83
timeval m_start
Definition: tools.hpp:93