XrdFileCacheInfo.hh

Go to the documentation of this file.
00001 #ifndef __XRDFILECACHE_INFO_HH__
00002 #define __XRDFILECACHE_INFO_HH__
00003 //----------------------------------------------------------------------------------
00004 // Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
00005 // Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
00006 //----------------------------------------------------------------------------------
00007 // XRootD is free software: you can redistribute it and/or modify
00008 // it under the terms of the GNU Lesser General Public License as published by
00009 // the Free Software Foundation, either version 3 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // XRootD is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public License
00018 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00019 //----------------------------------------------------------------------------------
00020 
00021 #include <stdio.h>
00022 #include <time.h>
00023 #include <assert.h>
00024 
00025 #include "XrdSys/XrdSysPthread.hh"
00026 #include "XrdCl/XrdClLog.hh"
00027 #include "XrdCl/XrdClConstants.hh"
00028 #include "XrdCl/XrdClDefaultEnv.hh"
00029 
00030 class XrdOssDF;
00031 
00032 namespace XrdCl
00033 {
00034    class Log;
00035 }
00036 
00037 namespace XrdFileCache
00038 {
00039    class Stats;
00040 
00041    //----------------------------------------------------------------------------
00043    //----------------------------------------------------------------------------
00044    class Info
00045    {
00046       private:
00047          static unsigned char cfiBIT(int n) { return 1 << n; }
00048 
00049       public:
00050          // !Access statistics
00051          struct AStat
00052          {
00053             time_t    DetachTime;  
00054             long long BytesDisk;   
00055             long long BytesRam;    
00056             long long BytesMissed; 
00057          };
00058 
00059          //------------------------------------------------------------------------
00061          //------------------------------------------------------------------------
00062          Info(long long bufferSize);
00063 
00064          //------------------------------------------------------------------------
00066          //------------------------------------------------------------------------
00067          ~Info();
00068 
00069          //---------------------------------------------------------------------
00073          //---------------------------------------------------------------------
00074          void SetBitFetched(int i);
00075 
00079          //---------------------------------------------------------------------
00080          void SetBitWriteCalled(int i);
00081 
00082          //---------------------------------------------------------------------
00086          //---------------------------------------------------------------------
00087          void ResizeBits(int n);
00088 
00089          //---------------------------------------------------------------------
00095          //---------------------------------------------------------------------
00096          int Read(XrdOssDF* fp);
00097 
00098          //---------------------------------------------------------------------
00100          //---------------------------------------------------------------------
00101          void  WriteHeader(XrdOssDF* fp);
00102 
00103          //---------------------------------------------------------------------
00105          //---------------------------------------------------------------------
00106          void AppendIOStat(AStat& stat, XrdOssDF* fp);
00107 
00108          //---------------------------------------------------------------------
00110          //---------------------------------------------------------------------
00111          bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const;
00112 
00113          //---------------------------------------------------------------------
00115          //---------------------------------------------------------------------
00116          int GetSizeInBytes() const;
00117 
00118          //---------------------------------------------------------------------
00120          //---------------------------------------------------------------------
00121          int GetSizeInBits() const;
00122 
00123          //----------------------------------------------------------------------
00125          //----------------------------------------------------------------------
00126          int GetHeaderSize() const;
00127 
00128          //---------------------------------------------------------------------
00130          //---------------------------------------------------------------------
00131          bool GetLatestDetachTime(time_t& t, XrdOssDF* fp) const;
00132 
00133          //---------------------------------------------------------------------
00135          //---------------------------------------------------------------------
00136          long long GetBufferSize() const;
00137 
00138          //---------------------------------------------------------------------
00140          //---------------------------------------------------------------------
00141          bool TestBit(int i) const;
00142 
00143          //---------------------------------------------------------------------
00145          //---------------------------------------------------------------------
00146          bool IsComplete() const;
00147 
00148          //---------------------------------------------------------------------
00150          //---------------------------------------------------------------------
00151          int GetNDownloadedBlocks() const;
00152 
00153          //---------------------------------------------------------------------
00155          //---------------------------------------------------------------------
00156          long long GetNDownloadedBytes() const;
00157 
00158          //---------------------------------------------------------------------
00160          //---------------------------------------------------------------------
00161          void CheckComplete();
00162 
00163          //---------------------------------------------------------------------
00165          //---------------------------------------------------------------------
00166          int GetAccessCnt() { return  m_accessCnt; }
00167 
00168          //---------------------------------------------------------------------
00170          //---------------------------------------------------------------------
00171          int GetVersion() { return  m_version; }
00172 
00173 
00174          const static char* m_infoExtension;
00175 
00176       protected:
00177 
00178          XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
00179 
00180          //---------------------------------------------------------------------
00182          //---------------------------------------------------------------------
00183 
00184          int            m_version;    
00185          long long      m_bufferSize; 
00186          int            m_sizeInBits; 
00187          unsigned char *m_buff_fetched;       
00188          unsigned char *m_buff_write_called;  
00189          int            m_accessCnt;  
00190          bool           m_complete;   
00191    };
00192 
00193    inline bool Info::TestBit(int i) const
00194    {
00195       int cn = i/8;
00196       assert(cn < GetSizeInBytes());
00197 
00198       int off = i - cn*8;
00199       return (m_buff_fetched[cn] & cfiBIT(off)) == cfiBIT(off);
00200    }
00201 
00202 
00203    inline int Info::GetNDownloadedBlocks() const
00204    {
00205       int cntd = 0;
00206       for (int i = 0; i < m_sizeInBits; ++i)
00207          if (TestBit(i)) cntd++;
00208 
00209       return cntd;
00210    }
00211 
00212    inline long long Info::GetNDownloadedBytes() const
00213    {
00214       return m_bufferSize * GetNDownloadedBlocks();
00215    }
00216 
00217    inline int Info::GetSizeInBytes() const
00218    {
00219       return ((m_sizeInBits -1)/8 + 1);
00220    }
00221 
00222    inline int Info::GetSizeInBits() const
00223    {
00224       return m_sizeInBits;
00225    }
00226 
00227    inline bool Info::IsComplete() const
00228    {
00229       return m_complete;
00230    }
00231 
00232    inline bool Info::IsAnythingEmptyInRng(int firstIdx, int lastIdx) const
00233    {
00234       for (int i = firstIdx; i <= lastIdx; ++i)
00235          if (!TestBit(i)) return true;
00236 
00237       return false;
00238    }
00239 
00240    inline void Info::CheckComplete()
00241    {
00242       m_complete = !IsAnythingEmptyInRng(0, m_sizeInBits-1);
00243    }
00244 
00245    inline void Info::SetBitWriteCalled(int i)
00246    {
00247       int cn = i/8;
00248       assert(cn < GetSizeInBytes());
00249 
00250       int off = i - cn*8;
00251       m_buff_write_called[cn] |= cfiBIT(off);
00252    }
00253 
00254    inline void Info::SetBitFetched(int i)
00255    {
00256       int cn = i/8;
00257       assert(cn < GetSizeInBytes());
00258 
00259       int off = i - cn*8;
00260       m_buff_fetched[cn] |= cfiBIT(off);
00261    }
00262 
00263    inline long long Info::GetBufferSize() const
00264    {
00265       return m_bufferSize;
00266    }
00267 }
00268 #endif

Generated on 5 Oct 2016 for xrootd by  doxygen 1.4.7