diff --git a/xflaim/csharp/cstest/cstest.cs b/xflaim/csharp/cstest/cstest.cs index 450b3cb..39a4c14 100644 --- a/xflaim/csharp/cstest/cstest.cs +++ b/xflaim/csharp/cstest/cstest.cs @@ -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; + } } } diff --git a/xflaim/csharp/xflaim/CacheInfo.cs b/xflaim/csharp/xflaim/CacheInfo.cs new file mode 100644 index 0000000..2cfb25f --- /dev/null +++ b/xflaim/csharp/xflaim/CacheInfo.cs @@ -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 +{ + + /// + /// Information about slab usage + /// IMPORTANT NOTE: This structure must be kept in sync + /// with the corresponding structure in ftk.h + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class FLM_SLAB_USAGE + { + /// Total slabs currently allocated. + public ulong ulSlabs; + /// Total bytes currently allocated in slabs. + public ulong ulSlabBytes; + /// Total cells allocated within slabs. + public ulong ulAllocatedCells; + /// Total cells that are free within slabs. + public ulong ulFreeCells; + } + + /// + /// 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 + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class CS_XFLM_CACHE_USAGE + { + /// Total bytes allocated for current versions of objects + public ulong ulByteCount; + /// Count of current versions of objects + public ulong ulCount; + /// Count of older versions of objects + public ulong ulOldVerCount; + /// Total bytes allocated for older versions of objects + public ulong ulOldVerBytes; + /// Cache hits + public uint uiCacheHits; + /// Cache hit looks + public uint uiCacheHitLooks; + /// Cache faults + public uint uiCacheFaults; + /// cache fault looks + public uint uiCacheFaultLooks; + /// Slab usage + public FLM_SLAB_USAGE slabUsage; + } + + /// + /// Information about the current state of cache. + /// IMPORTANT NOTE: This structure must be kept in sync + /// with the corresponding structure in xflaim.h + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class CS_XFLM_CACHE_INFO + { + /// Current limit for cache + public ulong ulMaxBytes; + /// Total bytes allocated to cache + public ulong ulTotalBytesAllocated; + /// Flag indicating if cache limit is being dynamically adjusted + public int bDynamicCacheAdjust; + /// + /// 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. + /// + public uint uiCacheAdjustPercent; + /// + /// 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. + /// + public ulong ulCacheAdjustMin; + /// + /// 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. + /// + public ulong ulCacheAdjustMax; + /// + /// 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. + /// + public ulong ulCacheAdjustMinToLeave; + /// Number of blocks in block cache that are dirty + public ulong ulDirtyCount; + /// Number of bytes in block cache that are dirty + public ulong ulDirtyBytes; + /// + /// 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. + /// + public ulong ulNewCount; + /// Total bytes in new blocks. + public ulong ulNewBytes; + /// Number of blocks that need to be written to the rollback log. + public ulong ulLogCount; + /// Total bytes for blocks that need to be written to the rollback log. + public ulong ulLogBytes; + /// Total blocks that need to be freed + public ulong ulFreeCount; + /// Total bytes in freed blocks. + public ulong ulFreeBytes; + /// + /// Total blocks that can be replaced without having to write them + /// to disk or the rollback log. + /// + public ulong ulReplaceableCount; + /// Total bytes in the replaceable blocks. + public ulong ulReplaceableBytes; + /// Statistics on block cache. + public CS_XFLM_CACHE_USAGE blockCache; + /// Statistics on node cache. + public CS_XFLM_CACHE_USAGE nodeCache; + /// Flag indicating whether cache was preallocated. + public int bPreallocatedCache; + } +}