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

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

Most Popular Programming Stories

More for Developers

RSS Feeds

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