Author: mladen.turk(a)jboss.com
Date: 2007-10-01 06:29:06 -0400 (Mon, 01 Oct 2007)
New Revision: 1071
Modified:
trunk/sight/native/os/windows/cpustat.c
Log:
Seal Windows cpustat JNI calls
Modified: trunk/sight/native/os/windows/cpustat.c
===================================================================
--- trunk/sight/native/os/windows/cpustat.c 2007-10-01 10:24:15 UTC (rev 1070)
+++ trunk/sight/native/os/windows/cpustat.c 2007-10-01 10:29:06 UTC (rev 1071)
@@ -153,78 +153,82 @@
return APR_EINVAL;
if ((DWORD)cpuid > sight_osinf->dwNumberOfProcessors)
return APR_EINVAL;
+ SIGHT_LOCAL_TRY(no) {
+ if (GetSystemTimes(&ft[0], &ft[1], &ft[2])) {
+ jt[0] = filetime_to_ms(&ft[2]);
+ jt[1] = filetime_to_ms(&ft[1]);
+ jt[2] = filetime_to_ms(&ft[0]);
+ has_aggregate = 1;
+ }
+ if (!cpuid && !has_aggregate) {
+ DWORD i;
+ for (i = 0; i < sight_osinf->dwNumberOfProcessors; i++) {
+ if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
+ (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
+ PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi =
+ (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&b[0];
- if (GetSystemTimes(&ft[0], &ft[1], &ft[2])) {
- jt[0] = filetime_to_ms(&ft[2]);
- jt[1] = filetime_to_ms(&ft[1]);
- jt[2] = filetime_to_ms(&ft[0]);
- has_aggregate = 1;
- }
- if (!cpuid && !has_aggregate) {
- DWORD i;
- for (i = 0; i < sight_osinf->dwNumberOfProcessors; i++) {
+ jt[0] += largeint_to_ms(&(pspi[i].UserTime));
+ jt[1] += largeint_to_ms(&(pspi[i].KernelTime));
+ jt[2] += largeint_to_ms(&(pspi[i].IdleTime));
+ }
+ }
+ }
+ if (cpuid) {
if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
- (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
+ (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi =
(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&b[0];
- jt[0] += largeint_to_ms(&(pspi[i].UserTime));
- jt[1] += largeint_to_ms(&(pspi[i].KernelTime));
- jt[2] += largeint_to_ms(&(pspi[i].IdleTime));
+ jt[0] = largeint_to_ms(&(pspi[cpuid - 1].UserTime));
+ jt[1] = largeint_to_ms(&(pspi[cpuid - 1].KernelTime));
+ jt[2] = largeint_to_ms(&(pspi[cpuid - 1].IdleTime));
}
}
- }
- if (cpuid) {
- if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
- (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
- PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi =
- (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&b[0];
-
- jt[0] = largeint_to_ms(&(pspi[cpuid - 1].UserTime));
- jt[1] = largeint_to_ms(&(pspi[cpuid - 1].KernelTime));
- jt[2] = largeint_to_ms(&(pspi[cpuid - 1].IdleTime));
- }
- }
- else {
- HANDLE hProcessSnap;
- PROCESSENTRY32 pe32;
- hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (!IS_INVALID_HANDLE(hProcessSnap)) {
- DWORD pc = 0, tc = 0;
- pe32.dwSize = sizeof(PROCESSENTRY32);
- if (Process32First(hProcessSnap, &pe32)) {
- do {
- pc += 1;
- tc += pe32.cntThreads;
- if (!cached_boot_time && (apr_strnatcasecmp(pe32.szExeFile,
"smss.exe") == 0)) {
- HANDLE wp = OpenProcess(PROCESS_QUERY_INFORMATION,
- FALSE,
- pe32.th32ProcessID);
- if (!IS_INVALID_HANDLE(wp)) {
- if (GetProcessTimes(wp, &ft[0], &ft[1],
- &ft[2], &ft[3])) {
- cached_boot_time = winftime_to_ms(&ft[0]);
+ else {
+ HANDLE hProcessSnap;
+ PROCESSENTRY32 pe32;
+ hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (!IS_INVALID_HANDLE(hProcessSnap)) {
+ DWORD pc = 0, tc = 0;
+ pe32.dwSize = sizeof(PROCESSENTRY32);
+ if (Process32First(hProcessSnap, &pe32)) {
+ do {
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINTR;
+ }
+ pc += 1;
+ tc += pe32.cntThreads;
+ if (!cached_boot_time &&
(apr_strnatcasecmp(pe32.szExeFile, "smss.exe") == 0)) {
+ HANDLE wp = OpenProcess(PROCESS_QUERY_INFORMATION,
+ FALSE,
+ pe32.th32ProcessID);
+ if (!IS_INVALID_HANDLE(wp)) {
+ if (GetProcessTimes(wp, &ft[0], &ft[1],
+ &ft[2], &ft[3])) {
+ cached_boot_time = winftime_to_ms(&ft[0]);
+ }
+ CloseHandle(wp);
}
- CloseHandle(wp);
}
- }
- } while(Process32Next(hProcessSnap, &pe32));
+ } while(Process32Next(hProcessSnap, &pe32));
+ }
+ CloseHandle(hProcessSnap);
+ SET_IFIELD_I(0009, thiz, pc + tc);
+ SET_IFIELD_I(0010, thiz, pc);
}
- CloseHandle(hProcessSnap);
- SET_IFIELD_I(0009, thiz, pc + tc);
- SET_IFIELD_I(0010, thiz, pc);
+ if (!cached_boot_time) {
+ GetSystemTimeAsFileTime(&ft[0]);
+ /* XXX: Using GetTickCount will give 49.7 days resolution */
+ cached_boot_time = winftime_to_ms(&ft[0]) - GetTickCount();
+ }
+ SET_IFIELD_J(0008, thiz, cached_boot_time);
+
}
- if (!cached_boot_time) {
- GetSystemTimeAsFileTime(&ft[0]);
- /* XXX: Using GetTickCount will give 49.7 days resolution */
- cached_boot_time = winftime_to_ms(&ft[0]) - GetTickCount();
- }
- SET_IFIELD_J(0008, thiz, cached_boot_time);
-
- }
- SET_IFIELD_J(0000, thiz, jt[0]);
- SET_IFIELD_J(0002, thiz, jt[1]);
- SET_IFIELD_J(0003, thiz, jt[2]);
-
+ SET_IFIELD_J(0000, thiz, jt[0]);
+ SET_IFIELD_J(0002, thiz, jt[1]);
+ SET_IFIELD_J(0003, thiz, jt[2]);
+ } SIGHT_LOCAL_END(no);
return APR_SUCCESS;
}