2009-02-10 18:37:48 +00:00
|
|
|
//====================================
|
|
|
|
// File: OBJLIST.CPP
|
|
|
|
// Author: Matt Pietrek
|
|
|
|
// From: Microsoft Systems Journal
|
|
|
|
// "Under the Hood", April 1996
|
|
|
|
//====================================
|
|
|
|
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winperf.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#pragma hdrstop
|
|
|
|
#include "titledb.h"
|
|
|
|
#include "objlist.h"
|
|
|
|
#include "perfobj.h"
|
|
|
|
#include "makeptr.h"
|
|
|
|
|
|
|
|
CPerfObjectList::CPerfObjectList(
|
2011-03-29 19:21:57 +00:00
|
|
|
CPerfSnapshot * const pPerfSnapshot,
|
|
|
|
CPerfTitleDatabase * const pPerfTitleDatabase )
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
m_pPerfSnapshot = pPerfSnapshot;
|
|
|
|
m_pPerfCounterTitles = pPerfTitleDatabase;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPerfObject *
|
|
|
|
CPerfObjectList::GetFirstPerfObject( void )
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
m_currentObjectListIndex = 0;
|
|
|
|
if ( m_currentObjectListIndex >= m_pPerfSnapshot->GetNumObjectTypes() )
|
|
|
|
return 0;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
m_pCurrObjectType =
|
|
|
|
(PPERF_OBJECT_TYPE)m_pPerfSnapshot->GetPostHeaderPointer();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
return new CPerfObject( m_pCurrObjectType, m_pPerfCounterTitles );
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPerfObject *
|
|
|
|
CPerfObjectList::GetNextPerfObject( void )
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
// Are we at the last object in the list? Return NULL if so.
|
|
|
|
if ( ++m_currentObjectListIndex >= m_pPerfSnapshot->GetNumObjectTypes() )
|
|
|
|
return 0;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
// Advance to the next PERF_OBJECT_TYPE structure
|
|
|
|
m_pCurrObjectType = MakePtr(PPERF_OBJECT_TYPE,
|
|
|
|
m_pCurrObjectType,
|
|
|
|
m_pCurrObjectType->TotalByteLength );
|
|
|
|
|
|
|
|
return new CPerfObject( m_pCurrObjectType, m_pPerfCounterTitles );
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
CPerfObject *
|
|
|
|
CPerfObjectList::GetPerfObject( PCTSTR const pszObjListName )
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
DWORD objListIdx
|
|
|
|
= m_pPerfCounterTitles->GetIndexFromTitleString( pszObjListName );
|
|
|
|
if ( 0 == objListIdx )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Point at first PERF_OBJECT_TYPE, and loop through the list, looking
|
|
|
|
// for one that matches.
|
|
|
|
PPERF_OBJECT_TYPE pCurrObjectType =
|
|
|
|
(PPERF_OBJECT_TYPE)m_pPerfSnapshot->GetPostHeaderPointer();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
for ( unsigned i=0; i < m_pPerfSnapshot->GetNumObjectTypes(); i++ )
|
|
|
|
{
|
|
|
|
// Is this the one that matches?
|
|
|
|
if ( pCurrObjectType->ObjectNameTitleIndex == objListIdx )
|
|
|
|
return new CPerfObject(pCurrObjectType, m_pPerfCounterTitles);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
// Nope... try the next object type
|
|
|
|
pCurrObjectType = MakePtr( PPERF_OBJECT_TYPE,
|
|
|
|
pCurrObjectType,
|
|
|
|
pCurrObjectType->TotalByteLength );
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
return 0;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|