home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Write to 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, 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 processed 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 publishing (writing) simple performance information to a custom
- 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 publish data about the total number of international
- orders for milk, try running the sample as follows:</p>
-
- </font><font face="Courier New" color="Blue" size="1"><blockquote>
- > PCWrite.exe "Orders" "Milk Orders" "International"
- </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 "Orders" performance object, "Milk Orders"
- counter, and "International" instance. Click "Add", close
- the dialog, and observe that you can use the PCWrite sample to change the
- published value by pressing "+" or "-".</p>
-
- <p>In its simplest form, writing to a custom 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>Setting the RawValue property of the counter:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- counter.RawValue = 50;
- </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/PCWrite">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">PCWrite.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/PerformanceCounters/PCWrite">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/PerformanceCounters/PCWrite/PCWrite.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/PerformanceCounters/PCWrite/PCWrite.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->