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

  1.  
  2. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  3.  
  4. <h4>How Do I...Count rate of change?</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, 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 the number of users currently
  14. connected to the system. Using the NGWS runtime's <span class="Bold">PerformanceCounter</span>
  15. component, you can easily create your own custom counters and publish
  16. performance data relevant to your application, such as those mentioned above.</p>
  17.  
  18. <p>This
  19. sample illustrates how to publish the number of orders processed per second using a
  20. custom performance counter. It's a small console application that can be run
  21. from a command prompt. Let's run it:</p>
  22.  
  23.     </font><font face="Courier New" color="Blue" size="1"><blockquote>
  24.         > PCDemo.exe
  25.     </blockquote></font><font face="Tahoma" size="1">
  26.  
  27. <p>Now,
  28. wait for the application to display "Started" and run the PerfMon.exe.
  29. In PerfMon, click on the "add" toolbar button. A dialog will open.
  30. Select the "ACounterDemo" performance object, "CountPerSecond"
  31. counter, and "_Total" instance. Click "Add", close the
  32. dialog, and observe that you can use the PCDemo sample to change the published
  33. value by pressing "+" or "-". When, the application starts, 
  34. it simulates processing two new orders per
  35. second. The "+" and "-" keys can be used to double or halve
  36. the number.</p>
  37.  
  38. <p>In its simplest form, writing to a custom performance counter that counts number of
  39. items per second involves:</p>
  40.  
  41. <ol>
  42. <li>Creating a counter of the RateOfChangePerSecond32 type:
  43.  
  44.     </font><font face="Courier New" color="Blue" size="1"><p>
  45.         if(!PerformanceCounter.CategoryExists(objectName))<br>
  46.         {<br>
  47.             CounterCreationData ccd = new CounterCreationData();<br>
  48.             ccd.CounterName = counterName;<br>
  49.             ccd.CounterType = PerformanceCounterType.RateOfChangePerSecond32;<br>
  50.             CounterCreationData[] ccds = new CounterCreationData[1];<br>
  51.             ccds[0] = ccd;<br>
  52.         <br>
  53.             PerformanceCounterCategory.Create(objectName, "Sample Object", ccds);<br>
  54.         }
  55.     </p></font><font face="Tahoma" size="1">
  56.  
  57. <li>Instantiating a PerformanceCounter component and pointing it to an appropriate performance
  58. counter:
  59.  
  60.     </font><font face="Courier New" color="Blue" size="1"><p>
  61.         PerformanceCounter counter;<br>
  62.         counter = new PerformanceCounter(objectName, counterName ,instanceName);
  63.     </p></font><font face="Tahoma" size="1">
  64.  
  65. <li>Setting the RawValue property of the counter:
  66.  
  67.     </font><font face="Courier New" color="Blue" size="1"><p>
  68.         counter.IncrementBy(1);
  69.     </p></font><font face="Tahoma" size="1">
  70.  
  71. </ol>
  72.  
  73. <p>Have a great time PerformanceCounter'ing!</p>
  74. </font></div>
  75.  
  76. <h4>Example</h4>
  77.  
  78. <p>
  79. <div class="indent">
  80. <a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCDemo">
  81. <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
  82. </a>
  83. <div class="caption">PCDemo.exe</div><br>
  84. [<a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCDemo">View Sample</a>] | 
  85. [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/PerformanceCounters/PCDemo/PCDemo.src">View Source</a>]<p>
  86. </div>
  87.  
  88. <h4>Source Code</h4>
  89.  
  90. <div class="code">
  91. <xmp>
  92. <!-- #include virtual="/quickstart/howto/samples/Services/PerformanceCounters/PCDemo/PCDemo.cs" -->
  93. </xmp>
  94. </div>
  95.  
  96. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->