00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef REPOSSTATS_H
00025 #define REPOSSTATS_H 1
00026
00027 #include <Basics.H>
00028 #include <SRPC.H>
00029
00030 #define USECS_PER_SEC 1000000
00031
00032 namespace ReposStats
00033 {
00034 enum StatKind
00035 {
00036
00037 invalid = 0,
00038
00039
00040 fdCache,
00041
00042
00043
00044
00045 dupeTotal,
00046 srpcTotal,
00047 nfsTotal,
00048
00049
00050 memUsage,
00051
00052
00053
00054 statKindEnd
00055 };
00056
00057 class Stat
00058 {
00059 public:
00060 virtual void send(SRPC *srpc) const throw (SRPC::failure) = 0;
00061 virtual void recv(SRPC *srpc) throw (SRPC::failure) = 0;
00062 };
00063
00064
00065 class FdCacheStats : public Stat
00066 {
00067 public:
00068 Basics::uint32 n_in_cache;
00069 Basics::uint64 hits;
00070 Basics::uint64 open_misses;
00071 Basics::uint64 try_misses;
00072 Basics::uint64 evictions;
00073 Basics::uint64 expirations;
00074
00075 FdCacheStats()
00076 : n_in_cache(0), hits(0), open_misses(0), try_misses(0),
00077 evictions(0), expirations(0)
00078 { }
00079 FdCacheStats(const FdCacheStats &other)
00080 : n_in_cache(other.n_in_cache), hits(other.hits),
00081 open_misses(other.open_misses), try_misses(other.try_misses),
00082 evictions(other.evictions), expirations(other.expirations)
00083 { }
00084
00085 FdCacheStats& operator=(const FdCacheStats &other)
00086 {
00087 n_in_cache = other.n_in_cache;
00088 hits = other.hits;
00089 open_misses = other.open_misses;
00090 try_misses = other.try_misses;
00091 evictions = other.evictions;
00092 expirations = other.expirations;
00093 return *this;
00094 }
00095
00096
00097
00098 inline FdCacheStats operator-(const FdCacheStats &other) const
00099 {
00100 FdCacheStats result;
00101
00102
00103 result.n_in_cache = n_in_cache;
00104 result.hits = hits - other.hits;
00105 result.open_misses = open_misses - other.open_misses;
00106 result.try_misses = try_misses - other.try_misses;
00107 result.evictions = evictions - other.evictions;
00108 result.expirations = expirations - other.expirations;
00109 return result;
00110 }
00111
00112 void send(SRPC *srpc) const throw (SRPC::failure);
00113 void recv(SRPC *srpc) throw (SRPC::failure);
00114 };
00115
00116
00117 class DupeStats : public Stat
00118 {
00119 public:
00120 Basics::uint64 non, inProcess, completed;
00121 DupeStats()
00122 : non(0), inProcess(0), completed(0)
00123 { }
00124 DupeStats(const DupeStats &other)
00125 : non(other.non), inProcess(other.inProcess), completed(other.completed)
00126 { }
00127
00128 DupeStats &operator=(const DupeStats &other)
00129 {
00130 non = other.non;
00131 inProcess = other.inProcess;
00132 completed = other.completed;
00133 return *this;
00134 }
00135
00136 inline Basics::uint64 total() const
00137 {
00138 return non+inProcess+completed;
00139 }
00140 inline void zero()
00141 {
00142 non = 0;
00143 inProcess = 0;
00144 completed = 0;
00145 }
00146 inline DupeStats &operator+=(const DupeStats &other)
00147 {
00148 non += other.non;
00149 inProcess += other.inProcess;
00150 completed += other.completed;
00151 return *this;
00152 }
00153 inline DupeStats operator-(const DupeStats &other) const
00154 {
00155 DupeStats result;
00156 result.non = non - other.non;
00157 result.inProcess = inProcess - other.inProcess;
00158 result.completed = completed - other.completed;
00159 return result;
00160 }
00161
00162 void send(SRPC *srpc) const throw (SRPC::failure);
00163 void recv(SRPC *srpc) throw (SRPC::failure);
00164 };
00165
00166
00167
00168 class TimedCalls : public Stat
00169 {
00170 public:
00171
00172 Basics::uint64 call_count;
00173
00174 Basics::uint64 elapsed_secs;
00175 Basics::uint32 elapsed_usecs;
00176
00177 TimedCalls()
00178 : call_count(0), elapsed_secs(0), elapsed_usecs(0)
00179 { }
00180 TimedCalls(const TimedCalls &other)
00181 : call_count(other.call_count),
00182 elapsed_secs(other.elapsed_secs),
00183 elapsed_usecs(other.elapsed_usecs)
00184 { }
00185 TimedCalls &operator=(const TimedCalls &other)
00186 {
00187 call_count = other.call_count;
00188 elapsed_secs = other.elapsed_secs;
00189 elapsed_usecs = other.elapsed_usecs;
00190 return *this;
00191 }
00192
00193 inline TimedCalls operator-(const TimedCalls &other) const
00194 {
00195 TimedCalls result;
00196 result.call_count = call_count - other.call_count;
00197 if(elapsed_secs == other.elapsed_secs)
00198 {
00199 result.elapsed_secs = 0;
00200 assert(elapsed_usecs >= other.elapsed_usecs);
00201 result.elapsed_usecs = elapsed_usecs - other.elapsed_usecs;
00202 }
00203 else
00204 {
00205 assert(elapsed_secs > other.elapsed_secs);
00206 result.elapsed_secs = (elapsed_secs - other.elapsed_secs) - 1;
00207 result.elapsed_usecs = ((elapsed_usecs + USECS_PER_SEC) -
00208 other.elapsed_usecs);
00209 if(result.elapsed_usecs > USECS_PER_SEC)
00210 {
00211 result.elapsed_secs += result.elapsed_usecs/USECS_PER_SEC;
00212 result.elapsed_usecs %= USECS_PER_SEC;
00213 }
00214 }
00215 return result;
00216 }
00217
00218 void send(SRPC *srpc) const throw (SRPC::failure);
00219 void recv(SRPC *srpc) throw (SRPC::failure);
00220 };
00221
00222 class MemStats : public Stat
00223 {
00224 public:
00225 Basics::uint64 total, resident;
00226 MemStats()
00227 : total(0), resident(0)
00228 { }
00229 MemStats(Basics::uint64 t, Basics::uint64 r)
00230 : total(t), resident(r)
00231 { }
00232 MemStats(const MemStats &other)
00233 : total(other.total), resident(other.resident)
00234 { }
00235
00236 MemStats &operator=(const MemStats &other)
00237 {
00238 total = other.total;
00239 resident = other.resident;
00240 return *this;
00241 }
00242
00243 void send(SRPC *srpc) const throw (SRPC::failure);
00244 void recv(SRPC *srpc) throw (SRPC::failure);
00245 };
00246
00247 }
00248
00249 #endif // REPOSSTATS_H