Performance Statistics Class

The CPerfStats class gather performance statistics from the Windows 9x Registry.

If you want to use CPerfStats class you should create own class derived from CPerfStats.

class MyPerfStats : public CPerfStats  
 virtual ~MyPerfStats();
 void OnHitCategory( CATEGORY_STRUCT * pCategory );
 void OnHitElement( ELEMENT_STRUCT * pElement );
You should define two function in your class. The first is OnHitCategory() and second OnHitElement().

Now, you can create MyPerfStats object and call EnumCategories().

MyPerfStats perf;
In your OnHitCategory() function you can take results of category enumerating.

void MyPerfStats::OnHitCategory( CATEGORY_STRUCT * pCategory )
 pCategoryList->SetItemData( pCategoryList->AddString( pCategory->Name), (DWORD)pCategory ) ;
The pCategoryList is pointer to ListBox. The pCategory->Name is name of category, for example "KERNEL" or "File System". You should remember pCategory for enumerating elements later.

Now, you can enumerating elements of categories. I wrote something like this.

void CPerfTestDlg::OnSelchangeListCategories() 
 perf.EnumElements( (CATEGORY_STRUCT *)m_CategoriesList.GetItemData( m_CategoriesList.GetCurSel() ) );	
In your OnHitElement() function you can take results of elements enumerating.

void MyPerfStats::OnHitElement( ELEMENT_STRUCT * pElement )
 pElementList->SetItemData( pElementList->AddString( pElement->Name), (DWORD)pElement );
The pElementList is pointer to ListBox. The pElement->Name is name of element, for example "Threads". You should remember pElement for taking its value later.

You can take element description...

void CPerfTestDlg::OnSelchangeListElements() 
 ELEMENT_STRUCT * pElement = (ELEMENT_STRUCT *)m_ElementsList.GetItemData( m_ElementsList.GetCurSel() );
 SetDlgItemText(IDC_STATIC_DESCRIPTION, pElement->Description);
and element value too.

void CPerfTestDlg::OnTimer(UINT nIDEvent) 
 if ( m_ElementsList.GetCurSel() !=  LB_ERR ) 
  ELEMENT_STRUCT * pElement = (ELEMENT_STRUCT *)m_ElementsList.GetItemData( m_ElementsList.GetCurSel() );
  DWORD value = perf.GetValue(pElement);
  if ( pElement->Differentiate   == FALSE )
   SetDlgItemInt(IDC_STATIC_VALUE, value);
   SetDlgItemInt(IDC_STATIC_VALUE, (value - LastValue) / 1); // 1 couse interval = 1000 ms = 1 s
   LastValue = value;
  SetDlgItemText(IDC_STATIC_VALUE, "");
What does pElement->Differentiate means ?

This flag indicates whether the statistic being collected is cumulative or not. If Differentiate is True, then the statistic is steadily increasing, and the value reported should be the difference between successive values divided by the interval expressed in seconds. If Differentiate is False, then the statistic should be reported unchanged.

Download demo project - 34 KB

Download source - 3 KB

Date Last Updated: April 4, 1999


  • Demo doesn't compile

    Posted by Legacy on 07/10/2003 12:00am

    Originally posted by: BadJake

    The demo doesn't cos of missing afxres.h

  • about memory

    Posted by Legacy on 06/17/2003 12:00am

    Originally posted by: Inferno

    How to get memory usage for a specific process/Application?

    I need a Task manager style memory counts.

  • monitor processor overall utilization of the given system

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: Ujjal

    Does any one know how to find out the processor overall utilization( in %) at given interval.

  • How to get cpu usage for a specific process under win2k.

    Posted by Legacy on 08/05/2002 12:00am

    Originally posted by: Daniel Kopta

    I need to know how I can determine the ammount of cpu usage for one specific process under Windows 2000, and use the data in another application.

  • How to get CPU usage of a particular process/application

    Posted by Legacy on 06/10/2001 12:00am

    Originally posted by: Sandy

    Can you please advise how can we find the CPU utizilation of a particuar process or application running in WIN 98/ME OS..

    Thanks in advance..

  • CPU Usage Reports 100%

    Posted by Legacy on 05/23/2001 12:00am

    Originally posted by: Ian Austin

    On my Win95 box (OSR2, IE 5.5) the CPU usage is always reported at 100%. What's going on?

  • How to use Performance Data Helper (PDH) Library

    Posted by Legacy on 03/23/2000 12:00am

    Originally posted by: Abhijit

    Microsoft provides a library called Performance Data Helper Library that provides an interface to the NT Performance Data. I am using this library in my application. But there is one problem. When calling function PdhOpenQuery() I get a runtime error saying "Unable to find the function PdhOpenQuery() function in Pdh.dll". I am using NT 4.0 with SP5 and VC++ with SP3. Can anybody help me out with this problem.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • Thanks to the Internet of Things (IoT), physical assets are turning into participants in real-time global digital markets. The countless types of assets around us will become as easily indexed, searched and traded as any online commodity. While some industries will be tougher to transform than others – those with physical limitations, such as manufacturing, will be harder to digitize – untold economic opportunities exist for growth and advancement. Our research shows this will create a new "Economy …

Most Popular Programming Stories

More for Developers

RSS Feeds

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