home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Count rate of change?</h4>
-
- <div class="indent" style="width:660"><font face="Tahoma" size="1">
-
- <p>Windows performance counters allow
- your applications and components to publish, capture, and analyze the
- performance data that applications, services, and drivers provide. You can use
- this information to determine system bottlenecks and fine-tune system and
- application performance. For example, you might use a performance counter to
- track the number of orders processes per second or the number of users currently
- connected to the system. Using the NGWS runtime's <span class="Bold">PerformanceCounter</span>
- component, you can easily create your own custom counters and publish
- performance data relevant to your application, such as those mentioned above.</p>
-
- <p>This
- sample illustrates how to publish the number of orders processed per second using a
- custom performance counter. It's a small console application that can be run
- from a command prompt. Let's run it:</p>
-
- </font><font face="Courier New" color="Blue" size="1"><blockquote>
- > PCDemo.exe
- </blockquote></font><font face="Tahoma" size="1">
-
- <p>Now,
- wait for the application to display "Started" and run the PerfMon.exe.
- In PerfMon, click on the "add" toolbar button. A dialog will open.
- Select the "ACounterDemo" performance object, "CountPerSecond"
- counter, and "_Total" instance. Click "Add", close the
- dialog, and observe that you can use the PCDemo sample to change the published
- value by pressing "+" or "-". When, the application starts,
- it simulates processing two new orders per
- second. The "+" and "-" keys can be used to double or halve
- the number.</p>
-
- <p>In its simplest form, writing to a custom performance counter that counts number of
- items per second involves:</p>
-
- <ol>
- <li>Creating a counter of the RateOfChangePerSecond32 type:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- if(!PerformanceCounter.CategoryExists(objectName))<br>
- {<br>
- CounterCreationData ccd = new CounterCreationData();<br>
- ccd.CounterName = counterName;<br>
- ccd.CounterType = PerformanceCounterType.RateOfChangePerSecond32;<br>
- CounterCreationData[] ccds = new CounterCreationData[1];<br>
- ccds[0] = ccd;<br>
- <br>
- PerformanceCounterCategory.Create(objectName, "Sample Object", ccds);<br>
- }
- </p></font><font face="Tahoma" size="1">
-
- <li>Instantiating a PerformanceCounter component and pointing it to an appropriate performance
- counter:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- PerformanceCounter counter;<br>
- counter = new PerformanceCounter(objectName, counterName ,instanceName);
- </p></font><font face="Tahoma" size="1">
-
- <li>Setting the RawValue property of the counter:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- counter.IncrementBy(1);
- </p></font><font face="Tahoma" size="1">
-
- </ol>
-
- <p>Have a great time PerformanceCounter'ing!</p>
- </font></div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCDemo">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">PCDemo.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCDemo">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/PerformanceCounters/PCDemo/PCDemo.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/PerformanceCounters/PCDemo/PCDemo.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->