mturk 2005/01/18 02:23:15 Modified: jni/native libtcnative.dsp tcnative.dsp jni/native/os/netware system.c jni/native/os/unix system.c jni/native/os/win32 system.c Log: Add system info for gathering stats. Revision Changes Path 1.4 +4 -4 jakarta-tomcat-connectors/jni/native/libtcnative.dsp Index: libtcnative.dsp =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/libtcnative.dsp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- libtcnative.dsp 17 Jan 2005 18:27:47 -0000 1.3 +++ libtcnative.dsp 18 Jan 2005 10:23:15 -0000 1.4 @@ -52,8 +52,8 @@ # ADD BASE BSC32 /nologo
# ADD BSC32 /nologo LINK32=link.exe -# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /opt:ref -# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /out:"Release/libtcnative-1.dll" /opt:ref +# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /opt:ref +# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /out:"Release/libtcnative-1.dll" /opt:ref !ELSEIF "$(CFG)" == "libtcnative - Win32 Debug" @@ -78,8 +78,8 @@ # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe -# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 -# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 /out:"Debug/libtcnative-1.dll" +# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 +# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 /out:"Debug/libtcnative-1.dll" !ENDIF 1.4 +4 -4 jakarta-tomcat-connectors/jni/native/tcnative.dsp Index: tcnative.dsp =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/tcnative.dsp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- tcnative.dsp 17 Jan 2005 18:27:47 -0000 1.3 +++ tcnative.dsp 18 Jan 2005 10:23:15 -0000 1.4 @@ -52,8 +52,8 @@ # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe -# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /opt:ref -# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib rpcrt4.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /out:"Release/tcnative-1.dll" /opt:ref +# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /opt:ref +# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib rpcrt4.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /out:"Release/tcnative-1.dll" /opt:ref !ELSEIF "$(CFG)" == "tcnative - Win32 Debug" @@ -78,8 +78,8 @@ # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe -# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 -# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib ole32.lib rpcrt4.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 /out:"Debug/tcnative-1.dll" +# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 +# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib rpcrt4.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 /out:"Debug/tcnative-1.dll" !ENDIF 1.3 +8 -0 jakarta-tomcat-connectors/jni/native/os/netware/system.c Index: system.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/os/netware/system.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- system.c 17 Jan 2005 18:28:32 -0000 1.2 +++ system.c 18 Jan 2005 10:23:15 -0000 1.3 @@ -27,3 +27,11 @@ else return JNI_FALSE; } + +TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS, + jlongArray inf) +{ + UNREFERENCED_STDARGS; + UNREFERENCED(inf); + return APR_ENOTIMPL; +} 1.3 +8 -0 jakarta-tomcat-connectors/jni/native/os/unix/system.c Index: system.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/os/unix/system.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- system.c 17 Jan 2005 18:28:32 -0000 1.2 +++ system.c 18 Jan 2005 10:23:15 -0000 1.3 @@ -27,3 +27,11 @@ else return JNI_FALSE; } + +TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS, + jlongArray inf) +{ + UNREFERENCED_STDARGS; + UNREFERENCED(inf); + return APR_ENOTIMPL; +} 1.3 +171 -1 jakarta-tomcat-connectors/jni/native/os/win32/system.c Index: system.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/os/win32/system.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- system.c 17 Jan 2005 18:28:32 -0000 1.2 +++ system.c 18 Jan 2005 10:23:15 -0000 1.3 @@ -13,13 +13,99 @@ * limitations under the License. */ +#define _WIN32_WINNT 0x0500 + #include "apr.h" #include "apr_pools.h" #include "apr_network_io.h" -#include "apr_arch_misc.h" /* for apr_os_level */ +#include "apr_arch_misc.h" /* for apr_os_level */ +#include "apr_arch_atime.h" /* for FileTimeToAprTime */ #include "tcn.h" +#pragma warning(push) +#pragma warning(disable : 4201) +#include <winternl.h> +#include <psapi.h> +#pragma warning(pop) + + +static CRITICAL_SECTION dll_critical_section; /* dll's critical section */ +static HINSTANCE dll_instance = NULL; +static SYSTEM_INFO dll_system_info; +static HANDLE h_kernel = NULL; +static HANDLE h_ntdll = NULL; + +typedef BOOL (WINAPI *pfnGetSystemTimes)(LPFILETIME, LPFILETIME, LPFILETIME); +typedef NTSTATUS (WINAPI *pfnNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); + +static pfnGetSystemTimes fnGetSystemTimes = NULL; +static pfnNtQuerySystemInformation fnNtQuerySystemInformation = NULL; + +BOOL +WINAPI +DllMain( + HINSTANCE instance, + DWORD reason, + LPVOID reserved) +{ + + switch (reason) { + /** The DLL is loading due to process + * initialization or a call to LoadLibrary. + */ + case DLL_PROCESS_ATTACH: + InitializeCriticalSection(&dll_critical_section); + dll_instance = instance; + GetSystemInfo(&dll_system_info); + if ((h_kernel = LoadLibrary("kernel32.dll")) != NULL) + fnGetSystemTimes = (pfnGetSystemTimes)GetProcAddress(h_kernel, + "GetSystemTimes"); + if (fnGetSystemTimes == NULL) { + FreeLibrary(h_kernel); + h_kernel = NULL; + if ((h_ntdll = LoadLibrary("ntdll.dll")) != NULL) + fnNtQuerySystemInformation = + (pfnNtQuerySystemInformation)GetProcAddress(h_ntdll, + "NtQuerySystemInformation"); + + if (fnNtQuerySystemInformation == NULL) { + FreeLibrary(h_ntdll); + h_ntdll = NULL; + } + } + break; + /** The attached process creates a new thread. + */ + case DLL_THREAD_ATTACH: + break; + + /** The thread of the attached process terminates. + */ + case DLL_THREAD_DETACH: + break; + + /** DLL unload due to process termination + * or FreeLibrary. + */ + case DLL_PROCESS_DETACH: + /* Make sure the library is always terminated */ + apr_terminate(); + if (h_kernel) + FreeLibrary(h_kernel); + if (h_ntdll) + FreeLibrary(h_ntdll); + DeleteCriticalSection(&dll_critical_section); + break; + + default: + break; + } + + return TRUE; + UNREFERENCED_PARAMETER(reserved); +} + TCN_IMPLEMENT_CALL(jboolean, OS, is)(TCN_STDARGS, jint type) { @@ -33,4 +119,88 @@ return JNI_TRUE; else return JNI_FALSE; +} + +TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS, + jlongArray inf) +{ + MEMORYSTATUSEX ms; + ULONGLONG st[4]; + FILETIME ft[4]; + PROCESS_MEMORY_COUNTERS pmc; + jint rv; + jsize ilen = (*e)->GetArrayLength(e, inf); + jlong *pvals = (*e)->GetLongArrayElements(e, inf, NULL); + + if (ilen < 14) { + + return APR_EINVAL; + } + ms.dwLength = sizeof(MEMORYSTATUSEX); + + UNREFERENCED(o); + if (GlobalMemoryStatusEx(&ms)) { + pvals[0] = (jlong)ms.ullTotalPhys; + pvals[1] = (jlong)ms.ullAvailPhys; + pvals[2] = (jlong)ms.ullTotalPageFile; + pvals[3] = (jlong)ms.ullAvailPageFile; + pvals[4] = (jlong)ms.dwMemoryLoad; + } + else + goto cleanup; + + memset(st, 0, sizeof(st)); + + if (fnGetSystemTimes) { + if ((*fnGetSystemTimes)(&ft[0], &ft[1], &ft[2])) { + st[0] = ((ft[0].dwHighDateTime << 32) | ft[0].dwLowDateTime) / 10; + st[1] = ((ft[1].dwHighDateTime << 32) | ft[1].dwLowDateTime) / 10; + st[2] = ((ft[2].dwHighDateTime << 32) | ft[2].dwLowDateTime) / 10; + } + else + goto cleanup; + } + else if (fnNtQuerySystemInformation) { + BYTE buf[2048]; /* This should ne enough for 32 processors */ + NTSTATUS rs = (*fnNtQuerySystemInformation)(SystemProcessorPerformanceInformation, + (LPVOID)buf, 2048, NULL); + if (rs == 0) { + PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&buf[0]; + DWORD i; + /* Calculate all processors */ + for (i = 0; i < dll_system_info.dwNumberOfProcessors; i++) { + st[0] += pspi[i].IdleTime.QuadPart / 10; + st[1] += pspi[i].KernelTime.QuadPart / 10; + st[2] += pspi[i].UserTime.QuadPart / 10; + } + } + else + goto cleanup; + } + pvals[5] = st[0]; + pvals[6] = st[1]; + pvals[7] = st[2]; + + memset(st, 0, sizeof(st)); + if (GetProcessTimes(GetCurrentProcess(), &ft[0], &ft[1], &ft[2], &ft[3])) { + FileTimeToAprTime((apr_time_t *)&st[0], &ft[0]); + st[1] = ((ft[2].dwHighDateTime << 32) | ft[2].dwLowDateTime) / 10; + st[2] = ((ft[3].dwHighDateTime << 32) | ft[3].dwLowDateTime) / 10; + } + pvals[8] = st[0]; + pvals[9] = st[1]; + pvals[10] = st[2]; + + if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) { + pvals[11] = pmc.WorkingSetSize; + pvals[12] = pmc.PeakWorkingSetSize; + pvals[13] = pmc.PageFaultCount; + } + + (*e)->ReleaseLongArrayElements(e, inf, pvals, 0); + return APR_SUCCESS; +cleanup: + rv = apr_get_os_error(); + (*e)->ReleaseLongArrayElements(e, inf, pvals, JNI_ABORT); + return rv; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]