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 namespace XrdPfc
23 {
24 
25 //----------------------------------------------------------------------------
27 // Used both as aggregation of usage by a single file as well as for
28 // collecting per-directory statistics on time-interval basis. In this second
29 // case they are used as "deltas" ... differences in respect to a previous
30 // reference value.
31 // For running averages / deltas, one might need a version with doubles, so
32 // it might make sense to template this. And add some timestamp.
33 //----------------------------------------------------------------------------
34 class Stats
35 {
36 public:
37  int m_NumIos = 0;
38  int m_Duration = 0;
39  long long m_BytesHit = 0;
40  long long m_BytesMissed = 0;
41  long long m_BytesBypassed = 0;
42  long long m_BytesWritten = 0;
43  long long m_StBlocksAdded = 0;
44  int m_NCksumErrors = 0;
45 
46  //----------------------------------------------------------------------
47 
48  Stats() = default;
49 
50  Stats(const Stats& s) = default;
51 
52  Stats& operator=(const Stats&) = default;
53 
54  Stats(const Stats& a, const Stats& b) :
55  m_NumIos (a.m_NumIos + b.m_NumIos),
63  {}
64 
65  //----------------------------------------------------------------------
66 
67  void AddReadStats(const Stats &s)
68  {
72  }
73 
74  void AddBytesHit(long long bh)
75  {
76  m_BytesHit += bh;
77  }
78 
79  void AddWriteStats(long long bytes_written, int n_cks_errs)
80  {
81  m_BytesWritten += bytes_written;
82  m_NCksumErrors += n_cks_errs;
83  }
84 
85  void IoAttach()
86  {
87  ++m_NumIos;
88  }
89 
90  void IoDetach(int duration)
91  {
92  m_Duration += duration;
93  }
94 
95  //----------------------------------------------------------------------
96 
97  long long BytesRead() const
98  {
100  }
101 
102  void DeltaToReference(const Stats& ref)
103  {
104  m_NumIos = ref.m_NumIos - m_NumIos;
112  }
113 
114  void AddUp(const Stats& s)
115  {
116  m_NumIos += s.m_NumIos;
117  m_Duration += s.m_Duration;
118  m_BytesHit += s.m_BytesHit;
124  }
125 
126  void Reset()
127  {
128  m_NumIos = 0;
129  m_Duration = 0;
130  m_BytesHit = 0;
131  m_BytesMissed = 0;
132  m_BytesBypassed = 0;
133  m_BytesWritten = 0;
134  m_StBlocksAdded = 0;
135  m_NCksumErrors = 0;
136  }
137 };
138 
139 //==============================================================================
140 
141 class DirStats : public Stats
142 {
143 public:
144  long long m_StBlocksRemoved = 0; // number of 512-byte blocks removed from the directory
145  int m_NFilesOpened = 0;
146  int m_NFilesClosed = 0;
148  int m_NFilesRemoved = 0; // purged or otherwise (error, direct requests)
151 
152  //----------------------------------------------------------------------
153 
154  DirStats() = default;
155 
156  DirStats(const DirStats& s) = default;
157 
158  DirStats& operator=(const DirStats&) = default;
159 
160  DirStats(const DirStats& a, const DirStats& b) :
161  Stats(a, b),
169  {}
170 
171  //----------------------------------------------------------------------
172 
173  using Stats::DeltaToReference; // activate overload based on arg
174  void DeltaToReference(const DirStats& ref)
175  {
184  }
185 
186  using Stats::AddUp; // activate overload based on arg
187  void AddUp(const DirStats& s)
188  {
189  Stats::AddUp(s);
197  }
198 
199  using Stats::Reset; // activate overload based on arg
200  void Reset()
201  {
202  Stats::Reset();
203  m_StBlocksRemoved = 0;
204  m_NFilesOpened = 0;
205  m_NFilesClosed = 0;
206  m_NFilesCreated = 0;
207  m_NFilesRemoved = 0;
210  }
211 };
212 
213 }
214 
215 #endif
DirStats(const DirStats &s)=default
void DeltaToReference(const DirStats &ref)
Definition: XrdPfcStats.hh:174
void AddUp(const DirStats &s)
Definition: XrdPfcStats.hh:187
DirStats & operator=(const DirStats &)=default
DirStats(const DirStats &a, const DirStats &b)
Definition: XrdPfcStats.hh:160
DirStats()=default
long long m_StBlocksRemoved
Definition: XrdPfcStats.hh:144
Statistics of cache utilisation by a File object.
Definition: XrdPfcStats.hh:35
void IoAttach()
Definition: XrdPfcStats.hh:85
long long m_BytesMissed
number of bytes served from remote and cached
Definition: XrdPfcStats.hh:40
void AddReadStats(const Stats &s)
Definition: XrdPfcStats.hh:67
Stats & operator=(const Stats &)=default
long long m_StBlocksAdded
number of 512-byte blocks the file has grown by
Definition: XrdPfcStats.hh:43
long long m_BytesBypassed
number of bytes served directly through XrdCl
Definition: XrdPfcStats.hh:41
void AddUp(const Stats &s)
Definition: XrdPfcStats.hh:114
void AddWriteStats(long long bytes_written, int n_cks_errs)
Definition: XrdPfcStats.hh:79
int m_NCksumErrors
number of checksum errors while getting data from remote
Definition: XrdPfcStats.hh:44
Stats()=default
int m_Duration
total duration of all IOs attached
Definition: XrdPfcStats.hh:38
void AddBytesHit(long long bh)
Definition: XrdPfcStats.hh:74
long long BytesRead() const
Definition: XrdPfcStats.hh:97
int m_NumIos
number of IO objects attached during this access
Definition: XrdPfcStats.hh:37
long long m_BytesHit
number of bytes served from disk
Definition: XrdPfcStats.hh:39
long long m_BytesWritten
number of bytes written to disk
Definition: XrdPfcStats.hh:42
void IoDetach(int duration)
Definition: XrdPfcStats.hh:90
void DeltaToReference(const Stats &ref)
Definition: XrdPfcStats.hh:102
Stats(const Stats &s)=default
Stats(const Stats &a, const Stats &b)
Definition: XrdPfcStats.hh:54
Definition: XrdPfc.hh:41