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;
40 
41  //----------------------------------------------------------------------
42 
43  Stats() :
44  m_NumIos (0), m_Duration(0),
47  {}
48 
49  Stats(const Stats& s) :
53  {}
54 
55  Stats& operator=(const Stats&) = default;
56 
57  //----------------------------------------------------------------------
58 
59  void AddReadStats(const Stats &s)
60  {
61  XrdSysMutexHelper _lock(&m_Mutex);
62 
66  }
67 
68  void AddBytesHit(long long bh)
69  {
70  XrdSysMutexHelper _lock(&m_Mutex);
71 
72  m_BytesHit += bh;
73  }
74 
75  void AddWriteStats(long long bytes_written, int n_cks_errs)
76  {
77  XrdSysMutexHelper _lock(&m_Mutex);
78 
79  m_BytesWritten += bytes_written;
80  m_NCksumErrors += n_cks_errs;
81  }
82 
83  void IoAttach()
84  {
85  XrdSysMutexHelper _lock(&m_Mutex);
86 
87  ++m_NumIos;
88  }
89 
90  void IoDetach(int duration)
91  {
92  XrdSysMutexHelper _lock(&m_Mutex);
93 
94  m_Duration += duration;
95  }
96 
98  {
99  XrdSysMutexHelper _lock(&m_Mutex);
100 
101  return Stats(*this);
102  }
103 
104  //----------------------------------------------------------------------
105 
106  void DeltaToReference(const Stats& ref)
107  {
108  // Not locked, only used from Cache / Purge thread.
109  m_NumIos = ref.m_NumIos - m_NumIos;
116  }
117 
118  void AddUp(const Stats& s)
119  {
120  // Not locked, only used from Cache / Purge thread.
121  m_NumIos += s.m_NumIos;
122  m_Duration += s.m_Duration;
123  m_BytesHit += s.m_BytesHit;
128  }
129 
130  void Reset()
131  {
132  // Not locked, only used from Cache / Purge thread.
133  m_NumIos = 0;
134  m_Duration = 0;
135  m_BytesHit = 0;
136  m_BytesMissed = 0;
137  m_BytesBypassed = 0;
138  m_BytesWritten = 0;
139  m_NCksumErrors = 0;
140  }
141 
142 private:
143  XrdSysMutex m_Mutex;
144 };
145 }
146 
147 #endif
148 
Statistics of cache utilisation by a File object.
Definition: XrdPfcStats.hh:31
void IoAttach()
Definition: XrdPfcStats.hh:83
Stats Clone()
Definition: XrdPfcStats.hh:97
long long m_BytesMissed
number of bytes served from remote and cached
Definition: XrdPfcStats.hh:36
void AddReadStats(const Stats &s)
Definition: XrdPfcStats.hh:59
Stats & operator=(const Stats &)=default
long long m_BytesBypassed
number of bytes served directly through XrdCl
Definition: XrdPfcStats.hh:37
void AddUp(const Stats &s)
Definition: XrdPfcStats.hh:118
Stats(const Stats &s)
Definition: XrdPfcStats.hh:49
void AddWriteStats(long long bytes_written, int n_cks_errs)
Definition: XrdPfcStats.hh:75
int m_NCksumErrors
number of checksum errors while getting data from remote
Definition: XrdPfcStats.hh:39
int m_Duration
total duration of all IOs attached
Definition: XrdPfcStats.hh:34
void AddBytesHit(long long bh)
Definition: XrdPfcStats.hh:68
int m_NumIos
number of IO objects attached during this access
Definition: XrdPfcStats.hh:33
long long m_BytesHit
number of bytes served from disk
Definition: XrdPfcStats.hh:35
long long m_BytesWritten
number of bytes written to disk
Definition: XrdPfcStats.hh:38
void IoDetach(int duration)
Definition: XrdPfcStats.hh:90
void DeltaToReference(const Stats &ref)
Definition: XrdPfcStats.hh:106
Definition: XrdPfc.hh:41