Ipopt Documentation  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
17 {
18 public:
20 
23  :
24  total_cputime_(0.),
25  total_systime_(0.),
26  total_walltime_(0.),
27  start_called_(false),
28  end_called_(true)
29  {}
30 
33  {}
35 
37  void Reset()
38  {
39  total_cputime_ = 0.;
40  total_systime_ = 0.;
41  total_walltime_ = 0.;
42  start_called_ = false;
43  end_called_ = true;
44  }
45 
47  void Start()
48  {
49  DBG_ASSERT(end_called_);
50  DBG_ASSERT(!start_called_);
51  end_called_ = false;
52  start_called_ = true;
53  start_cputime_ = CpuTime();
54  start_systime_ = SysTime();
55  start_walltime_ = WallclockTime();
56  }
57 
59  void End()
60  {
61  DBG_ASSERT(!end_called_);
62  DBG_ASSERT(start_called_);
63  end_called_ = true;
64  start_called_ = false;
65  total_cputime_ += CpuTime() - start_cputime_;
66  total_systime_ += SysTime() - start_systime_;
67  total_walltime_ += WallclockTime() - start_walltime_;
68  }
69 
74  void EndIfStarted()
75  {
76  if (start_called_)
77  {
78  end_called_ = true;
79  start_called_ = false;
80  total_cputime_ += CpuTime() - start_cputime_;
81  total_systime_ += SysTime() - start_systime_;
82  total_walltime_ += WallclockTime() - start_walltime_;
83  }
84  DBG_ASSERT(end_called_);
85  }
86 
89  {
90  DBG_ASSERT(end_called_);
91  return total_cputime_;
92  }
93 
96  {
97  DBG_ASSERT(end_called_);
98  return total_systime_;
99  }
100 
103  {
104  DBG_ASSERT(end_called_);
105  return total_walltime_;
106  }
107 
108 private:
115 
117  TimedTask(const TimedTask&);
118 
120  void operator=(const TimedTask&);
122 
135 
137  bool start_called_;
141 
142 };
143 } // namespace Ipopt
144 
145 #endif
Number total_walltime_
Total wall clock time for task measured so far.
Number TotalWallclockTime() const
Method returning total wall clock time spend for task so far.
TimedTask()
Default constructor.
Definition: IpTimedTask.hpp:22
IPOPTLIB_EXPORT Number WallclockTime()
method determining wallclock time since first call
Number TotalCpuTime() const
Method returning total CPU time spend for task so far.
Definition: IpTimedTask.hpp:88
This class is used to collect timing information for a particular task.
Definition: IpTimedTask.hpp:16
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Number total_cputime_
Total CPU time for task measured so far.
IPOPTLIB_EXPORT Number CpuTime()
method determining CPU time
Number start_cputime_
CPU time at beginning of task.
Number total_systime_
Total system time for task measured so far.
void Reset()
Method for resetting time to zero.
Definition: IpTimedTask.hpp:37
void End()
Method that is called after execution of the task.
Definition: IpTimedTask.hpp:59
Number start_walltime_
Wall clock time at beginning of task.
~TimedTask()
Default destructor.
Definition: IpTimedTask.hpp:32
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
#define IPOPTLIB_EXPORT
Number TotalSysTime() const
Method returning total system time spend for task so far.
Definition: IpTimedTask.hpp:95
IPOPTLIB_EXPORT Number SysTime()
method determining system time
Number start_systime_
System time at beginning of task.
void EndIfStarted()
Method that is called after execution of the task for which timing might have been started...
Definition: IpTimedTask.hpp:74
void Start()
Method that is called before execution of the task.
Definition: IpTimedTask.hpp:47