XRootD
XrdOucCacheStats.hh
Go to the documentation of this file.
1 #ifndef __XRDOUCCACHESTATS_HH__
2 #define __XRDOUCCACHESTATS_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c C a c h e S t a t s . h h */
6 /* */
7 /* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <cstdint>
34 #include <cstring>
35 
36 #include "XrdSys/XrdSysAtomics.hh"
37 #include "XrdSys/XrdSysPthread.hh"
38 
39 /* The XrdOucCacheStats object holds statistics on cache usage. It is available
40  in each Cache object that records the summary information for that cache.
41 */
42 
44 {
45 public:
46 
47 struct CacheStats
48 {
49 // General read/write information
50 //
51 long long BytesPead; // Bytes read via preread (not included in BytesRead)
52 long long BytesRead; // Total number of bytes read into the cache
53 long long BytesGet; // Number of bytes delivered from the cache
54 long long BytesPass; // Number of bytes read but not cached
55 long long BytesWrite; // Total number of bytes written from the cache
56 long long BytesPut; // Number of bytes updated in the cache
57 long long BytesSaved; // Number of bytes written from memory to disk
58 long long BytesPurged; // Number of bytes purged from the cache
59 long long Hits; // Number of times wanted data was in the cache
60 long long Miss; // Number of times wanted data was *not* in the cache
61 long long Pass; // Number of times wanted data was read but not cached
62 long long HitsPR; // Number of pages of wanted data was just preread
63 long long MissPR; // Number of pages of unwanted data was just preread
64 
65 // Local file information
66 //
67 long long FilesOpened; // Number of cache files opened
68 long long FilesClosed; // Number of cache files closed
69 long long FilesCreated;// Number of cache files created
70 long long FilesPurged; // Number of cache files purged (i.e. deleted)
71 long long FilesInCache;// Number of files currently in the cache
72 long long FilesAreFull;// Number of full files currently in the cache
73 
74 // Permanent storage information (all state information)
75 //
76 long long DiskSize; // Size of disk cache in bytes
77 long long DiskUsed; // Size of disk cache in use (bytes)
78 long long DiskMin; // Minimum bytes that were in use
79 long long DiskMax; // Maximum bytes that were in use
80 
81 // Memory information (all state information)
82 //
83 long long MemSize; // Maximum bytes that can be in memory
84 long long MemUsed; // Actual bytes that are allocated in memory
85 long long MemWriteQ; // Actual bytes that are in write queue
86 
87 // File information (supplied by the POSIX layer)
88 //
89 long long OpenDefers; // Number of opens that were deferred
90 long long DeferOpens; // Number of defers that were actually opened
91 long long ClosDefers; // Number of closes that were deferred
92 long long ClosedLost; // Number of closed file objects that were lost
93 } X; // This must be a POD type
94 
95 inline void Get(XrdOucCacheStats &D)
96  {sMutex.Lock();
97  memcpy(&D.X, &X, sizeof(CacheStats));
98  sMutex.UnLock();
99  }
100 
101 inline void Add(XrdOucCacheStats &S)
102  {sMutex.Lock();
104  X.BytesGet += S.X.BytesGet; X.BytesPass += S.X.BytesPass;
106 /* R/W Cache */ X.BytesWrite += S.X.BytesWrite; X.BytesPut += S.X.BytesPut;
107  X.Hits += S.X.Hits; X.Miss += S.X.Miss;
108  X.Pass += S.X.Pass;
109  X.HitsPR += S.X.HitsPR; X.MissPR += S.X.MissPR;
110  sMutex.UnLock();
111  }
112 
113 inline void Set(XrdOucCacheStats &S)
114  {sMutex.Lock();
118 
119  X.DiskSize = S.X.DiskSize; X.DiskUsed = S.X.DiskUsed;
120  X.DiskMin = S.X.DiskMin; X.DiskMax = S.X.DiskMax;
121 
122  X.MemSize = S.X.MemSize; X.MemUsed = S.X.MemUsed;
123  X.MemWriteQ = S.X.MemWriteQ;
124  sMutex.UnLock();
125  }
126 
127 inline void Add(long long &Dest, long long Val)
128  {sMutex.Lock(); Dest += Val; sMutex.UnLock();}
129 
130 inline void Count(long long &Dest)
131  {AtomicBeg(sMutex); AtomicInc(Dest); AtomicEnd(sMutex);}
132 
133 inline void Set(long long &Dest, long long Val)
134  {sMutex.Lock(); Dest = Val; sMutex.UnLock();}
135 
136 inline void Lock() {sMutex.Lock();}
137 inline void UnLock() {sMutex.UnLock();}
138 
139  XrdOucCacheStats() {memset(&X, 0, sizeof(CacheStats));}
141 private:
142 XrdSysMutex sMutex;
143 };
144 #endif
#define AtomicInc(x)
#define AtomicBeg(Mtx)
#define AtomicEnd(Mtx)
void Get(XrdOucCacheStats &D)
void Add(XrdOucCacheStats &S)
void Add(long long &Dest, long long Val)
struct XrdOucCacheStats::CacheStats X
void Set(long long &Dest, long long Val)
void Count(long long &Dest)
void Set(XrdOucCacheStats &S)