You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Ian Holsman <ia...@cnet.com> on 2001/07/08 07:07:14 UTC

Pool Replay Code

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

[PATCH] Re: Pool Replay Code

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Sun, Jul 08, 2001 at 10:11:11AM -0700, Justin Erenkrantz wrote:
> In the effort to place my code where my mouth is, I'm implementing this.
> Patch posting shortly.  -- justin

memory/unix/apr_sms_replay.c and a new apr_sms_pool.c that cleans up
things slightly (create_sms function centralizes which SMS we are using
- not sure if that is helpful) and define APR_POOL_REPLAY to do your
output format.  

I didn't bother to clean up the apr_instrument function, but if I would
actually commit this, I'd clean it up slightly.  =)  It's a hack.

You'll need David's other patches to do the POOLS_ARE_SMS.  -- justin

Re: Pool Replay Code

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Sun, Jul 08, 2001 at 01:21:36AM -0700, Justin Erenkrantz wrote:
> On Sat, Jul 07, 2001 at 10:07:14PM -0700, Ian Holsman wrote:
> > 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)
> 
> You know, this would be good to have a SMS.  *hint*, *hint*.  I'm
> not a fan of seeing more #ifdefs in the code.  The problem is that you'd
> have to instrument with an SMS-enabled httpd.  =)  Then, you could run
> your testpool against SMS or a pool.

In the effort to place my code where my mouth is, I'm implementing this.
Patch posting shortly.  -- justin


Re: Pool Replay Code

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Sat, Jul 07, 2001 at 10:07:14PM -0700, Ian Holsman wrote:
> 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)

You know, this would be good to have a SMS.  *hint*, *hint*.  I'm
not a fan of seeing more #ifdefs in the code.  The problem is that you'd
have to instrument with an SMS-enabled httpd.  =)  Then, you could run
your testpool against SMS or a pool.

apr_sms_replay_t would just be a child SMS of an apr_sms_trivial_t 
but it opens the log file and writes the operations out and calls 
its parent (the trivial SMS) to do the heavy lifting.  You can have an
#ifdef in apr_sms_pools.c that creates apr_sms_replay_t (you'd need
another pool create call to create the trivial SMS to pass to the
apr_sms_replay_t).  -- justin