00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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( ReposStats::StatsResult &result,
00093 const ReposStats::StatsRequest &request,
00094 AccessControl::Identity who,
00095 Text reposHost,
00096 Text reposPort)
00097 throw (SRPC::failure)
00098 {
00099
00100
00101
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
00123 delete [] request_seq;
00124 request_seq = 0;
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
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( 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