Aracılığıyla paylaş


System.Diagnostics.PerformanceData Ad Alanı

Sayaç verileri sağlamak için bu ad alanında sınıfları kullanın. Sayaçlar, performans ölçümlerini Performans İzleyicisi gibi tüketicilere göstermek için kullanılır. Ad alanı, sayaç verilerinin tüketilmesine yönelik sınıflar içermez. Performans sayaçları mimarisinin tam açıklaması için bkz. Performans Sayaçları.

Sınıflar

Name Description
CounterData

Bir sayacın ham verilerini içerir.

CounterSet

Bir mantıksal sayaç kümesi tanımlar.

CounterSetInstance

sınıfında tanımlanan mantıksal sayaçların bir örneğini CounterSet oluşturur.

CounterSetInstanceCounterDataSet

Sayaç değerleri koleksiyonunu içerir.

Numaralandırmalar

Name Description
CounterSetInstanceType

Sayaç kümesinin işlemler ve fiziksel diskler gibi birden çok örneğe veya bellek gibi tek bir örneğe izin verip vermeyeceğini belirtir.

CounterType

Olası sayaç türlerini tanımlar. Her sayaça bir sayaç türü atanır. Sayaç türü, sayaç verilerinin nasıl hesaplanıp ortalama alındığını ve görüntüleneceğini belirler.

Örnekler

Aşağıda basit bir bildirim gösterilmektedir:

<!-- <?xml version="1.0" encoding="UTF-16"?> -->
<instrumentationManifest xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd"
     xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:trace=http://schemas.microsoft.com/win/2004/08/events/trace>

    <instrumentation>

        <counters xmlns=http://schemas.microsoft.com/win/2005/12/counters>

            <provider
              applicationIdentity = "provider1.exe"
              providerType = "userMode"
              providerGuid = "{51D1685C-35ED-45be-99FE-17261A4F27F3}">

               <counterSet guid = "{582803C9-AACD-45e5-8C30-571141A22092}"
                  uri = "Microsoft.Windows.System.PerfCounters.Typing"
                  name = "$(string.CounterSet1.Name)"
                  description = "$(string.CounterSet1.Description)"
                  instances = "single">

                    <counter id = "1"
                      uri = "Microsoft.Windows.System.PerfCounters.Typing.TotalWords"
                      name = "$(string.CS1.Counter1.Name)"
                      description = "$(string.CS1.Counter1.Description)"
                      type = "perf_counter_rawcount"
                      detailLevel = "standard"/>

                    <counter id = "2"
                      uri = "Microsoft.Windows.System.PerfCounters.Typing.WordsInInterval"
                      name = "$(string.CS1.Counter2.Name)"
                      description = "$(string.CS1.Counter2.Description)"
                      type = "perf_counter_delta"
                      detailLevel = "standard"/>

                    <counter id = "3"
                      uri = "Microsoft.Windows.System.PerfCounters.Typing.LetterAPressed"
                      name = "$(string.CS1.Counter3.Name)"
                      description = "$(string.CS1.Counter3.Description)"
                      type = "perf_counter_rawcount"
                      detailLevel = "standard"/>

                    <counter id = "4"
                      uri = "Microsoft.Windows.System.PerfCounters.Typing.WordsContainingLetterA"
                      name = "$(string.CS1.Counter4.Name)"
                      description = "$(string.CS1.Counter4.Description)"
                      type = "perf_counter_rawcount"
                      detailLevel = "standard"/>

                    <counter id = "5"
                      uri = "Microsoft.Windows.System.PerfCounters.Typing.PercentOfWordsContainingLetterA"
                      name = "$(string.CS1.Counter5.Name)"
                      description = "$(string.CS1.Counter5.Description)"
                      type = "perf_sample_fraction"
                      baseID = "6"
                      detailLevel = "standard">
                      <counterAttributes>
                          <counterAttribute name = "displayAsReal" />
                      </counterAttributes>
                    </counter>

                    <counter id = "6"
                      uri = "Microsoft.Windows.System.PerfCounters.Typing.PercentBase"
                      type = "perf_sample_base"
                      detailLevel = "standard">
                      <counterAttributes>
                          <counterAttribute name = "noDisplay" />
                      </counterAttributes>
                    </counter>

                </counterSet>
            </provider>
        </counters>
    </instrumentation>

    <localization>
        <resources culture="en-US">
            <stringTable>

                <string id="CounterSet1.Name" value="Typing"/>
                <string id="CounterSet1.Description" value="Captures simple typing metrics."/>
                <string id="CS1.Counter1.Name" value="Total Words Typed"/>
                <string id="CS1.Counter1.Description" value="The total number of words typed."/>
                <string id="CS1.Counter2.Name" value="Words Typed In Interval"/>
                <string id="CS1.Counter2.Description" value="The total number of words typed in the interval."/>
                <string id="CS1.Counter3.Name" value="Letter A Pressed"/>
                <string id="CS1.Counter3.Description" value="The number of times that the letter A is pressed."/>
                <string id="CS1.Counter4.Name" value="Words Containing A"/>
                <string id="CS1.Counter4.Description" value="The number of words that contain the letter A."/>
                <string id="CS1.Counter5.Name" value="Percent of Words Containing A"/>
                <string id="CS1.Counter5.Description" value="The percent of words that contain the letter A in the last interval."/>

            </stringTable>
        </resources>
    </localization>
