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  long long BytesReadAndWritten() const
103  {
104  return BytesRead() + m_BytesWritten;
105  }
106 
107  void DeltaToReference(const Stats& ref)
108  {
109  m_NumIos = ref.m_NumIos - m_NumIos;
117  }
118 
119  void AddUp(const Stats& s)
120  {
121  m_NumIos += s.m_NumIos;
122  m_Duration += s.m_Duration;
123  m_BytesHit += s.m_BytesHit;
129  }
130 
131  void Reset()
132  {
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_StBlocksAdded = 0;
140  m_NCksumErrors = 0;
141  }
142 };
143 
144 //==============================================================================
145 
146 class DirStats : public Stats
147 {
148 public:
149  long long m_StBlocksRemoved = 0; // number of 512-byte blocks removed from the directory
150  int m_NFilesOpened = 0;
151  int m_NFilesClosed = 0;
153  int m_NFilesRemoved = 0; // purged or otherwise (error, direct requests)
156 
157  //----------------------------------------------------------------------
158 
159  DirStats() = default;
160 
161  DirStats(const DirStats& s) = default;
162 
163  DirStats& operator=(const DirStats&) = default;
164 
165  DirStats(const DirStats& a, const DirStats& b) :
166  Stats(a, b),
174  {}
175 
176  //----------------------------------------------------------------------
177 
178  using Stats::DeltaToReference; // activate overload based on arg
179  void DeltaToReference(const DirStats& ref)
180  {
189  }
190 
191  using Stats::AddUp; // activate overload based on arg
192  void AddUp(const DirStats& s)
193  {
194  Stats::AddUp(s);
202  }
203 
204  using Stats::Reset; // activate overload based on arg
205  void Reset()
206  {
207  Stats::Reset();
208  m_StBlocksRemoved = 0;
209  m_NFilesOpened = 0;
210  m_NFilesClosed = 0;
211  m_NFilesCreated = 0;
212  m_NFilesRemoved = 0;
215  }
216 };
217 
218 }
219 
220 #endif
DirStats(const DirStats &s)=default
void DeltaToReference(const DirStats &ref)
Definition: XrdPfcStats.hh:179
void AddUp(const DirStats &s)
Definition: XrdPfcStats.hh:192
DirStats & operator=(const DirStats &)=default
DirStats(const DirStats &a, const DirStats &b)
Definition: XrdPfcStats.hh:165
DirStats()=default
long long m_StBlocksRemoved
Definition: XrdPfcStats.hh:149
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:119
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
long long BytesReadAndWritten() const
Definition: XrdPfcStats.hh:102
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:107
Stats(const Stats &s)=default
Stats(const Stats &a, const Stats &b)
Definition: XrdPfcStats.hh:54
Definition: XrdPfc.hh:41