[9102] | 1 | ///
|
---|
| 2 | /// This file is part of ILNumerics Community Edition.
|
---|
| 3 | ///
|
---|
| 4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
| 5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
| 6 | ///
|
---|
| 7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
| 8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
| 9 | /// the Free Software Foundation.
|
---|
| 10 | ///
|
---|
| 11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
| 12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | /// GNU General Public License for more details.
|
---|
| 15 | ///
|
---|
| 16 | /// You should have received a copy of the GNU General Public License
|
---|
| 17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
| 18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | ///
|
---|
| 20 | /// In addition this software uses the following components and/or licenses:
|
---|
| 21 | ///
|
---|
| 22 | /// =================================================================================
|
---|
| 23 | /// The Open Toolkit Library License
|
---|
| 24 | ///
|
---|
| 25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
| 26 | ///
|
---|
| 27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
| 28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
| 29 | /// in the Software without restriction, including without limitation the rights to
|
---|
| 30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
| 31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
| 32 | /// so, subject to the following conditions:
|
---|
| 33 | ///
|
---|
| 34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
| 35 | /// copies or substantial portions of the Software.
|
---|
| 36 | ///
|
---|
| 37 | /// =================================================================================
|
---|
| 38 | ///
|
---|
| 39 |
|
---|
| 40 | using System;
|
---|
| 41 | using System.Collections.Generic;
|
---|
| 42 | using System.Linq;
|
---|
| 43 | using System.Text;
|
---|
| 44 | using System.Diagnostics;
|
---|
| 45 |
|
---|
| 46 | namespace ILNumerics.Misc {
|
---|
| 47 |
|
---|
| 48 | internal partial class ILMemoryPoolInternal<T> : IILMemoryPool {
|
---|
| 49 | internal class ILPerformanceCounter<Ti> {
|
---|
| 50 | // some constants (may get localized)
|
---|
| 51 | private static readonly string PERFORMANCECOUNTER_CATEGORY_NAME = "ILNumerics Memory Pool";
|
---|
| 52 | private static readonly string PERFORMANCECOUNTER_CATEGORY_NAME_HELP = "Monitors usage statistics for the ILNumerics Memory Pool";
|
---|
| 53 | private static readonly string PERFORMANCECOUNTER_OVERALLSIZE = "Overall Bytes";
|
---|
| 54 | private static readonly string PERFORMANCECOUNTER_OVERALLSIZE_HELP = "Sum of the sizes of all arrays currently hold in the pool.";
|
---|
| 55 | private static readonly string PERFORMANCECOUNTER_OOMCATCHED = "Number of catched OOMs";
|
---|
| 56 | private static readonly string PERFORMANCECOUNTER_OOMCATCHED_HELP = "The overall number of OutOfMemoryExceptions catched since the application started.";
|
---|
| 57 | private static readonly string PERFORMANCECOUNTER_SUCCESS_RATE = "Success Rate %";
|
---|
| 58 | private static readonly string PERFORMANCECOUNTER_SUCCESS_RATE_HELP = "Gives the percentage of successfully reused arrays for the last 100 requests.";
|
---|
| 59 | private static readonly string PERFORMANCECOUNTER_CUR_OBJECTS_COUNT = "Current Objects Count";
|
---|
| 60 | private static readonly string PERFORMANCECOUNTER_CUR_OBJECTS_COUNT_HELP = "Number of arrays of that type currently hold in the memory pool";
|
---|
| 61 | private static readonly string PERFORMANCECOUNTER_REC_OBJECTS_COUNT = "Reclaimed Objects Count";
|
---|
| 62 | private static readonly string PERFORMANCECOUNTER_REC_OBJECTS_COUNT_HELP = "Overall count of objects which could sucessfully get reclaimed from the pool.";
|
---|
| 63 | private static readonly string PERFORMANCECOUNTER_MAX_POOL_SIZE = "Max Pool Size";
|
---|
| 64 | private static readonly string PERFORMANCECOUNTER_MAX_POOL_SIZE_HELP = "The maximum size the pool currently is allowed to grow before it gets shrinked.";
|
---|
| 65 | private static readonly string PERFORMANCECOUNTER_SHRINK_COUNT = "Shrink Count";
|
---|
| 66 | private static readonly string PERFORMANCECOUNTER_SHRINK_COUNT_HELP = "Overall number of times the pool had to be shrinked because of the size getting to large or OOM exceptions being thrown.";
|
---|
| 67 | private static readonly string PERFORMANCECOUNTER_DISPOSED_HIGH = "Disposed large arrays";
|
---|
| 68 | private static readonly string PERFORMANCECOUNTER_DISPOSED_HIGH_HELP = "number of disposed large arrays which possibly would be stored in the pool";
|
---|
| 69 | private static readonly string PERFORMANCECOUNTER_LENGTH_FACTOR = "Lengthening Factor (Log.)";
|
---|
| 70 | private static readonly string PERFORMANCECOUNTER_LENGTH_FACTOR_HELP = "Current logarithmic setting of the relative length an array will be considered 'matching' on incoming requests";
|
---|
| 71 | private bool m_countingActive = false;
|
---|
| 72 | public PerformanceCounter m_PCcurObjectsCount;
|
---|
| 73 | public PerformanceCounter m_PCoverallSize;
|
---|
| 74 | public PerformanceCounter m_PCOOMcatched;
|
---|
| 75 | public PerformanceCounter m_PCsuccessRate;
|
---|
| 76 | public PerformanceCounter m_PCsuccessRateBase;
|
---|
| 77 | public PerformanceCounter m_PCreclaimedObjectsCount;
|
---|
| 78 | public PerformanceCounter m_PCmaximumPoolSize;
|
---|
| 79 | public PerformanceCounter m_PCshrinksCount;
|
---|
| 80 | public PerformanceCounter m_PCDisposedHigh;
|
---|
| 81 | public PerformanceCounter m_PCacceptLengthIncreaseRate;
|
---|
| 82 |
|
---|
| 83 | public ILPerformanceCounter() {
|
---|
| 84 | if (!Settings.s_measurePerformanceAtRuntime) return;
|
---|
| 85 | // check if the category is installed
|
---|
| 86 | if (!PerformanceCounterCategory.Exists(PERFORMANCECOUNTER_CATEGORY_NAME)) {
|
---|
| 87 | // even if we handle to install the category, the counters will be
|
---|
| 88 | // not available immediately. So we disable them for this session.
|
---|
| 89 | m_countingActive = false;
|
---|
| 90 | try {
|
---|
| 91 | // try to install
|
---|
| 92 | CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
|
---|
| 93 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_CUR_OBJECTS_COUNT, PERFORMANCECOUNTER_CUR_OBJECTS_COUNT_HELP, PerformanceCounterType.NumberOfItems32));
|
---|
| 94 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_MAX_POOL_SIZE, PERFORMANCECOUNTER_MAX_POOL_SIZE_HELP, PerformanceCounterType.NumberOfItems64));
|
---|
| 95 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_OOMCATCHED, PERFORMANCECOUNTER_OOMCATCHED_HELP, PerformanceCounterType.NumberOfItems32));
|
---|
| 96 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_OVERALLSIZE, PERFORMANCECOUNTER_OVERALLSIZE_HELP, PerformanceCounterType.NumberOfItems64));
|
---|
| 97 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_REC_OBJECTS_COUNT, PERFORMANCECOUNTER_REC_OBJECTS_COUNT_HELP, PerformanceCounterType.NumberOfItems64));
|
---|
| 98 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_SHRINK_COUNT, PERFORMANCECOUNTER_SHRINK_COUNT_HELP, PerformanceCounterType.NumberOfItems32));
|
---|
| 99 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_SUCCESS_RATE, PERFORMANCECOUNTER_SUCCESS_RATE_HELP, PerformanceCounterType.RawFraction));
|
---|
| 100 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_SUCCESS_RATE+ "Base", PERFORMANCECOUNTER_SUCCESS_RATE_HELP, PerformanceCounterType.RawBase));
|
---|
| 101 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_DISPOSED_HIGH, PERFORMANCECOUNTER_DISPOSED_HIGH_HELP, PerformanceCounterType.NumberOfItems64));
|
---|
| 102 | ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_LENGTH_FACTOR, PERFORMANCECOUNTER_LENGTH_FACTOR_HELP, PerformanceCounterType.NumberOfItems32));
|
---|
| 103 |
|
---|
| 104 | PerformanceCounterCategory.Create(PERFORMANCECOUNTER_CATEGORY_NAME, PERFORMANCECOUNTER_CATEGORY_NAME_HELP
|
---|
| 105 | ,PerformanceCounterCategoryType.MultiInstance,ccdc);
|
---|
| 106 | } catch (System.Security.SecurityException) { }
|
---|
| 107 | } else {
|
---|
| 108 | m_countingActive = true;
|
---|
| 109 | // init performance counters for this type
|
---|
| 110 | string currentGenericElementType = " <" + typeof(Ti).Name + ">";
|
---|
| 111 | m_PCcurObjectsCount = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_CUR_OBJECTS_COUNT, currentGenericElementType, false);
|
---|
| 112 | m_PCmaximumPoolSize = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_MAX_POOL_SIZE, currentGenericElementType, false);
|
---|
| 113 | m_PCOOMcatched = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_OOMCATCHED, currentGenericElementType, false);
|
---|
| 114 | m_PCoverallSize = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_OVERALLSIZE, currentGenericElementType, false);
|
---|
| 115 | m_PCreclaimedObjectsCount = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_REC_OBJECTS_COUNT, currentGenericElementType, false);
|
---|
| 116 | m_PCshrinksCount = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_SHRINK_COUNT, currentGenericElementType, false);
|
---|
| 117 | m_PCsuccessRate = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_SUCCESS_RATE, currentGenericElementType, false);
|
---|
| 118 | m_PCsuccessRateBase = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_SUCCESS_RATE+"Base", currentGenericElementType, false);
|
---|
| 119 | m_PCDisposedHigh = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME,PERFORMANCECOUNTER_DISPOSED_HIGH, currentGenericElementType, false);
|
---|
| 120 | m_PCacceptLengthIncreaseRate = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME, PERFORMANCECOUNTER_LENGTH_FACTOR, currentGenericElementType, false);
|
---|
| 121 |
|
---|
| 122 | m_PCcurObjectsCount.RawValue = 0;
|
---|
| 123 | m_PCmaximumPoolSize.RawValue = 0;
|
---|
| 124 | m_PCOOMcatched.RawValue = 0;
|
---|
| 125 | m_PCoverallSize.RawValue = 0;
|
---|
| 126 | m_PCreclaimedObjectsCount.RawValue = 0;
|
---|
| 127 | m_PCshrinksCount.RawValue = 0;
|
---|
| 128 | m_PCsuccessRate.RawValue = 0;
|
---|
| 129 | m_PCsuccessRateBase.RawValue = 0;
|
---|
| 130 | m_PCDisposedHigh.RawValue = 0;
|
---|
| 131 | m_PCacceptLengthIncreaseRate.RawValue = 0;
|
---|
| 132 |
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | public void PCcurObjectsCountSet(int val) {
|
---|
| 136 | if (m_PCcurObjectsCount != null)
|
---|
| 137 | m_PCcurObjectsCount.RawValue = val;
|
---|
| 138 | }
|
---|
| 139 | public void PCDisposedHighIncrement() {
|
---|
| 140 | if (m_PCDisposedHigh != null)
|
---|
| 141 | m_PCDisposedHigh.Increment();
|
---|
| 142 | }
|
---|
| 143 | public void PCAcceptLengthIncreaseSet(long value) {
|
---|
| 144 | if (m_PCacceptLengthIncreaseRate != null)
|
---|
| 145 | m_PCacceptLengthIncreaseRate.RawValue = value;
|
---|
| 146 | }
|
---|
| 147 | public void PCmaximumPoolSizeSet(long value) {
|
---|
| 148 | if (m_PCmaximumPoolSize != null)
|
---|
| 149 | m_PCmaximumPoolSize.RawValue = value;
|
---|
| 150 | }
|
---|
| 151 | public void PCOOMcatchedIncrement() {
|
---|
| 152 | if (m_PCOOMcatched != null)
|
---|
| 153 | m_PCOOMcatched.Increment();
|
---|
| 154 | }
|
---|
| 155 | public void PCreclaimedObjectsCountIncrement() {
|
---|
| 156 | if (m_PCreclaimedObjectsCount != null)
|
---|
| 157 | m_PCreclaimedObjectsCount.Increment();
|
---|
| 158 | }
|
---|
| 159 | public void PCshrinksCountIncrement() {
|
---|
| 160 | if (m_PCshrinksCount != null)
|
---|
| 161 | m_PCshrinksCount.Increment();
|
---|
| 162 | }
|
---|
| 163 | public void PCsuccessRateIncrement() {
|
---|
| 164 | if (m_PCsuccessRate != null)
|
---|
| 165 | m_PCsuccessRate.Increment();
|
---|
| 166 | }
|
---|
| 167 | public void PCsuccessRateBaseIncrement() {
|
---|
| 168 | if (m_PCsuccessRateBase != null)
|
---|
| 169 | m_PCsuccessRateBase.Increment();
|
---|
| 170 | }
|
---|
| 171 | internal void PCoverallSizeSet(long curBytes) {
|
---|
| 172 | if (m_PCoverallSize != null) {
|
---|
| 173 | m_PCoverallSize.RawValue = curBytes;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 |
|
---|