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

ReposStats.C

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.C - implementation of everything declared in
00020 // ReposStats.H and ReposStatsSRPC.H
00021 
00022 // Last modified on Fri Apr 22 12:31:44 EDT 2005 by ken@xorian.net
00023 
00024 #include "ReposStats.H"
00025 #include "ReposStatsSRPC.H"
00026 #include "VestaSourceSRPC.H"
00027 
00028 using std::cerr;
00029 using std::endl;
00030 
00031 void ReposStats::FdCacheStats::send(SRPC *srpc) const throw (SRPC::failure)
00032 {
00033   srpc->send_int32(this->n_in_cache);
00034   srpc->send_int64(this->hits);
00035   srpc->send_int64(this->open_misses);
00036   srpc->send_int64(this->try_misses);
00037   srpc->send_int64(this->evictions);
00038   srpc->send_int64(this->expirations);
00039 }
00040 
00041 void ReposStats::FdCacheStats::recv(SRPC *srpc) throw (SRPC::failure)
00042 {
00043   this->n_in_cache = srpc->recv_int32();
00044   this->hits = srpc->recv_int64();
00045   this->open_misses = srpc->recv_int64();
00046   this->try_misses = srpc->recv_int64();
00047   this->evictions = srpc->recv_int64();
00048   this->expirations = srpc->recv_int64();
00049 }
00050 
00051 void ReposStats::DupeStats::send(SRPC *srpc) const throw (SRPC::failure)
00052 {
00053   srpc->send_int64(this->non);
00054   srpc->send_int64(this->inProcess);
00055   srpc->send_int64(this->completed);
00056 }
00057 
00058 void ReposStats::DupeStats::recv(SRPC *srpc) throw (SRPC::failure)
00059 {
00060   this->non = srpc->recv_int64();
00061   this->inProcess = srpc->recv_int64();
00062   this->completed = srpc->recv_int64();
00063 }
00064 
00065 void ReposStats::TimedCalls::send(SRPC *srpc) const throw (SRPC::failure)
00066 {
00067   srpc->send_int64(this->call_count);
00068   srpc->send_int64(this->elapsed_secs);
00069   srpc->send_int32(this->elapsed_usecs);
00070 }
00071 
00072 void ReposStats::TimedCalls::recv(SRPC *srpc) throw (SRPC::failure)
00073 {
00074   this->call_count = srpc->recv_int64();
00075   this->elapsed_secs = srpc->recv_int64();
00076   this->elapsed_usecs = srpc->recv_int32();
00077 }
00078 
00079 void ReposStats::MemStats::send(SRPC *srpc) const throw (SRPC::failure)
00080 {
00081   srpc->send_int64(this->total);
00082   srpc->send_int64(this->resident);
00083 }
00084 
00085 void ReposStats::MemStats::recv(SRPC *srpc) throw (SRPC::failure)
00086 {
00087   this->total = srpc->recv_int64();
00088   this->resident = srpc->recv_int64();
00089 }
00090 
00091 void
00092 ReposStats::getStats(/*OUT*/ ReposStats::StatsResult &result,
00093                      const ReposStats::StatsRequest &request,
00094                      AccessControl::Identity who,
00095                      Text reposHost,
00096                      Text reposPort)
00097   throw (SRPC::failure)
00098 {
00099   // Convert the sequence of requested statistics into an array of
00100   // 16-bit integers for sending to the server, filtering for only the
00101   // kinds of statistics we actually know how to receive.
00102   Basics::int16 *request_seq = NEW_PTRFREE_ARRAY(Basics::int16,
00103                                                  request.size());
00104   int request_seq_len = 0;
00105   for(int i = 0; i < request.size(); i++)
00106     {
00107       ReposStats::StatKind kind = request.get(i);
00108       if((kind > ReposStats::invalid) && (kind < ReposStats::statKindEnd))
00109         {
00110           request_seq[request_seq_len++] = (Basics::int16) kind;
00111         }
00112     }
00113 
00114   SRPC* srpc;
00115   MultiSRPC::ConnId id = VestaSourceSRPC::Start(srpc, reposHost, reposPort);
00116 
00117   srpc->start_call(VestaSourceSRPC::GetStats,
00118                    VestaSourceSRPC::version);
00119   VestaSourceSRPC::send_identity(srpc, who);
00120   srpc->send_int16_array(request_seq, request_seq_len);
00121   srpc->send_end();
00122   // We're done with this now.
00123   delete [] request_seq;
00124   request_seq = 0;  // Help out GC programs.
00125 
00126   srpc->recv_seq_start();
00127   while(1)
00128     {
00129       bool done = false;
00130       ReposStats::StatKind kind =
00131         (ReposStats::StatKind) srpc->recv_int16(&done);
00132       if(done)
00133         break;
00134       switch(kind)
00135         {
00136         case ReposStats::fdCache:
00137           {
00138             ReposStats::FdCacheStats *fd_stats = NEW(ReposStats::FdCacheStats);
00139             fd_stats->recv(srpc);
00140             result.Put(kind, fd_stats);
00141           }
00142           break;
00143         case ReposStats::dupeTotal:
00144           {
00145             ReposStats::DupeStats *dupe_stats = NEW(ReposStats::DupeStats);
00146             dupe_stats->recv(srpc);
00147             result.Put(kind, dupe_stats);
00148           }
00149           break;
00150         case ReposStats::srpcTotal:
00151         case ReposStats::nfsTotal:
00152           {
00153             ReposStats::TimedCalls *call_stats = NEW(ReposStats::TimedCalls);
00154             call_stats->recv(srpc);
00155             result.Put(kind, call_stats);
00156           }
00157           break;
00158         case ReposStats::memUsage:
00159           {
00160             ReposStats::MemStats *mem_stats = NEW(ReposStats::MemStats);
00161             mem_stats->recv(srpc);
00162             result.Put(kind, mem_stats);
00163           }
00164           break;
00165         default:
00166           cerr << ("VDirSurrogate::getReposStats received unknown statistic "
00167                    "type (")
00168                << (unsigned int) kind <<")" << endl;
00169           // @@@ Need to signal failure to both client and server.
00170           break;
00171         }
00172     }
00173   srpc->recv_seq_end();
00174 
00175   srpc->recv_end();
00176   VestaSourceSRPC::End(id);
00177 }
00178 
00179 void
00180 ReposStats::getServerInfo(/*OUT*/ ServerInfo &result,
00181                           AccessControl::Identity who,
00182                           Text reposHost,
00183                           Text reposPort)
00184   throw (SRPC::failure)
00185 {
00186   SRPC* srpc;
00187   MultiSRPC::ConnId id = VestaSourceSRPC::Start(srpc, reposHost, reposPort);
00188 
00189   srpc->start_call(VestaSourceSRPC::GetServerInfo,
00190                    VestaSourceSRPC::version);
00191   VestaSourceSRPC::send_identity(srpc, who);
00192   srpc->send_end();
00193 
00194   char *version = srpc->recv_chars();
00195   result.version = version;
00196   delete [] version;
00197 
00198   result.start_time = srpc->recv_int64();
00199   result.uptime = srpc->recv_int32();
00200 
00201   srpc->recv_end();
00202   VestaSourceSRPC::End(id);
00203 }
00204 

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