Performance Statistics Class
Posted
by Krzysztof Kuczek
on April 3rd, 1999
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.
Date Last Updated: April 4, 1999

Comments
Demo doesn't compile
Posted by Legacy on 07/10/2003 12:00amOriginally posted by: BadJake
The demo doesn't cos of missing afxres.h
Replyabout memory
Posted by Legacy on 06/17/2003 12:00amOriginally posted by: Inferno
How to get memory usage for a specific process/Application?
I need a Task manager style memory counts.
Replymonitor processor overall utilization of the given system
Posted by Legacy on 08/13/2002 12:00amOriginally posted by: Ujjal
Does any one know how to find out the processor overall utilization( in %) at given interval.
ReplyHow to get cpu usage for a specific process under win2k.
Posted by Legacy on 08/05/2002 12:00amOriginally 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.
ReplyHow to get CPU usage of a particular process/application
Posted by Legacy on 06/10/2001 12:00amOriginally 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..
ReplyCPU Usage Reports 100%
Posted by Legacy on 05/23/2001 12:00amOriginally posted by: Ian Austin
On my Win95 box (OSR2, IE 5.5) the CPU usage is always reported at 100%. What's going on?
ReplyHow to use Performance Data Helper (PDH) Library
Posted by Legacy on 03/23/2000 12:00amOriginally 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