PerformanceCounterCategory.GetCounters Yöntem

Tanım

Bu performans sayacı kategorisindeki sayaçların listesini alır.

Aşırı Yüklemeler

Name Description
GetCounters()

Tam olarak bir örnek içeren bir performans sayacı kategorisindeki sayaçların listesini alır.

GetCounters(String)

Bir veya daha fazla örnek içeren bir performans sayacı kategorisindeki sayaçların listesini alır.

GetCounters()

Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs

Tam olarak bir örnek içeren bir performans sayacı kategorisindeki sayaçların listesini alır.

public:
 cli::array <System::Diagnostics::PerformanceCounter ^> ^ GetCounters();
public System.Diagnostics.PerformanceCounter[] GetCounters();
member this.GetCounters : unit -> System.Diagnostics.PerformanceCounter[]
Public Function GetCounters () As PerformanceCounter()

Döndürülenler

Bu tek örnekli performans sayacı kategorisiyle ilişkili sayaçları gösteren bir nesne dizisi PerformanceCounter .

Özel durumlar

Kategori tek bir örnek değildir.

Temel alınan sistem API'sine yapılan çağrı başarısız oldu.

Kategorinin ilişkili bir örneği yok.

Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.

Örnekler

Aşağıdaki kod örneği içindeki nesnelerin PerformanceCounterlistesini PerformanceCounterCategory alır. İlk olarak, bir bilgisayar adının belirtilip belirtilmediğinden yola çıkarak uygun oluşturucuyla bir oluşturur PerformanceCounterCategory . Daha sonra bir nesne dizisi GetCounters döndürmek için yöntemini kullanır PerformanceCounter ve bir örnek adının belirtilip belirtilmedidiğine göre aşırı yüklemeyi seçerGetCounters.

Bu GetCounters() aşırı yükleme, tek örnekli bir kategoriyle kullanılmadığı sürece başarısız olur.

public static void Main(string[] args)
{
    string categoryName = "";
    string machineName = "";
    string instanceName = "";
    PerformanceCounterCategory pcc;
    PerformanceCounter[] counters;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        machineName = args[1]=="."? "": args[1];
        instanceName = args[2];
    }
    catch
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        // Create the appropriate PerformanceCounterCategory object.
        if (machineName.Length>0)
        {
            pcc = new PerformanceCounterCategory(categoryName, machineName);
        }
        else
        {
            pcc = new PerformanceCounterCategory(categoryName);
        }

        // Get the counters for this instance or a single instance
        // of the selected category.
        if (instanceName.Length>0)
        {
            counters = pcc.GetCounters(instanceName);
        }
        else
        {
            counters = pcc.GetCounters();
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to get counter information for " +
            (instanceName.Length>0? "instance \"{2}\" in ": "single-instance ") +
            "category \"{0}\" on " + (machineName.Length>0? "computer \"{1}\":": "this computer:"),
            categoryName, machineName, instanceName);
        Console.WriteLine(ex.Message);
        return;
    }

    // Display the counter names if GetCounters was successful.
    if (counters!=null)
    {
        Console.WriteLine("These counters exist in " +
            (instanceName.Length>0? "instance \"{1}\" of": "single instance") +
            " category {0} on " + (machineName.Length>0? "computer \"{2}\":": "this computer:"),
            categoryName, instanceName, machineName);

        // Display a numbered list of the counter names.
        int objX;
        for(objX=0; objX<counters.Length; objX++)
        {
            Console.WriteLine("{0,4} - {1}", objX+1, counters[objX].CounterName);
        }
    }
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim machineName As String = ""
    Dim instanceName As String = ""
    Dim pcc As PerformanceCounterCategory
    Dim counters() As PerformanceCounter

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        machineName = IIf(args(1) = ".", "", args(1))
        instanceName = args(2)
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        ' Create the appropriate PerformanceCounterCategory object.
        If machineName.Length > 0 Then
            pcc = New PerformanceCounterCategory(categoryName, machineName)
        Else
            pcc = New PerformanceCounterCategory(categoryName)
        End If

        ' Get the counters for this instance or a single instance 
        ' of the selected category.
        If instanceName.Length > 0 Then
            counters = pcc.GetCounters(instanceName)
        Else
            counters = pcc.GetCounters()
        End If

    Catch ex As Exception
        Console.WriteLine("Unable to get counter information for " & _
            IIf(instanceName.Length > 0, "instance ""{2}"" in ", _
            "single-instance ") & "category ""{0}"" on " & _
            IIf(machineName.Length > 0, "computer ""{1}"":", _
            "this computer:"), _
            categoryName, machineName, instanceName)
        Console.WriteLine(ex.Message)
        Return
    End Try

    ' Display the counter names if GetCounters was successful.
    If Not counters Is Nothing Then
        Console.WriteLine("These counters exist in " & _
            IIf(instanceName.Length > 0, "instance ""{1}"" of", _
            "single instance") & " category {0} on " & _
            IIf(machineName.Length > 0, _
                "computer ""{2}"":", "this computer:"), _
            categoryName, instanceName, machineName)

        ' Display a numbered list of the counter names.
        Dim objX As Integer
        For objX = 0 To counters.Length - 1
            Console.WriteLine("{0,4} - {1}", objX + 1, _
                counters(objX).CounterName)
        Next objX
    End If
