COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
CCopasiTimeVariable Class Reference

#include <CopasiTime.h>

Public Member Functions

 CCopasiTimeVariable ()
 
 CCopasiTimeVariable (const CCopasiTimeVariable &src)
 
 CCopasiTimeVariable (const C_INT64 &value)
 
C_INT64 getDays () const
 
C_INT64 getHours (const bool &bounded=false) const
 
C_INT64 getMicroSeconds (const bool &bounded=false) const
 
C_INT64 getMilliSeconds (const bool &bounded=false) const
 
C_INT64 getMinutes (const bool &bounded=false) const
 
C_INT64 getSeconds (const bool &bounded=false) const
 
std::string isoFormat () const
 
CCopasiTimeVariable operator+ (const CCopasiTimeVariable &value)
 
CCopasiTimeVariable operator- (const CCopasiTimeVariable &value)
 
bool operator< (const CCopasiTimeVariable &value)
 
CCopasiTimeVariableoperator= (const CCopasiTimeVariable &rhs)
 
CCopasiTimeVariableoperator= (const C_INT64 &value)
 
 ~CCopasiTimeVariable ()
 

Static Public Member Functions

static CCopasiTimeVariable getCurrentWallTime ()
 
static CCopasiTimeVariable getProcessTime ()
 
static CCopasiTimeVariable getThreadTime ()
 
static std::string LL2String (const C_INT64 &value, const C_INT32 &digits=0)
 

Private Attributes

C_INT64 mTime
 

Detailed Description

This class is for handling execution time related values. static methods for retreiving wall clock and CPU time are provided.

Definition at line 28 of file CopasiTime.h.

Constructor & Destructor Documentation

CCopasiTimeVariable::CCopasiTimeVariable ( )

Default constructor.

Definition at line 41 of file CopasiTime.cpp.

41  :
42  mTime(LLONG_CONST(0))
43 {}
#define LLONG_CONST(n)
Definition: copasi.h:89
CCopasiTimeVariable::CCopasiTimeVariable ( const CCopasiTimeVariable src)

Copy constructor.

Parameters
constCCopasiTimeVariable & src

Definition at line 45 of file CopasiTime.cpp.

45  :
46  mTime(src.mTime)
47 {}
CCopasiTimeVariable::CCopasiTimeVariable ( const C_INT64 value)

Specific constructor from a C_INT64 value.

Parameters
constC_INT64 & value

Definition at line 49 of file CopasiTime.cpp.

49  :
50  mTime(value)
51 {}
CCopasiTimeVariable::~CCopasiTimeVariable ( )

Destructor.

Definition at line 53 of file CopasiTime.cpp.

53 {}

Member Function Documentation

CCopasiTimeVariable CCopasiTimeVariable::getCurrentWallTime ( )
static

Retrieve the current wall clock time in micro seconds since 1970-01-01:00:00:00.0

Returns
CCopasiTimeVariable time

Definition at line 160 of file CopasiTime.cpp.

References C_INT64, and LLONG_CONST.

Referenced by CCopasiTimer::CCopasiTimer(), CopasiPlot::compile(), CProcessReport::CProcessReport(), CRandom::getSystemSeed(), CProcessReport::proceed(), CCopasiTimer::refresh(), CopasiPlot::replot(), and CCopasiTimer::start().

161 {
162  timeval ttt;
163  gettimeofday(&ttt, 0);
164  C_INT64 time;
165  time = ((C_INT64) ttt.tv_sec) * LLONG_CONST(1000000) + (C_INT64) ttt.tv_usec;
166  return time;
167 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 CCopasiTimeVariable::getDays ( ) const

Retrieve the time in days.

Parameters
constbool & bounded (default: false)
Returns
C_INT64 days

Definition at line 150 of file CopasiTime.cpp.

References C_INT64, LLONG_CONST, and mTime.

Referenced by isoFormat().

151 {
152  C_INT64 Days = mTime / LLONG_CONST(86400000000);
153 
154  return Days;
155 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 CCopasiTimeVariable::getHours ( const bool &  bounded = false) const

Retrieve the time in hours. If bounded is true 0 <= hours < 24

Parameters
constbool & bounded (default: false)
Returns
C_INT64 hours

Definition at line 142 of file CopasiTime.cpp.

References C_INT64, LLONG_CONST, and mTime.

Referenced by isoFormat().

143 {
144  C_INT64 Hours = mTime / LLONG_CONST(3600000000);
145 
146  if (bounded) return Hours % LLONG_CONST(24);
147  else return Hours;
148 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 CCopasiTimeVariable::getMicroSeconds ( const bool &  bounded = false) const

Retrieve the time in micro seconds. If bounded is true 0 <= microSeconds < 1000

Parameters
constbool & bounded (default: false)
Returns
C_INT64 microSeconds

Definition at line 112 of file CopasiTime.cpp.

References LLONG_CONST, and mTime.

Referenced by CRandom::getSystemSeed(), isoFormat(), CCopasiTimer::refresh(), and CopasiPlot::replot().

113 {
114  if (bounded) return mTime % LLONG_CONST(1000);
115  else return mTime;
116 }
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 CCopasiTimeVariable::getMilliSeconds ( const bool &  bounded = false) const

Retrieve the time in milli seconds. If bounded is true 0 <= milliSeconds < 1000

Parameters
constbool & bounded (default: false)
Returns
C_INT64 milliSeconds

Definition at line 118 of file CopasiTime.cpp.

References C_INT64, LLONG_CONST, and mTime.

Referenced by isoFormat(), CFitProblem::printResult(), and COptProblem::printResult().

119 {
120  C_INT64 MilliSeconds = mTime / LLONG_CONST(1000);
121 
122  if (bounded) return MilliSeconds % LLONG_CONST(1000);
123  else return MilliSeconds;
124 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 CCopasiTimeVariable::getMinutes ( const bool &  bounded = false) const

Retrieve the time in minutes. If bounded is true 0 <= minutes < 60

Parameters
constbool & bounded (default: false)
Returns
C_INT64 minutes

Definition at line 134 of file CopasiTime.cpp.

References C_INT64, LLONG_CONST, and mTime.

Referenced by isoFormat().

135 {
136  C_INT64 Minutes = mTime / LLONG_CONST(60000000);
137 
138  if (bounded) return Minutes % LLONG_CONST(60);
139  else return Minutes;
140 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
CCopasiTimeVariable CCopasiTimeVariable::getProcessTime ( )
static

Retrieve the current process CPU time used since the start of the process.

Returns
CCopasiTimeVariable time

Definition at line 180 of file CopasiTime.cpp.

References C_INT64, and LLONG_CONST.

Referenced by CCopasiTimer::CCopasiTimer(), CCopasiTimer::refresh(), and CCopasiTimer::start().

181 {
182 #ifdef WIN32
183  LARGE_INTEGER CreationTime;
184  LARGE_INTEGER ExitTime;
185  LARGE_INTEGER KernelTime;
186  LARGE_INTEGER UserTime;
187 
188  GetProcessTimes(GetCurrentProcess(),
189  (FILETIME *) &CreationTime,
190  (FILETIME *) &ExitTime,
191  (FILETIME *) &KernelTime,
192  (FILETIME *) &UserTime);
193 
194  return (KernelTime.QuadPart + UserTime.QuadPart) / LLONG_CONST(10);
195 
196 #else
197  struct rusage ResourceUsage;
198 
199  getrusage(RUSAGE_SELF, &ResourceUsage);
200 
201  return ((C_INT64) ResourceUsage.ru_utime.tv_sec) * LLONG_CONST(1000000)
202  + (C_INT64) ResourceUsage.ru_utime.tv_usec;
203 #endif // WIN32
204 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 CCopasiTimeVariable::getSeconds ( const bool &  bounded = false) const

Retrieve the time in seconds. If bounded is true 0 <= seconds < 60

Parameters
constbool & bounded (default: false)
Returns
C_INT64 seconds

Definition at line 126 of file CopasiTime.cpp.

References C_INT64, LLONG_CONST, and mTime.

Referenced by isoFormat(), CFitProblem::printResult(), and COptProblem::printResult().

127 {
128  C_INT64 Seconds = mTime / LLONG_CONST(1000000);
129 
130  if (bounded) return Seconds % LLONG_CONST(60);
131  else return Seconds;
132 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
CCopasiTimeVariable CCopasiTimeVariable::getThreadTime ( )
static

Retrieve the current process thread time used since the start of the process.

Returns
CCopasiTimeVariable time

Definition at line 206 of file CopasiTime.cpp.

References C_INT64, LLONG_CONST, and RUSAGE_THREAD.

Referenced by CCopasiTimer::CCopasiTimer(), CCopasiTimer::refresh(), and CCopasiTimer::start().

207 {
208 #ifdef WIN32
209  LARGE_INTEGER CreationTime;
210  LARGE_INTEGER ExitTime;
211  LARGE_INTEGER KernelTime;
212  LARGE_INTEGER UserTime;
213 
214  GetThreadTimes(GetCurrentThread(),
215  (FILETIME *) &CreationTime,
216  (FILETIME *) &ExitTime,
217  (FILETIME *) &KernelTime,
218  (FILETIME *) &UserTime);
219 
220  return (KernelTime.QuadPart + UserTime.QuadPart) / LLONG_CONST(10);
221 
222 #elif defined Darwin
223 
224  struct thread_basic_info t_info;
225  mach_msg_type_number_t t_info_count = THREAD_BASIC_INFO_COUNT;
226 
227  if (KERN_SUCCESS != task_info(mach_task_self(),
228  THREAD_BASIC_INFO, (task_info_t) & t_info, & t_info_count))
229  {
230  return -1;
231  }
232 
233  return ((C_INT64) t_info.user_time.seconds) * LLONG_CONST(1000000)
234  + (C_INT64) t_info.user_time.microseconds;
235 
236 #else
237  struct rusage ResourceUsage;
238 
239  getrusage(RUSAGE_THREAD, &ResourceUsage);
240 
241  return ((C_INT64) ResourceUsage.ru_utime.tv_sec) * LLONG_CONST(1000000)
242  + (C_INT64) ResourceUsage.ru_utime.tv_usec;
243 #endif // WIN32
244 }
#define C_INT64
Definition: copasi.h:88
#define LLONG_CONST(n)
Definition: copasi.h:89
#define RUSAGE_THREAD
Definition: CopasiTime.cpp:31
std::string CCopasiTimeVariable::isoFormat ( ) const

Create a iso formated string (D:HH:MM:SS.ssssss)

Returns
std::string

Definition at line 76 of file CopasiTime.cpp.

References getDays(), getHours(), getMicroSeconds(), getMilliSeconds(), getMinutes(), getSeconds(), isoFormat(), LL2String(), LLONG_CONST, and mTime.

Referenced by isoFormat().

77 {
78  std::stringstream Iso;
79  bool first = true;
80 
81  if (mTime < LLONG_CONST(0))
82  {
84  Iso << "-";
85  Iso << Tmp.isoFormat();
86 
87  return Iso.str();
88  }
89 
90  if (mTime >= LLONG_CONST(86400000000))
91  {
92  Iso << LL2String(getDays()) << ":";
93  first = false;
94  }
95 
96  if (mTime >= LLONG_CONST(3600000000))
97  Iso << LL2String(getHours(true), first ? 0 : 2) << ":";
98 
99  if (mTime >= LLONG_CONST(60000000))
100  Iso << LL2String(getMinutes(true), first ? 0 : 2) << ":";
101 
102  if (mTime >= LLONG_CONST(1000000))
103  Iso << LL2String(getSeconds(true), first ? 0 : 2) << ".";
104  else
105  Iso << "0.";
106 
107  Iso << LL2String(getMilliSeconds(true), 3) << LL2String(getMicroSeconds(true), 3);
108 
109  return Iso.str();
110 }
C_INT64 getHours(const bool &bounded=false) const
Definition: CopasiTime.cpp:142
static std::string LL2String(const C_INT64 &value, const C_INT32 &digits=0)
Definition: CopasiTime.cpp:246
C_INT64 getMinutes(const bool &bounded=false) const
Definition: CopasiTime.cpp:134
C_INT64 getDays() const
Definition: CopasiTime.cpp:150
#define LLONG_CONST(n)
Definition: copasi.h:89
C_INT64 getSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:126
C_INT64 getMicroSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:112
C_INT64 getMilliSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:118
std::string CCopasiTimeVariable::LL2String ( const C_INT64 value,
const C_INT32 digits = 0 
)
static

Helper function to convert a C_INT32 to a std::string. If the number of digits is non zero the value is padded with zeros.

Parameters
constC_INT64 & value
constC_INT32 & digits (default: 0)
Returns
std::string

Definition at line 246 of file CopasiTime.cpp.

References StringPrint().

Referenced by isoFormat(), CFitProblem::printResult(), and COptProblem::printResult().

248 {
249  std::string format;
250 
251  if (digits > 0)
252  format = "%0" + StringPrint("%d", digits);
253  else
254  format = "%";
255 
256 #ifdef WIN32
257  format += "I64d";
258 #else
259  format += "lld";
260 #endif
261 
262  return StringPrint(format.c_str(), value);
263 }
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
CCopasiTimeVariable CCopasiTimeVariable::operator+ ( const CCopasiTimeVariable value)

Operator + for adding CCopasiTimeVariables

Parameters
constCCopasiTimeVariable & value
Returns
CCopasiTimeVariable sum

Definition at line 55 of file CopasiTime.cpp.

References mTime.

56 {return mTime + value.mTime;}
CCopasiTimeVariable CCopasiTimeVariable::operator- ( const CCopasiTimeVariable value)

Operator - for subtracting CCopasiTimeVariables

Parameters
constCCopasiTimeVariable & value
Returns
CCopasiTimeVariable difference

Definition at line 58 of file CopasiTime.cpp.

References mTime.

59 {return mTime - value.mTime;}
bool CCopasiTimeVariable::operator< ( const CCopasiTimeVariable value)

Coparison operator <

Parameters
constCCopasiTimeVariable & value
Returns
bool isLess

Definition at line 73 of file CopasiTime.cpp.

References mTime.

74 {return (mTime < value.mTime);}
CCopasiTimeVariable & CCopasiTimeVariable::operator= ( const CCopasiTimeVariable rhs)

Assignement operator

Parameters
constCCopasiTimeVariable & rhs
Returns
CCopasiTimeVariable & this

Definition at line 61 of file CopasiTime.cpp.

References mTime.

62 {
63  mTime = rhs.mTime;
64  return *this;
65 }
CCopasiTimeVariable & CCopasiTimeVariable::operator= ( const C_INT64 value)

Assignement operator assigning a C_INT64 value to a CCopasiTimeVariable

Parameters
constCCopasiTimeVariable & rhs
Returns
CCopasiTimeVariable & this

Definition at line 67 of file CopasiTime.cpp.

References mTime.

68 {
69  mTime = value;
70  return *this;
71 }

Member Data Documentation

C_INT64 CCopasiTimeVariable::mTime
private

Value containing the time in micro seconds.

Definition at line 175 of file CopasiTime.h.

Referenced by getDays(), getHours(), getMicroSeconds(), getMilliSeconds(), getMinutes(), getSeconds(), isoFormat(), operator+(), operator-(), operator<(), and operator=().


The documentation for this class was generated from the following files: