trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject svn commit: r1165851 - in /trafficserver/traffic/trunk: lib/ts/Resource.cc lib/ts/Resource.h lib/ts/ink_memory.cc lib/ts/ink_queue.cc lib/ts/ink_resource.cc lib/ts/ink_resource.h proxy/signals.cc
Date Tue, 06 Sep 2011 21:11:50 GMT
Author: zwoop
Date: Tue Sep  6 21:11:49 2011
New Revision: 1165851

URL: http://svn.apache.org/viewvc?rev=1165851&view=rev
Log:
TS-567 This removes the debugging capabilities of xmalloc etc. We will replace that with tcmalloc
/ jemalloc in the next steps of this massive change set.

Modified:
    trafficserver/traffic/trunk/lib/ts/Resource.cc
    trafficserver/traffic/trunk/lib/ts/Resource.h
    trafficserver/traffic/trunk/lib/ts/ink_memory.cc
    trafficserver/traffic/trunk/lib/ts/ink_queue.cc
    trafficserver/traffic/trunk/lib/ts/ink_resource.cc
    trafficserver/traffic/trunk/lib/ts/ink_resource.h
    trafficserver/traffic/trunk/proxy/signals.cc

Modified: trafficserver/traffic/trunk/lib/ts/Resource.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/Resource.cc?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/Resource.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/Resource.cc Tue Sep  6 21:11:49 2011
@@ -33,8 +33,8 @@
 
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
-void *operator
-new(size_t size)
+void *
+operator new(size_t size)
 {
   return xmalloc((unsigned int) size);
 }
@@ -50,7 +50,8 @@ delete(void *p)
 
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
-void *operator  new[] (size_t size)
+void *
+operator  new[] (size_t size)
 {
   return xmalloc((unsigned int) size);
 }
@@ -58,7 +59,8 @@ void *operator  new[] (size_t size)
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
 
-void operator  delete[] (void *p)
+void
+operator  delete[] (void *p)
 {
   _xfree(p);
 }

Modified: trafficserver/traffic/trunk/lib/ts/Resource.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/Resource.h?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/Resource.h (original)
+++ trafficserver/traffic/trunk/lib/ts/Resource.h Tue Sep  6 21:11:49 2011
@@ -28,6 +28,8 @@
 #include <stdlib.h>
 #include "ink_resource.h"
 
+// TODO: TS-567 Clean this up!
+
 #ifdef TRACK_MEMORY
 
 #define NEW(mem)        _xtrack_helper (mem, RES_MEM_PATH)

Modified: trafficserver/traffic/trunk/lib/ts/ink_memory.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_memory.cc?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_memory.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_memory.cc Tue Sep  6 21:11:49 2011
@@ -44,7 +44,7 @@ ats_malloc(size_t size)
 
   /*
    * There's some nasty code in libts that expects
-   * a MALLOC of a zero-sized item to wotk properly. Rather
+   * a MALLOC of a zero-sized item to work properly. Rather
    * than allocate any space, we simply return a NULL to make
    * certain they die quickly & don't trash things.
    */
@@ -60,7 +60,6 @@ ats_malloc(size_t size)
   return ptr;
 }                               /* End ats_malloc */
 
-
 void *
 ats_calloc(size_t nelem, size_t elsize)
 {
@@ -72,7 +71,6 @@ ats_calloc(size_t nelem, size_t elsize)
   return ptr;
 }                               /* End ats_calloc */
 
-
 void *
 ats_realloc(void *ptr, size_t size)
 {
@@ -84,7 +82,6 @@ ats_realloc(void *ptr, size_t size)
   return newptr;
 }                               /* End ats_realloc */
 
-
 void
 ats_memalign_free(void *ptr)
 {
@@ -93,7 +90,6 @@ ats_memalign_free(void *ptr)
   }
 }
 
-
 void *
 ats_memalign(size_t alignment, size_t size)
 {

Modified: trafficserver/traffic/trunk/lib/ts/ink_queue.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_queue.cc?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_queue.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_queue.cc Tue Sep  6 21:11:49 2011
@@ -111,12 +111,10 @@ ink_freelist_init(InkFreeList * f,
 
   /* its safe to add to this global list because ink_freelist_init()
      is only called from single-threaded initialization code. */
-  if ((fll = (ink_freelist_list *)ats_malloc(sizeof(ink_freelist_list))) != 0) {
-    fll->fl = f;
-    fll->next = freelists;
-    freelists = fll;
-  }
-  ink_assert(fll != NULL);
+  fll = (ink_freelist_list *)ats_malloc(sizeof(ink_freelist_list));
+  fll->fl = f;
+  fll->next = freelists;
+  freelists = fll;
 
   f->name = name;
   f->offset = offset;
@@ -218,9 +216,7 @@ ink_freelist_new(InkFreeList * f)
     } else {
       foo = ats_malloc(type_size);
     }
-    if (likely(foo))
-      fl_memadd(type_size);
-
+    fl_memadd(type_size);
 
 #ifdef MEMPROTECT
     if (type_size >= MEMPROTECT_SIZE) {
@@ -262,8 +258,7 @@ ink_freelist_new(InkFreeList * f)
         newp = ats_memalign(f->alignment, f->chunk_size * type_size);
       else
         newp = ats_malloc(f->chunk_size * type_size);
-      if (newp)
-        fl_memadd(f->chunk_size * type_size);
+      fl_memadd(f->chunk_size * type_size);
 #ifdef DEBUG
       newsbrk = (char *) sbrk(0);
       ink_atomic_increment(&fastmemtotal, newsbrk - oldsbrk);
@@ -282,8 +277,7 @@ ink_freelist_new(InkFreeList * f)
         mask = ~0;
       }
       newp = ats_malloc(f->chunk_size * type_size + add);
-      if (newp)
-        fl_memadd(f->chunk_size * type_size + add);
+      fl_memadd(f->chunk_size * type_size + add);
       newp = (void *) ((((uintptr_t) newp) + add) & mask);
       SET_FREELIST_POINTER_VERSION(item, newp, 0);
 #endif

Modified: trafficserver/traffic/trunk/lib/ts/ink_resource.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_resource.cc?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_resource.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_resource.cc Tue Sep  6 21:11:49 2011
@@ -29,678 +29,8 @@
 #include "ink_resource.h"
 #include "ink_stack_trace.h"
 
-volatile int64_t resource_allocated_mem = 0;
 volatile int res_track_memory = RES_TRACK_MEMORY_DEFAULT;
 
-#ifdef TRACK_MEMORY
-
-#define FENCE_POST_SIZE   16
-
-// TODO: Move this to ink_align.h
-#define ADJUST(mem,x)  (((char*) (mem)) + x)
-// TODO: Use INK_ALIGN instead
-#define ROUND(x,l)     (((x) + ((l) - 1L)) & ~((l) - 1L))
-#define TSIZE          16387
-
-#define MAKE_MAGIC(m)    (((char*) (m)) - 1)
-#define CHECK_MAGIC(m,c) ((char*) (m) == MAKE_MAGIC (c))
-
-
-typedef struct ResMemInfo ResMemInfo;
-typedef struct Resource Resource;
-
-struct ResMemInfo
-{
-  void *magic;
-  unsigned int size:31;
-  unsigned int fence_post:1;
-  Resource *res;
-};
-
-
-static unsigned int res_hash(const char *s);
-Resource *res_lookup(const char *path);
-
-
-static const int res_extra_space = ROUND(sizeof(ResMemInfo), sizeof(double));
-static volatile Resource *res_table[TSIZE];
-
-static const char fence_post_pattern[FENCE_POST_SIZE] = {
-  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
-  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
-  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
-  (char) 0xde, (char) 0xad, (char) 0xbe, (char) 0xef,
-};
-
-
-volatile int res_zorch_mem = 0;
-volatile int res_fence_post = 0;
-
-#define res_memadd(_x_) \
-   ink_atomic_increment64(&resource_allocated_mem, (int64_t) (_x_));
-
-#define res_memsub(_x_) \
-   ink_atomic_increment64(&resource_allocated_mem, (int64_t) -(_x_));
-
-static int
-_xres_init()
-{
-  res_zorch_mem = (getenv("ZORCH_MEM") != NULL);
-  res_fence_post = (getenv("FENCE_POST") != NULL);
-
-  if (res_zorch_mem) {
-    fprintf(stderr, "memory zorching enabled\n");
-  }
-
-  if (res_fence_post) {
-    fprintf(stderr, "memory fence posting enabled\n");
-  }
-
-  return 0;
-}
-
-static int dummy_var = _xres_init();
-
-
-/* INKqa03012 - Digital OSF seems to issue some bad frees in
- *  the iostream destructor.  These variables and the the exit_cb()
- *  let us know if exit has been called.  If exit has been, called
- *  we will refrain from issuing warnings regarding bad frees
- */
-static int exit_called = 0;
-static void
-exit_cb()
-{
-  exit_called = 1;
-}
-static int unused = atexit(exit_cb);
-
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-#define res_inc(res,delta) \
-   ink_atomic_increment64 (&res->value, delta); \
-   res_memadd(delta)
-
-#define res_check(res) \
-    if (res && !CHECK_MAGIC ((res)->magic, (res))) { \
-        fprintf (stderr, "FATAL: resource table is corrupt [%d]\n", __LINE__); \
-        abort (); \
-    }
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-
-unsigned int
-res_hash(const char *s)
-{
-#if !defined(linux) && !defined(freebsd) && !defined(__i386__)
-#define HASH_ONE(h,one)       ((h << 3) + (one) + (h >> 29))
-#define WORD_HAS_NULLBYTE(w)  ((((w) - 0x01010101) ^ (w)) & 0x80808080)
-
-  unsigned int h;
-  unsigned int ibp;
-
-  ink_assert(!((uintptr_t) s & 3));
-
-  for (h = 0;;) {
-    ibp = *(unsigned int *) s;
-
-    if (WORD_HAS_NULLBYTE(ibp)) {
-      unsigned char t[4];
-
-      if (!s[0]) {
-        return h;
-      } else if (!s[1]) {
-        *(unsigned int *) &t[0] = ibp;
-        t[2] = 0;
-        t[3] = 0;
-        h = HASH_ONE(h, *(unsigned int *) &t[0]);
-        return h;
-      } else if (!s[2]) {
-        *(unsigned int *) &t[0] = ibp;
-        t[3] = 0;
-        h = HASH_ONE(h, *(unsigned int *) &t[0]);
-        return h;
-      } else if (!s[3]) {
-        h = HASH_ONE(h, ibp);
-        return h;
-      }
-    } else {
-      h = HASH_ONE(h, ibp);
-    }
-    s += 4;
-  }
-
-#undef HASH_ONE
-#undef WORD_HAS_NULLBYTE
-#else
-  unsigned int h = 0, g;
-
-  for (; *s; s++) {
-    h = (h << 4) + *s;
-    if ((g = h & 0xf0000000))
-      h = (h ^ (g >> 24)) ^ g;
-  }
-  return h;
-#endif
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-Resource *
-res_lookup(const char *path)
-{
-  unsigned int hash_val;
-  Resource *node;
-  Resource *old;
-
-  hash_val = res_hash(path) % TSIZE;
-
-  for (;;) {
-    old = (Resource *) res_table[hash_val];
-    node = old;
-
-    while (node) {
-      res_check(node);
-      if ((path == node->path) || (strcmp(path, node->path) == 0)) {
-        return node;
-      }
-      node = node->next;
-    }
-
-    if (old == res_table[hash_val]) {
-      node = (Resource *) _xmalloc(sizeof(Resource), NULL);
-      node->magic = MAKE_MAGIC(node);
-      node->path = path;
-      node->value = 0;
-      node->snapshot = 0;
-      node->baseline = 0;
-      node->next = old;
-
-      if (ink_atomic_cas_ptr((pvvoidp) & res_table[hash_val], old, node))
-        return node;
-
-      _xfree(node);
-      node = NULL;
-    }
-  }
-  return NULL;                  // DEC compiler complains
-}
-
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-static Resource *
-res_stat(const char *path, int64_t value)
-{
-  if (path) {
-    Resource *res;
-
-    res = res_lookup(path);
-    res_inc(res, value);
-
-    return res;
-  } else {
-    return NULL;
-  }
-}
-
-
-#if defined(linux) || defined(freebsd)
-static const int magic_array_offset = 0;
-#else
-#error "I do not know about this platform."
-#endif
-
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-int
-_xcheck_fence_post(char *mem, unsigned int size)
-{
-  if (memcmp(mem, fence_post_pattern, FENCE_POST_SIZE) != 0) {
-    return 1;
-  }
-  if (memcmp(mem + size - FENCE_POST_SIZE, fence_post_pattern, FENCE_POST_SIZE) != 0) {
-    return 1;
-  }
-  return 0;
-}
-
-void
-_xvalidate(void *ptr, char *file, int line)
-{
-  ResMemInfo *info;
-
-  info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
-  if (!CHECK_MAGIC(info->magic, info)) {
-    info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
-  }
-  if (!CHECK_MAGIC(info->magic, info)) {
-    ink_debug_assert(!"bad pointer");
-  } else {
-    if (info->res) {
-      res_check(info->res);
-    }
-    char *mem = (char *) info;
-
-    if (info->fence_post) {
-      mem -= FENCE_POST_SIZE;
-      if (_xcheck_fence_post(mem, info->size + res_extra_space + FENCE_POST_SIZE * 2))
{
-        fprintf(stderr, "MEMORY: free: fence-post mangled [%s]\n", info->res ? info->res->path
: "<unknown>");
-        abort();
-      }
-    }
-  }
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void
-_xfree(void *ptr)
-{
-  if (!ptr) {
-    // fprintf (stderr, "WARNING: freeing NULL pointer\n");
-  } else {
-    ResMemInfo *info;
-
-    info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
-    if (!CHECK_MAGIC(info->magic, info)) {
-      info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
-    }
-
-    if (CHECK_MAGIC(info->magic, info)) {
-      char *mem;
-
-      if (info->res) {
-        res_check(info->res);
-        res_inc(info->res, -((int64_t) info->size));
-      }
-
-      mem = (char *) info;
-
-      if (info->fence_post) {
-        mem -= FENCE_POST_SIZE;
-        if (_xcheck_fence_post(mem, info->size + res_extra_space + FENCE_POST_SIZE * 2))
{
-          fprintf(stderr, "MEMORY: free: fence-post mangled [%s]\n", info->res ? info->res->path
: "<unknown>");
-          abort();
-        }
-      }
-
-      if (res_zorch_mem) {
-        memset(info, 0x81, info->size + res_extra_space);
-      }
-
-      memset(info, 0, res_extra_space);
-
-      free(mem);
-
-    } else {
-      /* This is a bad free. Let it leak.  Issue a
-       *  warning if we are not in an exit routine
-       * (INKqa03012)
-       */
-      if (exit_called == 0) {
-        fprintf(stderr, "WARNING: freeing bad pointer\n");
-        ink_debug_assert(!"WARNING: freeing bad pointer");
-      }
-    }
-  }
-}
-
-void *
-_xfree_null(void *ptr)
-{
-  _xfree(ptr);
-  return NULL;
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void *
-_xmalloc(unsigned int size, const char *path)
-{
-  ResMemInfo *info;
-  char *mem;
-  int extra;
-  int fence_post;
-
-  extra = res_extra_space;
-
-  fence_post = res_fence_post;
-
-  if (fence_post) {
-    extra += FENCE_POST_SIZE * 2;
-  }
-
-  mem = (char *) malloc(size + extra);
-
-  if (unlikely(mem == NULL)) {
-    fprintf(stderr, "FATAL: _xmalloc could not allocate %u + %u bytes [%s]\n",
-            size, extra, path ? path : "memory/anonymous");
-    xdump();
-    _exit(1);
-  }
-
-  if (fence_post) {
-    memcpy(mem, fence_post_pattern, FENCE_POST_SIZE);
-    memcpy(mem + size + extra - FENCE_POST_SIZE, fence_post_pattern, FENCE_POST_SIZE);
-    mem += FENCE_POST_SIZE;
-  }
-
-  memset(mem, 0, res_extra_space);
-
-  info = (ResMemInfo *) mem;
-  info->magic = MAKE_MAGIC(mem);
-  info->size = size;
-  info->fence_post = fence_post;
-
-  if (res_track_memory) {
-    info->res = res_stat(path, size);
-    res_check(info->res);
-  } else {
-    info->res = NULL;
-  }
-
-  mem = mem + res_extra_space;
-
-  return mem;
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-char *
-_xstrdup(const char *str, int64_t length, const char *path)
-{
-  char *newstr;
-
-  if (unlikely(str == NULL)) {
-    return NULL;
-  }
-
-  if (length < 0) {
-    length = (int) strlen(str);
-  }
-
-  newstr = (char *) _xmalloc(length + 1, path);
-  strncpy(newstr, str, length);
-  newstr[length] = '\0';
-
-  return newstr;
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void *
-_xrealloc(void *ptr, unsigned int size, const char *path)
-{
-  if (!ptr) {
-    return _xmalloc(size, path);
-  } else {
-    ResMemInfo *info;
-    char *mem;
-    int extra;
-    int fence_post;
-
-    info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
-    if (!CHECK_MAGIC(info->magic, info)) {
-      info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
-    }
-
-    if (info->res) {
-      res_check(info->res);
-      res_inc(info->res, -((int64_t) info->size));
-    }
-
-    mem = (char *) info;
-    extra = res_extra_space;
-
-    if (info->fence_post) {
-      mem -= FENCE_POST_SIZE;
-      if (_xcheck_fence_post(mem, info->size + res_extra_space + FENCE_POST_SIZE * 2))
{
-        fprintf(stderr, "MEMORY: realloc: fence-post mangled [%s] [%s]\n",
-                info->res ? info->res->path : "<unknown>", path);
-        abort();
-      }
-    }
-
-    memset(info, 0, res_extra_space);
-
-    fence_post = res_fence_post;
-
-    if (fence_post) {
-      extra += FENCE_POST_SIZE * 2;
-    }
-
-    mem = (char *) realloc(mem, size + extra);
-    if (unlikely(mem == NULL)) {
-      fprintf(stderr, "FATAL: could not reallocate %u + %u bytes [%s]\n",
-              size, extra, path ? path : "memory/anonymous");
-      xdump();
-      _exit(1);
-    }
-
-    if (fence_post) {
-      memcpy(mem, fence_post_pattern, FENCE_POST_SIZE);
-      memcpy(mem + size + extra - FENCE_POST_SIZE, fence_post_pattern, FENCE_POST_SIZE);
-      mem += FENCE_POST_SIZE;
-    }
-
-    memset(mem, 0, res_extra_space);
-
-    info = (ResMemInfo *) mem;
-    info->magic = MAKE_MAGIC(mem);
-    info->size = size;
-    info->fence_post = fence_post;
-
-    if (res_track_memory) {
-      info->res = res_stat(path, size);
-      res_check(info->res);
-    } else {
-      info->res = NULL;
-    }
-
-    mem = mem + res_extra_space;
-
-    return mem;
-  }
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void *
-_xtrack(void *ptr, const char *path)
-{
-  if (unlikely(ptr == NULL)) {
-    fprintf(stderr, "WARNING: cannot track NULL pointer\n");
-    return ptr;
-  } else {
-    ResMemInfo *info;
-
-    info = (ResMemInfo *) ADJUST(ptr, -res_extra_space);
-    if (!CHECK_MAGIC(info->magic, info)) {
-      info = (ResMemInfo *) ADJUST(info, -magic_array_offset);
-    }
-
-    if (!CHECK_MAGIC(info->magic, info)) {
-      return ptr;
-    }
-
-    if (info->res) {
-      res_check(info->res);
-      res_inc(info->res, -((int64_t) info->size));
-    }
-
-    if (res_track_memory) {
-      info->res = res_stat(path, info->size);
-      res_check(info->res);
-    } else {
-      info->res = NULL;
-    }
-
-    return ptr;
-  }
-}
-
-void
-xdump_snap_baseline()
-{
-  int i;
-  Resource *res;
-
-  for (i = 0; i < TSIZE; i++) {
-    res = (Resource *) res_table[i];
-    while (res) {
-      res_check(res);
-      res->baseline = res->value;
-      res = res->next;
-    }
-  }
-}
-
-void
-xdump_to_file_baseline_rel(FILE * fp)
-{
-  Resource *res;
-  int64_t value;
-  int64_t diff;
-  int i;
-  struct timeval timestamp;
-  char time_string[32], *time_str;
-  int length_to_write;
-
-  ink_gethrtimeofday(&timestamp, NULL);
-  time_str = ctime((time_t *) & timestamp.tv_sec);
-
-  length_to_write = squid_timestamp_to_buf(time_string, 32, timestamp.tv_sec, timestamp.tv_usec);
-  time_string[length_to_write] = '\0';
-
-  fprintf(fp, "PID: %d %s  %s", getpid(), time_string, time_str);
-  fprintf(fp, "   value    |   delta    |   location\n");
-  fprintf(fp, "rel. to base|            |           \n");
-  fprintf(fp, "------------|------------|-----------------------------------------------\n");
-
-  for (i = 0; i < TSIZE; i++) {
-    res = (Resource *) res_table[i];
-    while (res) {
-      res_check(res);
-
-      value = res->value - res->baseline;
-      diff = res->value - res->snapshot;
-      if (value != 0) {
-        fprintf(fp, " % 10d | % 10d | %s\n", (int) value, (int) diff, res->path);
-      }
-
-      res->snapshot = res->value;
-      res = res->next;
-    }
-  }
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void
-xdump_to_file(FILE * fp)
-{
-  Resource *res;
-  int64_t value;
-  int64_t diff;
-  int i;
-  struct timeval timestamp;
-  char time_string[32], *time_str;
-  int length_to_write;
-
-  ink_gethrtimeofday(&timestamp, NULL);
-  time_str = ctime((time_t *) & timestamp.tv_sec);
-
-  length_to_write = squid_timestamp_to_buf(time_string, 32, timestamp.tv_sec, timestamp.tv_usec);
-  time_string[length_to_write] = '\0';
-
-  fprintf(fp, "PID: %d %s  %s", getpid(), time_string, time_str);
-  fprintf(fp, "   value    |   delta    |   location\n");
-  fprintf(fp, "------------|------------|-----------------------------------------------\n");
-
-  for (i = 0; i < TSIZE; i++) {
-    res = (Resource *) res_table[i];
-    while (res) {
-      res_check(res);
-      if (strncmp(res->path, "memory/IOBuffer/", strlen("memory/IOBuffer/"))
-          != 0) {
-        value = res->value;
-        diff = value - res->snapshot;
-        if (diff != 0) {
-          fprintf(fp, " % 10d | % 10d | %s\n", (int) value, (int) diff, res->path);
-        }
-        res->snapshot = res->value;
-      }
-      res = res->next;
-    }
-  }
-
-  fprintf(fp, "   value    |   delta    |   location\n");
-  fprintf(fp, "------------|------------|-----------------------------------------------\n");
-  for (i = 0; i < TSIZE; i++) {
-    res = (Resource *) res_table[i];
-    while (res) {
-      res_check(res);
-      if (strncmp(res->path, "memory/IOBuffer/", strlen("memory/IOBuffer/"))
-          == 0) {
-        value = res->value;
-        diff = value - res->snapshot;
-        if (diff != 0) {
-          fprintf(fp, " % 10d | % 10d | %s\n", (int) value, (int) diff, res->path);
-        }
-        res->snapshot = res->value;
-      }
-      res = res->next;
-    }
-  }
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void
-xdump()
-{
-  ink_stack_trace_dump();
-  xdump_to_file(stderr);
-}
-
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
-void
-xsnap()
-{
-  Resource *res;
-  int i;
-
-  for (i = 0; i < TSIZE; i++) {
-    res = (Resource *) res_table[i];
-    while (res) {
-      res_check(res);
-      res->snapshot = res->value;
-      res = res->next;
-    }
-  }
-}
-
-
-#else /* TRACK_MEMORY */
-
 /*-------------------------------------------------------------------------
 -------------------------------------------------------------------------*/
 void
@@ -743,6 +73,7 @@ _xstrdup(const char *str, int length, co
     if (length < 0) {
       length = strlen(str);
     }
+    // TODO: TS-567 shouldn't have to check the return value here.
     newstr = (char *)ats_malloc(length + 1);
     if (likely(newstr != NULL)) {
       strncpy(newstr, str, length);
@@ -770,6 +101,3 @@ xdump(void)
 {
   ink_stack_trace_dump();
 }
-
-
-#endif /* TRACK_MEMORY */

Modified: trafficserver/traffic/trunk/lib/ts/ink_resource.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_resource.h?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_resource.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_resource.h Tue Sep  6 21:11:49 2011
@@ -32,14 +32,11 @@
 #include "ink_port.h"
 #include "ink_memory.h"
 
-extern volatile int64_t resource_allocated_mem;
 extern volatile int res_track_memory;   /* set this to zero to disable resource tracking
*/
 
 #define __RES_PATH(x)   #x
 #define _RES_PATH(x)    __RES_PATH (x)
 #define RES_PATH(x)     x __FILE__ ":" _RES_PATH (__LINE__)
-#define RES_MEM_PATH    RES_PATH ("memory/")
-#define RES_DESC_PATH   RES_PATH ("descriptor/")
 
 struct Resource
 {
@@ -51,34 +48,9 @@ struct Resource
   int64_t baseline;
 };
 
-//#define TRACK_MEMORY
-
-#if defined(TRACK_MEMORY)
-#define RES_TRACK_MEMORY_DEFAULT 1      /* default value for res_track_memory variable */
-
-#define xfree(p)       _xfree(p)
-#define xfree_null(p)  _xfree_null(p)
-#define xmalloc(s)     _xmalloc((s), RES_MEM_PATH)
-#define xrealloc(p,s)  _xrealloc((p), (s), RES_MEM_PATH)
-#define xstrdup(p)     _xstrdup((p), -1, RES_MEM_PATH)
-#define xstrndup(p,n)  _xstrdup((p), (n), RES_MEM_PATH)
-#define xtrack(p)      _xtrack((p), RES_MEM_PATH)
-#define xvalidate(p)   _xvalidate((p),__FILE__,__LINE__)
-
-void _xvalidate(void *ptr, char *file, int line);
-void _xfree(void *ptr);
-void *_xfree_null(void *ptr);
-void *_xmalloc(unsigned int size, const char *path);
-void *_xrealloc(void *ptr, unsigned int size, const char *path);
-char *_xstrdup(const char *str, int length, const char *path);
-void *_xtrack(void *ptr, const char *path);
-void xdump_snap_baseline();
-void xdump_to_file_baseline_rel(FILE * fp);
-void xdump_to_file(FILE * fp);
-void xdump(void);
-void xsnap(void);
-
-#else /* #if defined(TRACK_MEMORY) */
+// TODO: TS-567 Support turning this off in the case of "memory debugging" being
+// enabled in the ./configure phase. Also, figure out if / how this could integrate
+// with jemalloc / tcmalloc's features of enabling memory debugging.
 #define RES_TRACK_MEMORY_DEFAULT 0      /* default value for res_track_memory variable */
 
 #ifdef __cplusplus
@@ -95,19 +67,12 @@ xfree_null(void *mem)
     ats_free(mem);
   return NULL;
 }
-
 #endif
 
 #define xmalloc(s)        ats_malloc ((s))
 #define xrealloc(p,s)     ats_realloc ((p),(s))
 #define xstrdup(p)        _xstrdup ((p), -1, NULL)
 #define xstrndup(p,n)     _xstrdup ((p), n, NULL)
-#define xtrack(p)         p
-#define xdump_snap_baseline() do { } while (0)
-#define xdump_to_file_baseline_rel(f) do { } while (0)
-#define xdump_to_file(f)  do { } while (0)
-#define xsnap()           do { } while (0)
-#define xvalidate(p) do {} while (0)
 
 void *_xmalloc(unsigned int size, const char *path);
 void *_xrealloc(void *ptr, unsigned int size, const char *path);
@@ -127,20 +92,31 @@ void xdump(void);
     class but one step at a time. It's better than doing this by
     hand every time.
 */
-template <
-  typename T ///< Type of pointer.
-> class xptr {
+template <typename T> class xptr {
 public:
-  typedef xptr self; ///< Self reference type.
-  /// Default constructor, zero initialized.
-  xptr() : m_ptr(0) { }
+  typedef xptr self;
+
+  xptr()
+    : m_ptr(0)
+  { }
+
   /// Construct from allocated memory.
   /// @note @a ptr must refer to memory allocated @c xmalloc.
-  explicit xptr(T* ptr) : m_ptr(ptr) { }
+  explicit xptr(T* ptr)
+    : m_ptr(ptr)
+  { }
+
   /// Construct and initialized with memory for @a n instances of @a T.
-  explicit xptr(size_t n) : m_ptr(xmalloc(sizeof(T) * n)) { }
+  explicit xptr(size_t n)
+    : m_ptr(xmalloc(sizeof(T) * n))
+  { }
+
   /// Destructor - free memory held by this instance.
-  ~xptr() { xfree(m_ptr); }
+  ~xptr()
+  {
+    xfree(m_ptr);
+  }
+
   /// Assign memory.
   /// @note @a ptr must be allocated via @c xmalloc.
   self& operator = (T* ptr) {
@@ -148,10 +124,13 @@ public:
     m_ptr = ptr;
     return *this;
   }
+
   /// Auto convert to a raw pointer.
   operator T* () { return m_ptr; }
+
   /// Auto conver to raw pointer.
   operator T const* () const { return m_ptr; }
+
   /** Release memory from control of this instance.
 
       @note Although direct assignment is forbidden due to the
@@ -167,36 +146,44 @@ public:
     m_ptr = 0;
     return zret;
   }
+
 private:
   T* m_ptr; ///< Pointer to allocated memory.
+
   /// Copy constructor - forbidden.
   xptr(self const& that);
+
   /// Self assignment - forbidden.
   self& operator = (self const& that);
 };
 
+
 // Special operators for xptr<char>
 /** Combine two strings as file paths.
     Trailing and leading separators for @a lhs and @a rhs respectively
     are handled to yield exactly one separator.
     @return A newly @x xmalloc string of the combined paths.
 */
-inline char* path_join (xptr<char> const& lhs, xptr<char> const& rhs)
{
+inline char*
+path_join (xptr<char> const& lhs, xptr<char> const& rhs)
+{
   size_t ln = strlen(lhs);
   size_t rn = strlen(rhs);
   char const* rptr = rhs; // May need to be modified.
+
   if (ln && lhs[ln-1] == '/') --ln; // drop trailing separator.
   if (rn && *rptr == '/') --rn, ++rptr; // drop leading separator.
+
   char* x = static_cast<char*>(xmalloc(ln + rn + 2));
+
   memcpy(x, lhs, ln);
   x[ln] = '/';
   memcpy(x + ln + 1,  rptr, rn);
   x[ln+rn+1] = 0; // terminate string.
+
   return x;
 }
 
 #endif // c++
 
-#endif /* TRACK_MEMORY */
-
 #endif /* __INK_RESOURCE_H__ */

Modified: trafficserver/traffic/trunk/proxy/signals.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/signals.cc?rev=1165851&r1=1165850&r2=1165851&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/signals.cc (original)
+++ trafficserver/traffic/trunk/proxy/signals.cc Tue Sep  6 21:11:49 2011
@@ -72,8 +72,7 @@ public:
     NOWARN_UNUSED(e);
     if (sigusr1_received) {
       sigusr1_received = 0;
-
-      xdump_to_file(stderr);
+      // TODO: TS-567 Integrate with debugging allocators "dump" features?
       ink_freelists_dump(stderr);
       if (!end)
         end = (char *) sbrk(0);
@@ -125,15 +124,15 @@ public:
     NOWARN_UNUSED(event);
     NOWARN_UNUSED(e);
     if (use_baseline) {
-      xdump_to_file_baseline_rel(stderr);
+      // TODO: TS-567 Integrate with debugging allocators "dump" features?
       ink_freelists_dump_baselinerel(stderr);
     } else {
-      xdump_to_file(stderr);
+      // TODO: TS-567 Integrate with debugging allocators "dump" features?
       ink_freelists_dump(stderr);
     }
     if (!baseline_taken && use_baseline) {
       ink_freelists_snap_baseline();
-      xdump_snap_baseline();
+      // TODO: TS-567 Integrate with debugging allocators "dump" features?
       baseline_taken = 1;
     }
     return EVENT_CONT;



Mime
View raw message