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 // $Id$
6 //
7 // Authors: Andreas Waechter IBM 2005-09-19
8 
9 #ifndef __IPTIMEDTASK_HPP__
10 #define __IPTIMEDTASK_HPP__
11 
12 #include "IpUtils.hpp"
13 
14 namespace Ipopt
15 {
19 {
20 public:
25  :
26  total_cputime_(0.),
27  total_systime_(0.),
28  total_walltime_(0.),
29  start_called_(false),
30  end_called_(true)
31  {}
32 
35  {}
37 
39  void Reset()
40  {
41  total_cputime_ = 0.;
42  total_systime_ = 0.;
43  total_walltime_ = 0.;
44  start_called_ = false;
45  end_called_ = true;
46  }
47 
49  void Start()
50  {
51  DBG_ASSERT(end_called_);
52  DBG_ASSERT(!start_called_);
53  end_called_ = false;
54  start_called_ = true;
55  start_cputime_ = CpuTime();
56  start_systime_ = SysTime();
57  start_walltime_ = WallclockTime();
58  }
59 
61  void End()
62  {
63  DBG_ASSERT(!end_called_);
64  DBG_ASSERT(start_called_);
65  end_called_ = true;
66  start_called_ = false;
67  total_cputime_ += CpuTime() - start_cputime_;
68  total_systime_ += SysTime() - start_systime_;
69  total_walltime_ += WallclockTime() - start_walltime_;
70  }
71 
76  void EndIfStarted()
77  {
78  if (start_called_)
79  {
80  end_called_ = true;
81  start_called_ = false;
82  total_cputime_ += CpuTime() - start_cputime_;
83  total_systime_ += SysTime() - start_systime_;
84  total_walltime_ += WallclockTime() - start_walltime_;
85  }
86  DBG_ASSERT(end_called_);
87  }
88 
91  {
92  DBG_ASSERT(end_called_);
93  return total_cputime_;
94  }
95 
98  {
99  DBG_ASSERT(end_called_);
100  return total_systime_;
101  }
102 
105  {
106  DBG_ASSERT(end_called_);
107  return total_walltime_;
108  }
109 
110 private:
120 
122  void operator=(const TimedTask&);
124 
137 
143 
144 };
145 } // namespace Ipopt
146 
147 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
This class is used to collect timing information for a particular task.
Definition: IpTimedTask.hpp:19
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.
Definition: IpTimedTask.hpp:76
~TimedTask()
Default destructor.
Definition: IpTimedTask.hpp:34
Number total_systime_
Total system time for task measured so far.
Number TotalCpuTime() const
Method returning total CPU time spend for task so far.
Definition: IpTimedTask.hpp:90
Number total_cputime_
Total CPU time for task measured so far.
void End()
Method that is called after execution of the task.
Definition: IpTimedTask.hpp:61
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:39
Number TotalSysTime() const
Method returning total system time spend for task so far.
Definition: IpTimedTask.hpp:97
TimedTask()
Default constructor.
Definition: IpTimedTask.hpp:24
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.
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:49
#define IPOPTLIB_EXPORT
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
IPOPTLIB_EXPORT Number WallclockTime()
method determining wallclock time since first call
double Number
Type of all numbers.
Definition: IpTypes.hpp:15