VirtualBox

Changeset 1438 in kBuild


Ignore:
Timestamp:
Mar 29, 2008 1:49:27 AM (17 years ago)
Author:
bird
Message:

Added $(make-stats ) that provides access to memory and hash stats (if CONFIG_WITH_MAKE_STATS is defined).

Location:
trunk/src/kmk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.am

    r1409 r1438  
    125125        -DCONFIG_WITH_WHICH \
    126126        -DCONFIG_WITH_EVALCTX \
     127        -DCONFIG_WITH_MAKE_STATS \
    127128        -DCONFIG_PRETTY_COMMAND_PRINTING \
    128129        \
  • trunk/src/kmk/Makefile.kmk

    r1422 r1438  
    125125        CONFIG_WITH_WHICH \
    126126        CONFIG_WITH_EVALCTX \
     127        CONFIG_WITH_MAKE_STATS \
    127128        CONFIG_PRETTY_COMMAND_PRINTING \
    128129        \
  • trunk/src/kmk/function.c

    r1409 r1438  
    116116
    117117static struct hash_table function_table;
     118
     119#ifdef CONFIG_WITH_MAKE_STATS
     120unsigned long make_stats_allocations = 0;
     121unsigned long make_stats_allocated = 0;
     122unsigned long make_stats_allocated_sum = 0;
     123unsigned long make_stats_ht_lookups = 0;
     124unsigned long make_stats_ht_collisions = 0;
     125#endif
    118126
    119127
     
    34603468#endif  /* CONFIG_WITH_OS2_LIBPATH */
    34613469
     3470#ifdef CONFIG_WITH_MAKE_STATS
     3471/* Retrieve make statistics. */
     3472static char *
     3473func_make_stats (char *o, char **argv, const char *funcname)
     3474{
     3475  char buf[512];
     3476  int len;
     3477
     3478  if (!argv[0] || (!argv[0][0] && !argv[1]))
     3479    {
     3480      len = sprintf (buf, "alloc-cur: %5lu %6luKB (/%3luMB)  hash: %5lu %2lu%%",
     3481                     make_stats_allocations,
     3482                     make_stats_allocated / 1024,
     3483                     make_stats_allocated_sum / (1024*1024),
     3484                     make_stats_ht_lookups,
     3485                     (make_stats_ht_collisions * 100) / make_stats_ht_lookups);
     3486      o = variable_buffer_output (o, buf, len);
     3487    }
     3488  else
     3489    {
     3490      /* selective */
     3491      int i;
     3492      for (i = 0; argv[i]; i++)
     3493        {
     3494          unsigned long val;
     3495          if (i != 0)
     3496            o = variable_buffer_output (o, " ", 1);
     3497          if (!strcmp(argv[i], "allocations"))
     3498            val = make_stats_allocations;
     3499          else if (!strcmp(argv[i], "allocated"))
     3500            val = make_stats_allocated;
     3501          else if (!strcmp(argv[i], "allocated_sum"))
     3502            val = make_stats_allocated_sum;
     3503          else if (!strcmp(argv[i], "ht_lookups"))
     3504            val = make_stats_ht_lookups;
     3505          else if (!strcmp(argv[i], "ht_collisions"))
     3506            val = make_stats_ht_collisions;
     3507          else if (!strcmp(argv[i], "ht_collisions_pct"))
     3508            val = (make_stats_ht_collisions * 100) / make_stats_ht_lookups;
     3509          else
     3510            { 
     3511              o = variable_buffer_output (o, argv[i], strlen (argv[i]));
     3512              continue;
     3513            }
     3514
     3515          len = sprintf (buf, "%ld", val);
     3516          o = variable_buffer_output (o, buf, len);
     3517        }
     3518    }
     3519  return o;
     3520}
     3521#endif
     3522
    34623523/* Lookup table for builtin functions.
    34633524
     
    35763637  { STRING_SIZE_TUPLE("libpath"),       1,  2,  1,  func_os2_libpath},
    35773638#endif
     3639#ifdef CONFIG_WITH_MAKE_STATS
     3640  { STRING_SIZE_TUPLE("make-stats"),    0, ~0,  0,  func_make_stats},
     3641#endif
    35783642#ifdef KMK_HELPERS
    35793643  { STRING_SIZE_TUPLE("kb-src-tool"),   1,  1,  0,  func_kbuild_source_tool},
  • trunk/src/kmk/hash.c

    r503 r1438  
    9292
    9393  ht->ht_lookups++;
     94#ifdef CONFIG_WITH_MAKE_STATS
     95  make_stats_ht_lookups++;
     96#endif
    9497  for (;;)
    9598    {
     
    111114            return slot;
    112115          ht->ht_collisions++;
     116#ifdef CONFIG_WITH_MAKE_STATS
     117    make_stats_ht_collisions++;
     118#endif
    113119        }
    114120      if (!hash_2)
  • trunk/src/kmk/make.h

    r903 r1438  
    690690
    691691#endif /* __EMX__ (bird) */
     692
     693#ifdef CONFIG_WITH_MAKE_STATS
     694extern unsigned long make_stats_allocations;
     695extern unsigned long make_stats_allocated;
     696extern unsigned long make_stats_allocated_sum;
     697extern unsigned long make_stats_ht_lookups;
     698extern unsigned long make_stats_ht_collisions;
     699
     700# ifdef __APPLE__
     701#  include <malloc/malloc.h>
     702#  define SIZE_OF_HEAP_BLOCK(ptr)   malloc_size(ptr)
     703
     704# elif defined(__linux__) /* glibc */
     705#  include <malloc.h>
     706#  define SIZE_OF_HEAP_BLOCK(ptr)   malloc_usable_size(ptr)
     707
     708# elif defined(_MSC_VER) || defined(__OS2__)
     709#  define SIZE_OF_HEAP_BLOCK(ptr)   _msize(ptr)
     710
     711# else
     712#  include <stdlib.h>
     713#  define SIZE_OF_HEAP_BLOCK(ptr)   0
     714#endif
     715
     716# if defined(CONFIG_WITH_MAKE_STATS) && !defined(ELECTRIC_HEAP)
     717#  define free xfree
     718extern void xfree (void *);
     719# endif
     720
     721#endif
     722
  • trunk/src/kmk/misc.c

    r909 r1438  
    361361  if (result == 0)
    362362    fatal (NILF, _("virtual memory exhausted"));
     363#ifdef CONFIG_WITH_MAKE_STATS
     364  make_stats_allocations++;
     365  make_stats_allocated += SIZE_OF_HEAP_BLOCK (result);
     366  make_stats_allocated_sum += SIZE_OF_HEAP_BLOCK (result);
     367#endif
    363368  return result;
    364369}
     
    369374{
    370375  void *result;
     376#ifdef CONFIG_WITH_MAKE_STATS
     377  make_stats_allocated -= SIZE_OF_HEAP_BLOCK (ptr);
     378  make_stats_allocated_sum -= SIZE_OF_HEAP_BLOCK (ptr);
     379#endif
    371380
    372381  /* Some older implementations of realloc() don't conform to ANSI.  */
     
    376385  if (result == 0)
    377386    fatal (NILF, _("virtual memory exhausted"));
     387#ifdef CONFIG_WITH_MAKE_STATS
     388  make_stats_allocated += SIZE_OF_HEAP_BLOCK (result);
     389  make_stats_allocated_sum += SIZE_OF_HEAP_BLOCK (result);
     390#endif
    378391  return result;
    379392}
     
    394407    fatal (NILF, _("virtual memory exhausted"));
    395408
     409#ifdef CONFIG_WITH_MAKE_STATS
     410  make_stats_allocations++;
     411  make_stats_allocated += SIZE_OF_HEAP_BLOCK (result);
     412  make_stats_allocated_sum += SIZE_OF_HEAP_BLOCK (result);
     413#endif
    396414#ifdef HAVE_STRDUP
    397415  return result;
     
    924942    }
    925943}
     944
     945#if defined(CONFIG_WITH_MAKE_STATS) && !defined(ELECTRIC_HEAP)
     946#undef free
     947void xfree(void *ptr)
     948{
     949  if (ptr)
     950    {
     951      make_stats_allocations--;
     952      make_stats_allocated -= SIZE_OF_HEAP_BLOCK (ptr);
     953      free (ptr);
     954    }
     955}
     956#endif
     957
  • trunk/src/kmk/variable.c

    r1408 r1438  
    10421042  && defined (CONFIG_WITH_FILE_SIZE) \
    10431043  && defined (CONFIG_WITH_WHICH) \
     1044  && defined (CONFIG_WITH_EVALCTX) \
     1045  && defined (CONFIG_WITH_MAKE_STATS) \
    10441046  && defined (KMK_HELPERS)
    10451047  (void) define_variable ("KMK_FEATURES", 12,
     
    10581060                          " file-size"
    10591061                          " which"
     1062                          " evalctx"
     1063                          " make-stats"
    10601064                          " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one "
    10611065                          , o_default, 0);
     
    11021106  strcat (buf, " which");
    11031107#  endif
     1108#  if defined (CONFIG_WITH_EVALCTX)
     1109  strcat (buf, " evalctx");
     1110#  endif
     1111#  if defined (CONFIG_WITH_MAKE_STATS)
     1112  strcat (buf, " make-stats");
     1113#  endif
    11041114#  if defined (KMK_HELPERS)
    11051115  strcat (buf, " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one");
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette