mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Fixed line endings and applied gitignore
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
// MakePtr is a macro that allows you to easily add two values (including
|
||||
// pointers) together without dealing with C's pointer arithmetic. It
|
||||
// essentially treats the last two parameters as DWORDs. The first
|
||||
// parameter is used to typecast the result to the appropriate pointer type.
|
||||
#ifdef _WIN64
|
||||
#define MakePtr(cast, ptr, addValue) (cast)( (DWORD64)(ptr) + (DWORD64)(addValue))
|
||||
#else
|
||||
#define MakePtr(cast, ptr, addValue) (cast)( (DWORD)(ptr) + (DWORD)(addValue))
|
||||
#endif
|
||||
|
||||
// MakePtr is a macro that allows you to easily add two values (including
|
||||
// pointers) together without dealing with C's pointer arithmetic. It
|
||||
// essentially treats the last two parameters as DWORDs. The first
|
||||
// parameter is used to typecast the result to the appropriate pointer type.
|
||||
#ifdef _WIN64
|
||||
#define MakePtr(cast, ptr, addValue) (cast)( (DWORD64)(ptr) + (DWORD64)(addValue))
|
||||
#else
|
||||
#define MakePtr(cast, ptr, addValue) (cast)( (DWORD)(ptr) + (DWORD)(addValue))
|
||||
#endif
|
||||
|
||||
|
@ -1,137 +1,137 @@
|
||||
//====================================
|
||||
// File: OBJINST.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 "objinst.h"
|
||||
#include "perfcntr.h"
|
||||
#include "makeptr.h"
|
||||
|
||||
CPerfObjectInstance::CPerfObjectInstance(
|
||||
PPERF_INSTANCE_DEFINITION const pPerfInstDef,
|
||||
PPERF_COUNTER_DEFINITION const pPerfCntrDef,
|
||||
DWORD nCounters, CPerfTitleDatabase * const pPerfCounterTitles,
|
||||
BOOL fDummy)
|
||||
{
|
||||
m_pPerfInstDef = pPerfInstDef;
|
||||
m_pPerfCntrDef = pPerfCntrDef;
|
||||
m_nCounters = nCounters;
|
||||
m_pPerfCounterTitles = pPerfCounterTitles;
|
||||
|
||||
m_fDummy = fDummy;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfObjectInstance::GetObjectInstanceName(
|
||||
PTSTR pszObjInstName, DWORD nSize )
|
||||
{
|
||||
if ( m_fDummy )
|
||||
{
|
||||
*pszObjInstName = 0; // Return an empty string
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( nSize < (m_pPerfInstDef->NameLength / sizeof(TCHAR)) )
|
||||
return FALSE;
|
||||
|
||||
PWSTR pszName = MakePtr(PWSTR, m_pPerfInstDef, m_pPerfInstDef->NameOffset);
|
||||
|
||||
#ifdef UNICODE
|
||||
lstrcpy( pszObjInstName, pszName );
|
||||
#else
|
||||
wcstombs( pszObjInstName, pszName, nSize );
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::MakeCounter( PPERF_COUNTER_DEFINITION const pCounterDef )
|
||||
{
|
||||
// Look up the name of this counter in the title database
|
||||
PTSTR pszName = m_pPerfCounterTitles->GetTitleStringFromIndex(
|
||||
pCounterDef->CounterNameTitleIndex );
|
||||
|
||||
DWORD nInstanceDefSize = m_fDummy ? 0 : m_pPerfInstDef->ByteLength;
|
||||
|
||||
// Create a new CPerfCounter. The caller is responsible for deleting it.
|
||||
return new CPerfCounter(pszName,
|
||||
pCounterDef->CounterType,
|
||||
MakePtr( PBYTE, m_pPerfInstDef,
|
||||
nInstanceDefSize +
|
||||
pCounterDef->CounterOffset ),
|
||||
pCounterDef->CounterSize );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetCounterByIndex( DWORD index )
|
||||
{
|
||||
PPERF_COUNTER_DEFINITION pCurrentCounter;
|
||||
|
||||
if ( index >= m_nCounters )
|
||||
return 0;
|
||||
|
||||
pCurrentCounter = m_pPerfCntrDef;
|
||||
|
||||
// Find the correct PERF_COUNTER_DEFINITION by looping
|
||||
for ( DWORD i = 0; i < index; i++ )
|
||||
{
|
||||
pCurrentCounter = MakePtr( PPERF_COUNTER_DEFINITION,
|
||||
pCurrentCounter,
|
||||
pCurrentCounter->ByteLength );
|
||||
}
|
||||
|
||||
if ( pCurrentCounter->ByteLength == 0 )
|
||||
return 0;
|
||||
|
||||
return MakeCounter( pCurrentCounter );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetFirstCounter( void )
|
||||
{
|
||||
m_currentCounter = 0;
|
||||
return GetCounterByIndex( m_currentCounter );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetNextCounter( void )
|
||||
{
|
||||
m_currentCounter++;
|
||||
return GetCounterByIndex( m_currentCounter );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetCounterByName( PCTSTR const pszName )
|
||||
{
|
||||
DWORD cntrIdx = m_pPerfCounterTitles->GetIndexFromTitleString(pszName);
|
||||
if ( cntrIdx == 0 )
|
||||
return 0;
|
||||
|
||||
PPERF_COUNTER_DEFINITION pCurrentCounter = m_pPerfCntrDef;
|
||||
|
||||
// Find the correct PERF_COUNTER_DEFINITION by looping and comparing
|
||||
for ( DWORD i = 0; i < m_nCounters; i++ )
|
||||
{
|
||||
if ( pCurrentCounter->CounterNameTitleIndex == cntrIdx )
|
||||
return MakeCounter( pCurrentCounter );
|
||||
|
||||
// Nope. Not this one. Advance to the next counter
|
||||
pCurrentCounter = MakePtr( PPERF_COUNTER_DEFINITION,
|
||||
pCurrentCounter,
|
||||
pCurrentCounter->ByteLength );
|
||||
}
|
||||
|
||||
return 0;
|
||||
//====================================
|
||||
// File: OBJINST.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 "objinst.h"
|
||||
#include "perfcntr.h"
|
||||
#include "makeptr.h"
|
||||
|
||||
CPerfObjectInstance::CPerfObjectInstance(
|
||||
PPERF_INSTANCE_DEFINITION const pPerfInstDef,
|
||||
PPERF_COUNTER_DEFINITION const pPerfCntrDef,
|
||||
DWORD nCounters, CPerfTitleDatabase * const pPerfCounterTitles,
|
||||
BOOL fDummy)
|
||||
{
|
||||
m_pPerfInstDef = pPerfInstDef;
|
||||
m_pPerfCntrDef = pPerfCntrDef;
|
||||
m_nCounters = nCounters;
|
||||
m_pPerfCounterTitles = pPerfCounterTitles;
|
||||
|
||||
m_fDummy = fDummy;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfObjectInstance::GetObjectInstanceName(
|
||||
PTSTR pszObjInstName, DWORD nSize )
|
||||
{
|
||||
if ( m_fDummy )
|
||||
{
|
||||
*pszObjInstName = 0; // Return an empty string
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( nSize < (m_pPerfInstDef->NameLength / sizeof(TCHAR)) )
|
||||
return FALSE;
|
||||
|
||||
PWSTR pszName = MakePtr(PWSTR, m_pPerfInstDef, m_pPerfInstDef->NameOffset);
|
||||
|
||||
#ifdef UNICODE
|
||||
lstrcpy( pszObjInstName, pszName );
|
||||
#else
|
||||
wcstombs( pszObjInstName, pszName, nSize );
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::MakeCounter( PPERF_COUNTER_DEFINITION const pCounterDef )
|
||||
{
|
||||
// Look up the name of this counter in the title database
|
||||
PTSTR pszName = m_pPerfCounterTitles->GetTitleStringFromIndex(
|
||||
pCounterDef->CounterNameTitleIndex );
|
||||
|
||||
DWORD nInstanceDefSize = m_fDummy ? 0 : m_pPerfInstDef->ByteLength;
|
||||
|
||||
// Create a new CPerfCounter. The caller is responsible for deleting it.
|
||||
return new CPerfCounter(pszName,
|
||||
pCounterDef->CounterType,
|
||||
MakePtr( PBYTE, m_pPerfInstDef,
|
||||
nInstanceDefSize +
|
||||
pCounterDef->CounterOffset ),
|
||||
pCounterDef->CounterSize );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetCounterByIndex( DWORD index )
|
||||
{
|
||||
PPERF_COUNTER_DEFINITION pCurrentCounter;
|
||||
|
||||
if ( index >= m_nCounters )
|
||||
return 0;
|
||||
|
||||
pCurrentCounter = m_pPerfCntrDef;
|
||||
|
||||
// Find the correct PERF_COUNTER_DEFINITION by looping
|
||||
for ( DWORD i = 0; i < index; i++ )
|
||||
{
|
||||
pCurrentCounter = MakePtr( PPERF_COUNTER_DEFINITION,
|
||||
pCurrentCounter,
|
||||
pCurrentCounter->ByteLength );
|
||||
}
|
||||
|
||||
if ( pCurrentCounter->ByteLength == 0 )
|
||||
return 0;
|
||||
|
||||
return MakeCounter( pCurrentCounter );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetFirstCounter( void )
|
||||
{
|
||||
m_currentCounter = 0;
|
||||
return GetCounterByIndex( m_currentCounter );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetNextCounter( void )
|
||||
{
|
||||
m_currentCounter++;
|
||||
return GetCounterByIndex( m_currentCounter );
|
||||
}
|
||||
|
||||
CPerfCounter *
|
||||
CPerfObjectInstance::GetCounterByName( PCTSTR const pszName )
|
||||
{
|
||||
DWORD cntrIdx = m_pPerfCounterTitles->GetIndexFromTitleString(pszName);
|
||||
if ( cntrIdx == 0 )
|
||||
return 0;
|
||||
|
||||
PPERF_COUNTER_DEFINITION pCurrentCounter = m_pPerfCntrDef;
|
||||
|
||||
// Find the correct PERF_COUNTER_DEFINITION by looping and comparing
|
||||
for ( DWORD i = 0; i < m_nCounters; i++ )
|
||||
{
|
||||
if ( pCurrentCounter->CounterNameTitleIndex == cntrIdx )
|
||||
return MakeCounter( pCurrentCounter );
|
||||
|
||||
// Nope. Not this one. Advance to the next counter
|
||||
pCurrentCounter = MakePtr( PPERF_COUNTER_DEFINITION,
|
||||
pCurrentCounter,
|
||||
pCurrentCounter->ByteLength );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,59 +1,59 @@
|
||||
#ifndef __Obinst_h__
|
||||
#define __Objinst_h__
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
|
||||
class CPerfTitleDatabase;
|
||||
class CPerfCounter;
|
||||
|
||||
class CPerfObjectInstance
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfObjectInstance(
|
||||
PPERF_INSTANCE_DEFINITION const pPerfInstDef,
|
||||
PPERF_COUNTER_DEFINITION const pPerfCntrDef, DWORD nCounters,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase, BOOL fDummy );
|
||||
|
||||
~CPerfObjectInstance( void ){ }
|
||||
|
||||
BOOL GetObjectInstanceName( PTSTR pszObjInstName, DWORD nSize );
|
||||
|
||||
// Functions that return CPerfCounter pointers. Caller is
|
||||
// responsible for deleting the CPerfCounter * when done with it.
|
||||
|
||||
CPerfCounter * GetFirstCounter( void );
|
||||
|
||||
CPerfCounter * GetNextCounter( void );
|
||||
|
||||
CPerfCounter * GetCounterByName( PCTSTR const pszName );
|
||||
|
||||
protected:
|
||||
|
||||
PPERF_INSTANCE_DEFINITION m_pPerfInstDef;
|
||||
|
||||
unsigned m_nCounters;
|
||||
|
||||
unsigned m_currentCounter;
|
||||
|
||||
PPERF_COUNTER_DEFINITION m_pPerfCntrDef;
|
||||
|
||||
CPerfTitleDatabase * m_pPerfCounterTitles;
|
||||
|
||||
CPerfCounter * MakeCounter( PPERF_COUNTER_DEFINITION const pCounter );
|
||||
|
||||
CPerfCounter * GetCounterByIndex( DWORD index );
|
||||
|
||||
CPerfTitleDatabase *m_pCounterTitleDatabase;
|
||||
|
||||
BOOL m_fDummy; // FALSE normally, TRUE when an object with no instances
|
||||
};
|
||||
|
||||
typedef CPerfObjectInstance * PCPerfObjectInstance;
|
||||
|
||||
#ifndef __Obinst_h__
|
||||
#define __Objinst_h__
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
|
||||
class CPerfTitleDatabase;
|
||||
class CPerfCounter;
|
||||
|
||||
class CPerfObjectInstance
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfObjectInstance(
|
||||
PPERF_INSTANCE_DEFINITION const pPerfInstDef,
|
||||
PPERF_COUNTER_DEFINITION const pPerfCntrDef, DWORD nCounters,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase, BOOL fDummy );
|
||||
|
||||
~CPerfObjectInstance( void ){ }
|
||||
|
||||
BOOL GetObjectInstanceName( PTSTR pszObjInstName, DWORD nSize );
|
||||
|
||||
// Functions that return CPerfCounter pointers. Caller is
|
||||
// responsible for deleting the CPerfCounter * when done with it.
|
||||
|
||||
CPerfCounter * GetFirstCounter( void );
|
||||
|
||||
CPerfCounter * GetNextCounter( void );
|
||||
|
||||
CPerfCounter * GetCounterByName( PCTSTR const pszName );
|
||||
|
||||
protected:
|
||||
|
||||
PPERF_INSTANCE_DEFINITION m_pPerfInstDef;
|
||||
|
||||
unsigned m_nCounters;
|
||||
|
||||
unsigned m_currentCounter;
|
||||
|
||||
PPERF_COUNTER_DEFINITION m_pPerfCntrDef;
|
||||
|
||||
CPerfTitleDatabase * m_pPerfCounterTitles;
|
||||
|
||||
CPerfCounter * MakeCounter( PPERF_COUNTER_DEFINITION const pCounter );
|
||||
|
||||
CPerfCounter * GetCounterByIndex( DWORD index );
|
||||
|
||||
CPerfTitleDatabase *m_pCounterTitleDatabase;
|
||||
|
||||
BOOL m_fDummy; // FALSE normally, TRUE when an object with no instances
|
||||
};
|
||||
|
||||
typedef CPerfObjectInstance * PCPerfObjectInstance;
|
||||
|
||||
#endif
|
@ -1,83 +1,83 @@
|
||||
//====================================
|
||||
// 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(
|
||||
CPerfSnapshot * const pPerfSnapshot,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase )
|
||||
{
|
||||
m_pPerfSnapshot = pPerfSnapshot;
|
||||
m_pPerfCounterTitles = pPerfTitleDatabase;
|
||||
}
|
||||
|
||||
CPerfObject *
|
||||
CPerfObjectList::GetFirstPerfObject( void )
|
||||
{
|
||||
m_currentObjectListIndex = 0;
|
||||
if ( m_currentObjectListIndex >= m_pPerfSnapshot->GetNumObjectTypes() )
|
||||
return 0;
|
||||
|
||||
m_pCurrObjectType =
|
||||
(PPERF_OBJECT_TYPE)m_pPerfSnapshot->GetPostHeaderPointer();
|
||||
|
||||
return new CPerfObject( m_pCurrObjectType, m_pPerfCounterTitles );
|
||||
}
|
||||
|
||||
CPerfObject *
|
||||
CPerfObjectList::GetNextPerfObject( void )
|
||||
{
|
||||
// Are we at the last object in the list? Return nullptr if so.
|
||||
if ( ++m_currentObjectListIndex >= m_pPerfSnapshot->GetNumObjectTypes() )
|
||||
return 0;
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
CPerfObject *
|
||||
CPerfObjectList::GetPerfObject( PCTSTR const pszObjListName )
|
||||
{
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
// Nope... try the next object type
|
||||
pCurrObjectType = MakePtr( PPERF_OBJECT_TYPE,
|
||||
pCurrObjectType,
|
||||
pCurrObjectType->TotalByteLength );
|
||||
}
|
||||
|
||||
return 0;
|
||||
//====================================
|
||||
// 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(
|
||||
CPerfSnapshot * const pPerfSnapshot,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase )
|
||||
{
|
||||
m_pPerfSnapshot = pPerfSnapshot;
|
||||
m_pPerfCounterTitles = pPerfTitleDatabase;
|
||||
}
|
||||
|
||||
CPerfObject *
|
||||
CPerfObjectList::GetFirstPerfObject( void )
|
||||
{
|
||||
m_currentObjectListIndex = 0;
|
||||
if ( m_currentObjectListIndex >= m_pPerfSnapshot->GetNumObjectTypes() )
|
||||
return 0;
|
||||
|
||||
m_pCurrObjectType =
|
||||
(PPERF_OBJECT_TYPE)m_pPerfSnapshot->GetPostHeaderPointer();
|
||||
|
||||
return new CPerfObject( m_pCurrObjectType, m_pPerfCounterTitles );
|
||||
}
|
||||
|
||||
CPerfObject *
|
||||
CPerfObjectList::GetNextPerfObject( void )
|
||||
{
|
||||
// Are we at the last object in the list? Return nullptr if so.
|
||||
if ( ++m_currentObjectListIndex >= m_pPerfSnapshot->GetNumObjectTypes() )
|
||||
return 0;
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
CPerfObject *
|
||||
CPerfObjectList::GetPerfObject( PCTSTR const pszObjListName )
|
||||
{
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
// Nope... try the next object type
|
||||
pCurrObjectType = MakePtr( PPERF_OBJECT_TYPE,
|
||||
pCurrObjectType,
|
||||
pCurrObjectType->TotalByteLength );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,46 +1,46 @@
|
||||
#ifndef __Objlist_h__
|
||||
#define __Objlist_h__
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
#ifndef __Perfsnap_h__
|
||||
#include "perfsnap.h"
|
||||
#endif
|
||||
|
||||
class CPerfObject;
|
||||
|
||||
class CPerfObjectList
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfObjectList(CPerfSnapshot * const pPerfSnapshot,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase );
|
||||
|
||||
~CPerfObjectList( void ){ };
|
||||
|
||||
// Functions that return CPerfObject pointers. Caller is responsible
|
||||
// for deleting the CPerfObject * when done with it.
|
||||
|
||||
CPerfObject * GetFirstPerfObject( void );
|
||||
|
||||
CPerfObject * GetNextPerfObject( void );
|
||||
|
||||
CPerfObject * GetPerfObject( PCTSTR const pszObjListName );
|
||||
|
||||
protected:
|
||||
|
||||
CPerfSnapshot * m_pPerfSnapshot;
|
||||
|
||||
CPerfTitleDatabase * m_pPerfCounterTitles;
|
||||
|
||||
unsigned m_currentObjectListIndex;
|
||||
|
||||
PPERF_OBJECT_TYPE m_pCurrObjectType; // current first/next object ptr
|
||||
};
|
||||
|
||||
typedef CPerfObjectList * PCPerfObjectList;
|
||||
#ifndef __Objlist_h__
|
||||
#define __Objlist_h__
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
#ifndef __Perfsnap_h__
|
||||
#include "perfsnap.h"
|
||||
#endif
|
||||
|
||||
class CPerfObject;
|
||||
|
||||
class CPerfObjectList
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfObjectList(CPerfSnapshot * const pPerfSnapshot,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase );
|
||||
|
||||
~CPerfObjectList( void ){ };
|
||||
|
||||
// Functions that return CPerfObject pointers. Caller is responsible
|
||||
// for deleting the CPerfObject * when done with it.
|
||||
|
||||
CPerfObject * GetFirstPerfObject( void );
|
||||
|
||||
CPerfObject * GetNextPerfObject( void );
|
||||
|
||||
CPerfObject * GetPerfObject( PCTSTR const pszObjListName );
|
||||
|
||||
protected:
|
||||
|
||||
CPerfSnapshot * m_pPerfSnapshot;
|
||||
|
||||
CPerfTitleDatabase * m_pPerfCounterTitles;
|
||||
|
||||
unsigned m_currentObjectListIndex;
|
||||
|
||||
PPERF_OBJECT_TYPE m_pCurrObjectType; // current first/next object ptr
|
||||
};
|
||||
|
||||
typedef CPerfObjectList * PCPerfObjectList;
|
||||
#endif
|
@ -1,123 +1,123 @@
|
||||
//====================================
|
||||
// File: PERFCNTR.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>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <tchar.h>
|
||||
#pragma hdrstop
|
||||
#include "perfcntr.h"
|
||||
|
||||
CPerfCounter::CPerfCounter( PTSTR const pszName, DWORD type,
|
||||
PBYTE const pData, DWORD cbData )
|
||||
{
|
||||
m_pszName = _tcsdup( pszName );
|
||||
m_type = type;
|
||||
m_cbData = cbData;
|
||||
m_pData = new BYTE[m_cbData];
|
||||
memcpy( m_pData, pData, m_cbData );
|
||||
}
|
||||
|
||||
CPerfCounter::~CPerfCounter( void )
|
||||
{
|
||||
free( m_pszName );
|
||||
delete []m_pData;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfCounter::GetData( PBYTE pBuffer, DWORD cbBuffer, DWORD *pType )
|
||||
{
|
||||
if ( cbBuffer < m_cbData ) // Make sure the buffer is big enough
|
||||
return FALSE;
|
||||
|
||||
memcpy( pBuffer, m_pData, m_cbData ); // copy the data
|
||||
|
||||
if ( pType ) // If the user wants the type, give it to them
|
||||
*pType = m_type;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfCounter::Format( PTSTR pszBuffer, DWORD nSize, BOOL fHex )
|
||||
{
|
||||
// Do better formatting!!! Check length!!!
|
||||
|
||||
PTSTR pszPrefix = TEXT("");
|
||||
TCHAR szTemp[512];
|
||||
|
||||
// First, ascertain the basic type (number, counter, text, or zero)
|
||||
switch ( m_type & 0x00000C00 )
|
||||
{
|
||||
case PERF_TYPE_ZERO:
|
||||
{
|
||||
wsprintf( pszBuffer, TEXT("ZERO") ); return TRUE;
|
||||
}
|
||||
case PERF_TYPE_TEXT:
|
||||
{
|
||||
wsprintf( pszBuffer, TEXT("text counter") ); return TRUE;
|
||||
}
|
||||
case PERF_TYPE_COUNTER:
|
||||
{
|
||||
switch( m_type & 0x00070000 )
|
||||
{
|
||||
case PERF_COUNTER_RATE:
|
||||
pszPrefix = TEXT("counter rate "); break;
|
||||
case PERF_COUNTER_FRACTION:
|
||||
pszPrefix = TEXT("counter fraction "); break;
|
||||
case PERF_COUNTER_BASE:
|
||||
pszPrefix = TEXT("counter base "); break;
|
||||
case PERF_COUNTER_ELAPSED:
|
||||
pszPrefix = TEXT("counter elapsed "); break;
|
||||
case PERF_COUNTER_QUEUELEN:
|
||||
pszPrefix = TEXT("counter queuelen "); break;
|
||||
case PERF_COUNTER_HISTOGRAM:
|
||||
pszPrefix = TEXT("counter histogram "); break;
|
||||
default:
|
||||
pszPrefix = TEXT("counter value "); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PTSTR pszFmt = fHex ? TEXT("%s%Xh") : TEXT("%s%u");
|
||||
|
||||
switch ( m_cbData )
|
||||
{
|
||||
case 1: wsprintf(szTemp, pszFmt, pszPrefix, *(PBYTE)m_pData);
|
||||
break;
|
||||
case 2: wsprintf(szTemp, pszFmt, pszPrefix, *(PWORD)m_pData);
|
||||
break;
|
||||
case 4: wsprintf(szTemp, pszFmt, pszPrefix, *(PDWORD)m_pData);
|
||||
break;
|
||||
case 8: // Danger! Assumes little-endian (X86) byte ordering
|
||||
wsprintf( szTemp, TEXT("%s%X%X"), pszPrefix,
|
||||
*(PDWORD)(m_pData+4), *(PDWORD)m_pData ); break;
|
||||
break;
|
||||
|
||||
default: wsprintf( szTemp, TEXT("<unhandled size %u>"), m_cbData );
|
||||
}
|
||||
|
||||
switch ( m_type & 0x70000000 )
|
||||
{
|
||||
case PERF_DISPLAY_SECONDS:
|
||||
_tcscat( szTemp, TEXT(" secs") ); break;
|
||||
case PERF_DISPLAY_PERCENT:
|
||||
_tcscat( szTemp, TEXT(" %") ); break;
|
||||
case PERF_DISPLAY_PER_SEC:
|
||||
_tcscat( szTemp, TEXT(" /sec") ); break;
|
||||
}
|
||||
|
||||
lstrcpyn( pszBuffer, szTemp, nSize );
|
||||
|
||||
return TRUE;
|
||||
//====================================
|
||||
// File: PERFCNTR.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>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <tchar.h>
|
||||
#pragma hdrstop
|
||||
#include "perfcntr.h"
|
||||
|
||||
CPerfCounter::CPerfCounter( PTSTR const pszName, DWORD type,
|
||||
PBYTE const pData, DWORD cbData )
|
||||
{
|
||||
m_pszName = _tcsdup( pszName );
|
||||
m_type = type;
|
||||
m_cbData = cbData;
|
||||
m_pData = new BYTE[m_cbData];
|
||||
memcpy( m_pData, pData, m_cbData );
|
||||
}
|
||||
|
||||
CPerfCounter::~CPerfCounter( void )
|
||||
{
|
||||
free( m_pszName );
|
||||
delete []m_pData;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfCounter::GetData( PBYTE pBuffer, DWORD cbBuffer, DWORD *pType )
|
||||
{
|
||||
if ( cbBuffer < m_cbData ) // Make sure the buffer is big enough
|
||||
return FALSE;
|
||||
|
||||
memcpy( pBuffer, m_pData, m_cbData ); // copy the data
|
||||
|
||||
if ( pType ) // If the user wants the type, give it to them
|
||||
*pType = m_type;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfCounter::Format( PTSTR pszBuffer, DWORD nSize, BOOL fHex )
|
||||
{
|
||||
// Do better formatting!!! Check length!!!
|
||||
|
||||
PTSTR pszPrefix = TEXT("");
|
||||
TCHAR szTemp[512];
|
||||
|
||||
// First, ascertain the basic type (number, counter, text, or zero)
|
||||
switch ( m_type & 0x00000C00 )
|
||||
{
|
||||
case PERF_TYPE_ZERO:
|
||||
{
|
||||
wsprintf( pszBuffer, TEXT("ZERO") ); return TRUE;
|
||||
}
|
||||
case PERF_TYPE_TEXT:
|
||||
{
|
||||
wsprintf( pszBuffer, TEXT("text counter") ); return TRUE;
|
||||
}
|
||||
case PERF_TYPE_COUNTER:
|
||||
{
|
||||
switch( m_type & 0x00070000 )
|
||||
{
|
||||
case PERF_COUNTER_RATE:
|
||||
pszPrefix = TEXT("counter rate "); break;
|
||||
case PERF_COUNTER_FRACTION:
|
||||
pszPrefix = TEXT("counter fraction "); break;
|
||||
case PERF_COUNTER_BASE:
|
||||
pszPrefix = TEXT("counter base "); break;
|
||||
case PERF_COUNTER_ELAPSED:
|
||||
pszPrefix = TEXT("counter elapsed "); break;
|
||||
case PERF_COUNTER_QUEUELEN:
|
||||
pszPrefix = TEXT("counter queuelen "); break;
|
||||
case PERF_COUNTER_HISTOGRAM:
|
||||
pszPrefix = TEXT("counter histogram "); break;
|
||||
default:
|
||||
pszPrefix = TEXT("counter value "); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PTSTR pszFmt = fHex ? TEXT("%s%Xh") : TEXT("%s%u");
|
||||
|
||||
switch ( m_cbData )
|
||||
{
|
||||
case 1: wsprintf(szTemp, pszFmt, pszPrefix, *(PBYTE)m_pData);
|
||||
break;
|
||||
case 2: wsprintf(szTemp, pszFmt, pszPrefix, *(PWORD)m_pData);
|
||||
break;
|
||||
case 4: wsprintf(szTemp, pszFmt, pszPrefix, *(PDWORD)m_pData);
|
||||
break;
|
||||
case 8: // Danger! Assumes little-endian (X86) byte ordering
|
||||
wsprintf( szTemp, TEXT("%s%X%X"), pszPrefix,
|
||||
*(PDWORD)(m_pData+4), *(PDWORD)m_pData ); break;
|
||||
break;
|
||||
|
||||
default: wsprintf( szTemp, TEXT("<unhandled size %u>"), m_cbData );
|
||||
}
|
||||
|
||||
switch ( m_type & 0x70000000 )
|
||||
{
|
||||
case PERF_DISPLAY_SECONDS:
|
||||
_tcscat( szTemp, TEXT(" secs") ); break;
|
||||
case PERF_DISPLAY_PERCENT:
|
||||
_tcscat( szTemp, TEXT(" %") ); break;
|
||||
case PERF_DISPLAY_PER_SEC:
|
||||
_tcscat( szTemp, TEXT(" /sec") ); break;
|
||||
}
|
||||
|
||||
lstrcpyn( pszBuffer, szTemp, nSize );
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -1,35 +1,35 @@
|
||||
#ifndef __Perfcntr_h__
|
||||
#define __Perfcntr_h__
|
||||
|
||||
class CPerfCounter
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfCounter( PTSTR const pszName, DWORD type,
|
||||
PBYTE const pData, DWORD cbData );
|
||||
|
||||
~CPerfCounter( void );
|
||||
|
||||
PTSTR GetName( void ) { return m_pszName; }
|
||||
|
||||
DWORD GetType( void ) { return m_type; }
|
||||
|
||||
DWORD GetSize( void ) { return m_cbData; }
|
||||
|
||||
BOOL GetData( PBYTE pBuffer, DWORD cbBuffer, DWORD *pType );
|
||||
|
||||
BOOL Format( PTSTR pszBuffer, DWORD nSize, BOOL fHex = FALSE );
|
||||
|
||||
protected:
|
||||
|
||||
PTSTR m_pszName;
|
||||
|
||||
DWORD m_type;
|
||||
|
||||
PBYTE m_pData;
|
||||
|
||||
DWORD m_cbData;
|
||||
};
|
||||
|
||||
typedef CPerfCounter * PCPerfCounter;
|
||||
#ifndef __Perfcntr_h__
|
||||
#define __Perfcntr_h__
|
||||
|
||||
class CPerfCounter
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfCounter( PTSTR const pszName, DWORD type,
|
||||
PBYTE const pData, DWORD cbData );
|
||||
|
||||
~CPerfCounter( void );
|
||||
|
||||
PTSTR GetName( void ) { return m_pszName; }
|
||||
|
||||
DWORD GetType( void ) { return m_type; }
|
||||
|
||||
DWORD GetSize( void ) { return m_cbData; }
|
||||
|
||||
BOOL GetData( PBYTE pBuffer, DWORD cbBuffer, DWORD *pType );
|
||||
|
||||
BOOL Format( PTSTR pszBuffer, DWORD nSize, BOOL fHex = FALSE );
|
||||
|
||||
protected:
|
||||
|
||||
PTSTR m_pszName;
|
||||
|
||||
DWORD m_type;
|
||||
|
||||
PBYTE m_pData;
|
||||
|
||||
DWORD m_cbData;
|
||||
};
|
||||
|
||||
typedef CPerfCounter * PCPerfCounter;
|
||||
#endif
|
@ -1,206 +1,206 @@
|
||||
/*
|
||||
Copyright (C) 2004 Kimmo Pekkola
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
#include "Titledb.h"
|
||||
#include "PerfSnap.h"
|
||||
#include "PerfObj.h"
|
||||
#include "PerfCntr.h"
|
||||
#include "ObjList.h"
|
||||
#include "ObjInst.h"
|
||||
#include "../API/RainmeterAPI.h"
|
||||
#include "../../Common/RawString.h"
|
||||
|
||||
struct MeasureData
|
||||
{
|
||||
RawString objectName;
|
||||
RawString counterName;
|
||||
RawString instanceName;
|
||||
ULONGLONG oldValue;
|
||||
bool difference;
|
||||
bool firstTime;
|
||||
|
||||
MeasureData() :
|
||||
oldValue(),
|
||||
difference(false),
|
||||
firstTime(true)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static CPerfTitleDatabase g_TitleCounter(PERF_TITLE_COUNTER);
|
||||
|
||||
ULONGLONG GetPerfData(PCTSTR ObjectName, PCTSTR InstanceName, PCTSTR CounterName);
|
||||
|
||||
PLUGIN_EXPORT void Initialize(void** data, void* rm)
|
||||
{
|
||||
MeasureData* measure = new MeasureData;
|
||||
*data = measure;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
bool changed = false;
|
||||
|
||||
LPCWSTR value = RmReadString(rm, L"PerfMonObject", L"");
|
||||
if (_wcsicmp(value, measure->objectName.c_str()) != 0)
|
||||
{
|
||||
measure->objectName = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
value = RmReadString(rm, L"PerfMonCounter", L"");
|
||||
if (_wcsicmp(value, measure->counterName.c_str()) != 0)
|
||||
{
|
||||
measure->counterName = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
value = RmReadString(rm, L"PerfMonInstance", L"");
|
||||
if (_wcsicmp(value, measure->instanceName.c_str()) != 0)
|
||||
{
|
||||
measure->instanceName = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
bool diff = RmReadInt(rm, L"PerfMonDifference", 1) == 1;
|
||||
if (diff != measure->difference)
|
||||
{
|
||||
measure->difference = diff;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
measure->oldValue = 0;
|
||||
measure->firstTime = true;
|
||||
*maxValue = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT double Update(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
double value = 0;
|
||||
|
||||
ULONGLONG longValue = GetPerfData(
|
||||
measure->objectName.c_str(),
|
||||
measure->instanceName.c_str(),
|
||||
measure->counterName.c_str());
|
||||
|
||||
if (measure->difference)
|
||||
{
|
||||
// Compare with the old value
|
||||
if (!measure->firstTime)
|
||||
{
|
||||
value = (double)(longValue - measure->oldValue);
|
||||
}
|
||||
|
||||
measure->oldValue = longValue;
|
||||
measure->firstTime = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (double)longValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void Finalize(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
delete measure;
|
||||
|
||||
CPerfSnapshot::CleanUp();
|
||||
}
|
||||
|
||||
ULONGLONG GetPerfData(LPCWSTR objectName, LPCWSTR instanceName, LPCWSTR counterName)
|
||||
{
|
||||
BYTE data[256];
|
||||
WCHAR name[256];
|
||||
ULONGLONG value = 0;
|
||||
|
||||
CPerfSnapshot snapshot(&g_TitleCounter);
|
||||
CPerfObjectList objList(&snapshot, &g_TitleCounter);
|
||||
|
||||
if (snapshot.TakeSnapshot(objectName))
|
||||
{
|
||||
CPerfObject* pPerfObj = objList.GetPerfObject(objectName);
|
||||
|
||||
if (pPerfObj)
|
||||
{
|
||||
for (CPerfObjectInstance* pObjInst = pPerfObj->GetFirstObjectInstance();
|
||||
pObjInst != nullptr;
|
||||
pObjInst = pPerfObj->GetNextObjectInstance())
|
||||
{
|
||||
if (*instanceName)
|
||||
{
|
||||
if (pObjInst->GetObjectInstanceName(name, 256))
|
||||
{
|
||||
if (_wcsicmp(instanceName, name) != 0)
|
||||
{
|
||||
delete pObjInst;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pObjInst;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
CPerfCounter* pPerfCntr = pObjInst->GetCounterByName(counterName);
|
||||
if (pPerfCntr != nullptr)
|
||||
{
|
||||
pPerfCntr->GetData(data, 256, nullptr);
|
||||
|
||||
if (pPerfCntr->GetSize() == 1)
|
||||
{
|
||||
value = *(BYTE*)data;
|
||||
}
|
||||
else if (pPerfCntr->GetSize() == 2)
|
||||
{
|
||||
value = *(WORD*)data;
|
||||
}
|
||||
else if (pPerfCntr->GetSize() == 4)
|
||||
{
|
||||
value = *(DWORD*)data;
|
||||
}
|
||||
else if (pPerfCntr->GetSize() == 8)
|
||||
{
|
||||
value = *(ULONGLONG*)data;
|
||||
}
|
||||
|
||||
delete pPerfCntr;
|
||||
delete pObjInst;
|
||||
break; // No need to continue
|
||||
}
|
||||
|
||||
delete pObjInst;
|
||||
}
|
||||
|
||||
delete pPerfObj;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
/*
|
||||
Copyright (C) 2004 Kimmo Pekkola
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
#include "Titledb.h"
|
||||
#include "PerfSnap.h"
|
||||
#include "PerfObj.h"
|
||||
#include "PerfCntr.h"
|
||||
#include "ObjList.h"
|
||||
#include "ObjInst.h"
|
||||
#include "../API/RainmeterAPI.h"
|
||||
#include "../../Common/RawString.h"
|
||||
|
||||
struct MeasureData
|
||||
{
|
||||
RawString objectName;
|
||||
RawString counterName;
|
||||
RawString instanceName;
|
||||
ULONGLONG oldValue;
|
||||
bool difference;
|
||||
bool firstTime;
|
||||
|
||||
MeasureData() :
|
||||
oldValue(),
|
||||
difference(false),
|
||||
firstTime(true)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static CPerfTitleDatabase g_TitleCounter(PERF_TITLE_COUNTER);
|
||||
|
||||
ULONGLONG GetPerfData(PCTSTR ObjectName, PCTSTR InstanceName, PCTSTR CounterName);
|
||||
|
||||
PLUGIN_EXPORT void Initialize(void** data, void* rm)
|
||||
{
|
||||
MeasureData* measure = new MeasureData;
|
||||
*data = measure;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
bool changed = false;
|
||||
|
||||
LPCWSTR value = RmReadString(rm, L"PerfMonObject", L"");
|
||||
if (_wcsicmp(value, measure->objectName.c_str()) != 0)
|
||||
{
|
||||
measure->objectName = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
value = RmReadString(rm, L"PerfMonCounter", L"");
|
||||
if (_wcsicmp(value, measure->counterName.c_str()) != 0)
|
||||
{
|
||||
measure->counterName = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
value = RmReadString(rm, L"PerfMonInstance", L"");
|
||||
if (_wcsicmp(value, measure->instanceName.c_str()) != 0)
|
||||
{
|
||||
measure->instanceName = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
bool diff = RmReadInt(rm, L"PerfMonDifference", 1) == 1;
|
||||
if (diff != measure->difference)
|
||||
{
|
||||
measure->difference = diff;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
measure->oldValue = 0;
|
||||
measure->firstTime = true;
|
||||
*maxValue = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT double Update(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
double value = 0;
|
||||
|
||||
ULONGLONG longValue = GetPerfData(
|
||||
measure->objectName.c_str(),
|
||||
measure->instanceName.c_str(),
|
||||
measure->counterName.c_str());
|
||||
|
||||
if (measure->difference)
|
||||
{
|
||||
// Compare with the old value
|
||||
if (!measure->firstTime)
|
||||
{
|
||||
value = (double)(longValue - measure->oldValue);
|
||||
}
|
||||
|
||||
measure->oldValue = longValue;
|
||||
measure->firstTime = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (double)longValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void Finalize(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
delete measure;
|
||||
|
||||
CPerfSnapshot::CleanUp();
|
||||
}
|
||||
|
||||
ULONGLONG GetPerfData(LPCWSTR objectName, LPCWSTR instanceName, LPCWSTR counterName)
|
||||
{
|
||||
BYTE data[256];
|
||||
WCHAR name[256];
|
||||
ULONGLONG value = 0;
|
||||
|
||||
CPerfSnapshot snapshot(&g_TitleCounter);
|
||||
CPerfObjectList objList(&snapshot, &g_TitleCounter);
|
||||
|
||||
if (snapshot.TakeSnapshot(objectName))
|
||||
{
|
||||
CPerfObject* pPerfObj = objList.GetPerfObject(objectName);
|
||||
|
||||
if (pPerfObj)
|
||||
{
|
||||
for (CPerfObjectInstance* pObjInst = pPerfObj->GetFirstObjectInstance();
|
||||
pObjInst != nullptr;
|
||||
pObjInst = pPerfObj->GetNextObjectInstance())
|
||||
{
|
||||
if (*instanceName)
|
||||
{
|
||||
if (pObjInst->GetObjectInstanceName(name, 256))
|
||||
{
|
||||
if (_wcsicmp(instanceName, name) != 0)
|
||||
{
|
||||
delete pObjInst;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pObjInst;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
CPerfCounter* pPerfCntr = pObjInst->GetCounterByName(counterName);
|
||||
if (pPerfCntr != nullptr)
|
||||
{
|
||||
pPerfCntr->GetData(data, 256, nullptr);
|
||||
|
||||
if (pPerfCntr->GetSize() == 1)
|
||||
{
|
||||
value = *(BYTE*)data;
|
||||
}
|
||||
else if (pPerfCntr->GetSize() == 2)
|
||||
{
|
||||
value = *(WORD*)data;
|
||||
}
|
||||
else if (pPerfCntr->GetSize() == 4)
|
||||
{
|
||||
value = *(DWORD*)data;
|
||||
}
|
||||
else if (pPerfCntr->GetSize() == 8)
|
||||
{
|
||||
value = *(ULONGLONG*)data;
|
||||
}
|
||||
|
||||
delete pPerfCntr;
|
||||
delete pObjInst;
|
||||
break; // No need to continue
|
||||
}
|
||||
|
||||
delete pObjInst;
|
||||
}
|
||||
|
||||
delete pPerfObj;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -1,96 +1,96 @@
|
||||
//====================================
|
||||
// File: PERFOBJ.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 "perfobj.h"
|
||||
#include "objinst.h"
|
||||
#include "makeptr.h"
|
||||
|
||||
CPerfObject::CPerfObject( PPERF_OBJECT_TYPE const pObjectList,
|
||||
CPerfTitleDatabase * const pPerfCounterTitles)
|
||||
{
|
||||
m_pObjectList = pObjectList;
|
||||
m_pPerfCounterTitles = pPerfCounterTitles;
|
||||
}
|
||||
|
||||
CPerfObjectInstance *
|
||||
CPerfObject::GetFirstObjectInstance( void )
|
||||
{
|
||||
m_currentObjectInstance = 0;
|
||||
if ( m_currentObjectInstance >= GetObjectInstanceCount() )
|
||||
return 0;
|
||||
|
||||
// Point at the first PERF_INSTANCE_DEFINITION
|
||||
m_pCurrentObjectInstanceDefinition =
|
||||
MakePtr( PPERF_INSTANCE_DEFINITION, m_pObjectList,
|
||||
m_pObjectList->DefinitionLength );
|
||||
|
||||
return new CPerfObjectInstance(
|
||||
m_pCurrentObjectInstanceDefinition,
|
||||
MakePtr(PPERF_COUNTER_DEFINITION,
|
||||
m_pObjectList, m_pObjectList->HeaderLength),
|
||||
m_pObjectList->NumCounters,
|
||||
m_pPerfCounterTitles,
|
||||
m_pObjectList->NumInstances ==
|
||||
PERF_NO_INSTANCES ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
CPerfObjectInstance *
|
||||
CPerfObject::GetNextObjectInstance( void )
|
||||
{
|
||||
if ( m_pObjectList->NumInstances == PERF_NO_INSTANCES )
|
||||
return 0;
|
||||
|
||||
if ( ++m_currentObjectInstance >= GetObjectInstanceCount() )
|
||||
return 0;
|
||||
|
||||
// Advance to the next PERF_INSTANCE_DEFINITION in the list. However,
|
||||
// following the current PERF_INSTANCE_DEFINITION is the counter data,
|
||||
// which is also of variable length. So, we gotta take that into
|
||||
// account when finding the next PERF_INSTANCE_DEFINITION
|
||||
|
||||
// First, get a pointer to the counter data size field
|
||||
PDWORD pCounterDataSize
|
||||
= MakePtr(PDWORD, m_pCurrentObjectInstanceDefinition,
|
||||
m_pCurrentObjectInstanceDefinition->ByteLength);
|
||||
|
||||
// Now we can point at the next PPERF_INSTANCE_DEFINITION
|
||||
m_pCurrentObjectInstanceDefinition = MakePtr(PPERF_INSTANCE_DEFINITION,
|
||||
m_pCurrentObjectInstanceDefinition,
|
||||
m_pCurrentObjectInstanceDefinition->ByteLength
|
||||
+ *pCounterDataSize);
|
||||
|
||||
// Create a CPerfObjectInstance based around the PPERF_INSTANCE_DEFINITION
|
||||
return new CPerfObjectInstance(m_pCurrentObjectInstanceDefinition,
|
||||
MakePtr(PPERF_COUNTER_DEFINITION,
|
||||
m_pObjectList,
|
||||
m_pObjectList->HeaderLength),
|
||||
m_pObjectList->NumCounters,
|
||||
m_pPerfCounterTitles,
|
||||
FALSE );
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfObject::GetObjectTypeName( PTSTR pszObjTypeName, DWORD nSize )
|
||||
{
|
||||
PTSTR pszName = m_pPerfCounterTitles->GetTitleStringFromIndex(
|
||||
m_pObjectList->ObjectNameTitleIndex );
|
||||
|
||||
if ( !pszName )
|
||||
return FALSE;
|
||||
|
||||
lstrcpyn( pszObjTypeName, pszName, nSize );
|
||||
return TRUE;
|
||||
//====================================
|
||||
// File: PERFOBJ.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 "perfobj.h"
|
||||
#include "objinst.h"
|
||||
#include "makeptr.h"
|
||||
|
||||
CPerfObject::CPerfObject( PPERF_OBJECT_TYPE const pObjectList,
|
||||
CPerfTitleDatabase * const pPerfCounterTitles)
|
||||
{
|
||||
m_pObjectList = pObjectList;
|
||||
m_pPerfCounterTitles = pPerfCounterTitles;
|
||||
}
|
||||
|
||||
CPerfObjectInstance *
|
||||
CPerfObject::GetFirstObjectInstance( void )
|
||||
{
|
||||
m_currentObjectInstance = 0;
|
||||
if ( m_currentObjectInstance >= GetObjectInstanceCount() )
|
||||
return 0;
|
||||
|
||||
// Point at the first PERF_INSTANCE_DEFINITION
|
||||
m_pCurrentObjectInstanceDefinition =
|
||||
MakePtr( PPERF_INSTANCE_DEFINITION, m_pObjectList,
|
||||
m_pObjectList->DefinitionLength );
|
||||
|
||||
return new CPerfObjectInstance(
|
||||
m_pCurrentObjectInstanceDefinition,
|
||||
MakePtr(PPERF_COUNTER_DEFINITION,
|
||||
m_pObjectList, m_pObjectList->HeaderLength),
|
||||
m_pObjectList->NumCounters,
|
||||
m_pPerfCounterTitles,
|
||||
m_pObjectList->NumInstances ==
|
||||
PERF_NO_INSTANCES ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
CPerfObjectInstance *
|
||||
CPerfObject::GetNextObjectInstance( void )
|
||||
{
|
||||
if ( m_pObjectList->NumInstances == PERF_NO_INSTANCES )
|
||||
return 0;
|
||||
|
||||
if ( ++m_currentObjectInstance >= GetObjectInstanceCount() )
|
||||
return 0;
|
||||
|
||||
// Advance to the next PERF_INSTANCE_DEFINITION in the list. However,
|
||||
// following the current PERF_INSTANCE_DEFINITION is the counter data,
|
||||
// which is also of variable length. So, we gotta take that into
|
||||
// account when finding the next PERF_INSTANCE_DEFINITION
|
||||
|
||||
// First, get a pointer to the counter data size field
|
||||
PDWORD pCounterDataSize
|
||||
= MakePtr(PDWORD, m_pCurrentObjectInstanceDefinition,
|
||||
m_pCurrentObjectInstanceDefinition->ByteLength);
|
||||
|
||||
// Now we can point at the next PPERF_INSTANCE_DEFINITION
|
||||
m_pCurrentObjectInstanceDefinition = MakePtr(PPERF_INSTANCE_DEFINITION,
|
||||
m_pCurrentObjectInstanceDefinition,
|
||||
m_pCurrentObjectInstanceDefinition->ByteLength
|
||||
+ *pCounterDataSize);
|
||||
|
||||
// Create a CPerfObjectInstance based around the PPERF_INSTANCE_DEFINITION
|
||||
return new CPerfObjectInstance(m_pCurrentObjectInstanceDefinition,
|
||||
MakePtr(PPERF_COUNTER_DEFINITION,
|
||||
m_pObjectList,
|
||||
m_pObjectList->HeaderLength),
|
||||
m_pObjectList->NumCounters,
|
||||
m_pPerfCounterTitles,
|
||||
FALSE );
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfObject::GetObjectTypeName( PTSTR pszObjTypeName, DWORD nSize )
|
||||
{
|
||||
PTSTR pszName = m_pPerfCounterTitles->GetTitleStringFromIndex(
|
||||
m_pObjectList->ObjectNameTitleIndex );
|
||||
|
||||
if ( !pszName )
|
||||
return FALSE;
|
||||
|
||||
lstrcpyn( pszObjTypeName, pszName, nSize );
|
||||
return TRUE;
|
||||
}
|
@ -1,45 +1,45 @@
|
||||
#ifndef __Perfobj_h__
|
||||
#define __Perfobj_h__
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
|
||||
class CPerfObjectInstance;
|
||||
|
||||
class CPerfObject
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfObject( PPERF_OBJECT_TYPE const pObjectList,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase );
|
||||
|
||||
~CPerfObject( void ){ }
|
||||
|
||||
// Functions that return CPerfObjectInstance pointers. Caller is
|
||||
// responsible for deleting the CPerfObjectInstance * when done with it.
|
||||
|
||||
CPerfObjectInstance * GetFirstObjectInstance( void );
|
||||
|
||||
CPerfObjectInstance * GetNextObjectInstance( void );
|
||||
|
||||
unsigned GetObjectInstanceCount(void){return m_pObjectList->NumInstances;}
|
||||
|
||||
BOOL GetObjectTypeName( PTSTR pszObjTypeName, DWORD nSize );
|
||||
|
||||
protected:
|
||||
|
||||
PPERF_OBJECT_TYPE m_pObjectList;
|
||||
|
||||
unsigned m_currentObjectInstance;
|
||||
|
||||
PPERF_INSTANCE_DEFINITION m_pCurrentObjectInstanceDefinition;
|
||||
|
||||
CPerfTitleDatabase * m_pPerfCounterTitles;
|
||||
};
|
||||
|
||||
typedef CPerfObject * PCPerfObject;
|
||||
#ifndef __Perfobj_h__
|
||||
#define __Perfobj_h__
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
|
||||
class CPerfObjectInstance;
|
||||
|
||||
class CPerfObject
|
||||
{
|
||||
public:
|
||||
|
||||
CPerfObject( PPERF_OBJECT_TYPE const pObjectList,
|
||||
CPerfTitleDatabase * const pPerfTitleDatabase );
|
||||
|
||||
~CPerfObject( void ){ }
|
||||
|
||||
// Functions that return CPerfObjectInstance pointers. Caller is
|
||||
// responsible for deleting the CPerfObjectInstance * when done with it.
|
||||
|
||||
CPerfObjectInstance * GetFirstObjectInstance( void );
|
||||
|
||||
CPerfObjectInstance * GetNextObjectInstance( void );
|
||||
|
||||
unsigned GetObjectInstanceCount(void){return m_pObjectList->NumInstances;}
|
||||
|
||||
BOOL GetObjectTypeName( PTSTR pszObjTypeName, DWORD nSize );
|
||||
|
||||
protected:
|
||||
|
||||
PPERF_OBJECT_TYPE m_pObjectList;
|
||||
|
||||
unsigned m_currentObjectInstance;
|
||||
|
||||
PPERF_INSTANCE_DEFINITION m_pCurrentObjectInstanceDefinition;
|
||||
|
||||
CPerfTitleDatabase * m_pPerfCounterTitles;
|
||||
};
|
||||
|
||||
typedef CPerfObject * PCPerfObject;
|
||||
#endif
|
@ -1,165 +1,165 @@
|
||||
//============================================================================
|
||||
// File: PERFSNAP.CPP
|
||||
// Author: Matt Pietrek
|
||||
// From: Microsoft Systems Journal, "Under the Hood", March 1996
|
||||
//============================================================================
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <winperf.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
#pragma hdrstop
|
||||
#include "titledb.h"
|
||||
#include "perfsnap.h"
|
||||
#include "makeptr.h"
|
||||
|
||||
PBYTE CPerfSnapshot::c_pBuffer = nullptr;
|
||||
DWORD CPerfSnapshot::c_cbBufferSize = 0;
|
||||
|
||||
CPerfSnapshot::CPerfSnapshot(
|
||||
CPerfTitleDatabase * pCounterTitles )
|
||||
{
|
||||
m_pPerfDataHeader = 0;
|
||||
m_pCounterTitles = pCounterTitles;
|
||||
}
|
||||
|
||||
CPerfSnapshot::~CPerfSnapshot( void )
|
||||
{
|
||||
DisposeSnapshot();
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfSnapshot::TakeSnapshot( PCTSTR pszSnapshotItems )
|
||||
{
|
||||
DisposeSnapshot(); // Clear out any current snapshot
|
||||
|
||||
// Convert the input string (e.g., "Process") into the form required
|
||||
// by the HKEY_PERFORMANCE_DATA key (e.g., "232")
|
||||
|
||||
TCHAR szConvertedItemNames[ 256 ];
|
||||
if ( !ConvertSnapshotItemName( pszSnapshotItems, szConvertedItemNames,
|
||||
sizeof(szConvertedItemNames) ) )
|
||||
return FALSE;
|
||||
|
||||
DWORD cbAllocSize = 0;
|
||||
LONG retValue;
|
||||
|
||||
while ( 1 ) // Loop until we get the data, or we fail unexpectedly
|
||||
{
|
||||
retValue = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
|
||||
szConvertedItemNames, 0, 0,
|
||||
c_pBuffer, &c_cbBufferSize );
|
||||
|
||||
if ( retValue == ERROR_SUCCESS ) // We apparently got the snapshot
|
||||
{
|
||||
m_pPerfDataHeader = (PPERF_DATA_BLOCK)c_pBuffer;
|
||||
|
||||
// Verify that the signature is a unicode "PERF"
|
||||
if ( memcmp( m_pPerfDataHeader->Signature, L"PERF", 8 ) )
|
||||
break;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else if ( retValue != ERROR_MORE_DATA ) // Anything other failure
|
||||
break; // code means something
|
||||
// bad happened, so bail out.
|
||||
|
||||
// If we get here, our buffer wasn't big enough. Delete it and
|
||||
// try again with a bigger buffer.
|
||||
delete [] c_pBuffer;
|
||||
|
||||
// The new buffer size will be 4096 bytes bigger than the larger
|
||||
// of: 1) The previous allocation size, or 2) The size that the
|
||||
// RegQueryValueEx call said was necessary.
|
||||
if ( c_cbBufferSize > cbAllocSize )
|
||||
cbAllocSize = c_cbBufferSize + 4096;
|
||||
else
|
||||
cbAllocSize += 4096;
|
||||
|
||||
// Allocate a new, larger buffer in preparation to try again.
|
||||
c_pBuffer = new BYTE[ cbAllocSize ];
|
||||
if ( !c_pBuffer )
|
||||
break;
|
||||
|
||||
c_cbBufferSize = cbAllocSize;
|
||||
}
|
||||
|
||||
// If we get here, the RegQueryValueEx failed unexpectedly.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
CPerfSnapshot::DisposeSnapshot( void )
|
||||
{
|
||||
m_pPerfDataHeader = 0;
|
||||
}
|
||||
|
||||
void
|
||||
CPerfSnapshot::CleanUp( void )
|
||||
{
|
||||
delete [] c_pBuffer;
|
||||
c_pBuffer = 0;
|
||||
c_cbBufferSize = 0;
|
||||
}
|
||||
|
||||
DWORD
|
||||
CPerfSnapshot::GetNumObjectTypes( void )
|
||||
{
|
||||
return m_pPerfDataHeader ? m_pPerfDataHeader->NumObjectTypes: 0;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfSnapshot::GetSystemName( PTSTR pszSystemName, DWORD nSize )
|
||||
{
|
||||
if ( !m_pPerfDataHeader ) // If no snapshot data, bail out.
|
||||
return FALSE;
|
||||
|
||||
// Make sure the input buffer size is big enough
|
||||
if ( nSize < m_pPerfDataHeader->SystemNameLength )
|
||||
return FALSE;
|
||||
|
||||
// Make a unicode string point to the system name string
|
||||
// that's stored in the PERF_DATA_BLOCK
|
||||
LPWSTR lpwszName = MakePtr( LPWSTR, m_pPerfDataHeader,
|
||||
m_pPerfDataHeader->SystemNameOffset );
|
||||
|
||||
#ifdef UNICODE // Copy the PERF_DATA_BLOCK string to the input buffer
|
||||
lstrcpy( pszSystemName, lpwszName );
|
||||
#else
|
||||
wcstombs( pszSystemName, lpwszName, nSize );
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
PVOID
|
||||
CPerfSnapshot::GetPostHeaderPointer( void )
|
||||
{
|
||||
// Returns a header to the first byte following the PERF_DATA_BLOCK
|
||||
// (including the variable length system name string at the end)
|
||||
return m_pPerfDataHeader ?
|
||||
MakePtr(PVOID, m_pPerfDataHeader,m_pPerfDataHeader->HeaderLength)
|
||||
: 0;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfSnapshot::ConvertSnapshotItemName( PCTSTR pszIn,
|
||||
PTSTR pszOut, DWORD nSize )
|
||||
{
|
||||
if ( IsBadStringPtr( pszIn, 0xFFFFFFFF ) )
|
||||
return FALSE;
|
||||
|
||||
|
||||
DWORD objectID = m_pCounterTitles->GetIndexFromTitleString(pszIn);
|
||||
|
||||
if ( objectID )
|
||||
pszOut += wsprintf( pszOut, TEXT("%u "), objectID );
|
||||
else
|
||||
pszOut += wsprintf( pszOut, TEXT("%s "), pszIn );
|
||||
|
||||
return TRUE;
|
||||
//============================================================================
|
||||
// File: PERFSNAP.CPP
|
||||
// Author: Matt Pietrek
|
||||
// From: Microsoft Systems Journal, "Under the Hood", March 1996
|
||||
//============================================================================
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <winperf.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
#pragma hdrstop
|
||||
#include "titledb.h"
|
||||
#include "perfsnap.h"
|
||||
#include "makeptr.h"
|
||||
|
||||
PBYTE CPerfSnapshot::c_pBuffer = nullptr;
|
||||
DWORD CPerfSnapshot::c_cbBufferSize = 0;
|
||||
|
||||
CPerfSnapshot::CPerfSnapshot(
|
||||
CPerfTitleDatabase * pCounterTitles )
|
||||
{
|
||||
m_pPerfDataHeader = 0;
|
||||
m_pCounterTitles = pCounterTitles;
|
||||
}
|
||||
|
||||
CPerfSnapshot::~CPerfSnapshot( void )
|
||||
{
|
||||
DisposeSnapshot();
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfSnapshot::TakeSnapshot( PCTSTR pszSnapshotItems )
|
||||
{
|
||||
DisposeSnapshot(); // Clear out any current snapshot
|
||||
|
||||
// Convert the input string (e.g., "Process") into the form required
|
||||
// by the HKEY_PERFORMANCE_DATA key (e.g., "232")
|
||||
|
||||
TCHAR szConvertedItemNames[ 256 ];
|
||||
if ( !ConvertSnapshotItemName( pszSnapshotItems, szConvertedItemNames,
|
||||
sizeof(szConvertedItemNames) ) )
|
||||
return FALSE;
|
||||
|
||||
DWORD cbAllocSize = 0;
|
||||
LONG retValue;
|
||||
|
||||
while ( 1 ) // Loop until we get the data, or we fail unexpectedly
|
||||
{
|
||||
retValue = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
|
||||
szConvertedItemNames, 0, 0,
|
||||
c_pBuffer, &c_cbBufferSize );
|
||||
|
||||
if ( retValue == ERROR_SUCCESS ) // We apparently got the snapshot
|
||||
{
|
||||
m_pPerfDataHeader = (PPERF_DATA_BLOCK)c_pBuffer;
|
||||
|
||||
// Verify that the signature is a unicode "PERF"
|
||||
if ( memcmp( m_pPerfDataHeader->Signature, L"PERF", 8 ) )
|
||||
break;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else if ( retValue != ERROR_MORE_DATA ) // Anything other failure
|
||||
break; // code means something
|
||||
// bad happened, so bail out.
|
||||
|
||||
// If we get here, our buffer wasn't big enough. Delete it and
|
||||
// try again with a bigger buffer.
|
||||
delete [] c_pBuffer;
|
||||
|
||||
// The new buffer size will be 4096 bytes bigger than the larger
|
||||
// of: 1) The previous allocation size, or 2) The size that the
|
||||
// RegQueryValueEx call said was necessary.
|
||||
if ( c_cbBufferSize > cbAllocSize )
|
||||
cbAllocSize = c_cbBufferSize + 4096;
|
||||
else
|
||||
cbAllocSize += 4096;
|
||||
|
||||
// Allocate a new, larger buffer in preparation to try again.
|
||||
c_pBuffer = new BYTE[ cbAllocSize ];
|
||||
if ( !c_pBuffer )
|
||||
break;
|
||||
|
||||
c_cbBufferSize = cbAllocSize;
|
||||
}
|
||||
|
||||
// If we get here, the RegQueryValueEx failed unexpectedly.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
CPerfSnapshot::DisposeSnapshot( void )
|
||||
{
|
||||
m_pPerfDataHeader = 0;
|
||||
}
|
||||
|
||||
void
|
||||
CPerfSnapshot::CleanUp( void )
|
||||
{
|
||||
delete [] c_pBuffer;
|
||||
c_pBuffer = 0;
|
||||
c_cbBufferSize = 0;
|
||||
}
|
||||
|
||||
DWORD
|
||||
CPerfSnapshot::GetNumObjectTypes( void )
|
||||
{
|
||||
return m_pPerfDataHeader ? m_pPerfDataHeader->NumObjectTypes: 0;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfSnapshot::GetSystemName( PTSTR pszSystemName, DWORD nSize )
|
||||
{
|
||||
if ( !m_pPerfDataHeader ) // If no snapshot data, bail out.
|
||||
return FALSE;
|
||||
|
||||
// Make sure the input buffer size is big enough
|
||||
if ( nSize < m_pPerfDataHeader->SystemNameLength )
|
||||
return FALSE;
|
||||
|
||||
// Make a unicode string point to the system name string
|
||||
// that's stored in the PERF_DATA_BLOCK
|
||||
LPWSTR lpwszName = MakePtr( LPWSTR, m_pPerfDataHeader,
|
||||
m_pPerfDataHeader->SystemNameOffset );
|
||||
|
||||
#ifdef UNICODE // Copy the PERF_DATA_BLOCK string to the input buffer
|
||||
lstrcpy( pszSystemName, lpwszName );
|
||||
#else
|
||||
wcstombs( pszSystemName, lpwszName, nSize );
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
PVOID
|
||||
CPerfSnapshot::GetPostHeaderPointer( void )
|
||||
{
|
||||
// Returns a header to the first byte following the PERF_DATA_BLOCK
|
||||
// (including the variable length system name string at the end)
|
||||
return m_pPerfDataHeader ?
|
||||
MakePtr(PVOID, m_pPerfDataHeader,m_pPerfDataHeader->HeaderLength)
|
||||
: 0;
|
||||
}
|
||||
|
||||
BOOL
|
||||
CPerfSnapshot::ConvertSnapshotItemName( PCTSTR pszIn,
|
||||
PTSTR pszOut, DWORD nSize )
|
||||
{
|
||||
if ( IsBadStringPtr( pszIn, 0xFFFFFFFF ) )
|
||||
return FALSE;
|
||||
|
||||
|
||||
DWORD objectID = m_pCounterTitles->GetIndexFromTitleString(pszIn);
|
||||
|
||||
if ( objectID )
|
||||
pszOut += wsprintf( pszOut, TEXT("%u "), objectID );
|
||||
else
|
||||
pszOut += wsprintf( pszOut, TEXT("%s "), pszIn );
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -1,43 +1,43 @@
|
||||
#ifndef __Perfsnap_h__
|
||||
#define __Perfsnap_h__
|
||||
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
|
||||
class CPerfTitleDatabase;
|
||||
|
||||
class CPerfSnapshot
|
||||
{
|
||||
private:
|
||||
|
||||
static PBYTE c_pBuffer;
|
||||
static DWORD c_cbBufferSize;
|
||||
|
||||
PPERF_DATA_BLOCK m_pPerfDataHeader; // Points to snapshot data
|
||||
CPerfTitleDatabase * m_pCounterTitles; // The title conversion object
|
||||
|
||||
// Private function to convert the ASCII strings passedto TakeSnapshot()
|
||||
// into a suitable form for the RegQueryValue call
|
||||
BOOL ConvertSnapshotItemName( PCTSTR pszIn, PTSTR pszOut, DWORD nSize );
|
||||
|
||||
public:
|
||||
|
||||
CPerfSnapshot( CPerfTitleDatabase * pCounterTitles );
|
||||
|
||||
~CPerfSnapshot( void );
|
||||
|
||||
BOOL TakeSnapshot( PCTSTR pszSnapshotItems );
|
||||
|
||||
void DisposeSnapshot( void );
|
||||
|
||||
DWORD GetNumObjectTypes( void ); // # of objects the snapshot includes
|
||||
|
||||
BOOL GetSystemName( PTSTR pszSystemName, DWORD nSize );
|
||||
|
||||
PVOID GetPostHeaderPointer( void ); // Pointer to data following header
|
||||
|
||||
static void CleanUp( void );
|
||||
};
|
||||
|
||||
#ifndef __Perfsnap_h__
|
||||
#define __Perfsnap_h__
|
||||
|
||||
#ifndef _WINPERF_
|
||||
#include <winperf.h>
|
||||
#endif
|
||||
|
||||
class CPerfTitleDatabase;
|
||||
|
||||
class CPerfSnapshot
|
||||
{
|
||||
private:
|
||||
|
||||
static PBYTE c_pBuffer;
|
||||
static DWORD c_cbBufferSize;
|
||||
|
||||
PPERF_DATA_BLOCK m_pPerfDataHeader; // Points to snapshot data
|
||||
CPerfTitleDatabase * m_pCounterTitles; // The title conversion object
|
||||
|
||||
// Private function to convert the ASCII strings passedto TakeSnapshot()
|
||||
// into a suitable form for the RegQueryValue call
|
||||
BOOL ConvertSnapshotItemName( PCTSTR pszIn, PTSTR pszOut, DWORD nSize );
|
||||
|
||||
public:
|
||||
|
||||
CPerfSnapshot( CPerfTitleDatabase * pCounterTitles );
|
||||
|
||||
~CPerfSnapshot( void );
|
||||
|
||||
BOOL TakeSnapshot( PCTSTR pszSnapshotItems );
|
||||
|
||||
void DisposeSnapshot( void );
|
||||
|
||||
DWORD GetNumObjectTypes( void ); // # of objects the snapshot includes
|
||||
|
||||
BOOL GetSystemName( PTSTR pszSystemName, DWORD nSize );
|
||||
|
||||
PVOID GetPostHeaderPointer( void ); // Pointer to data following header
|
||||
|
||||
static void CleanUp( void );
|
||||
};
|
||||
|
||||
#endif
|
@ -1,40 +1,40 @@
|
||||
#include <VerRsrc.h>
|
||||
#include "../../Version.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,2,0,0
|
||||
PRODUCTVERSION PRODUCTVER
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT_UNKNOWN
|
||||
{
|
||||
BLOCK "StringFileInfo"
|
||||
{
|
||||
BLOCK "040904E4"
|
||||
{
|
||||
VALUE "FileVersion", "1.2.0.0"
|
||||
VALUE "LegalCopyright", "<22> 2010 - Rainy"
|
||||
VALUE "ProductName", "Rainmeter"
|
||||
#ifdef _WIN64
|
||||
VALUE "ProductVersion", STRPRODUCTVER " (64-bit)"
|
||||
#else
|
||||
VALUE "ProductVersion", STRPRODUCTVER " (32-bit)"
|
||||
#endif //_WIN64
|
||||
}
|
||||
}
|
||||
BLOCK "VarFileInfo"
|
||||
{
|
||||
VALUE "Translation", 0x409, 1252
|
||||
}
|
||||
}
|
||||
#include <VerRsrc.h>
|
||||
#include "../../Version.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,2,0,0
|
||||
PRODUCTVERSION PRODUCTVER
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT_UNKNOWN
|
||||
{
|
||||
BLOCK "StringFileInfo"
|
||||
{
|
||||
BLOCK "040904E4"
|
||||
{
|
||||
VALUE "FileVersion", "1.2.0.0"
|
||||
VALUE "LegalCopyright", "<22> 2010 - Rainy"
|
||||
VALUE "ProductName", "Rainmeter"
|
||||
#ifdef _WIN64
|
||||
VALUE "ProductVersion", STRPRODUCTVER " (64-bit)"
|
||||
#else
|
||||
VALUE "ProductVersion", STRPRODUCTVER " (32-bit)"
|
||||
#endif //_WIN64
|
||||
}
|
||||
}
|
||||
BLOCK "VarFileInfo"
|
||||
{
|
||||
VALUE "Translation", 0x409, 1252
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{5344B52B-BAC3-479C-B41D-D465B8BDA1AD}</ProjectGuid>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<TargetName>PerfMon</TargetName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.props" />
|
||||
<Import Project="$(SolutionDir)Build\VS\RainmeterPlugin.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MakePtr.h" />
|
||||
<ClInclude Include="ObjInst.h" />
|
||||
<ClInclude Include="ObjList.h" />
|
||||
<ClInclude Include="PerfCntr.h" />
|
||||
<ClInclude Include="PerfObj.h" />
|
||||
<ClInclude Include="PerfSnap.h" />
|
||||
<ClInclude Include="Titledb.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ObjInst.cpp" />
|
||||
<ClCompile Include="ObjList.cpp" />
|
||||
<ClCompile Include="PerfCntr.cpp" />
|
||||
<ClCompile Include="PerfData.cpp" />
|
||||
<ClCompile Include="PerfObj.cpp" />
|
||||
<ClCompile Include="PerfSnap.cpp" />
|
||||
<ClCompile Include="Titledb.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="PluginPerfMon.rc" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{5344B52B-BAC3-479C-B41D-D465B8BDA1AD}</ProjectGuid>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<TargetName>PerfMon</TargetName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.props" />
|
||||
<Import Project="$(SolutionDir)Build\VS\RainmeterPlugin.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MakePtr.h" />
|
||||
<ClInclude Include="ObjInst.h" />
|
||||
<ClInclude Include="ObjList.h" />
|
||||
<ClInclude Include="PerfCntr.h" />
|
||||
<ClInclude Include="PerfObj.h" />
|
||||
<ClInclude Include="PerfSnap.h" />
|
||||
<ClInclude Include="Titledb.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ObjInst.cpp" />
|
||||
<ClCompile Include="ObjList.cpp" />
|
||||
<ClCompile Include="PerfCntr.cpp" />
|
||||
<ClCompile Include="PerfData.cpp" />
|
||||
<ClCompile Include="PerfObj.cpp" />
|
||||
<ClCompile Include="PerfSnap.cpp" />
|
||||
<ClCompile Include="Titledb.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="PluginPerfMon.rc" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,158 +1,158 @@
|
||||
//===========================================================================
|
||||
// File: CTITLEDB.CPP
|
||||
// Author: Matt Pietrek
|
||||
// From: Microsoft Systems Journal, "Under the Hood", March 1996
|
||||
//===========================================================================
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <winperf.h>
|
||||
#include <tchar.h>
|
||||
#pragma hdrstop
|
||||
#include "Titledb.h"
|
||||
|
||||
CPerfTitleDatabase::CPerfTitleDatabase(
|
||||
PERFORMANCE_TITLE_TYPE titleType )
|
||||
{
|
||||
m_nLastIndex = 0;
|
||||
m_TitleStrings = 0;
|
||||
m_pszRawStrings = 0;
|
||||
|
||||
// Determine the appropriate strings to pass to RegOpenKeyEx
|
||||
PTSTR psz009RegValue, pszLastIndexRegValue;
|
||||
if ( PERF_TITLE_COUNTER == titleType )
|
||||
{
|
||||
psz009RegValue = TEXT("Counter 009");
|
||||
pszLastIndexRegValue = TEXT("Last Counter");
|
||||
}
|
||||
else if ( PERF_TITLE_EXPLAIN == titleType )
|
||||
{
|
||||
psz009RegValue = TEXT("Explain 009");
|
||||
pszLastIndexRegValue = TEXT("Last Help");
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
// Find out the max number of entries
|
||||
HKEY hKeyPerflib = 0;
|
||||
|
||||
// Open the registry key that has the values for the maximum number
|
||||
// of title strings
|
||||
if ( ERROR_SUCCESS != RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
TEXT("software\\microsoft\\windows nt\\currentversion\\perflib"),
|
||||
0, KEY_READ, &hKeyPerflib ) )
|
||||
return;
|
||||
|
||||
// Read in the number of title strings
|
||||
DWORD cbLastIndex = sizeof(m_nLastIndex);
|
||||
if ( ERROR_SUCCESS != RegQueryValueEx(
|
||||
hKeyPerflib, pszLastIndexRegValue, 0, 0,
|
||||
(PBYTE)&m_nLastIndex, &cbLastIndex ) )
|
||||
{
|
||||
RegCloseKey( hKeyPerflib );
|
||||
return;
|
||||
}
|
||||
|
||||
RegCloseKey( hKeyPerflib );
|
||||
|
||||
//
|
||||
// Now go find and process the raw string data
|
||||
//
|
||||
|
||||
// Determine how big the raw data in the REG_MULTI_SZ value is
|
||||
DWORD cbTitleStrings;
|
||||
if ( ERROR_SUCCESS != RegQueryValueEx( HKEY_PERFORMANCE_DATA, psz009RegValue, 0,0,0, &cbTitleStrings))
|
||||
return;
|
||||
|
||||
// Allocate memory for the raw registry title string data
|
||||
m_pszRawStrings = new TCHAR[cbTitleStrings];
|
||||
|
||||
// Read in the raw title strings
|
||||
if ( ERROR_SUCCESS != RegQueryValueEx( HKEY_PERFORMANCE_DATA,
|
||||
psz009RegValue, 0, 0, (PBYTE)m_pszRawStrings,
|
||||
&cbTitleStrings ) )
|
||||
{
|
||||
delete []m_pszRawStrings;
|
||||
return;
|
||||
}
|
||||
|
||||
// allocate memory for an array of string pointers.
|
||||
m_TitleStrings = new PTSTR[ m_nLastIndex+1 ];
|
||||
if ( !m_TitleStrings )
|
||||
{
|
||||
delete []m_pszRawStrings;
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize the m_TitleStrings to all NULLs, since there may
|
||||
// be some array slots that aren't used.
|
||||
memset( m_TitleStrings, 0, sizeof(PTSTR) * (m_nLastIndex+1) );
|
||||
|
||||
// The raw data entries are an ASCII string index (e.g., "242"), followed
|
||||
// by the corresponding string. Fill in the appropriate slot in the
|
||||
// m_TitleStrings array with the pointer to the string name. The end
|
||||
// of the list is indicated by a double nullptr.
|
||||
|
||||
PTSTR pszWorkStr = (PTSTR)m_pszRawStrings;
|
||||
unsigned cbCurrStr;
|
||||
|
||||
// While the length of the current string isn't 0...
|
||||
while ( 0 != (cbCurrStr = lstrlen( pszWorkStr)) )
|
||||
{
|
||||
// Convert the first string to a binary representation
|
||||
unsigned index = _ttoi( pszWorkStr ); // _ttoi -> atoi()
|
||||
|
||||
if ( index > m_nLastIndex )
|
||||
break;
|
||||
|
||||
// Now point to the string following it. This is the title string
|
||||
pszWorkStr += cbCurrStr + 1;
|
||||
|
||||
// Fill in the appropriate slot in the title strings array.
|
||||
m_TitleStrings[index] = pszWorkStr;
|
||||
|
||||
// Advance to the next index/title pair
|
||||
pszWorkStr += lstrlen(pszWorkStr) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
CPerfTitleDatabase::~CPerfTitleDatabase( )
|
||||
{
|
||||
delete []m_TitleStrings;
|
||||
m_TitleStrings = 0;
|
||||
delete []m_pszRawStrings;
|
||||
m_pszRawStrings = 0;
|
||||
m_nLastIndex = 0;
|
||||
}
|
||||
|
||||
PTSTR
|
||||
CPerfTitleDatabase::GetTitleStringFromIndex( unsigned index )
|
||||
{
|
||||
if ( index > m_nLastIndex ) // Is index within range?
|
||||
return 0;
|
||||
|
||||
return m_TitleStrings[ index ];
|
||||
}
|
||||
|
||||
unsigned
|
||||
CPerfTitleDatabase::GetIndexFromTitleString( PCTSTR pszTitleString )
|
||||
{
|
||||
if ( IsBadStringPtr(pszTitleString, 0xFFFFFFFF) )
|
||||
return 0;
|
||||
|
||||
// Loop through all the non-null string array entries, doing a case-
|
||||
// insensitive comparison. If found, return the correpsonding index
|
||||
for ( unsigned i = 1; i <= m_nLastIndex; i++ )
|
||||
{
|
||||
if ( m_TitleStrings[i] )
|
||||
if ( 0 == _tcsicmp( pszTitleString, m_TitleStrings[i] ) )
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//===========================================================================
|
||||
// File: CTITLEDB.CPP
|
||||
// Author: Matt Pietrek
|
||||
// From: Microsoft Systems Journal, "Under the Hood", March 1996
|
||||
//===========================================================================
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <winperf.h>
|
||||
#include <tchar.h>
|
||||
#pragma hdrstop
|
||||
#include "Titledb.h"
|
||||
|
||||
CPerfTitleDatabase::CPerfTitleDatabase(
|
||||
PERFORMANCE_TITLE_TYPE titleType )
|
||||
{
|
||||
m_nLastIndex = 0;
|
||||
m_TitleStrings = 0;
|
||||
m_pszRawStrings = 0;
|
||||
|
||||
// Determine the appropriate strings to pass to RegOpenKeyEx
|
||||
PTSTR psz009RegValue, pszLastIndexRegValue;
|
||||
if ( PERF_TITLE_COUNTER == titleType )
|
||||
{
|
||||
psz009RegValue = TEXT("Counter 009");
|
||||
pszLastIndexRegValue = TEXT("Last Counter");
|
||||
}
|
||||
else if ( PERF_TITLE_EXPLAIN == titleType )
|
||||
{
|
||||
psz009RegValue = TEXT("Explain 009");
|
||||
pszLastIndexRegValue = TEXT("Last Help");
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
// Find out the max number of entries
|
||||
HKEY hKeyPerflib = 0;
|
||||
|
||||
// Open the registry key that has the values for the maximum number
|
||||
// of title strings
|
||||
if ( ERROR_SUCCESS != RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
TEXT("software\\microsoft\\windows nt\\currentversion\\perflib"),
|
||||
0, KEY_READ, &hKeyPerflib ) )
|
||||
return;
|
||||
|
||||
// Read in the number of title strings
|
||||
DWORD cbLastIndex = sizeof(m_nLastIndex);
|
||||
if ( ERROR_SUCCESS != RegQueryValueEx(
|
||||
hKeyPerflib, pszLastIndexRegValue, 0, 0,
|
||||
(PBYTE)&m_nLastIndex, &cbLastIndex ) )
|
||||
{
|
||||
RegCloseKey( hKeyPerflib );
|
||||
return;
|
||||
}
|
||||
|
||||
RegCloseKey( hKeyPerflib );
|
||||
|
||||
//
|
||||
// Now go find and process the raw string data
|
||||
//
|
||||
|
||||
// Determine how big the raw data in the REG_MULTI_SZ value is
|
||||
DWORD cbTitleStrings;
|
||||
if ( ERROR_SUCCESS != RegQueryValueEx( HKEY_PERFORMANCE_DATA, psz009RegValue, 0,0,0, &cbTitleStrings))
|
||||
return;
|
||||
|
||||
// Allocate memory for the raw registry title string data
|
||||
m_pszRawStrings = new TCHAR[cbTitleStrings];
|
||||
|
||||
// Read in the raw title strings
|
||||
if ( ERROR_SUCCESS != RegQueryValueEx( HKEY_PERFORMANCE_DATA,
|
||||
psz009RegValue, 0, 0, (PBYTE)m_pszRawStrings,
|
||||
&cbTitleStrings ) )
|
||||
{
|
||||
delete []m_pszRawStrings;
|
||||
return;
|
||||
}
|
||||
|
||||
// allocate memory for an array of string pointers.
|
||||
m_TitleStrings = new PTSTR[ m_nLastIndex+1 ];
|
||||
if ( !m_TitleStrings )
|
||||
{
|
||||
delete []m_pszRawStrings;
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize the m_TitleStrings to all NULLs, since there may
|
||||
// be some array slots that aren't used.
|
||||
memset( m_TitleStrings, 0, sizeof(PTSTR) * (m_nLastIndex+1) );
|
||||
|
||||
// The raw data entries are an ASCII string index (e.g., "242"), followed
|
||||
// by the corresponding string. Fill in the appropriate slot in the
|
||||
// m_TitleStrings array with the pointer to the string name. The end
|
||||
// of the list is indicated by a double nullptr.
|
||||
|
||||
PTSTR pszWorkStr = (PTSTR)m_pszRawStrings;
|
||||
unsigned cbCurrStr;
|
||||
|
||||
// While the length of the current string isn't 0...
|
||||
while ( 0 != (cbCurrStr = lstrlen( pszWorkStr)) )
|
||||
{
|
||||
// Convert the first string to a binary representation
|
||||
unsigned index = _ttoi( pszWorkStr ); // _ttoi -> atoi()
|
||||
|
||||
if ( index > m_nLastIndex )
|
||||
break;
|
||||
|
||||
// Now point to the string following it. This is the title string
|
||||
pszWorkStr += cbCurrStr + 1;
|
||||
|
||||
// Fill in the appropriate slot in the title strings array.
|
||||
m_TitleStrings[index] = pszWorkStr;
|
||||
|
||||
// Advance to the next index/title pair
|
||||
pszWorkStr += lstrlen(pszWorkStr) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
CPerfTitleDatabase::~CPerfTitleDatabase( )
|
||||
{
|
||||
delete []m_TitleStrings;
|
||||
m_TitleStrings = 0;
|
||||
delete []m_pszRawStrings;
|
||||
m_pszRawStrings = 0;
|
||||
m_nLastIndex = 0;
|
||||
}
|
||||
|
||||
PTSTR
|
||||
CPerfTitleDatabase::GetTitleStringFromIndex( unsigned index )
|
||||
{
|
||||
if ( index > m_nLastIndex ) // Is index within range?
|
||||
return 0;
|
||||
|
||||
return m_TitleStrings[ index ];
|
||||
}
|
||||
|
||||
unsigned
|
||||
CPerfTitleDatabase::GetIndexFromTitleString( PCTSTR pszTitleString )
|
||||
{
|
||||
if ( IsBadStringPtr(pszTitleString, 0xFFFFFFFF) )
|
||||
return 0;
|
||||
|
||||
// Loop through all the non-null string array entries, doing a case-
|
||||
// insensitive comparison. If found, return the correpsonding index
|
||||
for ( unsigned i = 1; i <= m_nLastIndex; i++ )
|
||||
{
|
||||
if ( m_TitleStrings[i] )
|
||||
if ( 0 == _tcsicmp( pszTitleString, m_TitleStrings[i] ) )
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
#ifndef __Ctitledb_h__
|
||||
#define __Ctitledb_h__
|
||||
|
||||
enum PERFORMANCE_TITLE_TYPE { PERF_TITLE_COUNTER, PERF_TITLE_EXPLAIN };
|
||||
|
||||
class CPerfTitleDatabase
|
||||
{
|
||||
private:
|
||||
|
||||
unsigned m_nLastIndex;
|
||||
PTSTR * m_TitleStrings;
|
||||
PTSTR m_pszRawStrings;
|
||||
|
||||
public:
|
||||
|
||||
CPerfTitleDatabase( PERFORMANCE_TITLE_TYPE titleType );
|
||||
~CPerfTitleDatabase( );
|
||||
|
||||
unsigned GetLastTitleIndex(void) { return m_nLastIndex; }
|
||||
PTSTR GetTitleStringFromIndex( unsigned index );
|
||||
unsigned GetIndexFromTitleString( PCTSTR pszTitleString );
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef __Ctitledb_h__
|
||||
#define __Ctitledb_h__
|
||||
|
||||
enum PERFORMANCE_TITLE_TYPE { PERF_TITLE_COUNTER, PERF_TITLE_EXPLAIN };
|
||||
|
||||
class CPerfTitleDatabase
|
||||
{
|
||||
private:
|
||||
|
||||
unsigned m_nLastIndex;
|
||||
PTSTR * m_TitleStrings;
|
||||
PTSTR m_pszRawStrings;
|
||||
|
||||
public:
|
||||
|
||||
CPerfTitleDatabase( PERFORMANCE_TITLE_TYPE titleType );
|
||||
~CPerfTitleDatabase( );
|
||||
|
||||
unsigned GetLastTitleIndex(void) { return m_nLastIndex; }
|
||||
PTSTR GetTitleStringFromIndex( unsigned index );
|
||||
unsigned GetIndexFromTitleString( PCTSTR pszTitleString );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user