Added methods to C# for setting cache limits and getting cache information. Also added unit tests.
git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@905 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
@@ -828,6 +828,136 @@ namespace cstest
|
||||
return( true);
|
||||
}
|
||||
|
||||
static void printCacheUsage(
|
||||
CS_XFLM_CACHE_USAGE cacheUsage,
|
||||
string sWhat)
|
||||
{
|
||||
System.Console.WriteLine( "{0}", sWhat);
|
||||
System.Console.WriteLine( " Object Count..................... {0}", cacheUsage.ulCount);
|
||||
System.Console.WriteLine( " Byte Count....................... {0}", cacheUsage.ulByteCount);
|
||||
System.Console.WriteLine( " Old Version Object Count......... {0}", cacheUsage.ulOldVerCount);
|
||||
System.Console.WriteLine( " Old Version Byte Count........... {0}", cacheUsage.ulOldVerBytes);
|
||||
System.Console.WriteLine( " Cache Hits....................... {0}", cacheUsage.uiCacheHits);
|
||||
System.Console.WriteLine( " Cache Hit Looks.................. {0}", cacheUsage.uiCacheHitLooks);
|
||||
System.Console.WriteLine( " Cache Faults..................... {0}", cacheUsage.uiCacheFaults);
|
||||
System.Console.WriteLine( " Cache Fault Looks................ {0}", cacheUsage.uiCacheFaultLooks);
|
||||
System.Console.WriteLine( " Slab Count....................... {0}", cacheUsage.slabUsage.ulSlabs);
|
||||
System.Console.WriteLine( " Slab Bytes Count................. {0}", cacheUsage.slabUsage.ulSlabBytes);
|
||||
System.Console.WriteLine( " Slab Allocated Cells............. {0}", cacheUsage.slabUsage.ulAllocatedCells);
|
||||
System.Console.WriteLine( " Slab Free Cells.................. {0}", cacheUsage.slabUsage.ulFreeCells);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Cache tests
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cacheTests(
|
||||
DbSystem dbSystem)
|
||||
{
|
||||
uint uiCacheAdjustPercent = 66;
|
||||
ulong ulCacheAdjustMin = 20000000;
|
||||
ulong ulCacheAdjustMax = 1000000000;
|
||||
ulong ulCacheAdjustMinToLeave = 0;
|
||||
CS_XFLM_CACHE_INFO cacheInfo;
|
||||
|
||||
beginTest( "Set dynamic cache limit test");
|
||||
try
|
||||
{
|
||||
dbSystem.setDynamicMemoryLimit( uiCacheAdjustPercent,
|
||||
ulCacheAdjustMin, ulCacheAdjustMax,
|
||||
ulCacheAdjustMinToLeave);
|
||||
}
|
||||
catch (XFlaimException ex)
|
||||
{
|
||||
endTest( false, ex, "calling setDynamicMemoryLimit");
|
||||
return( false);
|
||||
}
|
||||
endTest( false, true);
|
||||
|
||||
beginTest( "Get cache info for dynamic cache limit test");
|
||||
try
|
||||
{
|
||||
cacheInfo = dbSystem.getCacheInfo();
|
||||
}
|
||||
catch (XFlaimException ex)
|
||||
{
|
||||
endTest( false, ex, "calling getCacheInfo");
|
||||
return( false);
|
||||
}
|
||||
endTest( false, true);
|
||||
|
||||
beginTest( "See if cache limits were set");
|
||||
if (cacheInfo.bDynamicCacheAdjust == 0 ||
|
||||
cacheInfo.uiCacheAdjustPercent != uiCacheAdjustPercent ||
|
||||
cacheInfo.ulCacheAdjustMin != ulCacheAdjustMin ||
|
||||
cacheInfo.ulCacheAdjustMax != ulCacheAdjustMax ||
|
||||
cacheInfo.ulCacheAdjustMinToLeave != ulCacheAdjustMinToLeave)
|
||||
{
|
||||
endTest( false, false);
|
||||
System.Console.WriteLine( "Dynamic cache adjust parameter mismatch");
|
||||
System.Console.WriteLine( "Dynamic Adjust Flag..... Set: true Get: {0}",
|
||||
cacheInfo.bDynamicCacheAdjust != 0 ? "true" : "false");
|
||||
System.Console.WriteLine( "Adjust Percent.......... Set: {0} Get: {1}",
|
||||
uiCacheAdjustPercent, cacheInfo.uiCacheAdjustPercent);
|
||||
System.Console.WriteLine( "Adjust Min.............. Set: {0} Get: {1}",
|
||||
ulCacheAdjustMin, cacheInfo.ulCacheAdjustMin);
|
||||
System.Console.WriteLine( "Adjust Max.............. Set: {0} Get: {1}",
|
||||
ulCacheAdjustMax, cacheInfo.ulCacheAdjustMax);
|
||||
System.Console.WriteLine( "Adjust Min To Leave..... Set: {0} Get: {1}",
|
||||
ulCacheAdjustMinToLeave, cacheInfo.ulCacheAdjustMinToLeave);
|
||||
return( false);
|
||||
}
|
||||
endTest( false, true);
|
||||
|
||||
// SET AND TEST A HARD LIMIT
|
||||
|
||||
beginTest( "Set hard cache limit test");
|
||||
try
|
||||
{
|
||||
dbSystem.setHardMemoryLimit( 0, false, 0, ulCacheAdjustMax,
|
||||
0, false);
|
||||
}
|
||||
catch (XFlaimException ex)
|
||||
{
|
||||
endTest( false, ex, "calling setHardMemoryLimit");
|
||||
return( false);
|
||||
}
|
||||
endTest( false, true);
|
||||
|
||||
beginTest( "Get cache info for hard cache limit test");
|
||||
try
|
||||
{
|
||||
cacheInfo = dbSystem.getCacheInfo();
|
||||
}
|
||||
catch (XFlaimException ex)
|
||||
{
|
||||
endTest( false, ex, "calling getCacheInfo");
|
||||
return( false);
|
||||
}
|
||||
endTest( false, true);
|
||||
|
||||
beginTest( "See if cache limits were set");
|
||||
if (cacheInfo.bDynamicCacheAdjust != 0 ||
|
||||
cacheInfo.ulCacheAdjustMax != ulCacheAdjustMax ||
|
||||
cacheInfo.ulMaxBytes != ulCacheAdjustMax)
|
||||
{
|
||||
endTest( false, false);
|
||||
System.Console.WriteLine( "Hard cache adjust parameter mismatch");
|
||||
System.Console.WriteLine( "Dynamic Adjust Flag..... Set: false Get: {0}",
|
||||
cacheInfo.bDynamicCacheAdjust != 0 ? "true" : "false");
|
||||
System.Console.WriteLine( "Max..................... Set: {0} Get: {1}",
|
||||
ulCacheAdjustMax, cacheInfo.ulCacheAdjustMax);
|
||||
System.Console.WriteLine( "Max Bytes............... Set: {0} Get: {1}",
|
||||
ulCacheAdjustMax, cacheInfo.ulMaxBytes);
|
||||
return( false);
|
||||
}
|
||||
endTest( false, true);
|
||||
|
||||
printCacheUsage( cacheInfo.blockCache, "BLOCK CACHE USAGE");
|
||||
printCacheUsage( cacheInfo.nodeCache, "NODE CACHE USAGE");
|
||||
|
||||
return( true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Main for tester program
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -947,6 +1077,13 @@ namespace cstest
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache tests
|
||||
|
||||
if (!cacheTests( dbSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
154
xflaim/csharp/xflaim/CacheInfo.cs
Normal file
154
xflaim/csharp/xflaim/CacheInfo.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Desc: Cache information structures.
|
||||
//
|
||||
// Tabs: 3
|
||||
//
|
||||
// Copyright (c) 2006 Novell, Inc. All Rights Reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the GNU General Public
|
||||
// License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, contact Novell, Inc.
|
||||
//
|
||||
// To contact Novell about this file by physical or electronic mail,
|
||||
// you may find current contact information at www.novell.com
|
||||
//
|
||||
// $Id$
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace xflaim
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Information about slab usage
|
||||
/// IMPORTANT NOTE: This structure must be kept in sync
|
||||
/// with the corresponding structure in ftk.h
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class FLM_SLAB_USAGE
|
||||
{
|
||||
/// <summary>Total slabs currently allocated.</summary>
|
||||
public ulong ulSlabs;
|
||||
/// <summary>Total bytes currently allocated in slabs.</summary>
|
||||
public ulong ulSlabBytes;
|
||||
/// <summary>Total cells allocated within slabs.</summary>
|
||||
public ulong ulAllocatedCells;
|
||||
/// <summary>Total cells that are free within slabs.</summary>
|
||||
public ulong ulFreeCells;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Information about usage within a particular cache - either block
|
||||
/// cache or node cache.
|
||||
/// IMPORTANT NOTE: This structure must be kept in sync
|
||||
/// with the corresponding structure in xflaim.h
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class CS_XFLM_CACHE_USAGE
|
||||
{
|
||||
/// <summary>Total bytes allocated for current versions of objects</summary>
|
||||
public ulong ulByteCount;
|
||||
/// <summary>Count of current versions of objects</summary>
|
||||
public ulong ulCount;
|
||||
/// <summary>Count of older versions of objects</summary>
|
||||
public ulong ulOldVerCount;
|
||||
/// <summary>Total bytes allocated for older versions of objects</summary>
|
||||
public ulong ulOldVerBytes;
|
||||
/// <summary>Cache hits</summary>
|
||||
public uint uiCacheHits;
|
||||
/// <summary>Cache hit looks</summary>
|
||||
public uint uiCacheHitLooks;
|
||||
/// <summary>Cache faults</summary>
|
||||
public uint uiCacheFaults;
|
||||
/// <summary>cache fault looks</summary>
|
||||
public uint uiCacheFaultLooks;
|
||||
/// <summary>Slab usage</summary>
|
||||
public FLM_SLAB_USAGE slabUsage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Information about the current state of cache.
|
||||
/// IMPORTANT NOTE: This structure must be kept in sync
|
||||
/// with the corresponding structure in xflaim.h
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class CS_XFLM_CACHE_INFO
|
||||
{
|
||||
/// <summary>Current limit for cache</summary>
|
||||
public ulong ulMaxBytes;
|
||||
/// <summary>Total bytes allocated to cache</summary>
|
||||
public ulong ulTotalBytesAllocated;
|
||||
/// <summary>Flag indicating if cache limit is being dynamically adjusted</summary>
|
||||
public int bDynamicCacheAdjust;
|
||||
/// <summary>
|
||||
/// Only used if bDynamicCacheAdjust is non-zero.
|
||||
/// Percent of available memory that the cache limit is to be set to. A
|
||||
/// new cache limit is periodically recalculated based on this percentage.
|
||||
/// </summary>
|
||||
public uint uiCacheAdjustPercent;
|
||||
/// <summary>
|
||||
/// Only used if bDynamicCacheAdjust is non-zero.
|
||||
/// Minimum value that the cache limit is to be set to whenever a new
|
||||
/// cache limit is calculated.
|
||||
/// </summary>
|
||||
public ulong ulCacheAdjustMin;
|
||||
/// <summary>
|
||||
/// Only used if bDynamicCacheAdjust is non-zero.
|
||||
/// Maximum value that the cache limit is to be set to whenever a new cache
|
||||
/// limit is calculated.
|
||||
/// </summary>
|
||||
public ulong ulCacheAdjustMax;
|
||||
/// <summary>
|
||||
/// Only used if bDynamicCacheAdjust is non-zero.
|
||||
/// This is an alternative way to specify a maximum cache limit. If zero,
|
||||
/// this parameter is ignored and uiCacheAdjustMax is used. If non-zero,
|
||||
/// the maximum cache limit is calculated to be the amount of available
|
||||
/// memory minus this number - the idea being to leave a certain amount of
|
||||
/// memory for other processes to use.
|
||||
/// </summary>
|
||||
public ulong ulCacheAdjustMinToLeave;
|
||||
/// <summary>Number of blocks in block cache that are dirty</summary>
|
||||
public ulong ulDirtyCount;
|
||||
/// <summary>Number of bytes in block cache that are dirty</summary>
|
||||
public ulong ulDirtyBytes;
|
||||
/// <summary>
|
||||
/// Number of blocks in block cache that are new. New blocks
|
||||
/// are blocks that were allocated at the end of a database when there
|
||||
/// were no blocks in the avail list to allocate.
|
||||
/// </summary>
|
||||
public ulong ulNewCount;
|
||||
/// <summary>Total bytes in new blocks.</summary>
|
||||
public ulong ulNewBytes;
|
||||
/// <summary>Number of blocks that need to be written to the rollback log.</summary>
|
||||
public ulong ulLogCount;
|
||||
/// <summary>Total bytes for blocks that need to be written to the rollback log.</summary>
|
||||
public ulong ulLogBytes;
|
||||
/// <summary>Total blocks that need to be freed</summary>
|
||||
public ulong ulFreeCount;
|
||||
/// <summary>Total bytes in freed blocks.</summary>
|
||||
public ulong ulFreeBytes;
|
||||
/// <summary>
|
||||
/// Total blocks that can be replaced without having to write them
|
||||
/// to disk or the rollback log.
|
||||
/// </summary>
|
||||
public ulong ulReplaceableCount;
|
||||
/// <summary>Total bytes in the replaceable blocks.</summary>
|
||||
public ulong ulReplaceableBytes;
|
||||
/// <summary>Statistics on block cache.</summary>
|
||||
public CS_XFLM_CACHE_USAGE blockCache;
|
||||
/// <summary>Statistics on node cache.</summary>
|
||||
public CS_XFLM_CACHE_USAGE nodeCache;
|
||||
/// <summary>Flag indicating whether cache was preallocated.</summary>
|
||||
public int bPreallocatedCache;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user