hpp-fcl: include/hpp/fcl/timings.h Source File

hpp-fcl 1.7.7 HPP fork of FCL -- The Flexible Collision Library

timings.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021 INRIA
3 //
4
5 #ifndef HPP_FCL_TIMINGS_FWD_H
6 #define HPP_FCL_TIMINGS_FWD_H
7
8 #include "hpp/fcl/fwd.hh"
9
10 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
11 #include <chrono>
12 #endif
13
14 namespace hpp { namespace fcl {
15
16 struct CPUTimes
17 {
18 double wall;
19 double user;
20 double system;
21
22 CPUTimes()
23 : wall(0)
24 , user(0)
25 , system(0)
26 {}
27
28 void clear()
29 {
30 wall = user = system = 0;
31 }
32
33 };
34
39 struct HPP_FCL_DLLAPI Timer
40 {
41
42 Timer()
43 : m_is_stopped(true)
44 {
45 start();
46 }
47
48 CPUTimes elapsed() const
49 {
50 if(m_is_stopped)
51 return m_times;
52
53 CPUTimes current(m_times);
54 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
55 std::chrono::time_point<std::chrono::steady_clock> current_clock = std::chrono::steady_clock::now();
56 current.user += static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(current_clock - m_start).count())*1e-3;
57 #endif
58 return current;
59 }
60
61 void start()
62 {
63 if(m_is_stopped)
64 {
65 m_is_stopped = false;
66 m_times.clear();
67
68 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
69 m_start = std::chrono::steady_clock::now();
70 #endif
71 }
72 }
73
74 void stop()
75 {
76 if(m_is_stopped)
77 return;
78 m_is_stopped = true;
79
80 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
81 m_end = std::chrono::steady_clock::now();
82 m_times.user += static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(m_end - m_start).count())*1e-3;
83 #endif
84
85 }
86
87 void resume()
88 {
89 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
90 if(m_is_stopped)
91 m_start = std::chrono::steady_clock::now();
92 #endif
93 }
94
95 bool is_stopped() const
96 {
97 return m_is_stopped;
98 }
99
100 protected:
101
102 CPUTimes m_times;
103 bool m_is_stopped;
104
105 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
106 std::chrono::time_point<std::chrono::steady_clock> m_start, m_end;
107 #endif
108 };
109
110 }}
111
112 #endif // ifndef HPP_FCL_TIMINGS_FWD_H
fwd.hh
hpp
Main namespace.
Definition: AABB.h:44
hpp::fcl::CPUTimes
Definition: timings.h:17
hpp::fcl::CPUTimes::user
double user
Definition: timings.h:19
hpp::fcl::CPUTimes::system
double system
Definition: timings.h:20
hpp::fcl::CPUTimes::CPUTimes
CPUTimes()
Definition: timings.h:22
hpp::fcl::CPUTimes::wall
double wall
Definition: timings.h:18
hpp::fcl::CPUTimes::clear
void clear()
Definition: timings.h:28
hpp::fcl::Timer
This class mimics the way "boost/timer/timer.hpp" operates while using the modern std::chrono library...
Definition: timings.h:40
hpp::fcl::Timer::start
void start()
Definition: timings.h:61
hpp::fcl::Timer::m_times
CPUTimes m_times
Definition: timings.h:102
hpp::fcl::Timer::Timer
Timer()
Definition: timings.h:42
hpp::fcl::Timer::stop
void stop()
Definition: timings.h:74
hpp::fcl::Timer::is_stopped
bool is_stopped() const
Definition: timings.h:95
hpp::fcl::Timer::elapsed
CPUTimes elapsed() const
Definition: timings.h:48
hpp::fcl::Timer::resume
void resume()
Definition: timings.h:87
hpp::fcl::Timer::m_is_stopped
bool m_is_stopped
Definition: timings.h:103