End Sub

Açıklamalar

Performans nesnesi örnekleri hakkında daha fazla bilgi için sınıfa genel bakış bölümüne PerformanceCounter bakın.

Note

Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition'da veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.

Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcıları grubuna ekleyin.

Windows Vista ve sonraki sürümlerde Kullanıcı Hesabı Denetimi (UAC), bir kullanıcının ayrıcalıklarını belirler. Yerleşik Yöneticiler grubunun üyesiyseniz, size iki çalışma zamanı erişim belirteci atanır: standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolündesiniz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek uygulamayı başlattığınızda bunu yapabilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

GetCounters(String)

Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs
Kaynak:
PerformanceCounterCategory.cs

Bir veya daha fazla örnek içeren bir performans sayacı kategorisindeki sayaçların listesini alır.

public:
 cli::array <System::Diagnostics::PerformanceCounter ^> ^ GetCounters(System::String ^ instanceName);
public System.Diagnostics.PerformanceCounter[] GetCounters(string instanceName);
member this.GetCounters : string -> System.Diagnostics.PerformanceCounter[]
Public Function GetCounters (instanceName As String) As PerformanceCounter()

Parametreler

instanceName
String

İlişkili sayaçların listesinin alındığı performans nesnesi örneği.

Döndürülenler

Bu performans sayacı kategorisinin PerformanceCounter belirtilen nesne örneğiyle ilişkili sayaçları gösteren bir nesne dizisi.

Özel durumlar

instanceName parametresi null'dir.

CategoryName Bu PerformanceCounterCategory örneğin özelliği ayarlanmadı.

-veya-

Kategori, parametresi tarafından instanceName belirtilen örneği içermez.

Temel alınan sistem API'sine yapılan çağrı başarısız oldu.

Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.

Örnekler

Aşağıdaki kod örneği içindeki nesnelerin PerformanceCounterlistesini PerformanceCounterCategory alır. İlk olarak, bir bilgisayar adının belirtilip belirtilmediğinden yola çıkarak uygun oluşturucuyla bir oluşturur PerformanceCounterCategory . Daha sonra bir nesne dizisi GetCounters döndürmek için yöntemini kullanır PerformanceCounter ve bir örnek adının belirtilip belirtilmedidiğine göre aşırı yüklemeyi seçerGetCounters.

Örnekleri GetCounters(String) içeren bir kategoriyle kullanılmadığı sürece bu aşırı yükleme başarısız olur.

