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  
{
public:
 MyPerfStats();
 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;
perf.EnumCategories();
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() 
{
 m_ElementsList.ResetContent();
 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);
  }else
  {
   SetDlgItemInt(IDC_STATIC_VALUE, (value - LastValue) / 1); // 1 couse interval = 1000 ms = 1 s
   LastValue = value;
  }
 }else
 {
  SetDlgItemText(IDC_STATIC_VALUE, "");
 }
 CDialog::OnTimer(nIDEvent);
}
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