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 "XrdSys/XrdSysPthread.hh" 00034 00035 /* The XrdOucCacheStats object holds statistics on cache usage. It is available 00036 in for each CacheIO and each Cache object. The former usually identifies 00037 a specific file while the latter provides summary information. 00038 */ 00039 00040 class XrdOucCacheStats 00041 { 00042 public: 00043 long long BytesPead; // Bytes read via preread (not included in BytesRead) 00044 long long BytesRead; // Total number of bytes read into the cache 00045 long long BytesGet; // Number of bytes delivered from the cache 00046 long long BytesPass; // Number of bytes read but not cached 00047 long long BytesWrite; // Total number of bytes written from the cache 00048 long long BytesPut; // Number of bytes updated in the cache 00049 int Hits; // Number of times wanted data was in the cache 00050 int Miss; // Number of times wanted data was *not* in the cache 00051 int HitsPR; // Number of pages wanted data was just preread 00052 int MissPR; // Number of pages wanted data was just read 00053 00054 inline void Get(XrdOucCacheStats &Dst) 00055 {sMutex.Lock(); 00056 Dst.BytesRead = BytesPead; Dst.BytesGet = BytesRead; 00057 Dst.BytesPass = BytesPass; 00058 Dst.BytesWrite = BytesWrite; Dst.BytesPut = BytesPut; 00059 Dst.Hits = Hits; Dst.Miss = Miss; 00060 Dst.HitsPR = HitsPR; Dst.MissPR = MissPR; 00061 sMutex.UnLock(); 00062 } 00063 00064 inline void Add(XrdOucCacheStats &Src) 00065 {sMutex.Lock(); 00066 BytesRead += Src.BytesPead; BytesGet += Src.BytesRead; 00067 BytesPass += Src.BytesPass; 00068 BytesWrite += Src.BytesWrite; BytesPut += Src.BytesPut; 00069 Hits += Src.Hits; Miss += Src.Miss; 00070 HitsPR += Src.HitsPR; MissPR += Src.MissPR; 00071 sMutex.UnLock(); 00072 } 00073 00074 inline void Add(long long &Dest, int &Val) 00075 {sMutex.Lock(); Dest += Val; sMutex.UnLock();} 00076 00077 inline void Lock() {sMutex.Lock();} 00078 inline void UnLock() {sMutex.UnLock();} 00079 00080 XrdOucCacheStats() : BytesPead(0), BytesRead(0), BytesGet(0), 00081 BytesPass(0), BytesWrite(0), BytesPut(0), 00082 Hits(0), Miss(0), 00083 HitsPR(0), MissPR(0) {} 00084 ~XrdOucCacheStats() {} 00085 private: 00086 XrdSysMutex sMutex; 00087 }; 00088 #endif