Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:31:05

0001 #ifndef __XRDOUCCACHESTATS_HH__
0002 #define __XRDOUCCACHESTATS_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                   X r d O u c C a c h e S t a t s . h h                    */
0006 /*                                                                            */
0007 /* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <cstdint>
0034 #include <cstring>
0035 
0036 #include "XrdSys/XrdSysAtomics.hh"
0037 #include "XrdSys/XrdSysPthread.hh"
0038 
0039 /* The XrdOucCacheStats object holds statistics on cache usage. It is available
0040    in each Cache object that records the summary information for that cache.
0041 */
0042 
0043 class XrdOucCacheStats
0044 {
0045 public:
0046 
0047 struct CacheStats
0048 {
0049 // General read/write information
0050 //
0051 long long  BytesPead;   // Bytes read via preread (not included in BytesRead)
0052 long long  BytesRead;   // Total number of bytes read into the cache
0053 long long  BytesGet;    // Number of bytes delivered from the cache
0054 long long  BytesPass;   // Number of bytes read but not cached
0055 long long  BytesWrite;  // Total number of bytes written from the cache
0056 long long  BytesPut;    // Number of bytes updated in the cache
0057 long long  BytesSaved;  // Number of bytes written from memory to disk
0058 long long  BytesPurged; // Number of bytes purged from the cache
0059 long long  Hits;        // Number of times wanted data was in the cache
0060 long long  Miss;        // Number of times wanted data was *not* in the cache
0061 long long  Pass;        // Number of times wanted data was read but not cached
0062 long long  HitsPR;      // Number of pages of   wanted data was just preread
0063 long long  MissPR;      // Number of pages of unwanted data was just preread
0064  
0065 // Local file information
0066 //
0067 long long  FilesOpened; // Number of cache files opened
0068 long long  FilesClosed; // Number of cache files closed
0069 long long  FilesCreated;// Number of cache files created
0070 long long  FilesPurged; // Number of cache files purged (i.e. deleted)
0071 long long  FilesInCache;// Number of      files currently in the cache
0072 long long  FilesAreFull;// Number of full files currently in the cache
0073  
0074 // Permanent storage information (all state information)
0075 //
0076 long long  DiskSize;    // Size of disk cache in bytes
0077 long long  DiskUsed;    // Size of disk cache in use (bytes)
0078 long long  DiskMin;     // Minimum bytes that were in use
0079 long long  DiskMax;     // Maximum bytes that were in use
0080  
0081 // Memory information (all state information)
0082 //
0083 long long  MemSize;     // Maximum bytes that can be in memory
0084 long long  MemUsed;     // Actual bytes that are allocated in memory
0085 long long  MemWriteQ;   // Actual bytes that are in write queue
0086  
0087 // File information (supplied by the POSIX layer)
0088 //
0089 long long  OpenDefers;  // Number of opens  that were deferred
0090 long long  DeferOpens;  // Number of defers that were actually opened
0091 long long  ClosDefers;  // Number of closes that were deferred
0092 long long  ClosedLost;  // Number of closed file objects that were lost
0093 }          X;           // This must be a POD type
0094 
0095 inline void Get(XrdOucCacheStats &D)
0096                {sMutex.Lock();
0097                 memcpy(&D.X, &X, sizeof(CacheStats));
0098                 sMutex.UnLock();
0099                }
0100 
0101 inline void Add(XrdOucCacheStats &S)
0102                {sMutex.Lock();
0103                 X.BytesPead   += S.X.BytesPead;   X.BytesRead  += S.X.BytesRead;
0104                 X.BytesGet    += S.X.BytesGet;    X.BytesPass  += S.X.BytesPass;
0105                 X.BytesSaved  += S.X.BytesSaved;  X.BytesPurged+= S.X.BytesPurged;
0106 /* R/W Cache */ X.BytesWrite  += S.X.BytesWrite;  X.BytesPut   += S.X.BytesPut;
0107                 X.Hits        += S.X.Hits;        X.Miss       += S.X.Miss;
0108                 X.Pass        += S.X.Pass;
0109                 X.HitsPR      += S.X.HitsPR;      X.MissPR     += S.X.MissPR;
0110                 sMutex.UnLock();
0111                }
0112 
0113 inline void Set(XrdOucCacheStats &S)
0114                {sMutex.Lock();
0115                 X.FilesOpened  = S.X.FilesOpened; X.FilesClosed = S.X.FilesClosed;
0116                 X.FilesCreated = S.X.FilesCreated;X.FilesPurged = S.X.FilesPurged;
0117                 X.FilesInCache = S.X.FilesInCache;X.FilesAreFull= S.X.FilesAreFull;
0118 
0119                 X.DiskSize     = S.X.DiskSize;    X.DiskUsed    = S.X.DiskUsed;
0120                 X.DiskMin      = S.X.DiskMin;     X.DiskMax     = S.X.DiskMax;
0121 
0122                 X.MemSize      = S.X.MemSize;     X.MemUsed     = S.X.MemUsed;
0123                 X.MemWriteQ    = S.X.MemWriteQ;
0124                 sMutex.UnLock();
0125                }
0126 
0127 inline void  Add(long long &Dest, long long Val)
0128                 {sMutex.Lock(); Dest += Val; sMutex.UnLock();}
0129 
0130 inline void  Count(long long &Dest)
0131                   {AtomicBeg(sMutex); AtomicInc(Dest); AtomicEnd(sMutex);}
0132 
0133 inline void  Set(long long &Dest, long long Val)
0134                 {sMutex.Lock(); Dest  = Val; sMutex.UnLock();}
0135 
0136 inline void  Lock()   {sMutex.Lock();}
0137 inline void  UnLock() {sMutex.UnLock();}
0138 
0139              XrdOucCacheStats() {memset(&X, 0, sizeof(CacheStats));}
0140             ~XrdOucCacheStats() {}
0141 private:
0142 XrdSysMutex sMutex;
0143 };
0144 #endif