</instrumentationManifest>

Aşağıda bildirim için basit bir sağlayıcı uygulaması gösterilmektedir:

using System.Diagnostics.PerformanceData;

        private static Guid providerId = new Guid("{51D1685C-35ED-45be-99FE-17261A4F27F3}");
        private static Guid typingCounterSetId = new Guid("{582803C9-AACD-45e5-8C30-571141A22092}");

        private static CounterSet typingCounterSet;         // Defines the counter set
        private static CounterSetInstance typingCsInstance; // Instance of the counter set

        private static int numberOfLetterAInWord = 0;

        . . .

            // Create the 'Typing' counter set.
            typingCounterSet = new CounterSet(providerId, typingCounterSetId, CounterSetInstanceType.Single);

            // Add the counters to the counter set definition.
            typingCounterSet.AddCounter(1, CounterType.RawData32, "Total Word Count");
            typingCounterSet.AddCounter(2, CounterType.Delta32, "Words Typed In Interval");
            typingCounterSet.AddCounter(3, CounterType.RawData32, "A Key Pressed");
            typingCounterSet.AddCounter(4, CounterType.RawData32, "Words Containing A");
            typingCounterSet.AddCounter(5, CounterType.SampleFraction, "Percent of Words Containing A");
            typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base");

            // Create an instance of the counter set (contains the counter data).
            typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance");
            typingCsInstance.Counters[1].Value = 0;
            typingCsInstance.Counters[2].Value = 0;
            typingCsInstance.Counters[3].Value = 0;
            typingCsInstance.Counters[4].Value = 0;
            typingCsInstance.Counters[5].Value = 0;
            typingCsInstance.Counters[6].Value = 0;

        . . .

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            typingCounterSet.Dispose();
        }

        // Simple effort to capture letter A key press and words typed.
        private void textInput_KeyDown(object sender, KeyEventArgs e)
        {
            Keys keyData = e.KeyData;

            switch (e.KeyData)
            {
                case Keys.A :
                    // In the .NET 3.5 Framework, you had to use the
                    // Value property to set and increment the counter
                    // value. Beginning with the .NET 4.0 Framework,
                    // the Value property is safe to use in a multi-
                    // threaded application.
                    typingCsInstance.Counters["A Key Pressed"].Value++;
                    numberOfLetterAInWord++;

                    break;

                case Keys.Enter:
                case Keys.Space:
                case Keys.Tab:

                    if (numberOfLetterAInWord > 0)
                    {
                        // Beginning with the .NET 4.0 Framework, you
                        // can use the Increment method to increment
                        // the counter value by 1. The Increment method
                        // is safe to use in a multi-threaded
                        // application.
                        typingCsInstance.Counters["Words Containing A"].Increment();
                        typingCsInstance.Counters["Percent of Words Containing A"].Increment();
                        numberOfLetterAInWord = 0;
                    }

                    typingCsInstance.Counters["Percent Base"].Increment();
                    typingCsInstance.Counters["Total Word Count"].Increment();
                    typingCsInstance.Counters["Words Typed In Interval"].Increment();

                    break;
            }
        }

Açıklamalar

