Skip to content
Snippets Groups Projects
Select Git revision
  • d58227b9ab0c81d6c19d4108df2887ca8c21d35d
  • master default
  • update-cudawrappers
  • migrate-cmake
4 results

TimeStamp.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    TimeStamp.h 5.39 KiB
    #ifndef TIMESTAMP_H
    #define TIMESTAMP_H
    
    #define EVEN_SECOND_HAS_MORE_SAMPLES
    
    #include <inttypes.h>
    
    #include <chrono>
    #include <iostream>
    
    // FIXME: the 1024 constant factor in clockSpeed is a design flaw
    
    class TimeStamp
    {
      public:
        TimeStamp(); // empty constructor to be able to create vectors of TimeStamps
        TimeStamp(int64_t time); // for conversion from ints, used to convert values like 0x7FFFFFFF and 0x0 for special cases.
        TimeStamp(int64_t time, unsigned clockSpeed);
        TimeStamp(unsigned seqId, unsigned blockId, unsigned clockSpeed);
    
        static TimeStamp fromDate(const char *date, unsigned clockSpeed);
        static TimeStamp now(unsigned clockSpeed);
        void	     wait() const;
    
        TimeStamp	    &setStamp(unsigned seqId, unsigned blockId);
        unsigned	    getSeqId() const;
        unsigned	    getBlockId() const;
        unsigned	    getClock() const { return clockSpeed; }
    
        template <typename T> TimeStamp &operator += (T increment);
        template <typename T> TimeStamp &operator -= (T decrement);
    			  TimeStamp  operator ++ (int); // postfix
    			  TimeStamp &operator ++ ();	  // prefix
    			  TimeStamp  operator -- (int);
    			  TimeStamp &operator -- ();
    
        template <typename T> TimeStamp  operator +  (T) const;
        template <typename T> TimeStamp  operator -  (T) const;
    			  int64_t    operator -  (const TimeStamp &) const;
    
    			  bool       operator >  (const TimeStamp &) const;
    			  bool       operator <  (const TimeStamp &) const;
    			  bool       operator >= (const TimeStamp &) const;
    			  bool       operator <= (const TimeStamp &) const;
    			  bool       operator == (const TimeStamp &) const;
    			  bool       operator != (const TimeStamp &) const;
    			  bool       operator !  () const;
    
    				     operator int64_t () const;
    				     operator double () const;
    				     operator struct timespec () const;
    				     typedef std::chrono::time_point<std::chrono::system_clock,std::chrono::duration<double>> time_point;
    				     operator time_point () const;
    
        friend std::ostream &operator << (std::ostream &os, const TimeStamp &ss);
    
      protected:
        int64_t  time;
        unsigned clockSpeed;
    };
    
    inline TimeStamp::TimeStamp()
    :
      time(0),
      clockSpeed(0)
    {
    }
    
    inline TimeStamp::TimeStamp(int64_t time)
    :