00001 #ifndef __XRDPFC_STATS_HH__
00002 #define __XRDPFC_STATS_HH__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "XrdOuc/XrdOucCache.hh"
00023 #include "XrdSys/XrdSysPthread.hh"
00024
00025 namespace XrdPfc
00026 {
00027
00029
00030 class Stats
00031 {
00032 public:
00033 int m_NumIos;
00034 int m_Duration;
00035 long long m_BytesHit;
00036 long long m_BytesMissed;
00037 long long m_BytesBypassed;
00038 long long m_BytesWritten;
00039
00040
00041
00042 Stats() :
00043 m_NumIos (0), m_Duration(0),
00044 m_BytesHit(0), m_BytesMissed(0), m_BytesBypassed(0),
00045 m_BytesWritten(0)
00046 {}
00047
00048 Stats(const Stats& s) :
00049 m_NumIos (s.m_NumIos), m_Duration(s.m_Duration),
00050 m_BytesHit(s.m_BytesHit), m_BytesMissed(s.m_BytesMissed), m_BytesBypassed(s.m_BytesBypassed),
00051 m_BytesWritten(s.m_BytesWritten)
00052 {}
00053
00054 Stats& operator=(const Stats&) = default;
00055
00056
00057
00058 void AddReadStats(const Stats &s)
00059 {
00060 XrdSysMutexHelper _lock(&m_Mutex);
00061
00062 m_BytesHit += s.m_BytesHit;
00063 m_BytesMissed += s.m_BytesMissed;
00064 m_BytesBypassed += s.m_BytesBypassed;
00065 }
00066
00067 void AddBytesWritten(long long bw)
00068 {
00069 XrdSysMutexHelper _lock(&m_Mutex);
00070
00071 m_BytesWritten += bw;
00072 }
00073
00074 void IoAttach()
00075 {
00076 XrdSysMutexHelper _lock(&m_Mutex);
00077
00078 ++m_NumIos;
00079 }
00080
00081 void IoDetach(int duration)
00082 {
00083 XrdSysMutexHelper _lock(&m_Mutex);
00084
00085 m_Duration += duration;
00086 }
00087
00088 Stats Clone()
00089 {
00090 XrdSysMutexHelper _lock(&m_Mutex);
00091
00092 return Stats(*this);
00093 }
00094
00095
00096
00097 void DeltaToReference(const Stats& ref)
00098 {
00099
00100 m_NumIos = ref.m_NumIos - m_NumIos;
00101 m_Duration = ref.m_Duration - m_Duration;
00102 m_BytesHit = ref.m_BytesHit - m_BytesHit;
00103 m_BytesMissed = ref.m_BytesMissed - m_BytesMissed;
00104 m_BytesBypassed = ref.m_BytesBypassed - m_BytesBypassed;
00105 m_BytesWritten = ref.m_BytesWritten - m_BytesWritten;
00106 }
00107
00108 void AddUp(const Stats& s)
00109 {
00110
00111 m_NumIos += s.m_NumIos;
00112 m_Duration += s.m_Duration;
00113 m_BytesHit += s.m_BytesHit;
00114 m_BytesMissed += s.m_BytesMissed;
00115 m_BytesBypassed += s.m_BytesBypassed;
00116 m_BytesWritten += s.m_BytesWritten;
00117 }
00118
00119 void Reset()
00120 {
00121
00122 m_NumIos = 0;
00123 m_Duration = 0;
00124 m_BytesHit = 0;
00125 m_BytesMissed = 0;
00126 m_BytesBypassed = 0;
00127 m_BytesWritten = 0;
00128 }
00129
00130 private:
00131 XrdSysMutex m_Mutex;
00132 };
00133 }
00134
00135 #endif
00136