public static void Main(string[] args)
{
    string categoryName = "";
    string machineName = "";
    string instanceName = "";
    PerformanceCounterCategory pcc;
    PerformanceCounter[] counters;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        machineName = args[1]=="."? "": args[1];
        instanceName = args[2];
    }
    catch
    {
        // Ignore the exception from non-supplied arguments.
    }

    try
    {
        // Create the appropriate PerformanceCounterCategory object.
        if (machineName.Length>0)
        {
            pcc = new PerformanceCounterCategory(categoryName, machineName);
        }
        else
        {
            pcc = new PerformanceCounterCategory(categoryName);
        }

        // Get the counters for this instance or a single instance
        // of the selected category.
        if (instanceName.Length>0)
        {
            counters = pcc.GetCounters(instanceName);
        }
        else
        {
            counters = pcc.GetCounters();
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to get counter information for " +
            (instanceName.Length>0? "instance \"{2}\" in ": "single-instance ") +
            "category \"{0}\" on " + (machineName.Length>0? "computer \"{1}\":": "this computer:"),
            categoryName, machineName, instanceName);
        Console.WriteLine(ex.Message);
        return;
    }

    // Display the counter names if GetCounters was successful.
    if (counters!=null)
    {
        Console.WriteLine("These counters exist in " +
            (instanceName.Length>0? "instance \"{1}\" of": "single instance") +
            " category {0} on " + (machineName.Length>0? "computer \"{2}\":": "this computer:"),
            categoryName, instanceName, machineName);

        // Display a numbered list of the counter names.
        int objX;
        for(objX=0; objX<counters.Length; objX++)
        {
            Console.WriteLine("{0,4} - {1}", objX+1, counters[objX].CounterName);
        }
    }
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim machineName As String = ""
    Dim instanceName As String = ""
    Dim pcc As PerformanceCounterCategory
    Dim counters() As PerformanceCounter

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        machineName = IIf(args(1) = ".", "", args(1))
        instanceName = args(2)
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Try
        ' Create the appropriate PerformanceCounterCategory object.
        If machineName.Length > 0 Then
            pcc = New PerformanceCounterCategory(categoryName, machineName)
        Else
            pcc = New PerformanceCounterCategory(categoryName)
        End If

        ' Get the counters for this instance or a single instance 
        ' of the selected category.
        If instanceName.Length > 0 Then
            counters = pcc.GetCounters(instanceName)
        Else
            counters = pcc.GetCounters()
        End If

    Catch ex As Exception
        Console.WriteLine("Unable to get counter information for " & _
            IIf(instanceName.Length > 0, "instance ""{2}"" in ", _
            "single-instance ") & "category ""{0}"" on " & _
            IIf(machineName.Length > 0, "computer ""{1}"":", _
            "this computer:"), _
            categoryName, machineName, instanceName)
        Console.WriteLine(ex.Message)
        Return
    End Try

    ' Display the counter names if GetCounters was successful.
    If Not counters Is Nothing Then
        Console.WriteLine("These counters exist in " & _
            IIf(instanceName.Length > 0, "instance ""{1}"" of", _
            "single instance") & " category {0} on " & _
            IIf(machineName.Length > 0, _
                "computer ""{2}"":", "this computer:"), _
            categoryName, instanceName, machineName)

        ' Display a numbered list of the counter names.
        Dim objX As Integer
        For objX = 0 To counters.Length - 1
            Console.WriteLine("{0,4} - {1}", objX + 1, _
                counters(objX).CounterName)
        Next objX
    End If
End Sub

Açıklamalar

Tek örnekli bir kategoriyi temsil etmek için parametresi için instanceName boş bir dize ("") geçirin.

Performans nesnesi örnekleri hakkında daha fazla bilgi için sınıfa genel bakış bölümüne PerformanceCounter bakın.

Note

Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition'da veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.

Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcıları grubuna ekleyin.

Windows Vista ve sonraki sürümlerde Kullanıcı Hesabı Denetimi (UAC), bir kullanıcının ayrıcalıklarını belirler. Yerleşik Yöneticiler grubunun üyesiyseniz, size iki çalışma zamanı erişim belirteci atanır: standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolündesiniz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek uygulamayı başlattığınızda bunu yapabilirsiniz.

Ayrıca bkz.

Şunlara uygulanır