RtTiming.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 Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2018
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <time.h>
27
28#include <IceUtil/Time.h>
29
30namespace armarx
31{
33 {
34 inline constexpr const std::int64_t seconds2MicroSeconds = 1e6;
35
36 static constexpr const std::int64_t nanoSeconds2MicroSeconds = 1000;
37 } // namespace rt_timing::constants
38
39 inline IceUtil::Time
41 {
42 using namespace rt_timing::constants;
43 struct timespec ts;
44 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
45 return IceUtil::Time::microSeconds(ts.tv_sec * seconds2MicroSeconds +
46 ts.tv_nsec / nanoSeconds2MicroSeconds);
47 }
48} // namespace armarx
49
50#define RT_TIMING_START(name) auto name = armarx::rtNow();
51//! \ingroup VirtualTime
52//! Prints duration with comment in front of it, yet only once per second.
53#define RT_TIMING_END_COMMENT(name, comment) \
54 printf("%s - duration: %.3f ms \n", comment, (armarx::rtNow() - name).toMilliSecondsDouble());
55//! \ingroup VirtualTime
56//! Prints duration
57#define RT_TIMING_END(name) RT_TIMING_END_COMMENT(name, #name)
58//! \ingroup VirtualTime
59//! Prints duration with comment in front of it if it took longer than threshold
60#define RT_TIMING_CEND_COMMENT(name, comment, thresholdMs) \
61 if ((armarx::rtNow() - name).toMilliSecondsDouble() >= thresholdMs) \
62 RT_TIMING_END_COMMENT(name, comment)
63//! \ingroup VirtualTime
64//! Prints duration if it took longer than thresholdMs
65#define RT_TIMING_CEND(name, thresholdMs) RT_TIMING_CEND_COMMENT(name, #name, thresholdMs)
constexpr const std::int64_t seconds2MicroSeconds
Definition RtTiming.h:34
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Time rtNow()
Definition RtTiming.h:40