Bu ad alanı içindeki sınıflar, Windows Vista'da tanıtılan performans sayaçları için yeni mimariyi (sürüm 2.0) destekler. Yeni mimaride sağlayıcı artık tüketici isteklerine doğrudan yanıt vermiyor, bunun yerine yalnızca sayaç verilerini koruyor. Sağlayıcı sayaç kümesinin bir örneğini oluşturduğunda sistem sağlayıcının işlemine bir iş parçacığı ekler; iş parçacığı, tüketici isteklerinin işlenmesinden sorumludur.

Aşağıdaki adımlarda sayaç sağlayıcısı yazma işlemi gösterilmektedir.

  1. Sağlayıcının sağladığı sayaçlar XML tabanlı bir bildirimde tanımlanır. Sayaçlar mantıksal olarak sayaç kümeleri halinde gruplandırılır. Sayaç kümesindeki sayaçlar, sayaç kümesi içinde benzersiz olan sayısal bir tanımlayıcıyla tanımlanır. Sağlayıcı bir veya daha fazla sayaç kümesi tanımlayabilir. Bir sayaç kümesi, bir sağlayıcıya özgü guid ile tanımlanır. Sağlayıcınızı yazmak için bu sınıfları kullanırsanız şunları unutmayın:

    • Sağlayıcı öğesinin geri çağırma özniteliği yoksayılır.

    • counterAttribute öğesinin name özniteliği için başvuru değeri yoksayılır.

    Bildirimi yazma hakkında ayrıntılı bilgi için bkz. Performans Sayaçları Şeması.

  2. Bildiriminizi yazdıktan sonra, bildirimi derlemek için CTRPP aracını kullanın (ctrpp provider.man). Araç dört dosya oluşturur: .h, .c, .rc ve *_r.h. .h ve .c dosyalarını yoksayabilirsiniz. .rc dosyası bildiriminizde tanımlanan yerelleştirilmiş dizeleri içerir. Projenize eklediğiniz derlenmiş kaynak dosyasını (.res) oluşturmak için .rc ve *_r.h dosyalarını kullanırsınız. Aşağıdaki çağrı kaynak dosyasının nasıl derleneceklerini gösterir:

    rc /r /i "c:\Program Files\Microsoft SDKs\Windows\v6.0\Include" provider.rc
    

    sal.h dosyasına başvuran bir hata alırsanız, Microsoft Visual Studio,Visual C include dizininizdeki sal.h dosyasını /i anahtarı için belirttiğiniz dizine kopyalayın.

    Projenizin Uygulama özelliği sayfasına derlenmiş kaynak dosyasına (.res) bir yol ekleyin.

  3. Sağlayıcınızı yazın. Aşağıdaki adımlar bir sağlayıcı tarafından yapılan çağrıları gösterir:

    1. CounterSet.CounterSet Sayaç kümesini tanımlamak için oluşturucuyu çağırın. Bildirimde tanımlanan her sayaç kümesi için bu yöntemi çağırın.

    2. Her sayaç kümesi için, sayaçları kümeye eklemek için yöntemlerden birini CounterSet.AddCounter çağırın. Sayaç kümesinde tanımlanan her sayaç için bu yöntemi çağırın.

    3. Sayaç kümesinin CounterSet.CreateCounterSetInstance bir örneğini oluşturmak için yöntemini çağırın (örnek sayaç verilerini içerir). Tek örnekli sayaç kümeleri için bu yöntemi bir kez çağır. Birden çok örnek sayaç kümesi için, sayaç verileri sağlamanız gereken her örnek için bu yöntemi çağırabilirsiniz (her örnek için benzersiz bir ad kullanın).

    4. Sayacın CounterSetInstance.Counters sayaç verilerine erişmek ve bunları ayarlamak için özelliğini kullanın.

  4. Sağlayıcınızı tamamladıktan sonra, sayaçları bilgisayara kaydetmek için LodCtr aracını kullanın. Örneğin

    lodctr /m:provider.man
    

    Örnekte, bildirimin ve yürütülebilir dosyanın geçerli dizinde olduğu varsayılır.

Bu ad alanında bulunan sınıfları Windows Vista ve sonraki işletim sistemlerini çalıştıran bilgisayarlarda kullanabilirsiniz.