mturk       2005/05/28 04:40:52

  Modified:    jni/java/org/apache/tomcat/jni OS.java
               jni/native/os/unix system.c
               jni/native/os/win32 system.c
  Log:
  Update OS info for linux
  
  Revision  Changes    Path
  1.6       +29 -17    
jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/OS.java
  
  Index: OS.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/OS.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- OS.java   12 May 2005 19:29:47 -0000      1.5
  +++ OS.java   28 May 2005 11:40:52 -0000      1.6
  @@ -29,6 +29,9 @@
       private static final int NETWARE  = 2;
       private static final int WIN32    = 3;
       private static final int WIN64    = 4;
  +    private static final int LINUX    = 5;
  +    private static final int SOLARIS  = 6;
  +    private static final int BSD      = 7;
   
       /**
        * Check for OS type.
  @@ -41,12 +44,18 @@
           IS_NETWARE = is(NETWARE);
           IS_WIN32   = is(WIN32);
           IS_WIN64   = is(WIN64);
  +        IS_LINUX   = is(LINUX);
  +        IS_SOLARIS = is(SOLARIS);
  +        IS_BSD     = is(BSD);
       }
   
       public static boolean IS_UNIX    = false;
       public static boolean IS_NETWARE = false;
       public static boolean IS_WIN32   = false;
       public static boolean IS_WIN64   = false;
  +    public static boolean IS_LINUX   = false;
  +    public static boolean IS_SOLARIS = false;
  +    public static boolean IS_BSD     = false;
   
       /**
        * Get the name of the system default characer set.
  @@ -73,26 +82,29 @@
        * Gather system info.
        * <PRE>
        * On exit the inf array will be filled with:
  -     * inf[0]  - Physical RAM
  -     * inf[1]  - Available RAM
  -     * inf[2]  - Total page file (swap + Physical RAM)
  -     * inf[3]  - Free page file
  -     * inf[4]  - Memory Load
  +     * inf[0]  - Total usable main memory size
  +     * inf[1]  - Available memory size
  +     * inf[2]  - Total page file/swap space size
  +     * inf[3]  - Page file/swap space still available
  +     * inf[4]  - Amount of shared memory
  +     * inf[5]  - Memory used by buffers
  +     * inf[6]  - Memory Load
        *
  -     * inf[5]  - Idle Time in microseconds
  -     * inf[6]  - Kernel Time in microseconds
  -     * inf[7]  - User Time in microseconds
  +     * inf[7]  - Idle Time in microseconds
  +     * inf[9]  - Kernel Time in microseconds
  +     * inf[9]  - User Time in microseconds
        *
  -     * inf[8]  - Process creation time (apr_time_t)
  -     * inf[9]  - Process Kernel Time in microseconds
  -     * inf[10] - Process User Time in microseconds
  +     * inf[10] - Process creation time (apr_time_t)
  +     * inf[11] - Process Kernel Time in microseconds
  +     * inf[12] - Process User Time in microseconds
        *
  -     * inf[11] - Current working set size.
  -     * inf[12] - Peak working set size.
  -     * inf[13] - Number of page faults.
  +     * inf[13] - Current working set size.
  +     * inf[14] - Peak working set size.
  +     * inf[15] - Number of page faults.
        * </PRE>
  -     * @param inf array that will be filled with system informations.
  +     * @param inf array that will be filled with system information.
  +     *            Array length must be at least 16.
        */
       public static native int info(long [] inf);
  -    
  +
   }
  
  
  
  1.5       +49 -5     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- system.c  24 May 2005 09:25:36 -0000      1.4
  +++ system.c  28 May 2005 11:40:52 -0000      1.5
  @@ -18,18 +18,33 @@
    * @author Mladen Turk
    * @version $Revision$, $Date$
    */
  - 
  +
   #include "apr.h"
   #include "apr_pools.h"
   #include "apr_network_io.h"
   
   #include "tcn.h"
  +#if defined(__linux__)
  +#include <sys/sysinfo.h>
  +#endif
   
   TCN_IMPLEMENT_CALL(jboolean, OS, is)(TCN_STDARGS, jint type)
   {
       UNREFERENCED_STDARGS;
       if (type == 1)
           return JNI_TRUE;
  +#if defined(__linux__)
  +    else if (type == 5)
  +        return JNI_TRUE;
  +#endif
  +#if defined(sun)
  +    else if (type == 6)
  +        return JNI_TRUE;
  +#endif
  +#if defined(__FreeBSD__) || defined(__NetBSD__)
  +    else if (type == 7)
  +        return JNI_TRUE;
  +#endif
       else
           return JNI_FALSE;
   }
  @@ -37,7 +52,36 @@
   TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS,
                                      jlongArray inf)
   {
  -    UNREFERENCED_STDARGS;
  -    UNREFERENCED(inf);
  -    return APR_ENOTIMPL;
  +    jint rv;
  +    int  i;
  +    jsize ilen = (*e)->GetArrayLength(e, inf);
  +    jlong *pvals = (*e)->GetLongArrayElements(e, inf, NULL);
  +
  +    UNREFERENCED(o);
  +    if (ilen < 16) {
  +        return APR_EINVAL;
  +    }
  +    for (i = 0; i < 16; i++)
  +        pvals[i] = 0;
  +#if defined(__linux__)
  +    {
  +        struct sysinfo info;
  +        if (sysinfo(&info))
  +            rv = apr_get_os_error();
  +        else {
  +            pvals[0] = (jlong)info.totalram;
  +            pvals[1] = (jlong)info.freeram;
  +            pvals[2] = (jlong)info.totalswap;
  +            pvals[3] = (jlong)info.freeswap;
  +            pvals[4] = (jlong)info.sharedram;
  +            pvals[5] = (jlong)info.bufferram;
  +            pvals[6] = (jlong)(100 - (info.freeram * 100 / info.totalram));
  +            rv = APR_SUCCESS;
  +        }
  +    }
  +#else
  +    rv = APR_ENOTIMPL;
  +#endif
  +   (*e)->ReleaseLongArrayElements(e, inf, pvals, 0);
  +    return rv;
   }
  
  
  
  1.5       +19 -15    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- system.c  24 May 2005 09:25:36 -0000      1.4
  +++ system.c  28 May 2005 11:40:52 -0000      1.5
  @@ -18,7 +18,7 @@
    * @author Mladen Turk
    * @version $Revision$, $Date$
    */
  - 
  +
   #define _WIN32_WINNT 0x0500
   
   #include "apr.h"
  @@ -135,13 +135,16 @@
       FILETIME ft[4];
       PROCESS_MEMORY_COUNTERS pmc;
       jint rv;
  +    int i;
       jsize ilen = (*e)->GetArrayLength(e, inf);
       jlong *pvals = (*e)->GetLongArrayElements(e, inf, NULL);
   
  -    if (ilen < 14) {
  -
  +    if (ilen < 16) {
           return APR_EINVAL;
       }
  +    for (i = 0; i < 16; i++)
  +        pvals[i] = 0;
  +
       ms.dwLength = sizeof(MEMORYSTATUSEX);
   
       UNREFERENCED(o);
  @@ -150,7 +153,8 @@
           pvals[1] = (jlong)ms.ullAvailPhys;
           pvals[2] = (jlong)ms.ullTotalPageFile;
           pvals[3] = (jlong)ms.ullAvailPageFile;
  -        pvals[4] = (jlong)ms.dwMemoryLoad;
  +        /* Slots 4 and 5 are for shared memory */
  +        pvals[6] = (jlong)ms.dwMemoryLoad;
       }
       else
           goto cleanup;
  @@ -183,9 +187,9 @@
           else
               goto cleanup;
       }
  -    pvals[5] = st[0];
  -    pvals[6] = st[1];
  -    pvals[7] = st[2];
  +    pvals[7] = st[0];
  +    pvals[8] = st[1];
  +    pvals[9] = st[2];
   
       memset(st, 0, sizeof(st));
       if (GetProcessTimes(GetCurrentProcess(), &ft[0], &ft[1], &ft[2], 
&ft[3])) {
  @@ -193,20 +197,20 @@
           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];
  +    pvals[10] = st[0];
  +    pvals[11] = st[1];
  +    pvals[12] = st[2];
   
       if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
  -        pvals[11] = pmc.WorkingSetSize;
  -        pvals[12] = pmc.PeakWorkingSetSize;
  -        pvals[13] = pmc.PageFaultCount;
  +        pvals[14] = pmc.WorkingSetSize;
  +        pvals[14] = pmc.PeakWorkingSetSize;
  +        pvals[15] = pmc.PageFaultCount;
       }
   
       (*e)->ReleaseLongArrayElements(e, inf, pvals, 0);
       return APR_SUCCESS;
   cleanup:
       rv = apr_get_os_error();
  -    (*e)->ReleaseLongArrayElements(e, inf, pvals, JNI_ABORT);
  +    (*e)->ReleaseLongArrayElements(e, inf, pvals, 0);
       return rv;
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to