Commit 17a72aeb authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Using std::chrono for real time measurement

parent 2eba6e84
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -312,18 +312,6 @@ endif()
####
# Check for some system header
#
find_path( SYS_TIME_INCLUDE_DIR sys/time.h  
           /usr/include/x86_64-linux-gnu
           /usr/include
           DOC "System timer headers." )
if( ${SYS_TIME_INCLUDE_DIR} STREQUAL "SYS_TIME_INCLUDE_DIR-NOTFOUND" )
    message(  "Missing header file sys/time.h" )
    set( HAVE_SYS_TIME_H "//#define HAVE_SYS_TIME_H 1" )
else()
    #include_directories( ${SYS_TIME_INCLUDE_DIR} )
    set( HAVE_SYS_TIME_H "#define HAVE_SYS_TIME_H 1" )
endif()

find_path( SYS_RESOURCE_INCLUDE_DIR sys/resource.h
           /usr/include/x86_64-linux-gnu
           /usr/include  
+14 −19
Original line number Diff line number Diff line
@@ -15,11 +15,6 @@
#ifdef HAVE_SYS_RESOURCE_H
   #include <sys/resource.h>
#endif
#ifdef HAVE_SYS_TIME_H
   #include <stddef.h>
   #include <sys/time.h>
   #define HAVE_TIME
#endif

namespace TNL {

@@ -34,8 +29,8 @@ void Timer::reset()
{
   this->initialCPUTime = 0;
   this->totalCPUTime = 0.0;
   this->initialRealTime = 0;
   this->totalRealTime = 0.0;
   this->initialRealTime = TimePoint();
   this->totalRealTime = Duration();
   this->initialCPUCycles = 0;
   this->totalCPUCycles = 0;
   this->stopState = true;
@@ -64,8 +59,8 @@ void Timer::start()
double Timer::getRealTime() const
{
   if( ! this->stopState )
    return this->readRealTime() - this->initialRealTime;
   return this->totalRealTime;
      return durationToDouble( this->readRealTime() - this->initialRealTime );
   return durationToDouble( this->totalRealTime );
}

double Timer::getCPUTime() const
@@ -82,15 +77,9 @@ unsigned long long int Timer::getCPUCycles() const
   return this->totalCPUCycles;
}

double Timer::readRealTime() const
typename Timer::TimePoint Timer::readRealTime() const
{
#ifdef HAVE_TIME
   struct timeval tp;
   int rtn = gettimeofday( &tp, NULL );
   return ( double ) tp. tv_sec + 1.0e-6 * ( double ) tp. tv_usec;
#else
   return -1;
#endif
   return std::chrono::high_resolution_clock::now();
}

double Timer::readCPUTime() const
@@ -109,6 +98,12 @@ unsigned long long int Timer::readCPUCycles() const
   return this->rdtsc();
}

double Timer::durationToDouble( const Duration& duration ) const
{
   std::chrono::duration< double > dur( duration );
   return dur.count();
}


bool Timer::writeLog( Logger& logger, int logLevel ) const
{
+14 −10
Original line number Diff line number Diff line
@@ -8,9 +8,10 @@

/* See Copyright Notice in tnl/Copyright */


#pragma once

#include <chrono>

namespace TNL {

class Logger;
@@ -91,10 +92,11 @@ class Timer

   protected:

      using TimePoint = typename std::chrono::high_resolution_clock::time_point;
      using Duration = typename std::chrono::high_resolution_clock::duration;

      /// \brief Function for measuring the real time.
      ///
      /// Returns number of seconds since Epoch, 1970-01-01 00:00:00 UTC.
      double readRealTime() const;
      TimePoint readRealTime() const;

      /// \brief Function for measuring the CPU time.
      ///
@@ -105,9 +107,12 @@ class Timer
      /// \brief Function for counting the number of CPU cycles (machine cycles).
      unsigned long long int readCPUCycles() const;

      double durationToDouble( const Duration& duration ) const;

   TimePoint initialRealTime;
   Duration totalRealTime;

   double initialRealTime, totalRealTime,
          initialCPUTime, totalCPUTime;
   double initialCPUTime, totalCPUTime;

   unsigned long long int initialCPUCycles, totalCPUCycles;

@@ -127,7 +132,6 @@ class Timer
   }
};

// !!! Odstranit ???!!!
extern Timer defaultTimer;

} // namespace TNL
+0 −2
Original line number Diff line number Diff line
@HAVE_SYS_TIME_H@

@HAVE_SYS_RESOURCE_H@

@HAVE_SYS_IOCTL_H@