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



Comments

  • 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

    Reply
  • 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.

    Reply
  • 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.

    Reply
  • 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.

    Reply
  • 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..

    Reply
  • 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?

    Reply
  • 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.

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds