advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Boost.org
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.8/5 | Rate this item | 4 users have rated this item.
 

Access Raw Data with Performance Counters in Visual C++

Though Windows allows you direct access to performance data, using the native C API is unwieldy. James Curran explains a few C++ techniques to help make it more manageable. 


advertisement
indows lets you monitor a large number of internal statistics. Most people only see them in the Performance Monitor utility. This is fine if all you need is to look at graphs, but to fully study and analyze the information, you'll need to get at the raw data. Windows gives you access to the raw data, but only through a cumbersome C API. However, with the proper application of a few C++ techniques, you can make the whole process much simpler.


Working with (and Wrapping) Queries
At the lowest level, the structures used are defined in the Platform SDK header <winperf.h>. Microsoft apparently realized that those were too tedious for most people to use, so they built a new interface on top of that, known as the Performance Data Helper (PDH) interface. Though the PDH was only a slight improvement, you can still build a useable interface with it.

The structure at the heart of performance monitoring is the HQUERY. It is initialized with the API function PdhOpenQuery(), and closed out with PdhCloseQuery(). Clearly this calls for a wrapper class, which I'll call Query, with a constructor and destructor handling these tasks. The main purpose for a HQUERY is to manage a number of HCOUNTER structures. They are attached to a HQUERY by calling PdhAddCounter(). Add a member function to Query to attach them. Also add a cast to access the underlying HQUERY, and you have a functioning minimal interface for Query (see Listing 1). It's fairly simple, and if that were all, I might not have even bothered with the C++ wrapper. But there is more.

  Next Page: Counters and Global Shared Memory


Page 1: IntroductionPage 3: Getting at the Data
Page 2: Counters and Global Shared Memory 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs