xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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)
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:
143 };
144 #endif
XrdOucCacheStats()
Definition: XrdOucCacheStats.hh:139
long long DeferOpens
Definition: XrdOucCacheStats.hh:90
long long FilesAreFull
Definition: XrdOucCacheStats.hh:72
Definition: XrdOucCacheStats.hh:47
#define AtomicInc(x)
Definition: XrdSysAtomics.hh:72
long long OpenDefers
Definition: XrdOucCacheStats.hh:89
long long BytesWrite
Definition: XrdOucCacheStats.hh:55
long long DiskSize
Definition: XrdOucCacheStats.hh:76
long long BytesPass
Definition: XrdOucCacheStats.hh:54
long long BytesPurged
Definition: XrdOucCacheStats.hh:58
~XrdOucCacheStats()
Definition: XrdOucCacheStats.hh:140
long long MemUsed
Definition: XrdOucCacheStats.hh:84
void Add(long long &Dest, long long Val)
Definition: XrdOucCacheStats.hh:127
long long FilesClosed
Definition: XrdOucCacheStats.hh:68
void Set(long long &Dest, long long Val)
Definition: XrdOucCacheStats.hh:133
long long MemWriteQ
Definition: XrdOucCacheStats.hh:85
long long BytesGet
Definition: XrdOucCacheStats.hh:53
void Add(XrdOucCacheStats &S)
Definition: XrdOucCacheStats.hh:101
long long BytesPut
Definition: XrdOucCacheStats.hh:56
#define AtomicBeg(Mtx)
Definition: XrdSysAtomics.hh:63
void Get(XrdOucCacheStats &D)
Definition: XrdOucCacheStats.hh:95
Definition: XrdSysPthread.hh:164
long long ClosedLost
Definition: XrdOucCacheStats.hh:92
long long BytesPead
Definition: XrdOucCacheStats.hh:51
long long DiskMax
Definition: XrdOucCacheStats.hh:79
#define AtomicEnd(Mtx)
Definition: XrdSysAtomics.hh:64
long long FilesInCache
Definition: XrdOucCacheStats.hh:71
long long DiskUsed
Definition: XrdOucCacheStats.hh:77
long long BytesRead
Definition: XrdOucCacheStats.hh:52
long long MissPR
Definition: XrdOucCacheStats.hh:63
long long HitsPR
Definition: XrdOucCacheStats.hh:62
long long Pass
Definition: XrdOucCacheStats.hh:61
long long DiskMin
Definition: XrdOucCacheStats.hh:78
struct XrdOucCacheStats::CacheStats X
long long Miss
Definition: XrdOucCacheStats.hh:60
void Lock()
Definition: XrdSysPthread.hh:222
long long BytesSaved
Definition: XrdOucCacheStats.hh:57
long long MemSize
Definition: XrdOucCacheStats.hh:83
void UnLock()
Definition: XrdOucCacheStats.hh:137
XrdSysMutex sMutex
Definition: XrdOucCacheStats.hh:142
long long FilesPurged
Definition: XrdOucCacheStats.hh:70
long long FilesCreated
Definition: XrdOucCacheStats.hh:69
void Lock()
Definition: XrdOucCacheStats.hh:136
Definition: XrdOucCacheStats.hh:43
long long FilesOpened
Definition: XrdOucCacheStats.hh:67
void UnLock()
Definition: XrdSysPthread.hh:224
long long Hits
Definition: XrdOucCacheStats.hh:59
long long ClosDefers
Definition: XrdOucCacheStats.hh:91
void Count(long long &Dest)
Definition: XrdOucCacheStats.hh:130
void Set(XrdOucCacheStats &S)
Definition: XrdOucCacheStats.hh:113