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

hpp-fcl 1.7.0 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 <boost/chrono.hpp>
9
10 #include "hpp/fcl/fwd.hh"
11
12 namespace hpp { namespace fcl {
13
14 struct CPUTimes
15 {
16 FCL_REAL wall;
17 FCL_REAL user;
18 FCL_REAL system;
19
20 CPUTimes()
21 : wall(0)
22 , user(0)
23 , system(0)
24 {}
25
26 void clear()
27 {
28 wall = user = system = 0;
29 }
30
31 };
32
33 namespace internal
34 {
35 inline void get_cpu_times(CPUTimes & current)
36 {
37 using namespace boost::chrono;
38
39 process_real_cpu_clock::time_point wall = process_real_cpu_clock::now();
40 process_user_cpu_clock::time_point user = process_user_cpu_clock::now();
41 process_system_cpu_clock::time_point system = process_system_cpu_clock::now();
42
43 current.wall = time_point_cast<nanoseconds>(wall).time_since_epoch().count()*1e-3;
44 current.user = time_point_cast<nanoseconds>(user).time_since_epoch().count()*1e-3;
45 current.system = time_point_cast<nanoseconds>(system).time_since_epoch().count()*1e-3;
46 }
47 }
48
52 struct Timer
53 {
54
55 Timer()
56 {
57 start();
58 }
59
60 CPUTimes elapsed() const
61 {
62 if(m_is_stopped)
63 return m_times;
64
65 CPUTimes current;
66 internal::get_cpu_times(current);
67 current.wall -= m_times.wall;
68 current.user -= m_times.user;
69 current.system -= m_times.system;
70 return current;
71 }
72
73 void start()
74 {
75 m_is_stopped = false;
76 internal::get_cpu_times(m_times);
77 }
78
79 void stop()
80 {
81 if(m_is_stopped)
82 return;
83 m_is_stopped = true;
84
85 CPUTimes current;
86 internal::get_cpu_times(current);
87 m_times.wall = (current.wall - m_times.wall);
88 m_times.user = (current.user - m_times.user);
89 m_times.system = (current.system - m_times.system);
90
91 }
92
93 void resume()
94 {
95 if(m_is_stopped)
96 {
97 CPUTimes current(m_times);
98 start();
99 m_times.wall -= current.wall;
100 m_times.user -= current.user;
101 m_times.system -= current.system;
102 }
103 }
104
105 bool is_stopped() const
106 {
107 return m_is_stopped;
108 }
109
110 protected:
111
112 CPUTimes m_times;
113 bool m_is_stopped;
114 };
115
116 }}
117
118 #endif // ifndef HPP_FCL_TIMINGS_FWD_H
fwd.hh
hpp::fcl::internal::get_cpu_times
void get_cpu_times(CPUTimes &current)
Definition: timings.h:35
hpp::fcl::FCL_REAL
double FCL_REAL
Definition: data_types.h:66
hpp
Main namespace.
Definition: AABB.h:44
hpp::fcl::CPUTimes
Definition: timings.h:15
hpp::fcl::CPUTimes::system
FCL_REAL system
Definition: timings.h:18
hpp::fcl::CPUTimes::CPUTimes
CPUTimes()
Definition: timings.h:20
hpp::fcl::CPUTimes::wall
FCL_REAL wall
Definition: timings.h:16
hpp::fcl::CPUTimes::user
FCL_REAL user
Definition: timings.h:17
hpp::fcl::CPUTimes::clear
void clear()
Definition: timings.h:26
hpp::fcl::Timer
This class mimics the way "boost/timer/timer.hpp" operates while using moder boost::chrono library.
Definition: timings.h:53
hpp::fcl::Timer::start
void start()
Definition: timings.h:73
hpp::fcl::Timer::m_times
CPUTimes m_times
Definition: timings.h:112
hpp::fcl::Timer::Timer
Timer()
Definition: timings.h:55
hpp::fcl::Timer::stop
void stop()
Definition: timings.h:79
hpp::fcl::Timer::is_stopped
bool is_stopped() const
Definition: timings.h:105
hpp::fcl::Timer::elapsed
CPUTimes elapsed() const
Definition: timings.h:60
hpp::fcl::Timer::resume
void resume()
Definition: timings.h:93
hpp::fcl::Timer::m_is_stopped
bool m_is_stopped
Definition: timings.h:113