home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / pcread.aspx < prev    next >
Encoding:
Text File  |  2000-06-08  |  3.1 KB  |  77 lines

  1.  
  2. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  3.  
  4. <h4>How Do I...Read from a performance counter?</h4>
  5.  
  6. <div class="indent" style="width:660"><font face="Tahoma" size="1">
  7.  
  8. <p>Windows performance counters allow
  9. your applications and components to publish, capture (read), and analyze the
  10. performance data that applications, services, and drivers provide. You can use
  11. this information to determine system bottlenecks and fine-tune system and
  12. application performance. For example, you might use a performance counter to
  13. track the number of orders processes per second or system's processor
  14. utilization. Using the NGWS runtime's <span class="Bold">PerformanceCounter</span>
  15. component, you can easily read  performance data relevant to your
  16. application, such as those mentioned above.</p>
  17.  
  18. <p>This sample illustrates how to read simple performance information from a
  19. performance counter. It's a small console application that can be run from a
  20. command prompt. The application takes three command line arguments. The first is
  21. a performance object name (category). The second argument is the counter name.
  22. The third argument is the counter instance name.</p>
  23.  
  24. <p>For example, if you want to see the processor utilization on your machine run
  25. the sample with the following command line arguments:</p>
  26.  
  27.     </font><font face="Courier New" color="Blue" size="1"><blockquote>
  28.         > PCRead.exe "Processor" "% Processor Time" "_Total"
  29.     </blockquote></font><font face="Tahoma" size="1">
  30.  
  31. <p>You will see the processor utilization data updated every half-second.</p>
  32.  
  33. <p>In its simplest form, reading a performance counter involves:</p>
  34.  
  35. <ol>
  36. <li>Instantiating a PerformanceCounter component and pointing it to an appropriate
  37. performance counter:
  38.  
  39.     </font><font face="Courier New" color="Blue" size="1"><p>
  40.         PerformanceCounter counter;<br>
  41.         counter = new PerformanceCounter(objectName, counterName ,instanceName);
  42.     </p></font><font face="Tahoma" size="1">
  43.  
  44. <li>Reading the NextValue property of the counter:
  45.  
  46.     </font><font face="Courier New" color="Blue" size="1"><p>
  47.         counter.NextValue();
  48.     </p></font><font face="Tahoma" size="1">
  49.  
  50. </ol>
  51.  
  52. <p>Remember
  53. that you have to read NextValue more than once to get a relevant data.<br>Have a
  54. great time PerformanceCounter'ing!</p>
  55. </font></div>
  56.  
  57. <h4>Example</h4>
  58.  
  59. <p>
  60. <div class="indent">
  61. <a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCRead">
  62. <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
  63. </a>
  64. <div class="caption">PCRead.exe</div><br>
  65. [<a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCRead">View Sample</a>] | 
  66. [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/PerformanceCounters/PCRead/PCRead.src">View Source</a>]<p>
  67. </div>
  68.  
  69. <h4>Source Code</h4>
  70.  
  71. <div class="code">
  72. <xmp>
  73. <!-- #include virtual="/quickstart/howto/samples/Services/PerformanceCounters/PCRead/PCRead.cs" -->
  74. </xmp>
  75. </div>
  76.  
  77. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->