00001 #ifndef __XRDOUCCACHESTATS_HH__ 00002 #define __XRDOUCCACHESTATS_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c C a c h e S t a t s . h h */ 00006 /* */ 00007 /* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <stdint.h> 00034 #include <string.h> 00035 00036 #include "XrdSys/XrdSysAtomics.hh" 00037 #include "XrdSys/XrdSysPthread.hh" 00038 00039 /* The XrdOucCacheStats object holds statistics on cache usage. It is available 00040 in each Cache object that records the summary information for that cache. 00041 */ 00042 00043 class XrdOucCacheStats 00044 { 00045 public: 00046 00047 struct CacheStats 00048 { 00049 // General read/write information 00050 // 00051 long long BytesPead; // Bytes read via preread (not included in BytesRead) 00052 long long BytesRead; // Total number of bytes read into the cache 00053 long long BytesGet; // Number of bytes delivered from the cache 00054 long long BytesPass; // Number of bytes read but not cached 00055 long long BytesWrite; // Total number of bytes written from the cache 00056 long long BytesPut; // Number of bytes updated in the cache 00057 long long BytesSaved; // Number of bytes written from memory to disk 00058 long long BytesPurged; // Number of bytes purged from the cache 00059 long long Hits; // Number of times wanted data was in the cache 00060 long long Miss; // Number of times wanted data was *not* in the cache 00061 long long Pass; // Number of times wanted data was read but not cached 00062 long long HitsPR; // Number of pages of wanted data was just preread 00063 long long MissPR; // Number of pages of unwanted data was just preread 00064 00065 // Local file information 00066 // 00067 long long FilesOpened; // Number of cache files opened 00068 long long FilesClosed; // Number of cache files closed 00069 long long FilesCreated;// Number of cache files created 00070 long long FilesPurged; // Number of cache files purged (i.e. deleted) 00071 long long FilesInCache;// Number of files currently in the cache 00072 long long FilesAreFull;// Number of full files currently in the cache 00073 00074 // Permanent storage information (all state information) 00075 // 00076 long long DiskSize; // Size of disk cache in bytes 00077 long long DiskUsed; // Size of disk cache in use (bytes) 00078 long long DiskMin; // Minimum bytes that were in use 00079 long long DiskMax; // Maximum bytes that were in use 00080 00081 // Memory information (all state information) 00082 // 00083 long long MemSize; // Maximum bytes that can be in memory 00084 long long MemUsed; // Actual bytes that are allocated in memory 00085 long long MemWriteQ; // Actual bytes that are in write queue 00086 00087 // File information (supplied by the POSIX layer) 00088 // 00089 long long OpenDefers; // Number of opens that were deferred 00090 long long DeferOpens; // Number of defers that were actually opened 00091 long long ClosDefers; // Number of closes that were deferred 00092 long long ClosedLost; // Number of closed file objects that were lost 00093 } X; // This must be a POD type 00094 00095 inline void Get(XrdOucCacheStats &D) 00096 {sMutex.Lock(); 00097 memcpy(&D.X, &X, sizeof(CacheStats)); 00098 sMutex.UnLock(); 00099 } 00100 00101 inline void Add(XrdOucCacheStats &S) 00102 {sMutex.Lock(); 00103 X.BytesPead += S.X.BytesPead; X.BytesRead += S.X.BytesRead; 00104 X.BytesGet += S.X.BytesGet; X.BytesPass += S.X.BytesPass; 00105 X.BytesSaved += S.X.BytesSaved; X.BytesPurged+= S.X.BytesPurged; 00106 /* R/W Cache */ X.BytesWrite += S.X.BytesWrite; X.BytesPut += S.X.BytesPut; 00107 X.Hits += S.X.Hits; X.Miss += S.X.Miss; 00108 X.Pass += S.X.Pass; 00109 X.HitsPR += S.X.HitsPR; X.MissPR += S.X.MissPR; 00110 sMutex.UnLock(); 00111 } 00112 00113 inline void Set(XrdOucCacheStats &S) 00114 {sMutex.Lock(); 00115 X.FilesOpened = S.X.FilesOpened; X.FilesClosed = S.X.FilesClosed; 00116 X.FilesCreated = S.X.FilesCreated;X.FilesPurged = S.X.FilesPurged; 00117 X.FilesInCache = S.X.FilesInCache;X.FilesAreFull= S.X.FilesAreFull; 00118 00119 X.DiskSize = S.X.DiskSize; X.DiskUsed = S.X.DiskUsed; 00120 X.DiskMin = S.X.DiskMin; X.DiskMax = S.X.DiskMax; 00121 00122 X.MemSize = S.X.MemSize; X.MemUsed = S.X.MemUsed; 00123 X.MemWriteQ = S.X.MemWriteQ; 00124 sMutex.UnLock(); 00125 } 00126 00127 inline void Add(long long &Dest, long long Val) 00128 {sMutex.Lock(); Dest += Val; sMutex.UnLock();} 00129 00130 inline void Count(long long &Dest) 00131 {AtomicBeg(sMutex); AtomicInc(Dest); AtomicEnd(sMutex);} 00132 00133 inline void Set(long long &Dest, long long Val) 00134 {sMutex.Lock(); Dest = Val; sMutex.UnLock();} 00135 00136 inline void Lock() {sMutex.Lock();} 00137 inline void UnLock() {sMutex.UnLock();} 00138 00139 XrdOucCacheStats() {memset(&X, 0, sizeof(CacheStats));} 00140 ~XrdOucCacheStats() {} 00141 private: 00142 XrdSysMutex sMutex; 00143 }; 00144 #endif