- Main Page
- Classes
- Files

- File List
- File Members

# src/Common/IpTimedTask.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2006, 2009 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Eclipse Public License.
    00004 //
    00005 // $Id: IpTimedTask.hpp 1861 2010-12-21 21:34:47Z andreasw $
    00006 //
    00007 // Authors:  Andreas Waechter               IBM    2005-09-19
    00008
    00009 #ifndef __IPTIMEDTASK_HPP__
    00010 #define __IPTIMEDTASK_HPP__
    00011
    00012 #include "IpUtils.hpp"
    00013
    00014 namespace Ipopt
    00015 {
    00018   class TimedTask
    00019   {
    00020   public:
    00024     TimedTask()
    00025         :
    00026         total_cputime_(0.),
    00027         total_systime_(0.),
    00028         total_walltime_(0.),
    00029         start_called_(false),
    00030         end_called_(true)
    00031     {}
    00032
    00034     ~TimedTask()
    00035     {}
    00037
    00039     void Reset()
    00040     {
    00041       total_cputime_ = 0.;
    00042       total_systime_ = 0.;
    00043       total_walltime_ = 0.;
    00044       start_called_ = false;
    00045       end_called_ = true;
    00046     }
    00047
    00049     void Start()
    00050     {
    00051       DBG_ASSERT(end_called_);
    00052       DBG_ASSERT(!start_called_);
    00053       end_called_ = false;
    00054       start_called_ = true;
    00055       start_cputime_ = CpuTime();
    00056       start_systime_ = SysTime();
    00057       start_walltime_ = WallclockTime();
    00058     }
    00059
    00061     void End()
    00062     {
    00063       DBG_ASSERT(!end_called_);
    00064       DBG_ASSERT(start_called_);
    00065       end_called_ = true;
    00066       start_called_ = false;
    00067       total_cputime_ += CpuTime() - start_cputime_;
    00068       total_systime_ += SysTime() - start_systime_;
    00069       total_walltime_ += WallclockTime() - start_walltime_;
    00070     }
    00071
    00076     void EndIfStarted()
    00077     {
    00078       if (start_called_) {
    00079         end_called_ = true;
    00080         start_called_ = false;
    00081         total_cputime_ += CpuTime() - start_cputime_;
    00082         total_systime_ += SysTime() - start_systime_;
    00083         total_walltime_ += WallclockTime() - start_walltime_;
    00084       }
    00085       DBG_ASSERT(end_called_);
    00086     }
    00087
    00089     Number TotalCpuTime() const
    00090     {
    00091       DBG_ASSERT(end_called_);
    00092       return total_cputime_;
    00093     }
    00094
    00096     Number TotalSysTime() const
    00097     {
    00098       DBG_ASSERT(end_called_);
    00099       return total_systime_;
    00100     }
    00101
    00103     Number TotalWallclockTime() const
    00104     {
    00105       DBG_ASSERT(end_called_);
    00106       return total_walltime_;
    00107     }
    00108
    00109   private:
    00118     TimedTask(const TimedTask&);
    00119
    00121     void operator=(const TimedTask&);
    00123
    00125     Number start_cputime_;
    00127     Number total_cputime_;
    00129     Number start_systime_;
    00131     Number total_systime_;
    00133     Number start_walltime_;
    00135     Number total_walltime_;
    00136
    00139     bool start_called_;
    00140     bool end_called_;
    00142
    00143   };
    00144 } // namespace Ipopt
    00145
    00146 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines