Sir_Yaro Opublikowano 25 Listopada 2003 Zgłoś Opublikowano 25 Listopada 2003 Jak z linii polecen sprawdzic obciazenie kompa (% zajetosc procesora)? Efekt/wynik ma sie wyswietlic w trybie tekstowym albo zapisac do pliku. Moge ew. uzyc czegos w rodzaju program.exe>wynik.txt tylko nie wiem jaki prg. Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
phranzee Opublikowano 25 Listopada 2003 Zgłoś Opublikowano 25 Listopada 2003 top Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
Sir_Yaro Opublikowano 25 Listopada 2003 Zgłoś Opublikowano 25 Listopada 2003 W windzie...... Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
phranzee Opublikowano 25 Listopada 2003 Zgłoś Opublikowano 25 Listopada 2003 aha :P malo jest programikow tekstowych dla tego sysa. przyznam sie, ze nie widzialem takiego. jak masz pol godzikni to mozesz napisac :) nie mowie tego zlosliwie :) Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
Sir_Yaro Opublikowano 25 Listopada 2003 Zgłoś Opublikowano 25 Listopada 2003 moze i tak tylko nie wiem jakiej funcji API uzyc.... Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
phranzee Opublikowano 25 Listopada 2003 Zgłoś Opublikowano 25 Listopada 2003 Here is a document I got from a web site:The one of most popular question I see in the newsgroups is a question aboutreceiving and calculating the CPU usage, so I've decided to describe it inthis trick. At first, I should say that there is a big difference betweengetting the CPU usage on Windows 95/98 and on Windows NT/2000, in thisarticle I'll show you a method that perfectly works on Windows 9x (forexample in my free screen saver - CPU Indicator SS ). About getting the CPUusage on NT you'll read in my next trick.Like NT the Windows 9x has the Performance Counters but on Windows 9x theyare more easy to use so we will use one of these counters to receive the CPUusage.Our first step is starting selected counter because by default all countersare stoped. To start the counter we should read the corresponding registrykey:HKEY hkey;RegOpenKeyEx ( HKEY_DYN_DATA,"PerfStats\\StartStat",0,KEY_ALL_ACCESS,&hkey );DWORD dwDataSize;DWORD dwType;DWORD dwDummy;dwDataSize=sizeof(dwDummy); RegQueryValueEx ( hkey,"KERNEL\\CPUUsage",NULL,&dwType,(LPBYTE)&dwDummy,&dwDataSize );RegCloseKey(hkey);The next step is reading the CPU usage directly from the registry:HKEY hkey;RegOpenKeyEx ( HKEY_DYN_DATA,"PerfStats\\StatData",0,KEY_ALL_ACCESS,&hkey );DWORD dwDataSize;DWORD dwType;DWORD dwCpuUsage;dwDataSize=sizeof(dwCpuUsage); RegQueryValueEx ( hkey,"KERNEL\\CPUUsage",NULL,&dwType,(LPBYTE)&dwCpuUsage,&dwDataSize );RegCloseKey(hkey);Now the dwCpuUsage variable contains current CPU usage in percent. Youshould call above code in the loop to see the dynamic changes.And the final step is stoping the counter previously started:HKEY hkey;RegOpenKeyEx ( HKEY_DYN_DATA,"PerfStats\\StopStat",0,KEY_ALL_ACCESS,&hkey );DWORD dwDataSize;DWORD dwType;DWORD dwDummy;dwDataSize=sizeof(dwDummy); RegQueryValueEx ( hkey,"KERNEL\\CPUUsage",NULL,&dwType,(LPBYTE)&dwDummy,&dwDataSize );RegCloseKey(hkey);-------------------#include <winreg.h>int getCpuUsage(void){ int trug=-1; DWORD rc; HKEY hOpen; LPVOID lpMsgBuf; unsigned char data[4]; unsigned long size=4; bool error=false; if ((rc = RegOpenKeyEx(HKEY_DYN_DATA,"PerfStats\\StatData", 0,KEY_READ,&hOpen)) == ERROR_SUCCESS) { if ((rc=RegQueryValueEx(hOpen,"KERNEL\\CPUUsage",NULL,NULL,(unsignedchar *)data,&size)) == ERROR_SUCCESS) trug=data[0]; else error=true; RegCloseKey(hOpen); } else error=true; if (error) { FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &lpMsgBuf, 0, NULL); MessageBox( NULL, (LPSTR)lpMsgBuf, "Fout", MB_OK|MB_ICONINFORMATION ); LocalFree( lpMsgBuf ); } return trug;}------------------------#include <windows.h>#include <conio.h>#include <stdio.h>#define SystemBasicInformation 0#define SystemPerformanceInformation 2#define SystemTimeInformation 3#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))typedef struct{ DWORD dwUnknown1; ULONG uKeMaximumIncrement; ULONG uPageSize; ULONG uMmNumberOfPhysicalPages; ULONG uMmLowestPhysicalPage; ULONG uMmHighestPhysicalPage; ULONG uAllocationGranularity; PVOID pLowestUserAddress; PVOID pMmHighestUserAddress; ULONG uKeActiveProcessors; BYTE bKeNumberProcessors; BYTE bUnknown2; WORD wUnknown3;} SYSTEM_BASIC_INFORMATION;typedef struct{ LARGE_INTEGER liIdleTime; DWORD dwSpare[76];} SYSTEM_PERFORMANCE_INFORMATION;typedef struct{ LARGE_INTEGER liKeBootTime; LARGE_INTEGER liKeSystemTime; LARGE_INTEGER liExpTimeZoneBias; ULONG uCurrentTimeZoneId; DWORD dwReserved;} SYSTEM_TIME_INFORMATION;// ntdll!NtQuerySystemInformation (NT specific!)//// The function copies the system information of the// specified type into a buffer//// NTSYSAPI// NTSTATUS// NTAPI// NtQuerySystemInformation(// IN UINT SystemInformationClass, // information type// OUT PVOID SystemInformation, // pointer to buffer// IN ULONG SystemInformationLength, // buffer size in bytes// OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit// // variable that receives// // the number of bytes// // written to the buffer // );typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);PROCNTQSI NtQuerySystemInformation;void main(void){ SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; SYSTEM_TIME_INFORMATION SysTimeInfo; SYSTEM_BASIC_INFORMATION SysBaseInfo; double dbIdleTime; double dbSystemTime; LONG status; LARGE_INTEGER liOldIdleTime = {0,0}; LARGE_INTEGER liOldSystemTime = {0,0}; NtQuerySystemInformation = (PROCNTQSI)GetProcAddress( GetModuleHandle("ntdll"), "NtQuerySystemInformation" ); if (!NtQuerySystemInformation) return; // get number of processors in the system status = NtQuerySystemInformation(SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL); if (status != NO_ERROR) return; printf("nCPU Usage (press any key to exit): "); while(!_kbhit()) { // get new system time status = NtQuerySystemInformation(SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0); if (status!=NO_ERROR) return; // get new CPU's idle time status = NtQuerySystemInformation(SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL); if (status != NO_ERROR) return; // if it's a first call - skip it if (liOldIdleTime.QuadPart != 0) { // CurrentValue = NewValue - OldValue dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime); dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime dbIdleTime = dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5; printf("bbbb%3d%%",(UINT)dbIdleTime); } // store new CPU's idle and system time liOldIdleTime = SysPerfInfo.liIdleTime; liOldSystemTime = SysTimeInfo.liKeSystemTime; // wait one second Sleep(1000); } printf("n");}--------------------// cpusagent.cpp (Windows NT/2000)//// Getting the CPU usage in percent on Windows NT/2000//// (c)2000 Ashot Oganesyan K, SmartLine, Inc// mailto:ashot@aha.ru, http://www.protect-me.com, http://www.codepile.com#include <windows.h>#include <conio.h>#include <stdio.h>#define SystemBasicInformation 0#define SystemPerformanceInformation 2#define SystemTimeInformation 3#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))typedef struct{ DWORD dwUnknown1; ULONG uKeMaximumIncrement; ULONG uPageSize; ULONG uMmNumberOfPhysicalPages; ULONG uMmLowestPhysicalPage; ULONG uMmHighestPhysicalPage; ULONG uAllocationGranularity; PVOID pLowestUserAddress; PVOID pMmHighestUserAddress; ULONG uKeActiveProcessors; BYTE bKeNumberProcessors; BYTE bUnknown2; WORD wUnknown3;} SYSTEM_BASIC_INFORMATION;typedef struct{ LARGE_INTEGER liIdleTime; DWORD dwSpare[76];} SYSTEM_PERFORMANCE_INFORMATION;typedef struct{ LARGE_INTEGER liKeBootTime; LARGE_INTEGER liKeSystemTime; LARGE_INTEGER liExpTimeZoneBias; ULONG uCurrentTimeZoneId; DWORD dwReserved;} SYSTEM_TIME_INFORMATION;// ntdll!NtQuerySystemInformation (NT specific!)//// The function copies the system information of the// specified type into a buffer//// NTSYSAPI// NTSTATUS// NTAPI// NtQuerySystemInformation(// IN UINT SystemInformationClass, // information type// OUT PVOID SystemInformation, // pointer to buffer// IN ULONG SystemInformationLength, // buffer size in bytes// OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit// // variable that receives// // the number of bytes// // written to the buffer // );typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);PROCNTQSI NtQuerySystemInformation;void main(void){ SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; SYSTEM_TIME_INFORMATION SysTimeInfo; SYSTEM_BASIC_INFORMATION SysBaseInfo; double dbIdleTime; double dbSystemTime; LONG status; LARGE_INTEGER liOldIdleTime = {0,0}; LARGE_INTEGER liOldSystemTime = {0,0}; NtQuerySystemInformation = (PROCNTQSI)GetProcAddress( GetModuleHandle("ntdll"), "NtQuerySystemInformation" ); if (!NtQuerySystemInformation) return; // get number of processors in the system status = NtQuerySystemInformation(SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL); if (status != NO_ERROR) return; printf("nCPU Usage (press any key to exit): "); while(!_kbhit()) { // get new system time status = NtQuerySystemInformation(SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0); if (status!=NO_ERROR) return; // get new CPU's idle time status = NtQuerySystemInformation(SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL); if (status != NO_ERROR) return; // if it's a first call - skip it if (liOldIdleTime.QuadPart != 0) { // CurrentValue = NewValue - OldValue dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime); dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime dbIdleTime = dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5; printf("bbbb%3d%%",(UINT)dbIdleTime); } // store new CPU's idle and system time liOldIdleTime = SysPerfInfo.liIdleTime; liOldSystemTime = SysTimeInfo.liKeSystemTime; // wait one second Sleep(1000); } printf("n");}sie mi po dysku poniewieralo, moze cos wyskubiesz z tego. pewnie gdzies jeszcze mam chodzacy program :) tak, wiem ze duzo wkleilem ;] Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
Sir_Yaro Opublikowano 26 Listopada 2003 Zgłoś Opublikowano 26 Listopada 2003 To moze daj to juz skompilowane... :) Bo ja nie mam zadnego kompilatora do C :P I dla takiej pie.rdołki nie chce nic nowego instalowac... Bede "dźwięczny".... Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
Sir_Yaro Opublikowano 26 Listopada 2003 Zgłoś Opublikowano 26 Listopada 2003 Znalazlem odpowiednie narzedzie w Windows 2000 Resource Kit: Dzial identycznie jak uniksowe top http://www.dynawell.com/reskit/microsoft/w...in2000/pmon.zip Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...