* fhandler_proc.cc (format_proc_uptime): Drop usage of GetSystemTimes.

Use NtQuerySystemInformation to evaluate uptime and idle_time from
	all CPU's processor times.  Fallback to GetTickCount.
This commit is contained in:
Corinna Vinschen 2005-12-12 12:18:14 +00:00
parent 74ecef0dea
commit e96abae130
2 changed files with 31 additions and 18 deletions

View File

@ -1,3 +1,9 @@
2005-12-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_proc.cc (format_proc_uptime): Drop usage of GetSystemTimes.
Use NtQuerySystemInformation to evaluate uptime and idle_time from
all CPU's processor times. Fallback to GetTickCount.
2005-12-12 Corinna Vinschen <corinna@vinschen.de> 2005-12-12 Corinna Vinschen <corinna@vinschen.de>
* mmap.cc (gen_create_protect): Always generate WRITECOPY protection * mmap.cc (gen_create_protect): Always generate WRITECOPY protection

View File

@ -468,30 +468,37 @@ static _off64_t
format_proc_uptime (char *destbuf, size_t maxsize) format_proc_uptime (char *destbuf, size_t maxsize)
{ {
unsigned long long uptime = 0ULL, idle_time = 0ULL; unsigned long long uptime = 0ULL, idle_time = 0ULL;
SYSTEM_PROCESSOR_TIMES spt;
if (!GetSystemTimes ((FILETIME *) &spt.IdleTime, (FILETIME *) &spt.KernelTime, if (wincap.is_winnt ())
(FILETIME *) &spt.UserTime)
&& GetLastError () == ERROR_PROC_NOT_FOUND)
{ {
NTSTATUS ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) &spt, NTSTATUS ret;
sizeof spt, NULL); SYSTEM_BASIC_INFORMATION sbi;
if (!ret && GetLastError () == ERROR_PROC_NOT_FOUND)
{ ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
uptime = GetTickCount () / 10; sizeof sbi, NULL);
goto out; if (!NT_SUCCESS (ret))
}
else if (ret != STATUS_SUCCESS)
{ {
__seterrno_from_nt_status (ret); __seterrno_from_nt_status (ret);
debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret); debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
return 0; sbi.NumberProcessors = 1;
} }
SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
sizeof spt[0] * sbi.NumberProcessors,
NULL);
if (NT_SUCCESS (ret))
for (int i = 0; i < sbi.NumberProcessors; i++)
{
uptime += (spt[i].KernelTime.QuadPart + spt[i].UserTime.QuadPart)
/ 100000ULL;
idle_time += spt[i].IdleTime.QuadPart / 100000ULL;
}
uptime /= sbi.NumberProcessors;
idle_time /= sbi.NumberProcessors;
} }
idle_time = spt.IdleTime.QuadPart / 100000ULL; if (!uptime)
uptime = (spt.KernelTime.QuadPart + uptime = GetTickCount () / 10;
spt.UserTime.QuadPart) / 100000ULL;
out:
return __small_sprintf (destbuf, "%U.%02u %U.%02u\n", return __small_sprintf (destbuf, "%U.%02u %U.%02u\n",
uptime / 100, long (uptime % 100), uptime / 100, long (uptime % 100),