Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Extracting Performance Data from Your .NET Applications : Page 2

Using only three classes from the .NET Framework class library, you can quickly create performance counters and publish performance data about your .NET applications.

Figure 2: The FileWatcher class waits for data files to be dropped into a file system directory. It then passes control to the Loader class to insert the records from the file into the Northwind database.
Creating Performance Counters
Your solution could take many different forms depending on the actual attributes of the system you want to develop. To set the stage a bit, consider a console application tasked with inserting rows into the Products table in the Northwind database. The data will arrive in the form of a CSV file that gets dropped into a pre-determined directory. The console application merely has to read each line in the file and copy its contents over verbatim to the Products table—as fast as it possibly can.

Figure 2 and Figure 3 show one possible design for this application. The FileWatcher class watches a specific file system directory. When a file arrives there, FileWatcher passes the filename to the Loader class, which will establish the database connection, read the file in line by line, and insert the data into the Northwind database.

To add performance data to this application, you must first identify the data that will enable useful performance analysis. Potential statistics useful for performance analysis might include:

  1. The number of records inserted per second. (This will provide a good indicator of raw processing speed.)
  2. The number of errors per second. (This will provide a slightly different view on the processing speed dimension.)
  3. A count of the total records inserted. (This will provide a view of the workload gradient over time.)
Figure 3: The basic design for the Northwinds DataLoader component involves a three-step execution. (1) Files containing the product data are dropped into a directory. (2) The DataLoader component waits for files to arrive in this directory. (3) New files are processed line by line, and their contents are inserted into the Northwind database.
Other possibilities include: percentage of errors to successful inserts, total execution time per file, average records per file, and so on. The three statistics listed above provides a good enough basis to use for exploring performance counters.

With the different counters identified, let's create them. You can add performance counters to the current inventory in one of three ways. You can add them programmatically at run-time, you can add them via an install action as part of a setup package, or you can add them via the Visual Studio .NET Server Explorer. In this article, we'll concentrate on creating counters using Server Explorer, and we'll also take a look at what it takes to create counters at run-time. Note that the Standard Edition of Visual Studio .NET does not ship with Server Explorer.

Creating Performance Counters with Server Explorer
To create your set of counters using Server Explorer, fire up a version of Visual Studio .NET that ships with Server Explorer (Enterprise Architect, Enterprise Developer, or Professional). Make Server Explorer visible. (Press Ctrl-Alt-S to make it active if it isn't currently being displayed.) Under the Servers node, locate and expand the tree for the computer that will host the performance counters. Expand the Performance Counters node. Figure 4 shows the performance counters configured on a machine.

Figure 4: The Visual Studio .NET Server Explorer will display the list of all performance counters registered on a particular machine. Server Explorer makes it easy to add custom performance counters to the current list of counters.
To add your own performance counter, you will first create a new category. A category is typically the name of the application that will publish the performance data, although you may wish to use multiple categories for larger systems. Right-click on the Performance Counters node and select Create New Category. This will launch the Performance Counter Builder dialog box shown in Figure 5.

To follow along with our Northwind data loader sample, type Northwinds Data Loader as the Category name then click New to add a new counter. Working through the list of previously identified counters, enter the name, type, and description for each one, filling in the information that you see in Table 1. Note that there is a slight disconnect in the nomenclature here. A category is the same thing as an "object." (Refer above where we discussed the organization of performance counters.)

Table 1: For the Northwinds DataLoader class, we are interested in tracking statistics across three different counters.



Load Errors/sec


Records Loaded/sec


Total Records Loaded


Click OK—and you're done. You've created the performance counters and registered them on your machine.

Figure 5: The Performance Counter Builder will allow you to create new performance counters or edit existing ones.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date