apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Holsman <i...@cnet.com>
Subject Pool Replay Code
Date Sun, 08 Jul 2001 05:07:14 GMT
The following belongs in apr/test.
It will replay files generated by the following patch:
There are 2 sample replay files which should also get commited at
webperf.org/a2/pool (they are too large to post)

..Ian
Index: apr_pools.c
===================================================================
RCS file: /home/cvspublic/apr/memory/unix/apr_pools.c,v
retrieving revision 1.99
diff -u -u -r1.99 apr_pools.c
--- apr_pools.c 2001/07/07 07:21:14     1.99
+++ apr_pools.c 2001/07/08 02:14:02
@@ -171,7 +171,16 @@
#include <sys/mman.h>
#endif

-
+/** 
+ * APR_INSTRUMENT is only intentended for debuging/performance tuning
+ * and should never be defined on a live system.
+/*
+#define APR_INSTRUMENT
+*/
+#ifdef APR_INSTRUMENT
+#include <sys/time.h>
+static void apr_instrument(const char*fn, apr_pool_t *pool, const
char*format,... );
+#endif
/** The memory allocation structure
  */
struct apr_pool_t {
@@ -670,6 +679,10 @@
     newpool->apr_abort = abortfunc;

     *newcont = newpool;
+
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_create",parent_pool, "%lu", newpool);
+#endif
     return APR_SUCCESS;
}

@@ -706,7 +719,9 @@
                                      apr_status_t (*child_cleanup)
(void *))
{
     struct cleanup *c;
-
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_cleanup_register",p,"-");
+#endif
     if (p != NULL) {
         c = (struct cleanup *) apr_palloc(p, sizeof(struct cleanup));
         c->data = data;
@@ -725,6 +740,10 @@

     if (p == NULL)
         return;
+
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_cleanup_kill",p,"-");
+#endif
     c = p->cleanups;
     lastp = &p->cleanups;
     while (c) {
@@ -804,6 +823,10 @@
     known_stack_point = &s;
     stack_var_init(&s);
#endif
+
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_alloc_init",globalp,"-");
+#endif
#if APR_HAS_THREADS
     status = apr_lock_create(&alloc_mutex, APR_MUTEX, APR_INTRAPROCESS,
                    NULL, globalp);
@@ -835,6 +858,10 @@
     alloc_mutex = NULL;
     spawn_mutex = NULL;
#endif
+
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_alloc_term",globalp,"-");
+#endif
     apr_pool_destroy(globalp);
}

@@ -848,6 +875,10 @@
{
     /* free the subpools. we can just loop -- the subpools will detach
        themselve from us, so this is easy. */
+
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_clear",a,"-");
+#endif
     while (a->sub_pools) {
        apr_pool_destroy(a->sub_pools);
     }
@@ -898,6 +929,9 @@
{
     union block_hdr *blok;

+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_destroy",a,"-");
+#endif
     /* toss everything in the pool. */
     apr_pool_clear(a);

@@ -1104,6 +1138,9 @@
     char *first_avail;
     char *new_first_avail;

+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_palloc",a,"%lu",reqsize);
+#endif
     nclicks = 1 + ((reqsize - 1) / CLICK_SZ);
     size = nclicks * CLICK_SZ;

@@ -1158,7 +1195,9 @@

APR_DECLARE(void *) apr_pcalloc(apr_pool_t *a, apr_size_t size)
{
+
     void *res = apr_palloc(a, size);
+
     memset(res, '\0', size);
     return res;
}
@@ -1174,6 +1213,9 @@
{
     apr_size_t keylen = strlen(key);

+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_userdata_set",cont,"%s",key);
+#endif
     if (cont->prog_data == NULL)
         cont->prog_data = apr_hash_make(cont);

@@ -1191,6 +1233,9 @@

APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char
*key, apr_pool_t *cont)
{
+#ifdef APR_INSTRUMENT
+       apr_instrument("apr_pool_userdata_get",cont,"%s",key);
+#endif
     if (cont->prog_data == NULL)
         *data = NULL;
     else
@@ -1466,3 +1511,27 @@
        }
     }
}
+
+#ifdef APR_INSTRUMENT
+static void apr_instrument(const char*fn, apr_pool_t *pool, const
char*format,... )
+{
+       static volatile int bfirst=1;
+
+       char buffer[1000];
+       char buffer2[1000];
+    va_list ap;
+       apr_os_thread_t pthread = apr_os_thread_current();
+       pid_t pid = getpid();
+       struct timeval tv;
+       gettimeofday(&tv, NULL);
+       if (bfirst==1) {
+               bfirst=0;
+               fprintf(stderr,
"#APR_INSTRUMENT:PID,THREAD,SECS,USEC,POOL,FN,ARGS\n");
+       }
+    va_start(ap, format);
+       vsnprintf(buffer,sizeof(buffer), format, ap);
+    va_end(ap);
+       snprintf(buffer2,sizeof(buffer2),
"APR_INSTRUMENT:POOL,%lu,%lu,%ld,%ld,%lu,%s,%s\n",pid,pthread,
tv.tv_sec, tv.tv_usec,pool,fn, buffer);
+       fputs(buffer2,stderr);
+}
+#endif

Index: Makefile.in
===================================================================
RCS file: /home/cvspublic/apr/test/Makefile.in,v
retrieving revision 1.59
diff -u -u -r1.59 Makefile.in
--- Makefile.in 2001/07/07 13:03:46     1.59
+++ Makefile.in 2001/07/08 02:11:09
@@ -25,7 +25,8 @@
         testpoll@EXEEXT@ \
         testmem@EXEEXT@ \
        occhild@EXEEXT@ \
-        teststr@EXEEXT@
+    teststr@EXEEXT@ \
+       testpool@EXEEXT@ 

TARGETS = $(PROGRAMS)

@@ -125,6 +126,9 @@

teststr@EXEEXT@: teststr.lo $(LOCAL_LIBS)
        $(LINK) teststr.lo $(LOCAL_LIBS) $(ALL_LIBS)
+
+testpool@EXEEXT@: testpool.lo $(LOCAL_LIBS)
+       $(LINK) testpool.lo $(LOCAL_LIBS) $(ALL_LIBS)

testsockets@EXEEXT@: testsockets.lo $(LOCAL_LIBS)
        $(LINK) testsockets.lo $(LOCAL_LIBS) $(ALL_LIBS)

--
Ian Holsman
Performance Measurement & Analysis
CNET Networks    -    415 364-8608

Mime
View raw message