fdhwlib  2.0.25
/home/kopmann/git-mirror/fdhwlib/fdhwlib/akutil/procDuration.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     procDuration.h  -  description
00003 
00004     begin                : Thu Jun 29 2000
00005     copyright            : (C) 2000 by Andreas Kopmann
00006     email                : kopmann@hpe.fzk.de
00007  ***************************************************************************/
00008 
00009 
00010 
00011 #ifndef _INC_PROCDURATION_1234_INCLUDED
00012 #define _INC_PROCDURATION_1234_INCLUDED
00013 
00014 
00015 #include <cstdio>
00016 
00017 // elapsed cpu time
00018 #include <ctime>
00019 
00020 // access to miliseconds of the real-time clock is system-dependent
00021 #include <sys/time.h>
00022 #include <unistd.h>
00023 
00024 
00025 // Define a system independand sleep function?!
00026 #ifdef __GNUC__
00027 #define SLEEP(_delay) usleep(_delay * 1000)  // us ?
00028 #endif
00029 
00030 #ifdef _WIN32 // Windows
00031 #include <windows.h>
00032 #define SLEEP(_delay) Sleep(_delay)    // miliseconds
00033 #endif
00034 
00035 
00036 
00046 class procDuration
00047 {
00048 
00049 public:
00050    procDuration();
00051 
00052    void setStart();
00053 
00054    void setStart(unsigned long time,unsigned long usec = 0);
00055 
00056    void setEnd();
00057 
00059    void setEndFromStart(procDuration *dur);
00060 
00063    double getDurationCPU();
00064 
00067    double getDurationRT();
00068 
00069    void displayDuration();
00070    void displayDuration(FILE *fout);
00071 
00072    void displayTransferRate(double blocksize);
00073    void displayTransferRate(FILE *fout, double blocksize);
00074 
00075    void displayStartTime(FILE *fout);
00076    void displayStartDate(FILE *fout);
00077 
00078 
00080    const char * cStartTime();
00082    const char * cStartDate();
00084    const char * cStartZone();
00085 
00087    const char * cEndTime();
00089    const char * cEndDate();
00091    const char * cEndZone();
00092 
00094    const char * cTime(time_t *t);
00096    const char * cGpsTime(unsigned long t);
00098    const char * cDate(time_t *t);
00100    const char * cGpsDate(unsigned long t);
00102    const char * cZone(time_t *t);
00103    
00106    unsigned long getStartSec();
00107 
00109    unsigned long getEndSec();
00110 
00112    int getStartMiliSec();
00113 
00115    int getEndMiliSec();
00116 
00118    int getStartMicroSec();
00119 
00121    int getEndMicroSec();
00122 
00124    int getStartNanoSec();
00125 
00127    int getEndNanoSec();
00128 
00131    void meanTime(procDuration &dur);
00132 
00134    void getDurationRT(int *sign, unsigned long *sec, unsigned long *usec);
00135 
00137    procDuration operator=(procDuration &dur);
00138 
00140    void set(procDuration dur);
00141 
00142 protected:
00143 
00144    clock_t startTick;
00145    clock_t endTick;
00146 
00147    struct timeval startTime;
00148    struct timezone startZone;
00149    struct timeval endTime;
00150    struct timezone endZone;
00151 
00152    double durationCPU;
00153    double durationRT;
00154 
00155 
00156    static const char dateformat[];
00157    static const char timeformat[];
00158    static const char zoneformat[];
00159 
00160    static char datestring[];
00161    static char timestring[];
00162    static char zonestring[];
00163 
00164 //   static char datestring[ 4+1+2+1+2+1 ];
00165 //   static char timestring[ 2+1+2+1+2+1 ];
00166 
00167    int diffTimeSign;
00168    unsigned long diffTimeSec;
00169    unsigned long diffTimeMicroSec;
00170 
00171 };
00172 
00173 #endif