Performance Statistics Class | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 3, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.