Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / PerfCounters.cs / 2 / PerfCounters.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* PerfCounters class
*/
namespace System.Web {
using System.Web.Util;
using System.Threading;
using System.Runtime.InteropServices;
internal sealed class PerfInstanceDataHandle: SafeHandle {
internal PerfInstanceDataHandle() : base(IntPtr.Zero, true) {
}
internal IntPtr UnsafeHandle {
get { return handle; }
}
public override bool IsInvalid {
get { return handle == IntPtr.Zero; }
}
override protected bool ReleaseHandle() {
UnsafeNativeMethods.PerfCloseAppCounters(handle);
handle = IntPtr.Zero;
return true;
}
}
internal sealed class PerfCounters {
private static PerfInstanceDataHandle _instance = null;
private static IntPtr _global = IntPtr.Zero;
private static IntPtr _stateService = IntPtr.Zero;
private PerfCounters () {}
internal static void Open(string appName) {
Debug.Assert(appName != null);
OpenCounter(appName);
}
internal static void OpenStateCounters() {
OpenCounter(null);
}
// The app name should either be a valid app name or be 'null' to get the state service
// counters initialized
private static void OpenCounter(string appName) {
try {
// Don't activate perf counters if webengine.dll isn't loaded
if (! HttpRuntime.IsEngineLoaded)
return;
// Open the global counters
if (_global == IntPtr.Zero) {
_global = UnsafeNativeMethods.PerfOpenGlobalCounters();
}
// If appName is null, then we want the state counters
if (appName == null) {
if (_stateService == IntPtr.Zero) {
_stateService = UnsafeNativeMethods.PerfOpenStateCounters();
}
}
else {
if (appName != null) {
_instance = UnsafeNativeMethods.PerfOpenAppCounters(appName);
}
}
}
catch (Exception e) {
Debug.Trace("Perfcounters", "Exception: " + e.StackTrace);
}
}
// Make sure webengine.dll is loaded before attempting to call into it (ASURT 98531)
internal static void IncrementCounter(AppPerfCounter counter) {
if (_instance != null)
UnsafeNativeMethods.PerfIncrementCounter(_instance.UnsafeHandle, (int) counter);
}
internal static void DecrementCounter(AppPerfCounter counter) {
if (_instance != null)
UnsafeNativeMethods.PerfDecrementCounter(_instance.UnsafeHandle, (int) counter);
}
internal static void IncrementCounterEx(AppPerfCounter counter, int delta) {
if (_instance != null)
UnsafeNativeMethods.PerfIncrementCounterEx(_instance.UnsafeHandle, (int) counter, delta);
}
internal static void SetCounter(AppPerfCounter counter, int value) {
if (_instance != null)
UnsafeNativeMethods.PerfSetCounter(_instance.UnsafeHandle, (int) counter, value);
}
// It's important that this be debug only. We don't want production
// code to access shared memory that another process could corrupt.
#if DBG
internal static int GetCounter(AppPerfCounter counter) {
if (_instance != null)
return UnsafeNativeMethods.PerfGetCounter(_instance.UnsafeHandle, (int) counter);
else
return -1;
}
#endif
internal static int GetGlobalCounter(GlobalPerfCounter counter) {
if (_global != IntPtr.Zero)
return UnsafeNativeMethods.PerfGetCounter(_global, (int) counter);
else
return -1;
}
internal static void IncrementGlobalCounter(GlobalPerfCounter counter) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfIncrementCounter(_global, (int) counter);
}
internal static void DecrementGlobalCounter(GlobalPerfCounter counter) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfDecrementCounter(_global, (int) counter);
}
#if UNUSED_CODE
internal static void IncrementGlobalCounterEx(GlobalPerfCounter counter, int delta) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfIncrementCounterEx(_global, (int) counter, delta);
}
#endif
internal static void SetGlobalCounter(GlobalPerfCounter counter, int value) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfSetCounter(_global, (int) counter, value);
}
internal static void IncrementStateServiceCounter(StateServicePerfCounter counter) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfIncrementCounter(_stateService, (int) counter);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED);
break;
default:
break;
}
}
internal static void DecrementStateServiceCounter(StateServicePerfCounter counter) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfDecrementCounter(_stateService, (int) counter);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED);
break;
default:
break;
}
}
#if UNUSED_CODE
internal static void IncrementStateServiceCounterEx(StateServicePerfCounter counter, int delta) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfIncrementCounterEx(_stateService, (int) counter, delta);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL, delta);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE, delta);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT, delta);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED, delta);
break;
default:
break;
}
}
#endif
internal static void SetStateServiceCounter(StateServicePerfCounter counter, int value) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfSetCounter(_stateService, (int) counter, value);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL, value);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE, value);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT, value);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED, value);
break;
default:
break;
}
}
};
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* PerfCounters class
*/
namespace System.Web {
using System.Web.Util;
using System.Threading;
using System.Runtime.InteropServices;
internal sealed class PerfInstanceDataHandle: SafeHandle {
internal PerfInstanceDataHandle() : base(IntPtr.Zero, true) {
}
internal IntPtr UnsafeHandle {
get { return handle; }
}
public override bool IsInvalid {
get { return handle == IntPtr.Zero; }
}
override protected bool ReleaseHandle() {
UnsafeNativeMethods.PerfCloseAppCounters(handle);
handle = IntPtr.Zero;
return true;
}
}
internal sealed class PerfCounters {
private static PerfInstanceDataHandle _instance = null;
private static IntPtr _global = IntPtr.Zero;
private static IntPtr _stateService = IntPtr.Zero;
private PerfCounters () {}
internal static void Open(string appName) {
Debug.Assert(appName != null);
OpenCounter(appName);
}
internal static void OpenStateCounters() {
OpenCounter(null);
}
// The app name should either be a valid app name or be 'null' to get the state service
// counters initialized
private static void OpenCounter(string appName) {
try {
// Don't activate perf counters if webengine.dll isn't loaded
if (! HttpRuntime.IsEngineLoaded)
return;
// Open the global counters
if (_global == IntPtr.Zero) {
_global = UnsafeNativeMethods.PerfOpenGlobalCounters();
}
// If appName is null, then we want the state counters
if (appName == null) {
if (_stateService == IntPtr.Zero) {
_stateService = UnsafeNativeMethods.PerfOpenStateCounters();
}
}
else {
if (appName != null) {
_instance = UnsafeNativeMethods.PerfOpenAppCounters(appName);
}
}
}
catch (Exception e) {
Debug.Trace("Perfcounters", "Exception: " + e.StackTrace);
}
}
// Make sure webengine.dll is loaded before attempting to call into it (ASURT 98531)
internal static void IncrementCounter(AppPerfCounter counter) {
if (_instance != null)
UnsafeNativeMethods.PerfIncrementCounter(_instance.UnsafeHandle, (int) counter);
}
internal static void DecrementCounter(AppPerfCounter counter) {
if (_instance != null)
UnsafeNativeMethods.PerfDecrementCounter(_instance.UnsafeHandle, (int) counter);
}
internal static void IncrementCounterEx(AppPerfCounter counter, int delta) {
if (_instance != null)
UnsafeNativeMethods.PerfIncrementCounterEx(_instance.UnsafeHandle, (int) counter, delta);
}
internal static void SetCounter(AppPerfCounter counter, int value) {
if (_instance != null)
UnsafeNativeMethods.PerfSetCounter(_instance.UnsafeHandle, (int) counter, value);
}
// It's important that this be debug only. We don't want production
// code to access shared memory that another process could corrupt.
#if DBG
internal static int GetCounter(AppPerfCounter counter) {
if (_instance != null)
return UnsafeNativeMethods.PerfGetCounter(_instance.UnsafeHandle, (int) counter);
else
return -1;
}
#endif
internal static int GetGlobalCounter(GlobalPerfCounter counter) {
if (_global != IntPtr.Zero)
return UnsafeNativeMethods.PerfGetCounter(_global, (int) counter);
else
return -1;
}
internal static void IncrementGlobalCounter(GlobalPerfCounter counter) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfIncrementCounter(_global, (int) counter);
}
internal static void DecrementGlobalCounter(GlobalPerfCounter counter) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfDecrementCounter(_global, (int) counter);
}
#if UNUSED_CODE
internal static void IncrementGlobalCounterEx(GlobalPerfCounter counter, int delta) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfIncrementCounterEx(_global, (int) counter, delta);
}
#endif
internal static void SetGlobalCounter(GlobalPerfCounter counter, int value) {
if (_global != IntPtr.Zero)
UnsafeNativeMethods.PerfSetCounter(_global, (int) counter, value);
}
internal static void IncrementStateServiceCounter(StateServicePerfCounter counter) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfIncrementCounter(_stateService, (int) counter);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED);
break;
default:
break;
}
}
internal static void DecrementStateServiceCounter(StateServicePerfCounter counter) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfDecrementCounter(_stateService, (int) counter);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
DecrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED);
break;
default:
break;
}
}
#if UNUSED_CODE
internal static void IncrementStateServiceCounterEx(StateServicePerfCounter counter, int delta) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfIncrementCounterEx(_stateService, (int) counter, delta);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL, delta);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE, delta);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT, delta);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
IncrementGlobalCounterEx(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED, delta);
break;
default:
break;
}
}
#endif
internal static void SetStateServiceCounter(StateServicePerfCounter counter, int value) {
if (_stateService == IntPtr.Zero)
return;
UnsafeNativeMethods.PerfSetCounter(_stateService, (int) counter, value);
switch (counter) {
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL, value);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE, value);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TIMED_OUT, value);
break;
case StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED:
SetGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ABANDONED, value);
break;
default:
break;
}
}
};
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- wmiprovider.cs
- ObjectSet.cs
- TextServicesLoader.cs
- ModifiableIteratorCollection.cs
- Dynamic.cs
- ValidationErrorEventArgs.cs
- ResourceIDHelper.cs
- ProfileModule.cs
- TextContainer.cs
- CodeTypeConstructor.cs
- PropertyManager.cs
- WebConfigurationFileMap.cs
- PropertyTabAttribute.cs
- MessageFault.cs
- LambdaCompiler.Binary.cs
- StringFunctions.cs
- SqlInternalConnectionSmi.cs
- Events.cs
- ListCommandEventArgs.cs
- WebDescriptionAttribute.cs
- DataGridViewBindingCompleteEventArgs.cs
- Rfc4050KeyFormatter.cs
- BitConverter.cs
- HyperLinkStyle.cs
- Transform.cs
- DataGridViewUtilities.cs
- Util.cs
- BitmapMetadata.cs
- DeviceContexts.cs
- SkipStoryboardToFill.cs
- WeakRefEnumerator.cs
- TextLineBreak.cs
- TextParagraphView.cs
- WindowsTab.cs
- WsatTransactionFormatter.cs
- ByteStreamGeometryContext.cs
- XmlProcessingInstruction.cs
- ControlCollection.cs
- MetadataWorkspace.cs
- Cell.cs
- SqlBulkCopy.cs
- AuthenticationModulesSection.cs
- GridItemPatternIdentifiers.cs
- DesignUtil.cs
- Transform3D.cs
- ResourcePart.cs
- ProviderMetadataCachedInformation.cs
- Style.cs
- Point3DCollection.cs
- ExpressionConverter.cs
- ManipulationVelocities.cs
- ListBoxItemAutomationPeer.cs
- XmlDownloadManager.cs
- CodeBinaryOperatorExpression.cs
- PixelFormat.cs
- CryptoApi.cs
- ClientRoleProvider.cs
- LineSegment.cs
- CloudCollection.cs
- Enumerable.cs
- TagPrefixInfo.cs
- AsyncMethodInvoker.cs
- DeclarativeCatalogPart.cs
- CursorConverter.cs
- EpmContentDeSerializerBase.cs
- AvTrace.cs
- ReachFixedPageSerializerAsync.cs
- EventSourceCreationData.cs
- Scripts.cs
- XmlIgnoreAttribute.cs
- SamlSubject.cs
- ListBindableAttribute.cs
- HtmlPageAdapter.cs
- ToolboxService.cs
- StickyNoteHelper.cs
- X509ImageLogo.cs
- HtmlInputPassword.cs
- ObjectDataSourceSelectingEventArgs.cs
- ElementMarkupObject.cs
- DataBoundControlAdapter.cs
- HttpResponse.cs
- PhonemeEventArgs.cs
- MILUtilities.cs
- DataGridViewButtonCell.cs
- UnwrappedTypesXmlSerializerManager.cs
- wgx_sdk_version.cs
- XmlWriter.cs
- DataGridViewElement.cs
- TextEffectResolver.cs
- DataBindingCollectionEditor.cs
- LookupNode.cs
- StrongNamePublicKeyBlob.cs
- NamespaceQuery.cs
- Column.cs
- OutKeywords.cs
- CompressedStack.cs
- BinaryOperationBinder.cs
- XmlSerializerSection.cs
- ManagementOperationWatcher.cs
- DataRow.cs