Changeset 1986 for trunk/src/kmk/misc.c


Ignore:
Timestamp:
Oct 28, 2008, 2:59:10 AM (17 years ago)
Author:
bird
Message:

kmk: some make stats cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/misc.c

    r1971 r1986  
    398398  if (result == 0)
    399399    fatal (NILF, _("virtual memory exhausted"));
     400
    400401#ifdef CONFIG_WITH_MAKE_STATS
    401402  make_stats_allocations++;
    402403  if (make_expensive_statistics)
    403     {
    404       unsigned int actual_size = SIZE_OF_HEAP_BLOCK (result);
    405       make_stats_allocated += actual_size;
    406       make_stats_allocated_sum += actual_size;
    407     }
     404    make_stats_allocated += SIZE_OF_HEAP_BLOCK (result);
     405  else
     406    make_stats_allocated += size;
    408407#endif
    409408  return result;
     
    417416#ifdef CONFIG_WITH_MAKE_STATS
    418417  if (make_expensive_statistics && ptr != NULL)
    419     {
    420       unsigned int actual_size = SIZE_OF_HEAP_BLOCK (ptr);
    421       make_stats_allocated -= actual_size;
    422       make_stats_allocated_sum -= actual_size;
    423     }
     418    make_stats_allocated -= SIZE_OF_HEAP_BLOCK (ptr);
     419  if (ptr)
     420    make_stats_reallocations++;
     421  else
     422    make_stats_allocations++;
    424423#endif
    425424
     
    430429  if (result == 0)
    431430    fatal (NILF, _("virtual memory exhausted"));
     431
    432432#ifdef CONFIG_WITH_MAKE_STATS
    433   if (!ptr)
    434     make_stats_allocations++;
    435433  if (make_expensive_statistics)
    436     {
    437       unsigned int actual_size = SIZE_OF_HEAP_BLOCK (result);
    438       make_stats_allocated += actual_size;
    439       make_stats_allocated_sum += actual_size;
    440     }
     434    make_stats_allocated += SIZE_OF_HEAP_BLOCK (result);
     435  else
     436    make_stats_allocated += size;
    441437#endif
    442438  return result;
     
    461457  make_stats_allocations++;
    462458  if (make_expensive_statistics)
    463     {
    464       unsigned int actual_size = SIZE_OF_HEAP_BLOCK (result);
    465       make_stats_allocated += actual_size;
    466       make_stats_allocated_sum += actual_size;
    467     }
     459    make_stats_allocated += SIZE_OF_HEAP_BLOCK (result);
     460  else
     461    make_stats_allocated += strlen (ptr) + 1;
    468462#endif
    469463#ifdef HAVE_STRDUP
     
    11651159}
    11661160
    1167 #if defined(CONFIG_WITH_MAKE_STATS) && !defined(ELECTRIC_HEAP)
    1168 #undef free
    1169 void xfree(void *ptr)
    1170 {
    1171   if (ptr)
    1172     {
    1173       make_stats_allocations--;
    1174       if (make_expensive_statistics)
    1175         make_stats_allocated -= SIZE_OF_HEAP_BLOCK (ptr);
    1176       free (ptr);
    1177     }
    1178 }
    1179 #endif
    1180 
    1181 
    11821161#ifdef CONFIG_WITH_ALLOC_CACHES
    11831162
     
    14031382# endif /* __GLIBC__ */
    14041383
     1384# ifdef CONFIG_WITH_MAKE_STATS
     1385  printf(_("#            %lu malloc calls,  %lu realloc calls\n"),
     1386         make_stats_allocations, make_stats_reallocations);
     1387  printf(_("#            %lu MBs alloc sum, not counting freed, add pinch of salt\n"), /* XXX: better wording */
     1388         make_stats_allocated / (1024*1024));
     1389# endif
     1390
    14051391  /* XXX: windows */
    14061392}
Note: See TracChangeset for help on using the changeset viewer.