You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2005/05/27 18:39:13 UTC

cvs commit: jakarta-tomcat-connectors/jni/native/src jnilib.c network.c poll.c

mturk       2005/05/27 09:39:13

  Modified:    jni/native/include tcn.h
               jni/native/src jnilib.c network.c poll.c
  Log:
  Add statistics data that is compiled in only if -DTCN_DO_STATISTICS
  is defined at compile time.
  
  Revision  Changes    Path
  1.6       +5 -3      jakarta-tomcat-connectors/jni/native/include/tcn.h
  
  Index: tcn.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/include/tcn.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- tcn.h	24 May 2005 09:24:39 -0000	1.5
  +++ tcn.h	27 May 2005 16:39:13 -0000	1.6
  @@ -18,7 +18,7 @@
    * @author Mladen Turk
    * @version $Revision$, $Date$
    */
  - 
  +
   #ifndef TCN_H
   #define TCN_H
   
  @@ -138,5 +138,7 @@
   
   typedef struct tcn_callback tcn_callback_t;
   
  -
  +#ifdef TCN_DO_STATISTICS
  +#define TCN_MAX(a, b) ((a) > (b) ? (a) : (b))
  +#endif
   #endif /* TCN_H */
  
  
  
  1.5       +17 -4     jakarta-tomcat-connectors/jni/native/src/jnilib.c
  
  Index: jnilib.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/jnilib.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jnilib.c	24 May 2005 09:24:40 -0000	1.4
  +++ jnilib.c	27 May 2005 16:39:13 -0000	1.5
  @@ -18,7 +18,7 @@
    * @author Mladen Turk
    * @version $Revision$, $Date$
    */
  - 
  +
   #include "apr.h"
   #include "apr_pools.h"
   #include "apr_version.h"
  @@ -30,6 +30,10 @@
   #include "tcn.h"
   #include "tcn_version.h"
   
  +#ifdef TCN_DO_STATISTICS
  +extern void sp_poll_dump_statistics();
  +extern void sp_network_dump_statistics();
  +#endif
   
   apr_pool_t *tcn_global_pool = NULL;
   static JavaVM     *tcn_global_vm = NULL;
  @@ -44,7 +48,7 @@
       JNIEnv *env;
   
       UNREFERENCED(reserved);
  -    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_2)) {
  +    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_4)) {
           return JNI_ERR;
       }
       tcn_global_vm = vm;
  @@ -63,7 +67,7 @@
           return JNI_ERR;
   
       apr_initialize();
  -    return  JNI_VERSION_1_2;
  +    return  JNI_VERSION_1_4;
   }
   
   
  @@ -73,6 +77,7 @@
       JNIEnv *env;
   
       UNREFERENCED(reserved);
  +
       if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_2)) {
           return;
       }
  @@ -161,8 +166,16 @@
   
       UNREFERENCED_STDARGS;
       if (tcn_global_pool) {
  +#ifdef TCN_DO_STATISTICS
  +        fprintf(stderr, "APR Statistical data ....\n");
  +#endif
           apr_pool_destroy(tcn_global_pool);
           tcn_global_pool = NULL;
  +#ifdef TCN_DO_STATISTICS
  +        sp_poll_dump_statistics();
  +        sp_network_dump_statistics();
  +        fprintf(stderr, "APR Terminated\n");
  +#endif
       }
   }
   
  
  
  
  1.21      +51 -3     jakarta-tomcat-connectors/jni/native/src/network.c
  
  Index: network.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/network.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- network.c	24 May 2005 09:24:40 -0000	1.20
  +++ network.c	27 May 2005 16:39:13 -0000	1.21
  @@ -18,12 +18,19 @@
    * @author Mladen Turk
    * @version $Revision$, $Date$
    */
  - 
  +
   #include "apr.h"
   #include "apr_pools.h"
   #include "apr_network_io.h"
  +#include "apr_portable.h"
   #include "tcn.h"
   
  +#ifdef TCN_DO_STATISTICS
  +static int sp_created  = 0;
  +static int sp_closed   = 0;
  +static int sp_cleared  = 0;
  +static int sp_accepted = 0;
  +#endif
   
   #if  !APR_HAVE_IPV6
   #define APR_INET6 APR_INET
  @@ -40,6 +47,25 @@
       else if (F == 1) T = SOCK_DGRAM; \
       else T = F
   
  +#ifdef TCN_DO_STATISTICS
  +
  +static apr_status_t sp_socket_cleanup(void *data)
  +{
  +    sp_cleared++;
  +    return APR_SUCCESS;
  +}
  +
  +void sp_network_dump_statistics()
  +{
  +    fprintf(stderr, "Network Statistics ......\n");
  +    fprintf(stderr, "Sockets created         : %d\n", sp_created);
  +    fprintf(stderr, "Sockets accepted        : %d\n", sp_accepted);
  +    fprintf(stderr, "Sockets closed          : %d\n", sp_closed);
  +    fprintf(stderr, "Sockets cleared         : %d\n", sp_cleared);
  +}
  +
  +#endif
  +
   TCN_IMPLEMENT_CALL(jlong, Address, info)(TCN_STDARGS,
                                            jstring hostname,
                                            jint family, jint port,
  @@ -138,6 +164,13 @@
       TCN_THROW_IF_ERR(apr_socket_create(&s,
                        f, t, protocol, p), s);
   
  +#ifdef TCN_DO_STATISTICS
  +    sp_created++;
  +    apr_pool_cleanup_register(p, (const void *)s,
  +                              sp_socket_cleanup,
  +                              apr_pool_cleanup_null);
  +#endif
  +
   cleanup:
       return P2J(s);
   
  @@ -159,6 +192,12 @@
   
       UNREFERENCED_STDARGS;
       TCN_ASSERT(sock != 0);
  +
  +#ifdef TCN_DO_STATISTICS
  +    sp_closed++;
  +    apr_pool_cleanup_kill((apr_pool_t *)s, s, sp_socket_cleanup);
  +#endif
  +
       return (jint)apr_socket_close(s);
   }
   
  @@ -193,7 +232,16 @@
       UNREFERENCED(o);
       TCN_ASSERT(sock != 0);
   
  -    TCN_THROW_IF_ERR(apr_socket_accept(&n, s, p), s);
  +    TCN_THROW_IF_ERR(apr_socket_accept(&n, s, p), n);
  +
  +#ifdef TCN_DO_STATISTICS
  +    if (n) {
  +        sp_accepted++;
  +        apr_pool_cleanup_register(p, (const void *)n,
  +                                  sp_socket_cleanup,
  +                                  apr_pool_cleanup_null);
  +    }
  +#endif
   
   cleanup:
       return P2J(n);
  
  
  
  1.15      +106 -6    jakarta-tomcat-connectors/jni/native/src/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/poll.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- poll.c	24 May 2005 09:24:40 -0000	1.14
  +++ poll.c	27 May 2005 16:39:13 -0000	1.15
  @@ -18,12 +18,19 @@
    * @author Mladen Turk
    * @version $Revision$, $Date$
    */
  - 
  +
   #include "apr.h"
   #include "apr_pools.h"
   #include "apr_poll.h"
   #include "tcn.h"
   
  +
  +#ifdef TCN_DO_STATISTICS
  +static int sp_created       = 0;
  +static int sp_destroyed     = 0;
  +static int sp_cleared       = 0;
  +#endif
  +
   /* Internal poll structure for queryset
    */
   
  @@ -35,8 +42,59 @@
       apr_pollfd_t  *socket_set;
       apr_interval_time_t *socket_ttl;
       apr_interval_time_t max_ttl;
  +#ifdef TCN_DO_STATISTICS
  +    int sp_added;
  +    int sp_max_count;
  +    int sp_poll;
  +    int sp_polled;
  +    int sp_max_polled;
  +    int sp_remove;
  +    int sp_removed;
  +    int sp_maintained;
  +    int sp_max_maintained;
  +    int sp_err_poll;
  +    int sp_poll_timeout;
  +    int sp_overflow;
  +    int sp_equals;
  +#endif
   } tcn_pollset_t;
   
  +#ifdef TCN_DO_STATISTICS
  +static void sp_poll_statistics(tcn_pollset_t *p)
  +{
  +    fprintf(stderr, "Pollset Statistics ......\n");
  +    fprintf(stderr, "Number of added sockets : %d\n", p->sp_added);
  +    fprintf(stderr, "Max. number of sockets  : %d\n", p->sp_max_count);
  +    fprintf(stderr, "Poll calls              : %d\n", p->sp_poll);
  +    fprintf(stderr, "Poll timeouts           : %d\n", p->sp_poll_timeout);
  +    fprintf(stderr, "Poll errors             : %d\n", p->sp_err_poll);
  +    fprintf(stderr, "Poll overflows          : %d\n", p->sp_overflow);
  +    fprintf(stderr, "Polled sockets          : %d\n", p->sp_polled);
  +    fprintf(stderr, "Max. Polled sockets     : %d\n", p->sp_max_polled);
  +    fprintf(stderr, "Poll remove             : %d\n", p->sp_remove);
  +    fprintf(stderr, "Total removed           : %d\n", p->sp_removed);
  +    fprintf(stderr, "Maintained              : %d\n", p->sp_maintained);
  +    fprintf(stderr, "Max. maintained         : %d\n", p->sp_max_maintained);
  +    fprintf(stderr, "Number of duplicates    : %d\n", p->sp_equals);
  +
  +}
  +
  +static apr_status_t sp_poll_cleanup(void *data)
  +{
  +    sp_cleared++;
  +    sp_poll_statistics(data);
  +    return APR_SUCCESS;
  +}
  +
  +void sp_poll_dump_statistics()
  +{
  +    fprintf(stderr, "Poll Statistics .........\n");
  +    fprintf(stderr, "Polls created           : %d\n", sp_created);
  +    fprintf(stderr, "Polls destroyed         : %d\n", sp_destroyed);
  +    fprintf(stderr, "Polls cleared           : %d\n", sp_cleared);
  +}
  +#endif
  +
   TCN_IMPLEMENT_CALL(jlong, Poll, create)(TCN_STDARGS, jint size,
                                           jlong pool, jint flags,
                                           jlong ttl)
  @@ -69,6 +127,12 @@
       tps->nalloc = size;
       tps->pool   = p;
       tps->max_ttl = J2T(ttl);
  +#ifdef TCN_DO_STATISTICS
  +    sp_created++;
  +    apr_pool_cleanup_register(p, (const void *)tps,
  +                              sp_poll_cleanup,
  +                              apr_pool_cleanup_null);
  +#endif
   cleanup:
       return P2J(tps);
   }
  @@ -79,6 +143,11 @@
   
       UNREFERENCED_STDARGS;
       TCN_ASSERT(pollset != 0);
  +#ifdef TCN_DO_STATISTICS
  +    sp_destroyed++;
  +    apr_pool_cleanup_kill(p->pool, p, sp_poll_cleanup);
  +    sp_poll_statistics(p);
  +#endif
       return (jint)apr_pollset_destroy(p->pollset);
   }
   
  @@ -92,9 +161,12 @@
       UNREFERENCED_STDARGS;
       TCN_ASSERT(socket != 0);
   
  -    if (p->nelts == p->nalloc)
  +    if (p->nelts == p->nalloc) {
  +#ifdef TCN_DO_STATISTICS
  +        p->sp_overflow++;
  +#endif
           return APR_ENOMEM;
  -
  +    }
       memset(&fd, 0, sizeof(apr_pollfd_t));
       fd.desc_type = APR_POLL_SOCKET;
       fd.reqevents = (apr_int16_t)reqevents;
  @@ -103,6 +175,10 @@
       p->socket_ttl[p->nelts] = apr_time_now();
       p->socket_set[p->nelts] = fd;
       p->nelts++;
  +#ifdef TCN_DO_STATISTICS
  +    p->sp_added++;
  +    p->sp_max_count = TCN_MAX(p->sp_max_count, p->sp_added);
  +#endif
       return (jint)apr_pollset_add(p->pollset, &fd);
   }
   
  @@ -116,8 +192,14 @@
               apr_int32_t dst = i;
               apr_int32_t old_nelts = p->nelts;
               p->nelts--;
  +#ifdef TCN_DO_STATISTICS
  +            p->sp_removed++;
  +#endif
               for (i++; i < old_nelts; i++) {
                   if (fd->desc.s == p->socket_set[i].desc.s) {
  +#ifdef TCN_DO_STATISTICS
  +                    p->sp_equals++;
  +#endif
                       p->nelts--;
                   }
                   else {
  @@ -143,6 +225,9 @@
       memset(&fd, 0, sizeof(apr_pollfd_t));
       fd.desc_type = APR_POLL_SOCKET;
       fd.desc.s = J2P(socket, apr_socket_t *);
  +#ifdef TCN_DO_STATISTICS
  +    p->sp_remove++;
  +#endif
   
       return (jint)do_remove(p, &fd);
   }
  @@ -161,12 +246,23 @@
       UNREFERENCED(o);
       TCN_ASSERT(pollset != 0);
   
  -    if (rv != APR_SUCCESS)
  -        return (jint)(-rv);
  +#ifdef TCN_DO_STATISTICS
  +     p->sp_poll++;
  +#endif
       if ((rv = apr_pollset_poll(p->pollset, J2T(timeout), &num, &fd)) != APR_SUCCESS) {
  +#ifdef TCN_DO_STATISTICS
  +        if (APR_STATUS_IS_TIMEUP(rv))
  +            p->sp_poll_timeout++;
  +        else
  +            p->sp_err_poll++;
  +#endif
           num = (apr_int32_t)(-rv);
       }
       if (num > 0) {
  +#ifdef TCN_DO_STATISTICS
  +         p->sp_polled += num;
  +         p->sp_max_polled = TCN_MAX(p->sp_max_polled, num);
  +#endif
           for (i = 0; i < num; i++) {
               pset[i*4+0] = (jlong)(fd->rtnevents);
               pset[i*4+1] = P2J(fd->desc.s);
  @@ -211,6 +307,10 @@
           }
           if (remove && num) {
               memset(&fd, 0, sizeof(apr_pollfd_t));
  +#ifdef TCN_DO_STATISTICS
  +             p->sp_maintained += num;
  +             p->sp_max_maintained = TCN_MAX(p->sp_max_maintained, num);
  +#endif
               for (i = 0; i < num; i++) {
                   fd.desc_type = APR_POLL_SOCKET;
                   fd.desc.s = J2P(pset[i*4+1], apr_socket_t *);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org