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

  • On-demand Event Event Date: May 18, 2015 While the idea of using facial and/or gesture recognition to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development efforts. There are many different ways in which Intel and Unity Technologies have been working together to help speed the development of games with the Intel&reag; RealSense™ SDK (software developer kit). Check out this webcast to join a panel of experts as they …

  • Employees must exchange sensitive emails with customers and partners. These emails might contain protected health information, protected financial information, or corporate information that should not be made public. Globalscape® Mail Express® allows you to encrypt the emails that it manages so that no one but the sender and recipient--not even the administrator--can view the contents of the email. "Secure the Transfer of Sensitive Emails" is the property of GlobalSCAPE

Most Popular Programming Stories

More for Developers

RSS Feeds

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