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 "nfsStats.H"
00025
00026 #include "ReposStats.H"
00027
00028 Basics::mutex NFS_Call_Stats::head_mu;
00029 NFS_Call_Stats *NFS_Call_Stats::head = 0;
00030
00031 void NFS_Call_Stats::accumulateStats( Basics::uint64 &calls,
00032 Basics::uint64 &secs,
00033 Basics::uint32 &usecs)
00034 {
00035 this->mu.lock();
00036 calls += this->call_count;
00037 secs += this->elapsed_secs;
00038 usecs += this->elapsed_usecs;
00039 this->mu.unlock();
00040 }
00041
00042 void NFS_Call_Stats::recordCall(Basics::uint32 secs, Basics::uint32 &usecs)
00043 {
00044 this->mu.lock();
00045
00046 this->call_count++;
00047
00048
00049 this->elapsed_secs += secs;
00050 this->elapsed_usecs += usecs;
00051 if(this->elapsed_usecs > USECS_PER_SEC)
00052 {
00053 this->elapsed_secs += this->elapsed_usecs/USECS_PER_SEC;
00054 this->elapsed_usecs %= USECS_PER_SEC;
00055 }
00056 this->mu.unlock();
00057 }
00058
00059 void NFS_Call_Stats::getStats( Basics::uint64 &calls,
00060 Basics::uint64 &secs,
00061 Basics::uint32 &usecs)
00062 {
00063
00064 calls = 0;
00065 secs = 0;
00066 usecs = 0;
00067
00068
00069 NFS_Call_Stats *list;
00070 NFS_Call_Stats::head_mu.lock();
00071 list = NFS_Call_Stats::head;
00072 NFS_Call_Stats::head_mu.unlock();
00073
00074 while(list != 0)
00075 {
00076
00077 list->accumulateStats(calls, secs, usecs);
00078
00079
00080 if(usecs > USECS_PER_SEC)
00081 {
00082 secs += usecs/USECS_PER_SEC;
00083 usecs %= USECS_PER_SEC;
00084 }
00085
00086
00087
00088
00089 list = list->next;
00090 }
00091 }
00092
00093 NFS_Call_Stats::NFS_Call_Stats()
00094 : next(0), call_count(0), elapsed_secs(0), elapsed_usecs(0)
00095 {
00096
00097 NFS_Call_Stats::head_mu.lock();
00098 this->next = NFS_Call_Stats::head;
00099 NFS_Call_Stats::head = this;
00100 NFS_Call_Stats::head_mu.unlock();
00101 }
00102
00103 NFS_Call_Stats::~NFS_Call_Stats()
00104 {
00105
00106 assert(false);
00107 }
00108
00109 NFS_Call_Stats::Helper::Helper(NFS_Call_Stats &my_stats)
00110 : stats(my_stats)
00111 {
00112
00113 struct timezone unused_tz;
00114 int err = gettimeofday(&this->call_start, &unused_tz);
00115 assert(err == 0);
00116 }
00117
00118 NFS_Call_Stats::Helper::~Helper()
00119 {
00120
00121 struct timezone unused_tz;
00122 struct timeval call_end;
00123 int err = gettimeofday(&call_end, &unused_tz);
00124 assert(err == 0);
00125
00126
00127 Basics::uint32 call_secs, call_usecs;
00128 if(call_end.tv_sec == this->call_start.tv_sec)
00129 {
00130 call_secs = 0;
00131 if(call_end.tv_usec >= this->call_start.tv_usec)
00132 call_usecs = call_end.tv_usec - this->call_start.tv_usec;
00133 else
00134
00135
00136 call_usecs = 0;
00137 }
00138 else if(call_end.tv_sec > this->call_start.tv_sec)
00139 {
00140 call_secs = (call_end.tv_sec - this->call_start.tv_sec) - 1;
00141 call_usecs = ((call_end.tv_usec + USECS_PER_SEC) -
00142 this->call_start.tv_usec);
00143 }
00144 else
00145 {
00146
00147
00148 call_secs = 0;
00149 call_usecs = 0;
00150 }
00151
00152
00153 stats.recordCall(call_secs, call_usecs);
00154 }