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


Monitor Your Applications With Vista's Performance Logs and Alerts : Page 5

Instrument real-time and logged performance monitoring in your applications with the new Performance Logs and Alerts API.

Creating Data Collectors
Adding data collectors using the RPM is the preferred method for creating collectors; however, you can also create them programmatically using the IDataCollectorSet.DataCollectors property:

   // Create a simple performance counter collector
   IPerformanceCounterDataCollector performanceCollector =
   performanceCollector.name = @"Sample performance counter collector";
   performanceCollector.PerformanceCounters = 
      new string[] { @"\Process(*)\% Processor Time" };
   performanceCollector.SampleInterval = 5;
   // Configure additional properties...
   // Add it to the data collector set
   // Commit the set under a new name
      @"Service\DevX with additonal collectors", null, 
The IDataCollectorSet.DataCollectors property is an instance of the DataCollectorCollection class. It provides two methods for creating a data collector. The first, DataCollectorCollection.CreateDataCollector, accepts a DataCollectorType enumeration as a parameter. You can cast the returned IDataCollector instance to the appropriate interface as shown in the preceding code snippet.

The other method, DataCollectorCollection.CreateDataCollectorFromXml, accepts an XML string used to configure the data collector. You can extract the appropriate XML segment from an exported data collector set's XML. For example, the DevX.Pla.Template.xml file used in this article contains this segment:

     <Name>Performance Counter</Name>
     <FileName>Performance Counter</FileName>
Figure 12. Scheduling Runs: You schedule data collector set runs using the Properties window. You don't have to provide a schedule, so some data collector sets may not be scheduled.
Save this segment as a separate XML file to create a performance counter data collector with DataCollectorCollection.CreateDataCollectorFromXml.

The same programmatic and XML file approaches for configuring a performance counter data collector apply to the other types of data collectors; however, the specifics of configuring each type of data collector are outside the scope of this article. See the Best Practices section at the end of this article for more information.

Scheduling Data Collector Set Runs
Open the properties dialog for a data collector set in the RPM to create and modify scheduled runs (see Figure 12).

Programmatically, use the IDataCollectorSet.Schedules property to schedule runs.

   if (collectorSet.SchedulesEnabled)
       // Create and configure a schedule
       ISchedule schedule = collectorSet.Schedules.CreateSchedule();
       DateTime now = DateTime.Now.AddHours(1);
       schedule.StartDate = now;
       schedule.EndDate = now.AddDays(7);
       schedule.Days = WeekDays.plaEveryday;
       schedule.StartTime = now;
       // Add the schedule to the data collector set
       // Commit the set under a new name
           @"Service\DevX with schedule", null, 
After running the preceding code, if you export this data collector set's XML file you'll find an appropriate section for the schedule:

      <StartTime>1:27:10 PM</StartTime>
Best Practices for Creating PLA-Enabled Applications
The PLA API can be intimidating to learn and tedious to program if you don't have some extra help. Consider adopting these best practices when approaching PLA-enabled applications:

  • Become familiar with the Windows Vista Reliability and Performance Monitor. It's a valuable development tool for PLA programmers.
  • Determine which data collectors you need for your application, and invest some time learning how to configure them properly. Most of the data collectors represent a deep topic area—it doesn't make sense to try to learn them all at once.
  • The deepest topic is performance counters. You might find the article Extracting Performance Data from Your .NET Applications valuable.
  • Use the XML capabilities of the PLA API to keep data collector set configuration decoupled from your application code.

Seth Livingston is the CTO of Adventos, LLC, a training, mentoring, and delivery partner for Microsoft solutions and software development best practices. Seth splits his time among seminars, classes, mentoring, and guiding Adventos' technical direction. He lives in McKinney, Texas.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date