"Fossies" - the Fresh Open Source Software Archive

Member "bonnie++-2.00a/duration.cpp" (30 Jun 2016, 1043 Bytes) of package /linux/privat/bonnie++-2.00a.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "duration.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.97_vs_1.97.3.

    1 using namespace std;
    2 
    3 #include <stdlib.h>
    4 
    5 #include "duration.h"
    6 #define TIMEVAL_TO_DOUBLE(XX) (double((XX).tv_sec) + double((XX).tv_usec) / 1000000.0)
    7 
    8 #include "conf.h"
    9 #include <unistd.h>
   10 #include <sys/resource.h>
   11 #include <sys/time.h>
   12 
   13 #ifdef HAVE_ALGORITHM
   14 #include <algorithm>
   15 #else
   16 #ifdef HAVE_ALGO
   17 #include <algo>
   18 #else
   19 #include <algo.h>
   20 #endif
   21 #endif
   22 
   23 Duration_Base::Duration_Base()
   24  : m_start(0.0)
   25  , m_max(0.0)
   26 {
   27 }
   28 
   29 double Duration_Base::start()
   30 {
   31   getTime(&m_start);
   32   return m_start;
   33 }
   34 
   35 double Duration_Base::stop()
   36 {
   37   double tv;
   38   getTime(&tv);
   39   double ret;
   40   ret = tv - m_start;
   41   m_max = max(m_max, ret);
   42   return ret;
   43 }
   44 
   45 bool Duration::getTime(double *tv)
   46 {
   47   TIMEVAL_TYPE t;
   48   if (gettimeofday(&t, static_cast<struct timezone *>(NULL)) == -1)
   49     return true;
   50   *tv = TIMEVAL_TO_DOUBLE(t);
   51   return false;
   52 }
   53 
   54 bool CPU_Duration::getTime(double *tv)
   55 {
   56   struct rusage res_usage;
   57  
   58   getrusage(RUSAGE_SELF, &res_usage);
   59   *tv = TIMEVAL_TO_DOUBLE(res_usage.ru_utime) + TIMEVAL_TO_DOUBLE(res_usage.ru_stime);
   60   return false;
   61 }