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

hpp-fcl 1.7.2 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
54 CPUTimes current(m_times);
55 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
56 std::chrono::time_point<std::chrono::steady_clock> current_clock = std::chrono::steady_clock::now();
57 current.user += std::chrono::duration_cast<std::chrono::nanoseconds>(current_clock - m_start).count()*1e-3;
58 #endif
59 return current;
60 }
61
62 void start()
63 {
64 if(m_is_stopped)
65 {
66 m_is_stopped = false;
67 m_times.clear();
68
69 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
70 m_start = std::chrono::steady_clock::now();
71 #endif
72 }
73 }
74
75 void stop()
76 {
77 if(m_is_stopped)
78 return;
79 m_is_stopped = true;
80
81 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
82 m_end = std::chrono::steady_clock::now();
83 m_times.user += std::chrono::duration_cast<std::chrono::nanoseconds>(m_end - m_start).count()*1e-3;
84 #endif
85
86 }
87
88 void resume()
89 {
90 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
91 if(m_is_stopped)
92 m_start = std::chrono::steady_clock::now();
93 #endif
94 }
95
96 bool is_stopped() const
97 {
98 return m_is_stopped;
99 }
100
101 protected:
102
103 CPUTimes m_times;
104 bool m_is_stopped;
105
106 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
107 std::chrono::time_point<std::chrono::steady_clock> m_start, m_end;
108 #endif
109 };
110
111 }}
112
113 #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:62
hpp::fcl::Timer::m_times
CPUTimes m_times
Definition: timings.h:103
hpp::fcl::Timer::Timer
Timer()
Definition: timings.h:42
hpp::fcl::Timer::stop
void stop()
Definition: timings.h:75
hpp::fcl::Timer::is_stopped
bool is_stopped() const
Definition: timings.h:96
hpp::fcl::Timer::elapsed
CPUTimes elapsed() const
Definition: timings.h:48
hpp::fcl::Timer::resume
void resume()
Definition: timings.h:88
hpp::fcl::Timer::m_is_stopped
bool m_is_stopped
Definition: timings.h:104