136 lines
4.2 KiB
C#
136 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace Thousandto.Core.Base
|
|
{
|
|
public class ObjectPoolDiagnostics
|
|
{
|
|
#region Public Properties and backing fields
|
|
/// <summary>
|
|
/// gets the total count of live instances, both in the pool and in use.
|
|
/// </summary>
|
|
public int TotalLiveInstancesCount
|
|
{
|
|
get { return _TotalInstancesCreated - _TotalInstancesDestroyed; }
|
|
}
|
|
|
|
internal int _ObjectResetFailedCount;
|
|
/// <summary>
|
|
/// gets the count of object reset failures occured while the pool tried to re-add the object into the pool.
|
|
/// </summary>
|
|
public int ObjectResetFailedCount
|
|
{
|
|
get { return _ObjectResetFailedCount; }
|
|
}
|
|
|
|
internal int _ReturnedToPoolByRessurectionCount;
|
|
/// <summary>
|
|
/// gets the total count of object that has been picked up by the GC, and returned to pool.
|
|
/// </summary>
|
|
public int ReturnedToPoolByRessurectionCount
|
|
{
|
|
get { return _ReturnedToPoolByRessurectionCount; }
|
|
}
|
|
|
|
internal int _PoolObjectHitCount;
|
|
/// <summary>
|
|
/// gets the total count of successful accesses. The pool had a spare object to provide to the user without creating it on demand.
|
|
/// </summary>
|
|
public int PoolObjectHitCount
|
|
{
|
|
get { return _PoolObjectHitCount; }
|
|
}
|
|
|
|
internal int _PoolObjectMissCount;
|
|
/// <summary>
|
|
/// gets the total count of unsuccessful accesses. The pool had to create an object in order to satisfy the user request. If the number is high, consider increasing the object minimum limit.
|
|
/// </summary>
|
|
public int PoolObjectMissCount
|
|
{
|
|
get { return _PoolObjectMissCount; }
|
|
}
|
|
|
|
internal int _TotalInstancesCreated;
|
|
/// <summary>
|
|
/// gets the total number of pooled objected created
|
|
/// </summary>
|
|
public int TotalInstancesCreated
|
|
{
|
|
get { return _TotalInstancesCreated; }
|
|
}
|
|
|
|
internal int _TotalInstancesDestroyed;
|
|
/// <summary>
|
|
/// gets the total number of objects destroyes, both in case of an pool overflow, and state corruption.
|
|
/// </summary>
|
|
public int TotalInstancesDestroyed
|
|
{
|
|
get { return _TotalInstancesDestroyed; }
|
|
}
|
|
|
|
internal int _PoolOverflowCount;
|
|
/// <summary>
|
|
/// gets the number of objects been destroyed because the pool was full at the time of returning the object to the pool.
|
|
/// </summary>
|
|
public int PoolOverflowCount
|
|
{
|
|
get { return _PoolOverflowCount; }
|
|
}
|
|
|
|
internal int _ReturnedToPoolCount;
|
|
/// <summary>
|
|
/// gets the total count of objects that been successfully returned to the pool
|
|
/// </summary>
|
|
public int ReturnedToPoolCount
|
|
{
|
|
get { return _ReturnedToPoolCount; }
|
|
}
|
|
#endregion
|
|
|
|
#region Internal Methods for incrementing the counters
|
|
internal void IncrementObjectsCreatedCount()
|
|
{
|
|
Interlocked.Increment(ref _TotalInstancesCreated);
|
|
}
|
|
|
|
internal void IncrementObjectsDestroyedCount()
|
|
{
|
|
Interlocked.Increment(ref _TotalInstancesDestroyed);
|
|
}
|
|
|
|
internal void IncrementPoolObjectHitCount()
|
|
{
|
|
Interlocked.Increment(ref _PoolObjectHitCount);
|
|
}
|
|
|
|
internal void IncrementPoolObjectMissCount()
|
|
{
|
|
Interlocked.Increment(ref _PoolObjectMissCount);
|
|
}
|
|
|
|
internal void IncrementPoolOverflowCount()
|
|
{
|
|
Interlocked.Increment(ref _PoolOverflowCount);
|
|
}
|
|
|
|
internal void IncrementResetStateFailedCount()
|
|
{
|
|
Interlocked.Increment(ref _ObjectResetFailedCount);
|
|
}
|
|
|
|
internal void IncrementObjectRessurectionCount()
|
|
{
|
|
Interlocked.Increment(ref _ReturnedToPoolByRessurectionCount);
|
|
}
|
|
|
|
internal void IncrementReturnedToPoolCount()
|
|
{
|
|
Interlocked.Increment(ref _ReturnedToPoolCount);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|