Пример #1
0
        protected override int GetCurrentPressure()
        {
            int  num  = GC.CollectionCount(2);
            SRef ref2 = this._sizedRef;

            if ((num != this._gen2Count) && (ref2 != null))
            {
                this._gen2Count = num;
                this._idx      ^= 1;
                this._cacheSizeSampleTimes[this._idx] = DateTime.UtcNow;
                this._cacheSizeSamples[this._idx]     = ref2.ApproximateSize;
                IMemoryCacheManager manager = s_memoryCacheManager;
                if (manager != null)
                {
                    manager.UpdateCacheSize(this._cacheSizeSamples[this._idx], this._memoryCache);
                }
            }
            if (this._memoryLimit <= 0L)
            {
                return(0);
            }
            long num2 = this._cacheSizeSamples[this._idx];

            if (num2 > this._memoryLimit)
            {
                num2 = this._memoryLimit;
            }
            return((int)((num2 * 100L) / this._memoryLimit));
        }
Пример #2
0
        private long[] _sizes;  // Getting SRef size in the debugger is extremely tedious so we keep the last read value here

        internal SRefMultiple(object[] targets)
        {
            _srefs = new SRef[targets.Length];
            _sizes = new long[targets.Length];
            for (int i = 0; i < targets.Length; i++)
            {
                _srefs[i] = new SRef(targets[i]);
            }
        }
        protected override int GetCurrentPressure()
        {
            // Call GetUpdatedTotalCacheSize to update the total
            // cache size, if there has been a recent Gen 2 Collection.
            // This update must happen, otherwise the CacheManager won't
            // know the total cache size.
            int  gen2Count = GC.CollectionCount(2);
            SRef sref      = _sizedRef;

            if (gen2Count != _gen2Count && sref != null)
            {
                // update _gen2Count
                _gen2Count = gen2Count;

                // the SizedRef is only updated after a Gen2 Collection

                // increment the index (it's either 1 or 0)
                Dbg.Assert(SAMPLE_COUNT == 2);
                _idx = _idx ^ 1;
                // remember the sample time
                _cacheSizeSampleTimes[_idx] = DateTime.UtcNow;
                // remember the sample value
                _cacheSizeSamples[_idx] = sref.ApproximateSize;
#if DBG
                Dbg.Trace("MemoryCacheStats", "SizedRef.ApproximateSize=" + _cacheSizeSamples[_idx]);
#endif
                IMemoryCacheManager memoryCacheManager = s_memoryCacheManager;
                if (memoryCacheManager != null)
                {
                    memoryCacheManager.UpdateCacheSize(_cacheSizeSamples[_idx], _memoryCache);
                }
            }

            // if there's no memory limit, then there's nothing more to do
            if (_memoryLimit <= 0)
            {
                return(0);
            }

            long cacheSize = _cacheSizeSamples[_idx];

            // use _memoryLimit as an upper bound so that pressure is a percentage (between 0 and 100, inclusive).
            if (cacheSize > _memoryLimit)
            {
                cacheSize = _memoryLimit;
            }

            // PerfCounter: Cache Percentage Process Memory Limit Used
            //    = memory used by this process / process memory limit at pressureHigh
            // Set private bytes used in kilobytes because the counter is a DWORD

            //


            int result = (int)(cacheSize * 100 / _memoryLimit);
            return(result);
        }
 private void InitDisposableMembers(int cacheMemoryLimitMegabytes) {
     bool dispose = true;
     try {
         _sizedRef = new SRef(_memoryCache);
         SetLimit(cacheMemoryLimitMegabytes);
         InitHistory();
         dispose = false;
     }
     finally {
         if (dispose) {
             Dispose();
         }
     }
 }
        public void Dispose()
        {
            SRef sref = _sizedRef;

            if (sref != null && Interlocked.CompareExchange(ref _sizedRef, null, sref) == sref)
            {
                sref.Dispose();
            }
            IMemoryCacheManager memoryCacheManager = s_memoryCacheManager;

            if (memoryCacheManager != null)
            {
                memoryCacheManager.ReleaseCache(_memoryCache);
            }
        }
Пример #6
0
        public void Dispose()
        {
            SRef comparand = this._sizedRef;

            if ((comparand != null) && (Interlocked.CompareExchange <SRef>(ref this._sizedRef, null, comparand) == comparand))
            {
                comparand.Dispose();
            }
            IMemoryCacheManager manager = s_memoryCacheManager;

            if (manager != null)
            {
                manager.ReleaseCache(this._memoryCache);
            }
        }
        private void InitDisposableMembers(int cacheMemoryLimitMegabytes)
        {
            bool dispose = true;

            try {
                _sizedRef = new SRef(_memoryCache);
                SetLimit(cacheMemoryLimitMegabytes);
                InitHistory();
                dispose = false;
            }
            finally {
                if (dispose)
                {
                    Dispose();
                }
            }
        }
Пример #8
0
        private void InitDisposableMembers(int cacheMemoryLimitMegabytes)
        {
            bool flag = true;

            try
            {
                this._sizedRef = new SRef(this._memoryCache);
                this.SetLimit(cacheMemoryLimitMegabytes);
                base.InitHistory();
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    this.Dispose();
                }
            }
        }
 private void InitDisposableMembers(int cacheMemoryLimitMegabytes)
 {
     bool flag = true;
     try
     {
         this._sizedRef = new SRef(this._memoryCache);
         this.SetLimit(cacheMemoryLimitMegabytes);
         base.InitHistory();
         flag = false;
     }
     finally
     {
         if (flag)
         {
             this.Dispose();
         }
     }
 }