Ipopt Documentation  
IpTimedTask.hpp
Go to the documentation of this file.
1 // Copyright (C) 2006, 2009 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors: Andreas Waechter IBM 2005-09-19
6 
7 #ifndef __IPTIMEDTASK_HPP__
8 #define __IPTIMEDTASK_HPP__
9 
10 #include "IpUtils.hpp"
11 
12 namespace Ipopt
13 {
16 {
17 public:
20 
22  :
23  total_cputime_(0.),
24  total_systime_(0.),
25  total_walltime_(0.),
26  enabled_(true),
27  start_called_(false),
28  end_called_(true)
29  {}
30 
33  {}
35 
38  void Enable()
39  {
40  enabled_ = true;
41  }
42 
47  void Disable()
48  {
49  enabled_ = false;
50  }
51 
53  void Reset()
54  {
55  total_cputime_ = 0.;
56  total_systime_ = 0.;
57  total_walltime_ = 0.;
58  start_called_ = false;
59  end_called_ = true;
60  }
61 
63  void Start()
64  {
65  if( !enabled_ )
66  {
67  return;
68  }
69 
70  DBG_ASSERT(end_called_);
71  DBG_ASSERT(!start_called_);
72  end_called_ = false;
73  start_called_ = true;
74  start_cputime_ = CpuTime();
75  start_systime_ = SysTime();
76  start_walltime_ = WallclockTime();
77  }
78 
80  void End()
81  {
82  if( !enabled_ )
83  {
84  return;
85  }
86 
87  DBG_ASSERT(!end_called_);
88  DBG_ASSERT(start_called_);
89  end_called_ = true;
90  start_called_ = false;
91  total_cputime_ += CpuTime() - start_cputime_;
92  total_systime_ += SysTime() - start_systime_;
93  total_walltime_ += WallclockTime() - start_walltime_;
94  }
95 
101  {
102  if( !enabled_ )
103  {
104  return;
105  }
106  if( start_called_ )
107  {
108  end_called_ = true;
109  start_called_ = false;
110  total_cputime_ += CpuTime() - start_cputime_;
111  total_systime_ += SysTime() - start_systime_;
112  total_walltime_ += WallclockTime() - start_walltime_;
113  }
114  DBG_ASSERT(end_called_);
115  }
116 
119  {
120  DBG_ASSERT(end_called_);
121  return total_cputime_;
122  }
123 
126  {
127  DBG_ASSERT(end_called_);
128  return total_systime_;
129  }
130 
133  {
134  DBG_ASSERT(end_called_);
135  return total_walltime_;
136  }
137 
142  {
143  DBG_ASSERT(start_called_);
144  DBG_ASSERT(!end_called_);
145  return start_cputime_;
146  }
147 
152  {
153  DBG_ASSERT(start_called_);
154  DBG_ASSERT(!end_called_);
155  return start_systime_;
156  }
157 
162  {
163  DBG_ASSERT(start_called_);
164  DBG_ASSERT(!end_called_);
165  return start_walltime_;
166  }
167 
169  bool IsEnabled() const
170  {
171  return enabled_;
172  }
173 
175  bool IsStarted() const
176  {
177  return start_called_;
178  }
179 
180 private:
188 
190 
192  void operator=(const TimedTask&);
194 
207 
210  bool enabled_;
214 
215 };
216 } // namespace Ipopt
217 
218 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
This class is used to collect timing information for a particular task.
Definition: IpTimedTask.hpp:16
Number start_walltime_
Wall clock time at beginning of task.
void EndIfStarted()
Method that is called after execution of the task for which timing might have been started.
~TimedTask()
Default destructor.
Definition: IpTimedTask.hpp:32
Number total_systime_
Total system time for task measured so far.
void Enable()
enable the timer
Definition: IpTimedTask.hpp:38
Number TotalCpuTime() const
Method returning total CPU time spend for task so far.
Number total_cputime_
Total CPU time for task measured so far.
Number StartCpuTime() const
Method returning start CPU time for started task.
Number StartSysTime() const
Method returning start system time for started task.
void End()
Method that is called after execution of the task.
Definition: IpTimedTask.hpp:80
Number start_systime_
System time at beginning of task.
TimedTask(const TimedTask &)
Copy Constructor.
void Reset()
Method for resetting time to zero.
Definition: IpTimedTask.hpp:53
bool IsEnabled() const
Number TotalSysTime() const
Method returning total system time spend for task so far.
bool IsStarted() const
TimedTask()
Default constructor.
Definition: IpTimedTask.hpp:21
void operator=(const TimedTask &)
Default Assignment Operator.
Number TotalWallclockTime() const
Method returning total wall clock time spend for task so far.
Number start_cputime_
CPU time at beginning of task.
void Disable()
disable the timer
Definition: IpTimedTask.hpp:47
Number StartWallclockTime() const
Method returning start wall clock time for started task.
Number total_walltime_
Total wall clock time for task measured so far.
void Start()
Method that is called before execution of the task.
Definition: IpTimedTask.hpp:63
#define IPOPTLIB_EXPORT
Definition: config.h:94
This file contains a base class for all exceptions and a set of macros to help with exceptions.
IPOPTLIB_EXPORT Number CpuTime()
method determining CPU time
IPOPTLIB_EXPORT Number SysTime()
method determining system time
ipnumber Number
Type of all numbers.
Definition: IpTypes.hpp:17
IPOPTLIB_EXPORT Number WallclockTime()
method determining wallclock time since first call