HKEY_DYNAMIC_DATA benutze ich bei mir (w98se), ich hatte mal vor ewigkeiten ein tut in VB drüber gelesen und es in C++ umgesetzt, nur bin ich mir sicher das es auch anders geht, den Windows muß diesen Wert auch ermitteln und in die Reg schreiben.
_________________ Fragt Floppy den HDD, warum bist du größer? Da sagt HDD: weil ich Hard bin und Du nur nen Flop
Klar muss auch Windows diesen Wert irgendwie ermitteln, aber das heißt deswegen noch lange nicht, dass du noch anders an diesen Wert kommst. Es kann natürlich sein, dass es noch eine Möglichkeit gibt, aber Windows kümmert sich eben und die Zuteilung der Rechenzeit, und weiß von daher, wieviel Rechenzeit der Windows-Leerlauf-Prozess bekommt (denke mal, dass das irgendwie so ermittelt wird)
_________________ ( Moderator im Webzeugs- und WinAPI-Forum )
Wegen der Unterstützung für 98, Me ... Systeme: Hat Ms den Task Manager zu NT Systemen nicht gründlich geändert. Wenn ich mich richtig erinnere, gab es damals solche Systeminfos Systemauslastung nicht im Taskmanager. (Da gabs auch noch bugs das nicht alle Programme aufgeführt wurden, spielte bei Viren mal ne Rolle).
-> Wenn Ms es damals nicht den Taskmanager eingebaut hat, war es entweder zu blöd dazu (besser hat es vergessen) oder es war zu schwirig diese Werte zu ermitteln.
Was wohl möglich ist ist die Ramauslastung rauszukriegen (IMHO), aber das ist ja nicht die Systemauslastung.
Zuletzt bearbeitet von flammenvogel am 20:38:03 27.09.2004, insgesamt 1-mal bearbeitet
Ich habe mich ein wenig Schlau gemacht, aber noch nicht Schlau genug um Endergebnisse zu liefern, aber so wie es Aussieht muß man das ziemlich hardware nah machen, sprich Assembler (Eingebettet) aber auch da giebt es noch Hürden.
Also für mich selbst reicht meine alte variante, ich brauch nicht von jeden die Auslastung.
_________________ Fragt Floppy den HDD, warum bist du größer? Da sagt HDD: weil ich Hard bin und Du nur nen Flop
//
// The performance data is accessed through the registry key
// HKEY_PEFORMANCE_DATA.
// However, although we use the registry to collect performance data,
// the data is not stored in the registry database.
// Instead, calling the registry functions with the HKEY_PEFORMANCE_DATA key
// causes the system to collect the data from the appropriate system
// object managers.
//
// QueryPerformanceData allocates memory block for getting the
// performance data.
//
// void QueryPerformanceData(PERF_DATA_BLOCK **pPerfData)
{
//
// Since i want to use the same allocated area for each query,
// i declare CBuffer as static.
// The allocated is changed only when RegQueryValueEx return ERROR_MORE_DATA
// static CBuffer Buffer(TOTALBYTES);
DWORD BufferSize = Buffer.GetSize();
LONG lRes;
Buffer.Reset();
while( (lRes = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
"Global",
NULL,
NULL,
Buffer,
&BufferSize )) == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.
//
// GetCounterValue gets performance object structure
// and returns the value of given counter index .
// This functions iterates through the counters of the input object
// structure and looks for the given counter index.
//
// For objects that have instances, this function returns the counter value
// of the instance pInstanceName.
//
T GetCounterValue(PPERF_OBJECT_TYPE pPerfObj, DWORD dwCounterIndex, LPCTSTR pInstanceName)
{
PPERF_COUNTER_DEFINITION pPerfCntr = NULL;
PPERF_INSTANCE_DEFINITION pPerfInst = NULL;
PPERF_COUNTER_BLOCK pCounterBlock = NULL;
// Look for instance pInstanceName
_bstr_t bstrInstance;
_bstr_t bstrInputInstance = pInstanceName;
for( int k=0; k < pPerfObj->NumInstances; k++ )
{
bstrInstance = (wchar_t *)((PBYTE)pPerfInst + pPerfInst->NameOffset);
if (!stricmp((LPCTSTR)bstrInstance, (LPCTSTR)bstrInputInstance))
{
pCounterBlock = (PPERF_COUNTER_BLOCK) ((LPBYTE) pPerfInst + pPerfInst->ByteLength);
break;
}
// Get the next instance.
pPerfInst = NextInstance( pPerfInst );
}
}
if (pCounterBlock)
{
T *lnValue = NULL;
lnValue = (T*)((LPBYTE) pCounterBlock + pPerfCntr->CounterOffset);
return *lnValue;
}
return -1;
}
/*****************************************************************
* *
* Functions used to navigate through the performance data. *
* *
*****************************************************************/
//
// The performance data is accessed through the registry key
// HKEY_PEFORMANCE_DATA.
// However, although we use the registry to collect performance data,
// the data is not stored in the registry database.
// Instead, calling the registry functions with the HKEY_PEFORMANCE_DATA key
// causes the system to collect the data from the appropriate system
// object managers.
//
// QueryPerformanceData allocates memory block for getting the
// performance data.
//
// void QueryPerformanceData(PERF_DATA_BLOCK **pPerfData)
{
//
// Since i want to use the same allocated area for each query,
// i declare CBuffer as static.
// The allocated is changed only when RegQueryValueEx return ERROR_MORE_DATA
// static CBuffer Buffer(TOTALBYTES);
DWORD BufferSize = Buffer.GetSize();
LONG lRes;
Buffer.Reset();
while( (lRes = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
"Global",
NULL,
NULL,
Buffer,
&BufferSize )) == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.
//
// GetCounterValue gets performance object structure
// and returns the value of given counter index .
// This functions iterates through the counters of the input object
// structure and looks for the given counter index.
//
// For objects that have instances, this function returns the counter value
// of the instance pInstanceName.
//
T GetCounterValue(PPERF_OBJECT_TYPE pPerfObj, DWORD dwCounterIndex, LPCTSTR pInstanceName)
{
PPERF_COUNTER_DEFINITION pPerfCntr = NULL;
PPERF_INSTANCE_DEFINITION pPerfInst = NULL;
PPERF_COUNTER_BLOCK pCounterBlock = NULL;
// Look for instance pInstanceName
_bstr_t bstrInstance;
_bstr_t bstrInputInstance = pInstanceName;
for( int k=0; k < pPerfObj->NumInstances; k++ )
{
bstrInstance = (wchar_t *)((PBYTE)pPerfInst + pPerfInst->NameOffset);
if (!stricmp((LPCTSTR)bstrInstance, (LPCTSTR)bstrInputInstance))
{
pCounterBlock = (PPERF_COUNTER_BLOCK) ((LPBYTE) pPerfInst + pPerfInst->ByteLength);
break;
}
// Get the next instance.
pPerfInst = NextInstance( pPerfInst );
}
}
if (pCounterBlock)
{
T *lnValue = NULL;
lnValue = (T*)((LPBYTE) pCounterBlock + pPerfCntr->CounterOffset);
return *lnValue;
}
return -1;
}
/*****************************************************************
* *
* Functions used to navigate through the performance data. *
* *
*****************************************************************/
//
// The performance data is accessed through the registry key
// HKEY_PEFORMANCE_DATA.
// However, although we use the registry to collect performance data,
// the data is not stored in the registry database.
// Instead, calling the registry functions with the HKEY_PEFORMANCE_DATA key
// causes the system to collect the data from the appropriate system
// object managers.
//
// QueryPerformanceData allocates memory block for getting the
// performance data.
//
// void QueryPerformanceData(PERF_DATA_BLOCK **pPerfData)
{
//
// Since i want to use the same allocated area for each query,
// i declare CBuffer as static.
// The allocated is changed only when RegQueryValueEx return ERROR_MORE_DATA
// static CBuffer Buffer(TOTALBYTES);
DWORD BufferSize = Buffer.GetSize();
LONG lRes;
Buffer.Reset();
while( (lRes = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
"Global",
NULL,
NULL,
Buffer,
&BufferSize )) == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.
//
// GetCounterValue gets performance object structure
// and returns the value of given counter index .
// This functions iterates through the counters of the input object
// structure and looks for the given counter index.
//
// For objects that have instances, this function returns the counter value
// of the instance pInstanceName.
//
T GetCounterValue(PPERF_OBJECT_TYPE pPerfObj, DWORD dwCounterIndex, LPCTSTR pInstanceName)
{
PPERF_COUNTER_DEFINITION pPerfCntr = NULL;
PPERF_INSTANCE_DEFINITION pPerfInst = NULL;
PPERF_COUNTER_BLOCK pCounterBlock = NULL;
// Look for instance pInstanceName
_bstr_t bstrInstance;
_bstr_t bstrInputInstance = pInstanceName;
for( int k=0; k < pPerfObj->NumInstances; k++ )
{
bstrInstance = (wchar_t *)((PBYTE)pPerfInst + pPerfInst->NameOffset);
if (!stricmp((LPCTSTR)bstrInstance, (LPCTSTR)bstrInputInstance))
{
pCounterBlock = (PPERF_COUNTER_BLOCK) ((LPBYTE) pPerfInst + pPerfInst->ByteLength);
break;
}
// Get the next instance.
pPerfInst = NextInstance( pPerfInst );
}
}
if (pCounterBlock)
{
T *lnValue = NULL;
lnValue = (T*)((LPBYTE) pCounterBlock + pPerfCntr->CounterOffset);
return *lnValue;
}
return -1;
}
/*****************************************************************
* *
* Functions used to navigate through the performance data. *
* *
*****************************************************************/
///////////////////////////////////////////////////////////////////
//
// GetCpuUsage uses the performance counters to retrieve the
// system cpu usage.
// The cpu usage counter is of type PERF_100NSEC_TIMER_INV
// which as the following calculation:
//
// Element Value
// ======= ===========
// X CounterData
// Y 100NsTime
// Data Size 8 Bytes
// Time base 100Ns
// Calculation 100*(1-(X1-X0)/(Y1-Y0))
//
// where the denominator (Y) represents the total elapsed time of the
// sample interval and the numerator (X) represents the time during
// the interval when the monitored components were inactive.
//
//
// Note:
// ====
// On windows NT, cpu usage counter is '% Total processor time'
// under 'System' object. However, in Win2K/XP Microsoft moved
// that counter to '% processor time' under '_Total' instance
// of 'Processor' object.
// Read 'INFO: Percent Total Performance Counter Changes on Windows 2000'
// Q259390 in MSDN.
//
///////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <atlbase.h> // for CRegKey use
#pragma pack(push,8)
#include "PerfCounters.h"
#pragma pack(pop)
#define SYSTEM_OBJECT_INDEX 2 // 'System' object
#define PROCESS_OBJECT_INDEX 230 // 'Process' object
#define PROCESSOR_OBJECT_INDEX 238 // 'Processor' object
#define TOTAL_PROCESSOR_TIME_COUNTER_INDEX 240 // '% Total processor time' counter (valid in WinNT under 'System' object)
#define PROCESSOR_TIME_COUNTER_INDEX 6 // '% processor time' counter (for Win2K/XP)
//
// GetCpuUsage returns the cpu usage.
// Since we calculate the cpu usage by two samplings, the first
// call to GetCpuUsage() returns 0 and keeps the values for the next
// sampling.
// Read the comment at the beginning of this file for the formula.
// int GetCpuUsage()
{
static bool bFirstTime = true;
static LONGLONG lnOldValue = 0;
static LARGE_INTEGER OldPerfTime100nSec = {0};
static PLATFORM Platform = GetPlatform();
if (bFirstTime)
EnablePerformaceCounters();
// Cpu usage counter is 8 byte length.
CPerfCounters<LONGLONG> PerfCounters;
char szInstance[256] = {0};
// Note:
// ====
// On windows NT, cpu usage counter is '% Total processor time'
// under 'System' object. However, in Win2K/XP Microsoft moved
// that counter to '% processor time' under '_Total' instance
// of 'Processor' object.
// Read 'INFO: Percent Total Performance Counter Changes on Windows 2000'
// Q259390 in MSDN.
///////////////////////////////////////////////////////////////////
//
// GetCpuUsage uses the performance counters to retrieve the
// system cpu usage.
// The cpu usage counter is of type PERF_100NSEC_TIMER_INV
// which as the following calculation:
//
// Element Value
// ======= ===========
// X CounterData
// Y 100NsTime
// Data Size 8 Bytes
// Time base 100Ns
// Calculation 100*(1-(X1-X0)/(Y1-Y0))
//
// where the denominator (Y) represents the total elapsed time of the
// sample interval and the numerator (X) represents the time during
// the interval when the monitored components were inactive.
//
//
// Note:
// ====
// On windows NT, cpu usage counter is '% Total processor time'
// under 'System' object. However, in Win2K/XP Microsoft moved
// that counter to '% processor time' under '_Total' instance
// of 'Processor' object.
// Read 'INFO: Percent Total Performance Counter Changes on Windows 2000'
// Q259390 in MSDN.
//
///////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <atlbase.h> // for CRegKey use
#pragma pack(push,8)
#include "PerfCounters.h"
#pragma pack(pop)
#define SYSTEM_OBJECT_INDEX 2 // 'System' object
#define PROCESS_OBJECT_INDEX 230 // 'Process' object
#define PROCESSOR_OBJECT_INDEX 238 // 'Processor' object
#define TOTAL_PROCESSOR_TIME_COUNTER_INDEX 240 // '% Total processor time' counter (valid in WinNT under 'System' object)
#define PROCESSOR_TIME_COUNTER_INDEX 6 // '% processor time' counter (for Win2K/XP)
//
// GetCpuUsage returns the cpu usage.
// Since we calculate the cpu usage by two samplings, the first
// call to GetCpuUsage() returns 0 and keeps the values for the next
// sampling.
// Read the comment at the beginning of this file for the formula.
// int GetCpuUsage()
{
static bool bFirstTime = true;
static LONGLONG lnOldValue = 0;
static LARGE_INTEGER OldPerfTime100nSec = {0};
static PLATFORM Platform = GetPlatform();
if (bFirstTime)
EnablePerformaceCounters();
// Cpu usage counter is 8 byte length.
CPerfCounters<LONGLONG> PerfCounters;
char szInstance[256] = {0};
// Note:
// ====
// On windows NT, cpu usage counter is '% Total processor time'
// under 'System' object. However, in Win2K/XP Microsoft moved
// that counter to '% processor time' under '_Total' instance
// of 'Processor' object.
// Read 'INFO: Percent Total Performance Counter Changes on Windows 2000'
// Q259390 in MSDN.
///////////////////////////////////////////////////////////////////
//
// GetCpuUsage uses the performance counters to retrieve the
// system cpu usage.
// The cpu usage counter is of type PERF_100NSEC_TIMER_INV
// which as the following calculation:
//
// Element Value
// ======= ===========
// X CounterData
// Y 100NsTime
// Data Size 8 Bytes
// Time base 100Ns
// Calculation 100*(1-(X1-X0)/(Y1-Y0))
//
// where the denominator (Y) represents the total elapsed time of the
// sample interval and the numerator (X) represents the time during
// the interval when the monitored components were inactive.
//
//
// Note:
// ====
// On windows NT, cpu usage counter is '% Total processor time'
// under 'System' object. However, in Win2K/XP Microsoft moved
// that counter to '% processor time' under '_Total' instance
// of 'Processor' object.
// Read 'INFO: Percent Total Performance Counter Changes on Windows 2000'
// Q259390 in MSDN.
//
///////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <atlbase.h> // for CRegKey use
#pragma pack(push,8)
#include "PerfCounters.h"
#pragma pack(pop)
#define SYSTEM_OBJECT_INDEX 2 // 'System' object
#define PROCESS_OBJECT_INDEX 230 // 'Process' object
#define PROCESSOR_OBJECT_INDEX 238 // 'Processor' object
#define TOTAL_PROCESSOR_TIME_COUNTER_INDEX 240 // '% Total processor time' counter (valid in WinNT under 'System' object)
#define PROCESSOR_TIME_COUNTER_INDEX 6 // '% processor time' counter (for Win2K/XP)
//
// GetCpuUsage returns the cpu usage.
// Since we calculate the cpu usage by two samplings, the first
// call to GetCpuUsage() returns 0 and keeps the values for the next
// sampling.
// Read the comment at the beginning of this file for the formula.
// int GetCpuUsage()
{
static bool bFirstTime = true;
static LONGLONG lnOldValue = 0;
static LARGE_INTEGER OldPerfTime100nSec = {0};
static PLATFORM Platform = GetPlatform();
if (bFirstTime)
EnablePerformaceCounters();
// Cpu usage counter is 8 byte length.
CPerfCounters<LONGLONG> PerfCounters;
char szInstance[256] = {0};
// Note:
// ====
// On windows NT, cpu usage counter is '% Total processor time'
// under 'System' object. However, in Win2K/XP Microsoft moved
// that counter to '% processor time' under '_Total' instance
// of 'Processor' object.
// Read 'INFO: Percent Total Performance Counter Changes on Windows 2000'
// Q259390 in MSDN.
Nächstes Thema anzeigen Vorheriges Thema anzeigen
Sie können keine Beiträge in dieses Forum schreiben. Sie können auf Beiträge in diesem Forum nicht antworten. Sie können Ihre Beiträge in diesem Forum nicht bearbeiten. Sie können Ihre Beiträge in diesem Forum nicht löschen. Sie können an Umfragen in diesem Forum nicht mitmachen.
c++.de ist Teilnehmer des Partnerprogramms von Amazon Europe S.à.r.l. und Partner des Werbeprogramms, das zur Bereitstellung eines Mediums
für Websites konzipiert wurde, mittels dessen durch die Platzierung von Werbeanzeigen und Links zu amazon.de
Werbekostenerstattung verdient werden kann.
Die Vervielfältigung der auf den Seiten www.c-plusplus.de, www.c-plusplus.info, www.c-sar.de, www.c-plusplus.net und www.baeckmann.de
enthaltenen Informationen ohne eine schriftliche Genehmigung des Seitenbetreibers ist untersagt
(vgl. §4 Urheberrechtsgesetz). Die Nutzung und Änderung der vorgestellten Strukturen und Verfahren in
privaten und kommerziellen Softwareanwendungen ist ausdrücklich erlaubt, soweit keine Rechte Dritter verletzt werden.
Der Seitenbetreiber übernimmt keine Gewähr für die Funktion einzelner Beiträge oder Programmfragmente, insbesondere
übernimmt er keine Haftung für eventuelle aus dem Gebrauch entstehenden Folgeschäden.