xrootd
XrdPfcStats.hh
Go to the documentation of this file.
1 #ifndef __XRDPFC_STATS_HH__
2 #define __XRDPFC_STATS_HH__
3 
4 //----------------------------------------------------------------------------------
5 // Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
6 // Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
7 //----------------------------------------------------------------------------------
8 // XRootD is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // XRootD is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------------
21 
22 #include "XrdOuc/XrdOucCache.hh"
23 #include "XrdSys/XrdSysPthread.hh"
24 
25 namespace XrdPfc
26 {
27 //----------------------------------------------------------------------------
29 //----------------------------------------------------------------------------
30 class Stats
31 {
32 public:
33  int m_NumIos;
34  int m_Duration;
35  long long m_BytesHit;
36  long long m_BytesMissed;
37  long long m_BytesBypassed;
38  long long m_BytesWritten;
39 
40  //----------------------------------------------------------------------
41 
42  Stats() :
43  m_NumIos (0), m_Duration(0),
46  {}
47 
48  Stats(const Stats& s) :
52  {}
53 
54  Stats& operator=(const Stats&) = default;
55 
56  //----------------------------------------------------------------------
57 
58  void AddReadStats(const Stats &s)
59  {
60  XrdSysMutexHelper _lock(&m_Mutex);
61 
65  }
66 
67  void AddBytesWritten(long long bw)
68  {
69  XrdSysMutexHelper _lock(&m_Mutex);
70 
71  m_BytesWritten += bw;
72  }
73 
74  void IoAttach()
75  {
76  XrdSysMutexHelper _lock(&m_Mutex);
77 
78  ++m_NumIos;
79  }
80 
81  void IoDetach(int duration)
82  {
83  XrdSysMutexHelper _lock(&m_Mutex);
84 
85  m_Duration += duration;
86  }
87 
89  {
90  XrdSysMutexHelper _lock(&m_Mutex);
91 
92  return Stats(*this);
93  }
94 
95  //----------------------------------------------------------------------
96 
97  void DeltaToReference(const Stats& ref)
98  {
99  // Not locked, only used from Cache / Purge thread.
100  m_NumIos = ref.m_NumIos - m_NumIos;
106  }
107 
108  void AddUp(const Stats& s)
109  {
110  // Not locked, only used from Cache / Purge thread.
111  m_NumIos += s.m_NumIos;
112  m_Duration += s.m_Duration;
113  m_BytesHit += s.m_BytesHit;
117  }
118 
119  void Reset()
120  {
121  // Not locked, only used from Cache / Purge thread.
122  m_NumIos = 0;
123  m_Duration = 0;
124  m_BytesHit = 0;
125  m_BytesMissed = 0;
126  m_BytesBypassed = 0;
127  m_BytesWritten = 0;
128  }
129 
130 private:
132 };
133 }
134 
135 #endif
136 
XrdSysMutex m_Mutex
Definition: XrdPfcStats.hh:131
void AddReadStats(const Stats &s)
Definition: XrdPfcStats.hh:58
void Reset()
Definition: XrdPfcStats.hh:119
void IoAttach()
Definition: XrdPfcStats.hh:74
Definition: XrdPfc.hh:40
Definition: XrdSysPthread.hh:165
Stats()
Definition: XrdPfcStats.hh:42
int m_Duration
total duration of all IOs attached
Definition: XrdPfcStats.hh:34
void AddBytesWritten(long long bw)
Definition: XrdPfcStats.hh:67
long long m_BytesWritten
number of bytes written to disk
Definition: XrdPfcStats.hh:38
long long m_BytesBypassed
number of bytes served directly through XrdCl
Definition: XrdPfcStats.hh:37
int m_NumIos
number of IO objects attached during this access
Definition: XrdPfcStats.hh:33
Statistics of cache utilisation by a File object.
Definition: XrdPfcStats.hh:30
void DeltaToReference(const Stats &ref)
Definition: XrdPfcStats.hh:97
void AddUp(const Stats &s)
Definition: XrdPfcStats.hh:108
long long m_BytesMissed
number of bytes served from RAM
Definition: XrdPfcStats.hh:36
Stats(const Stats &s)
Definition: XrdPfcStats.hh:48
long long m_BytesHit
number of bytes served from disk
Definition: XrdPfcStats.hh:35
Stats Clone()
Definition: XrdPfcStats.hh:88
void IoDetach(int duration)
Definition: XrdPfcStats.hh:81
Definition: XrdSysPthread.hh:262
Stats & operator=(const Stats &)=default