xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 AddWriteStats(long long bytes_written, int n_cks_errs)
69  {
70  XrdSysMutexHelper _lock(&m_Mutex);
71 
72  m_BytesWritten += bytes_written;
73  m_NCksumErrors += n_cks_errs;
74  }
75 
76  void IoAttach()
77  {
78  XrdSysMutexHelper _lock(&m_Mutex);
79 
80  ++m_NumIos;
81  }
82 
83  void IoDetach(int duration)
84  {
85  XrdSysMutexHelper _lock(&m_Mutex);
86 
87  m_Duration += duration;
88  }
89 
91  {
92  XrdSysMutexHelper _lock(&m_Mutex);
93 
94  return Stats(*this);
95  }
96 
97  //----------------------------------------------------------------------
98 
99  void DeltaToReference(const Stats& ref)
100  {
101  // Not locked, only used from Cache / Purge thread.
102  m_NumIos = ref.m_NumIos - m_NumIos;
109  }
110 
111  void AddUp(const Stats& s)
112  {
113  // Not locked, only used from Cache / Purge thread.
114  m_NumIos += s.m_NumIos;
115  m_Duration += s.m_Duration;
116  m_BytesHit += s.m_BytesHit;
121  }
122 
123  void Reset()
124  {
125  // Not locked, only used from Cache / Purge thread.
126  m_NumIos = 0;
127  m_Duration = 0;
128  m_BytesHit = 0;
129  m_BytesMissed = 0;
130  m_BytesBypassed = 0;
131  m_BytesWritten = 0;
132  m_NCksumErrors = 0;
133  }
134 
135 private:
137 };
138 }
139 
140 #endif
141 
XrdSysMutex m_Mutex
Definition: XrdPfcStats.hh:136
void AddReadStats(const Stats &s)
Definition: XrdPfcStats.hh:59
void Reset()
Definition: XrdPfcStats.hh:123
void IoAttach()
Definition: XrdPfcStats.hh:76
Definition: XrdSysPthread.hh:164
Stats()
Definition: XrdPfcStats.hh:43
int m_Duration
total duration of all IOs attached
Definition: XrdPfcStats.hh:34
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:99
void AddWriteStats(long long bytes_written, int n_cks_errs)
Definition: XrdPfcStats.hh:68
int m_NCksumErrors
number of checksum errors while getting data from remote
Definition: XrdPfcStats.hh:39
void AddUp(const Stats &s)
Definition: XrdPfcStats.hh:111
long long m_BytesMissed
number of bytes served from remote and cached
Definition: XrdPfcStats.hh:36
Stats(const Stats &s)
Definition: XrdPfcStats.hh:49
long long m_BytesHit
number of bytes served from disk
Definition: XrdPfcStats.hh:35
Stats Clone()
Definition: XrdPfcStats.hh:90
void IoDetach(int duration)
Definition: XrdPfcStats.hh:83
Definition: XrdSysPthread.hh:262
Stats & operator=(const Stats &)=default