00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _CSP_KERNEL_Resources_H
00030 #define _CSP_KERNEL_Resources_H
00031
00032
00033 #ifndef _WIN32
00034 #ifdef TIME_WITH_SYS_TIME
00035 #include <sys/time.h>
00036 #include <time.h>
00037 #else
00038 #ifdef CSP_HAVE_SYS_TIME_H
00039 #include <sys/time.h>
00040 #else
00041 #include <time.h>
00042 #endif
00043 #endif
00044 #endif // !_WIN32
00045
00046 #ifndef _WIN32
00047 #include <sys/resource.h>
00048 #endif // !_WIN32
00049
00050
00051 #ifdef _MSC_VER
00052
00053 struct rusage
00054 {
00055 struct timeval ru_utime;
00056 struct timeval ru_stime;
00057 long ru_maxrss;
00058 long ru_ixrss;
00059 long ru_idrss;
00060 long ru_isrss;
00061 long ru_minflt;
00062 long ru_majflt;
00063 long ru_nswap;
00064 long ru_inblock;
00065 long ru_oublock;
00066 long ru_msgsnd;
00067 long ru_msgrcv;
00068 long ru_nsignals;
00069 long ru_nvcsw;
00070 long ru_nivcsw;
00071 };
00072 #endif // _MSC_VER
00073
00074
00075 CSP_NAMESPACE_BEGIN(csp);
00076
00077
00100 class CSP_API Resources
00101 {
00102 public:
00111 Resources(bool max = false);
00112
00113
00114
00115
00116
00117 void start();
00118
00125 void record();
00126
00132 void stop();
00133
00140 void resume(bool countBreakResources = false);
00141
00146 const timeval userTime() const;
00147
00152 const timeval systemTime() const;
00153
00158 const timeval totalTime() const;
00159
00164 const timeval realTime() const;
00165
00166 long memory() const;
00167 long text() const;
00168 long data() const;
00169 long stack() const;
00170 long minorPageFaults() const;
00171 long majorPageFaults() const;
00172 long swaps() const;
00173 long inputBlocks() const;
00174 long outputBlocks() const;
00175 long messagesSent() const;
00176 long messagesReceived() const;
00177 long signalsReceived() const;
00178 long voluntaryContextSwitches() const;
00179 long involuntaryContextSwitches() const;
00180
00182 static void add(
00183 const timeval& time1,
00184 const timeval& time2,
00185 timeval& result);
00186
00188 static void substract(
00189 const timeval& final,
00190 const timeval& initial,
00191 timeval& result);
00192
00194 static int compare(
00195 const timeval& t1,
00196 const timeval& t2);
00197
00204 wostream& print(wostream& wos) const;
00205
00206 friend CSP_API wostream& operator<<(
00207 wostream& wos, const Resources& resources)
00208 {
00209 return resources.print(wos);
00210 }
00211
00212 protected:
00214 enum state_t { Started, Stopped };
00215
00217 void read(timeval& timeStamp, rusage& resourceUsage, bool initialReading);
00218
00220 static void move(
00221 timeval& initial,
00222 timeval& final,
00223 timeval& newFinal);
00224
00225 static wostream& printTime(wostream& wos, const timeval& tv);
00226
00227 private:
00229 rusage m_initialResourceUsage;
00230
00232 rusage m_finalResourceUsage;
00233
00235 timeval m_initialTimeStamp;
00236
00238 timeval m_finalTimeStamp;
00239
00241 state_t m_state;
00242 };
00243
00244
00245 CSP_NAMESPACE_END(csp);
00246
00247
00248 #endif // _CSP_KERNEL_Resources_H
00249
00250
00251
00252