Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ReposStats.H

Go to the documentation of this file.
00001 // Copyright (C) 2004, Kenneth C. Schalk
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // ReposStats.H - data structures representing statistics about the
00020 // rpeository
00021 
00022 // Last modified on Sat Jan  8 20:38:52 EST 2005 by ken@xorian.net
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       // 0 can be used when there is no StatKind available.
00037       invalid = 0,
00038 
00039       // Statistics about the file descriptor cache.
00040       fdCache,
00041 
00042       // These statistics are across all NFS/SRPC procedures.  At some
00043       // point in the future, there may also be statistics that are
00044       // split up by invidual procedure.
00045       dupeTotal,
00046       srpcTotal,
00047       nfsTotal,
00048 
00049       // Repository server memory usage
00050       memUsage,
00051 
00052       // Final enum elemnt is used as a marker of the end of allowable
00053       // statistics.
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   // Statistics for the file descriptor cache.
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     // No destructor needed
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     // Allow for subtraction to compute differences in a time
00097     // interval.
00098     inline FdCacheStats operator-(const FdCacheStats &other) const
00099     {
00100       FdCacheStats result;
00101       // Note: we just pass on our n_in_cache, as it's not a
00102       // cumulative count over the life of the repository.
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   // Statistics about duplicate suppression.
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     // No destructor needed
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   // This class is used to represent statistics for both SRPC calls
00167   // and NFS calls.
00168   class TimedCalls : public Stat
00169   {
00170   public:
00171     // Number of calls completed
00172     Basics::uint64 call_count;
00173     // Elapsed time over all calls
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     // No destructor needed
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

Generated on Mon May 8 00:48:46 2006 for Vesta by  doxygen 1.4.2