home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Read from a performance counter?</h4>
-
- <div class="indent" style="width:660"><font face="Tahoma" size="1">
-
- <p>Windows performance counters allow
- your applications and components to publish, capture (read), 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 system's processor
- utilization. Using the NGWS runtime's <span class="Bold">PerformanceCounter</span>
- component, you can easily read performance data relevant to your
- application, such as those mentioned above.</p>
-
- <p>This sample illustrates how to read simple performance information from a
- performance counter. It's a small console application that can be run from a
- command prompt. The application takes three command line arguments. The first is
- a performance object name (category). The second argument is the counter name.
- The third argument is the counter instance name.</p>
-
- <p>For example, if you want to see the processor utilization on your machine run
- the sample with the following command line arguments:</p>
-
- </font><font face="Courier New" color="Blue" size="1"><blockquote>
- > PCRead.exe "Processor" "% Processor Time" "_Total"
- </blockquote></font><font face="Tahoma" size="1">
-
- <p>You will see the processor utilization data updated every half-second.</p>
-
- <p>In its simplest form, reading a performance counter involves:</p>
-
- <ol>
- <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>Reading the NextValue property of the counter:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- counter.NextValue();
- </p></font><font face="Tahoma" size="1">
-
- </ol>
-
- <p>Remember
- that you have to read NextValue more than once to get a relevant data.<br>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/PCRead">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">PCRead.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCRead">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/PerformanceCounters/PCRead/PCRead.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/PerformanceCounters/PCRead/PCRead.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->