DefaultPerformanceCounters.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Diagnostics / DefaultPerformanceCounters.cs / 1 / DefaultPerformanceCounters.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Diagnostics
{ 
    using System.Collections.Generic;
    using System.ServiceModel.Channels; 
    using System.ServiceModel; 
    using System.ComponentModel;
    using System.Diagnostics; 
    using System.IO;
    using System.ServiceModel.Administration;
    using System.ServiceModel.Diagnostics;
    using System.Globalization; 
    using System.Runtime.InteropServices;
 
    internal class DefaultPerformanceCounters : PerformanceCountersBase 
    {
        string instanceName; 

        PerformanceCounter[] counters;

        enum PerfCounters : int 
        {
            Instances = 0, 
            TotalCounters = Instances + 1 
        }
 
        string[] perfCounterNames =
        {
            PerformanceCounterStrings.SERVICEMODELSERVICE.SInstances,
        }; 

 
        const int maxCounterLength = 64; 
        const int hashLength = 2;
        [Flags] 
        enum truncOptions : uint
        {
            NoBits = 0,
            service32 = 0x01, 
            uri31 = 0x04
        } 
 
        internal override PerformanceCounter[] Counters
        { 
            get
            {
                return this.counters;
            } 
            set
            { 
                this.counters = value; 
            }
        } 

        internal override string InstanceName
        {
            get 
            {
                return this.instanceName; 
            } 
        }
 
        internal override string[] CounterNames
        {
            get
            { 
                return this.perfCounterNames;
            } 
        } 

        internal override int PerfCounterStart 
        {
            get { return (int)PerfCounters.Instances; }
        }
 
        internal override int PerfCounterEnd
        { 
            get { return (int)PerfCounters.TotalCounters; } 
        }
 
        static internal string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
        {
            // It is a shared instance across all services which have the default counter enabled
            return "_WCF_Admin"; 
        }
 
        internal DefaultPerformanceCounters(ServiceHostBase serviceHost) 
        {
            this.instanceName = DefaultPerformanceCounters.CreateFriendlyInstanceName(serviceHost); 

            this.counters = new PerformanceCounter[(int)PerfCounters.TotalCounters];
            for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
            { 
                PerformanceCounter counter = PerformanceCounters.GetDefaultPerformanceCounter(this.perfCounterNames[i], this.instanceName);
                if (counter != null) 
                { 
                    try
                    { 
                        counter.RawValue = 0;
                        this.counters[i] = counter;
                    }
#pragma warning suppress 56500 // covered by FxCOP 
                    catch (Exception e)
                    { 
                        if (ExceptionUtility.IsFatal(e)) 
                            throw;
                        if (DiagnosticUtility.ShouldTraceError) 
                            TraceUtility.TraceEvent(TraceEventType.Error,
                                TraceCode.PerformanceCountersFailedForService,
                                null, e);
                        break; 
                    }
                } 
                else 
                {
                    break; 
                }
            }
        }
 
        internal bool Initialized
        { 
            get { return this.counters != null; } 
        }
 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK