Timing.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5*
6* ArmarX is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* ArmarX is distributed in the hope that it will be useful, but
11* WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* @package ArmarX
19* @author Stefan Reither( stefan dot reither at kit dot edu)
20* @date 2021
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
25#pragma once
26
28
29#include "ErrorReporting.h"
30
32{
33 namespace timing
34 {
35 constexpr bool enableTimingInformation = false;
36
37 namespace general
38 {
39 class Timer
40 {
41 public:
42 void
44 {
45 start_ = armarx::rtNow();
46 }
47
48 void
49 end(const char* comment)
50 {
51 GENERAL_INFO("%s - duration: %.3f ms",
52 comment,
53 (armarx::rtNow() - start_).toMilliSecondsDouble());
54 }
55
56 void
57 end(const char* comment, double thresholdMS)
58 {
59 const double diff = (armarx::rtNow() - start_).toMilliSecondsDouble();
60 if (diff >= thresholdMS)
61 {
62 GENERAL_INFO("%s - duration: %.3f ms", comment, diff);
63 }
64 }
65
66 private:
67 IceUtil::Time start_;
68 };
69 } // namespace general
70
71 namespace bus
72 {
73 class Timer
74 {
75 public:
76 void
78 {
79 start_ = armarx::rtNow();
80 }
81
82 void
83 end(const std::uint64_t bin, const char* comment)
84 {
85 BUS_INFO(bin,
86 "%s - duration: %.3f ms",
87 comment,
88 (armarx::rtNow() - start_).toMilliSecondsDouble());
89 }
90
91 void
92 end(const std::uint64_t bin, const char* comment, double thresholdMS)
93 {
94 const auto diff = (armarx::rtNow() - start_).toMilliSecondsDouble();
95 if (diff >= thresholdMS)
96 {
97 BUS_INFO(bin, "%s - duration: %.3f ms", comment, diff);
98 }
99 }
100
101 private:
102 IceUtil::Time start_;
103 };
104 } // namespace bus
105
106 namespace slave
107 {
108 class Timer
109 {
110 public:
111 void
113 {
114 start_ = armarx::rtNow();
115 }
116
117 void
118 end(const SlaveIdentifier sid, const char* comment)
119 {
120 SLAVE_INFO(sid,
121 "%s - duration: %.3f ms",
122 comment,
123 (armarx::rtNow() - start_).toMilliSecondsDouble());
124 }
125
126 void
127 end(const SlaveIdentifier sid, const char* comment, double thresholdMS)
128 {
129 const auto diff = (armarx::rtNow() - start_).toMilliSecondsDouble();
130 if (diff >= thresholdMS)
131 {
132 SLAVE_INFO(sid, "%s - duration: %.3f ms", comment, diff);
133 }
134 }
135
136 private:
137 IceUtil::Time start_;
138 };
139 } // namespace slave
140 } // namespace timing
141
142#define GENERAL_TIMING_START(name) \
143 auto name = armarx::control::ethercat::timing::general::Timer(); \
144 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
145 { \
146 name.start(); \
147 }
148#define GENERAL_TIMING_END_COMMENT(name, comment) \
149 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
150 { \
151 name.end(comment); \
152 }
153#define GENERAL_TIMING_END(name) GENERAL_TIMING_END_COMMENT(name, #name)
154#define GENERAL_TIMING_CEND_COMMENT(name, comment, thresholdMs) \
155 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
156 { \
157 name.end(comment, thresholdMs); \
158 }
159#define GENERAL_TIMING_CEND(name, thresholdMs) GENERAL_TIMING_CEND_COMMENT(name, #name, thresholdMs)
160
161 /////////////////////////////////////////////////////////////////////////////////////////////////
162
163#define BUS_TIMING_START(name) \
164 auto name = armarx::control::ethercat::timing::bus::Timer(); \
165 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
166 { \
167 name.start(); \
168 }
169
170#define BUS_TIMING_END_COMMENT(name, bin, comment) \
171 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
172 { \
173 name.end(bin, comment); \
174 }
175#define BUS_TIMING_END(name, bin) BUS_TIMING_END_COMMENT(name, bin, #name)
176#define BUS_TIMING_CEND_COMMENT(name, bin, comment, thresholdMs) \
177 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
178 { \
179 name.end(bin, comment, thresholdMs); \
180 }
181#define BUS_TIMING_CEND(name, bin, thresholdMs) \
182 BUS_TIMING_CEND_COMMENT(name, bin, #name, thresholdMs)
183
184 /////////////////////////////////////////////////////////////////////////////////////////////////
185
186#define SLAVE_TIMING_START(name) \
187 auto name = armarx::control::ethercat::timing::slave::Timer(); \
188 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
189 { \
190 name.start(); \
191 }
192#define SLAVE_TIMING_END_COMMENT(sid, name, comment) \
193 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
194 { \
195 name.end(sid, comment); \
196 }
197#define SLAVE_TIMING_END(sid, name) SLAVE_TIMING_END_COMMENT(sid, name, #name)
198#define SLAVE_TIMING_CEND_COMMENT(sid, name, comment, thresholdMs) \
199 if constexpr (armarx::control::ethercat::timing::enableTimingInformation) \
200 { \
201 name.end(sid, comment, thresholdMs); \
202 }
203#define SLAVE_TIMING_CEND(sid, name, thresholdMs) \
204 SLAVE_TIMING_CEND_COMMENT(sid, name, #name, thresholdMs)
205
206} // namespace armarx::control::ethercat
#define SLAVE_INFO(sid,...)
#define GENERAL_INFO(...)
#define BUS_INFO(bin,...)
The SlaveIdentifier class is a POD-type representing a unique set of values identifying an EtherCAT s...
void end(const std::uint64_t bin, const char *comment)
Definition Timing.h:83
void end(const std::uint64_t bin, const char *comment, double thresholdMS)
Definition Timing.h:92
void end(const char *comment, double thresholdMS)
Definition Timing.h:57
void end(const SlaveIdentifier sid, const char *comment, double thresholdMS)
Definition Timing.h:127
void end(const SlaveIdentifier sid, const char *comment)
Definition Timing.h:118
constexpr bool enableTimingInformation
Definition Timing.h:35
IceUtil::Time rtNow()
Definition RtTiming.h:40